diff --git a/after/ftplugin/c_snips.vim b/after/ftplugin/c_snips.vim index 3061755..8693cdb 100644 --- a/after/ftplugin/c_snips.vim +++ b/after/ftplugin/c_snips.vim @@ -13,13 +13,10 @@ exe 'Snipp Inc #include "${1:`Filename("$1.h")`}"${2}' " #ifndef ... #define ... #endif exe "Snipp def #ifndef $1\n#define ${1:SYMBOL} ${2:value}\n#endif${3}" " Header Include-Guard -" (the randomizer code is taken directly from TextMate; I don't know how to do -" it in vim script, it could probably be cleaner) +" (the randomizer code is taken directly from TextMate; it could probably be +" 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" \ ."#define $1\n\n${2}\n\n#endif /* end of include guard: $1 */" -" Read File Into Vector -exe "Snipp readfile std::vector 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 exe "Snipp if if (${1:/* condition */}) {\n\t${2:/* code */}\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}" " Typedef struct 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 " unfortunately version this isn't as nice as TextMates's, given the lack of a " dynamic `...` diff --git a/after/ftplugin/cpp_snips.vim b/after/ftplugin/cpp_snips.vim new file mode 100644 index 0000000..f54f592 --- /dev/null +++ b/after/ftplugin/cpp_snips.vim @@ -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 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};" diff --git a/after/ftplugin/vim_snips.vim b/after/ftplugin/vim_snips.vim index 6342c98..edd68ae 100644 --- a/after/ftplugin/vim_snips.vim +++ b/after/ftplugin/vim_snips.vim @@ -9,6 +9,9 @@ exe 'Snipp snip exe "Snipp ${1:trigger}"${2}' exe "Snipp snipp exe 'Snipp ${1:trigger}'${2}" exe 'Snipp gsnip 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 for for ${1:needle} in ${2:haystack}\n\t${3:\" code}\nendfor" diff --git a/doc/snipMate.txt b/doc/snipMate.txt index 7e0edd1..0616f3a 100644 --- a/doc/snipMate.txt +++ b/doc/snipMate.txt @@ -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. 'snippets///.snippet'. -To ensure snipMate.vim is loaded and 'compatible' is not set, make sure -to add: > +To ensure snipMate.vim is loaded, 'compatible' is not set, and your snippet +file is only loaded once make sure to add: > - if !exists('g:loaded_snips') - fini - en + if !exists('g:loaded_snips') || exists('s:did_my_snips') + finish + 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. ------------------------------------------------------------------------------