1
0
mirror of https://github.com/gryf/snipmate.vim.git synced 2025-12-20 12:58:05 +01:00

added a default "guard" snippet for checking if a snippet has been loaded more than once, and put cpp snippets in their own file"

This commit is contained in:
Michael Sanders
2009-03-02 21:38:07 -05:00
parent 4ec62447c8
commit 3db3319e80
4 changed files with 29 additions and 19 deletions

View File

@@ -13,13 +13,10 @@ exe 'Snipp Inc #include "${1:`Filename("$1.h")`}"${2}'
" #ifndef ... #define ... #endif " #ifndef ... #define ... #endif
exe "Snipp def #ifndef $1\n#define ${1:SYMBOL} ${2:value}\n#endif${3}" exe "Snipp def #ifndef $1\n#define ${1:SYMBOL} ${2:value}\n#endif${3}"
" Header Include-Guard " Header Include-Guard
" (the randomizer code is taken directly from TextMate; I don't know how to do " (the randomizer code is taken directly from TextMate; it could probably be
" it in vim script, it could probably be cleaner) " cleaner, I don't know how to do it in vim script)
exe "Snipp once #ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system(\"/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'\"))`}\n" exe "Snipp once #ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system(\"/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'\"))`}\n"
\ ."#define $1\n\n${2}\n\n#endif /* end of include guard: $1 */" \ ."#define $1\n\n${2}\n\n#endif /* end of include guard: $1 */"
" Read File Into Vector
exe "Snipp readfile std::vector<char> v;\nif (FILE *${2:fp} = fopen(${1:\"filename\"}, \"r\")) {\n\tchar buf[1024];\n\twhile (size_t len = "
\ ."fread(buf, 1, sizeof(buf), $2))\n\t\tv.insert(v.end(), buf, buf + len);\n\tfclose($2);\n}${3}"
" If Condition " If Condition
exe "Snipp if if (${1:/* condition */}) {\n\t${2:/* code */}\n}" exe "Snipp if if (${1:/* condition */}) {\n\t${2:/* code */}\n}"
exe "Snipp el else {\n\t${1}\n}" exe "Snipp el else {\n\t${1}\n}"
@@ -41,14 +38,6 @@ exe 'Snipp td typedef ${1:int} ${2:MyCustomType};'
exe "Snipp st struct ${1:`Filename('$1_t', 'name')`} {\n\t${2:/* data */}\n}${3: /* optional variable list */};${4}" exe "Snipp st struct ${1:`Filename('$1_t', 'name')`} {\n\t${2:/* data */}\n}${3: /* optional variable list */};${4}"
" Typedef struct " Typedef struct
exe "Snipp tds typedef struct ${2:$1 }{\n\t${3:/* data */}\n} ${1:`Filename('$1_t', 'name')`};" exe "Snipp tds typedef struct ${2:$1 }{\n\t${3:/* data */}\n} ${1:`Filename('$1_t', 'name')`};"
" Class
exe "Snipp cl class ${1:`Filename('$1_t', 'name')`} {\npublic:\n\t$1 (${2:arguments});\n\tvirtual ~$1 ();\n\nprivate:\n\t${3:/* data */}\n};"
" Namespace
exe "Snipp ns namespace ${1:`Filename('', 'my')`} {\n\t${2}\n} /* $1 */"
" std::map
exe "Snipp map std::map<${1:key}, ${2:value}> map${3};"
" std::vector
exe "Snipp vector std::vector<${1:char}> v${2};"
" printf " printf
" unfortunately version this isn't as nice as TextMates's, given the lack of a " unfortunately version this isn't as nice as TextMates's, given the lack of a
" dynamic `...` " dynamic `...`

View File

@@ -0,0 +1,16 @@
if !exists('g:loaded_snips') || exists('s:did_cpp_snips')
finish
endif
let s:did_cpp_snips = 1
" Read File Into Vector
exe "Snipp readfile std::vector<char> v;\nif (FILE *${2:fp} = fopen(${1:\"filename\"}, \"r\")) {\n\tchar buf[1024];\n\twhile (size_t len = "
\ ."fread(buf, 1, sizeof(buf), $2))\n\t\tv.insert(v.end(), buf, buf + len);\n\tfclose($2);\n}${3}"
" std::map
exe "Snipp map std::map<${1:key}, ${2:value}> map${3};"
" std::vector
exe "Snipp vector std::vector<${1:char}> v${2};"
" Namespace
exe "Snipp ns namespace ${1:`Filename('', 'my')`} {\n\t${2}\n} /* $1 */"
" Class
exe "Snipp cl class ${1:`Filename('$1_t', 'name')`} {\npublic:\n\t$1 (${2:arguments});\n\tvirtual ~$1 ();\n\nprivate:\n\t${3:/* data */}\n};"

View File

@@ -9,6 +9,9 @@ exe 'Snipp snip exe "Snipp ${1:trigger}"${2}'
exe "Snipp snipp exe 'Snipp ${1:trigger}'${2}" exe "Snipp snipp exe 'Snipp ${1:trigger}'${2}"
exe 'Snipp gsnip exe "GlobalSnip ${1:trigger}"${2}' exe 'Snipp gsnip exe "GlobalSnip ${1:trigger}"${2}'
exe "Snipp gsnipp exe 'GlobalSnip ${1:trigger}'${2}" exe "Snipp gsnipp exe 'GlobalSnip ${1:trigger}'${2}"
exe "Snipp guard if !exists('g:loaded_snips') || exists('s:did_".
\ "${1:`substitute(expand(\"%:t:r\"), \"_snips\", \"\", \"\")`}_snips')\n\t"
\ "finish\nendif\nlet s:did_$1_snips = 1${2}"
exe "Snipp f fun ${1:function_name}()\n\t${2:\" code}\nendfun" exe "Snipp f fun ${1:function_name}()\n\t${2:\" code}\nendfun"
exe "Snipp for for ${1:needle} in ${2:haystack}\n\t${3:\" code}\nendfor" exe "Snipp for for ${1:needle} in ${2:haystack}\n\t${3:\" code}\nendfor"

View File

@@ -105,14 +105,16 @@ To create a create a snippet with multiple matches using file-based snippets,
simply place all the snippets in a subdirectory with the trigger name, i.e. simply place all the snippets in a subdirectory with the trigger name, i.e.
'snippets/<filetype>/<trigger>/<name>.snippet'. 'snippets/<filetype>/<trigger>/<name>.snippet'.
To ensure snipMate.vim is loaded and 'compatible' is not set, make sure To ensure snipMate.vim is loaded, 'compatible' is not set, and your snippet
to add: > file is only loaded once make sure to add: >
if !exists('g:loaded_snips') if !exists('g:loaded_snips') || exists('s:did_my_snips')
fini finish
en endif
let s:did_my_snips = 1
to the top of your snippets files. to the top of your snippets files. The snippet "guard" comes with snipMate to
automate this if you'd rather not type it all out.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------