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

fixed bug with dotted filetypes

This commit is contained in:
Michael Sanders
2009-03-01 17:11:13 -05:00
parent 8f31a3b9bf
commit 3e7d478b91
14 changed files with 64 additions and 12 deletions

View File

@@ -1,7 +1,9 @@
if !exists('loaded_snips') || exists('s:did_'.&ft.'_snips') if !exists('loaded_snips') || exists('s:did_c_snips')
fini fini
en en
let s:did_{&ft}_snips = 1 let s:did_c_snips = 1
let ft = &ft
let &ft ='c'
" main() " main()
exe "Snipp main int main (int argc, char const* argv[])\n{\n\t${1}\n\treturn 0;\n}" exe "Snipp main int main (int argc, char const* argv[])\n{\n\t${1}\n\treturn 0;\n}"
@@ -29,7 +31,7 @@ exe "Snipp do do {\n\t${2:/* code */}\n} while (${1:/* condition */});"
" While Loop " While Loop
exe "Snipp wh while (${1:/* condition */}) {\n\t${2:/* code */}\n}" exe "Snipp wh while (${1:/* condition */}) {\n\t${2:/* code */}\n}"
" For Loop " For Loop
exe "Snipp for for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {\n\t${4:/* code */}\n}" exe "Snipp for for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {\n\t${4:/* code */}\n}${5}"
" Custom For Loop " Custom For Loop
exe "Snipp forr for (${1:i} = 0; ${2:$1 < 5}; $1${3:++}) {\n\t${4:/* code */}\n}" exe "Snipp forr for (${1:i} = 0; ${2:$1 < 5}; $1${3:++}) {\n\t${4:/* code */}\n}"
" Function " Function
@@ -54,3 +56,4 @@ exe "Snipp vector std::vector<${1:char}> v${2};"
exe 'Snipp pr printf("${1:%s}\n"${2});${3}' exe 'Snipp pr printf("${1:%s}\n"${2});${3}'
" fprintf (again, this isn't as nice as TextMate's version, but it works) " fprintf (again, this isn't as nice as TextMate's version, but it works)
exe 'Snipp fpr fprintf(${1:stderr}, "${2:%s}\n"${3});${4}' exe 'Snipp fpr fprintf(${1:stderr}, "${2:%s}\n"${3});${4}'
let &ft = ft

View File

@@ -1,10 +1,13 @@
if !exists('g:loaded_snips') || exists('s:did_'.&ft.'_snips') let filetype = stridx(&ft, 'xhtml') > -1 ? 'xhtml' : 'html'
if !exists('g:loaded_snips') || exists('s:did_'.filetype.'_snips')
fini fini
en en
let s:did_{&ft}_snips = 1 let s:did_{filetype}_snips = 1
let ft = &ft
let &ft = filetype
" automatically add a closing '/' to the end of xhtml tags " automatically add a closing '/' to the end of xhtml tags
let c = &ft == 'xhtml' ? ' /' : '' let c = filetype == 'xhtml' ? ' /' : ''
" Some useful Unicode entities " Some useful Unicode entities
" Non-Breaking Space " Non-Breaking Space
@@ -92,3 +95,4 @@ exe 'Snipp optt <option>${1:option}</option>${2}'
exe "Snipp select <select name=\"${1:some_name}\" id=\"${2:$1}\">\n\t<option value=\"${3:option}\">${4:$3}</option>\n</select>${5}" exe "Snipp select <select name=\"${1:some_name}\" id=\"${2:$1}\">\n\t<option value=\"${3:option}\">${4:$3}</option>\n</select>${5}"
exe "Snipp table <table border=\"${1:0}\">\n\t<tr><th>${2:Header}</th></tr>\n\t<tr><th>${3:Data}</th></tr>\n</table>${4}" exe "Snipp table <table border=\"${1:0}\">\n\t<tr><th>${2:Header}</th></tr>\n\t<tr><th>${3:Data}</th></tr>\n</table>${4}"
exe 'Snipp textarea <textarea name="${1:Name}" rows="${2:8}" cols="${3:40}">${4}</textarea>${5}' exe 'Snipp textarea <textarea name="${1:Name}" rows="${2:8}" cols="${3:40}">${4}</textarea>${5}'
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_java_snips')
fini fini
en en
let s:did_java_snips = 1 let s:did_java_snips = 1
let ft = &ft
let &ft ='java'
exe "Snipp main public static void main (String [] args)\n{\n\t${1:/* code */}\n}" exe "Snipp main public static void main (String [] args)\n{\n\t${1:/* code */}\n}"
exe 'Snipp pu public' exe 'Snipp pu public'
@@ -39,3 +41,5 @@ exe 'Snipp v ${1:String} ${2:var}${3: = null}${4};${5}'
exe 'Snipp co static public final ${1:String} ${2:var} = ${3};${4}' exe 'Snipp co static public final ${1:String} ${2:var} = ${3};${4}'
exe 'Snipp cos static public final String ${1:var} = "${2}";${3}' exe 'Snipp cos static public final String ${1:var} = "${2}";${3}'
exe 'Snipp as assert ${1:test} : "${2:Failure message}";${3}' exe 'Snipp as assert ${1:test} : "${2:Failure message}";${3}'
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_js_snips')
fini fini
en en
let s:did_js_snips = 1 let s:did_js_snips = 1
let ft = &ft
let &ft ='javascript'
" Prototype " Prototype
exe "Snipp proto ${1:class_name}.prototype.${2:method_name} =\nfunction(${3:first_argument}) {\n\t${4:// body...}\n};" exe "Snipp proto ${1:class_name}.prototype.${2:method_name} =\nfunction(${3:first_argument}) {\n\t${4:// body...}\n};"
@@ -35,3 +37,5 @@ exe 'Snipp timeout setTimeout(function() {${3}}${2}, ${1:10};'
exe "Snipp get getElementsBy${1:TagName}('${2}')${3}" exe "Snipp get getElementsBy${1:TagName}('${2}')${3}"
" Get Element " Get Element
exe "Snipp gett getElementBy${1:Id}('${2}')${3}" exe "Snipp gett getElementBy${1:Id}('${2}')${3}"
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_objc_snips')
fini fini
en en
let s:did_objc_snips = 1 let s:did_objc_snips = 1
let ft = &ft
let &ft ='objc'
" #import <...> " #import <...>
exe 'Snipp imp #import <${1:Cocoa/Cocoa.h}>${2}' exe 'Snipp imp #import <${1:Cocoa/Cocoa.h}>${2}'
@@ -52,3 +54,5 @@ exe 'Snipp alloc [[${1:foo} alloc] init]${2};${3}'
exe 'Snipp ret [${1:foo} retain];${2}' exe 'Snipp ret [${1:foo} retain];${2}'
" release " release
exe 'Snipp rel [${1:foo} release];${2}' exe 'Snipp rel [${1:foo} release];${2}'
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_perl_snips')
fini fini
en en
let s:did_perl_snips = 1 let s:did_perl_snips = 1
let ft = &ft
let &ft ='perl'
" Hash Pointer " Hash Pointer
exe 'Snipp . =>' exe 'Snipp . =>'
@@ -35,3 +37,5 @@ exe 'Snipp xfore ${1:expression} foreach @${2:array};${3}'
exe "Snipp cl package ${1:ClassName};\n\nuse base qw(${2:ParentClass});\n\nsub new {\n\tmy $class = shift;\n\t$class = ref $class if ref $class;\n\tmy $self = bless {}, $class;\n\t$self;\n}\n\n1;${3}" exe "Snipp cl package ${1:ClassName};\n\nuse base qw(${2:ParentClass});\n\nsub new {\n\tmy $class = shift;\n\t$class = ref $class if ref $class;\n\tmy $self = bless {}, $class;\n\t$self;\n}\n\n1;${3}"
" Read File " Read File
exe "Snipp slurp my $${1:var};\n{ local $/ = undef; local *FILE; open FILE, \"<${2:file}\"; $$1 = <FILE>; close FILE }${2}" exe "Snipp slurp my $${1:var};\n{ local $/ = undef; local *FILE; open FILE, \"<${2:file}\"; $$1 = <FILE>; close FILE }${2}"
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_php_snips')
fini fini
en en
let s:did_php_snips = 1 let s:did_php_snips = 1
let ft = &ft
let &ft ='php'
exe "Snipp php <?php\n${1}\n?>" exe "Snipp php <?php\n${1}\n?>"
exe 'Snipp ec echo "${1:string}"${2};' exe 'Snipp ec echo "${1:string}"${2};'
@@ -65,3 +67,4 @@ exe "Snipp foreach foreach ($${1:variable} as $${2:key}) {\n\t${3:// code...}\n}
exe "Snipp fun ${1:public }function ${2:FunctionName}(${3})\n{\n\t${4:// code...}\n}" exe "Snipp fun ${1:public }function ${2:FunctionName}(${3})\n{\n\t${4:// code...}\n}"
" $... = array (...) " $... = array (...)
exe "Snipp array $${1:arrayName} = array('${2}' => ${3});${4}" exe "Snipp array $${1:arrayName} = array('${2}' => ${3});${4}"
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_python_snips')
fini fini
en en
let s:did_python_snips = 1 let s:did_python_snips = 1
let ft = &ft
let &ft ='python'
" New Class " New Class
exe "Snipp cl class ${1:ClassName}(${2:object}):\n\t\"\"\"${3:docstring for $1}\"\"\"\n\tdef __init__(self, ${4:arg}):\n\t\t${5:super($1, self).__init__()}\n\t\tself.$4 = $4\n\t\t${6}" exe "Snipp cl class ${1:ClassName}(${2:object}):\n\t\"\"\"${3:docstring for $1}\"\"\"\n\tdef __init__(self, ${4:arg}):\n\t\t${5:super($1, self).__init__()}\n\t\tself.$4 = $4\n\t\t${6}"
@@ -26,3 +28,5 @@ exe "Snipp tryef try:\n\t${1:pass}\nexcept ${2:Exception}, ${3:e}:\n\t${4:raise
exe "Snipp ifmain if __name__ == '__main__':\n\t${1:main()}" exe "Snipp ifmain if __name__ == '__main__':\n\t${1:main()}"
" __magic__ " __magic__
exe 'Snipp _ __${1:init}__${2}' exe 'Snipp _ __${1:init}__${2}'
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_ruby_snips')
fini fini
en en
let s:did_ruby_snips = 1 let s:did_ruby_snips = 1
let ft = &ft
let &ft ='ruby'
" New Block " New Block
exe "Snipp =b =begin rdoc\n\t${1}\n=end" exe "Snipp =b =begin rdoc\n\t${1}\n=end"
@@ -165,3 +167,4 @@ exe 'Snipp clafn split("::").inject(Object) { |par, const| par.const_get(const)
exe 'Snipp sinc class << self; self end' exe 'Snipp sinc class << self; self end'
exe "Snipp nam namespace :${1:`Filename()`} do\n\t${2}\nend" exe "Snipp nam namespace :${1:`Filename()`} do\n\t${2}\nend"
exe "Snipp tas desc \"${1:Task description\}\"\ntask :${2:task_name => [:dependent, :tasks]} do\n\t${3}\nend" exe "Snipp tas desc \"${1:Task description\}\"\ntask :${2:task_name => [:dependent, :tasks]} do\n\t${3}\nend"
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_sh_snips')
fini fini
en en
let s:did_sh_snips = 1 let s:did_sh_snips = 1
let ft = &ft
let &ft = 'sh'
exe "Snipp if if [[ ${1:condition} ]]; then\n\t${2:#statements}\nfi" exe "Snipp if if [[ ${1:condition} ]]; then\n\t${2:#statements}\nfi"
exe "Snipp elif elif [[ ${1:condition} ]]; then\n\t${2:#statements}" exe "Snipp elif elif [[ ${1:condition} ]]; then\n\t${2:#statements}"
@@ -9,3 +11,5 @@ exe "Snipp for for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do\n\t${3:#statement
exe "Snipp wh while [[ ${1:condition} ]]; do\n\t${2:#statements}\ndone" exe "Snipp wh while [[ ${1:condition} ]]; do\n\t${2:#statements}\ndone"
exe "Snipp until [[ ${1:condition} ]]; do\n\t${2:#statements}\ndone" exe "Snipp until [[ ${1:condition} ]]; do\n\t${2:#statements}\ndone"
exe "Snipp case case ${1:word} in\n\t${2:pattern})\n\t\t${3};;\nesac" exe "Snipp case case ${1:word} in\n\t${2:pattern})\n\t\t${3};;\nesac"
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('loaded_snips') || exists('s:did_tex_snips')
fini fini
en en
let s:did_tex_snips = 1 let s:did_tex_snips = 1
let ft = &ft
let &ft = 'tex'
" \begin{}...\end{} " \begin{}...\end{}
exe "Snipp begin \\begin{${1:env}}\n\t${2}\n\\end{$1}" exe "Snipp begin \\begin{${1:env}}\n\t${2}\n\\end{$1}"
@@ -47,3 +49,5 @@ exe 'Snipp table ${1:Table}~\ref{${2:tab:}}${3}'
exe 'Snipp listing ${1:Listing}~\ref{${2:list}}${3}' exe 'Snipp listing ${1:Listing}~\ref{${2:list}}${3}'
exe 'Snipp section ${1:Section}~\ref{${2:sec:}}${3}' exe 'Snipp section ${1:Section}~\ref{${2:sec:}}${3}'
exe 'Snipp page ${1:page}~\pageref{${2}}${3}' exe 'Snipp page ${1:page}~\pageref{${2}}${3}'
let &ft = ft

View File

@@ -2,6 +2,8 @@ if !exists('g:loaded_snips') || exists('s:did_vim_snips')
fini fini
en en
let s:did_vim_snips = 1 let s:did_vim_snips = 1
let ft = &ft
let &ft = 'vim'
" snippets for making snippets :) " snippets for making snippets :)
exe 'Snipp snip exe "Snipp ${1:trigger}"${2}' exe 'Snipp snip exe "Snipp ${1:trigger}"${2}'
@@ -14,3 +16,5 @@ exe "Snipp for for ${1:needle} in ${2:haystack}\n\t${3:\" code}\nendfor"
exe "Snipp wh wh ${1:condition}\n\t${2:\" code}\nendw" exe "Snipp wh wh ${1:condition}\n\t${2:\" code}\nendw"
exe "Snipp if if ${1:condition}\n\t${2:\" code}\nendif" exe "Snipp if if ${1:condition}\n\t${2:\" code}\nendif"
exe "Snipp ife if ${1:condition}\n\t${2}\nelse\n\t${3}\nendif" exe "Snipp ife if ${1:condition}\n\t${2}\nelse\n\t${3}\nendif"
let &ft = ft

View File

@@ -12,6 +12,8 @@ snor ' b<bs>'
snor <right> <esc>a snor <right> <esc>a
snor <left> <esc>bi snor <left> <esc>bi
au FileType objc,cpp,cs let &ft .= '.c'
" By default load snippets in ~/.vim/snippets/<filetype> " By default load snippets in ~/.vim/snippets/<filetype>
if !exists('snippets_dir') if !exists('snippets_dir')
let snippets_dir = $HOME.(has('win16') || has('win32') || has('win64') ? let snippets_dir = $HOME.(has('win16') || has('win32') || has('win64') ?

View File

@@ -8,6 +8,7 @@
" For more help see snipMate.txt; you can do this by using: " For more help see snipMate.txt; you can do this by using:
" :helptags ~/.vim/doc " :helptags ~/.vim/doc
" :h snipMate.txt " :h snipMate.txt
" Last Modified: February 28, 2009.
if exists('loaded_snips') || &cp || version < 700 if exists('loaded_snips') || &cp || version < 700
finish finish
@@ -119,7 +120,11 @@ fun! TriggerSnippet()
call s:GetSuperTabSID() call s:GetSuperTabSID()
endif endif
let word = s:GetSnippet() for filetype in split(&ft, '\.') " deal with dotted file-types
let word = s:GetSnippet(filetype)
if exists('s:snippet') | break | endif
endfor
" if word is a trigger for a snippet, delete the trigger & expand the snippet " if word is a trigger for a snippet, delete the trigger & expand the snippet
if exists('s:snippet') if exists('s:snippet')
if s:snippet == '' " if user cancelled a multi snippet, quit if s:snippet == '' " if user cancelled a multi snippet, quit
@@ -136,16 +141,16 @@ endf
" Check if word under cursor is snippet trigger; if it isn't, try checking if " Check if word under cursor is snippet trigger; if it isn't, try checking if
" the text after non-word characters is (e.g. check for "foo" in "bar.foo") " the text after non-word characters is (e.g. check for "foo" in "bar.foo")
fun s:GetSnippet() fun s:GetSnippet(ft)
let origWord = matchstr(getline('.'), '\S\+\%'.col('.').'c') let origWord = matchstr(getline('.'), '\S\+\%'.col('.').'c')
wh !exists('s:snippet') wh !exists('s:snippet')
let word = s:Hash(origWord) let word = s:Hash(origWord)
if exists('s:snippets["'.&ft.'"]["'.word.'"]') if exists('s:snippets["'.a:ft.'"]["'.word.'"]')
let s:snippet = s:snippets[&ft][word] let s:snippet = s:snippets[a:ft][word]
elseif exists('s:snippets["_"]["'.word.'"]') elseif exists('s:snippets["_"]["'.word.'"]')
let s:snippet = s:snippets['_'][word] let s:snippet = s:snippets['_'][word]
elseif exists('s:multi_snips["'.&ft.'"]["'.word.'"]') elseif exists('s:multi_snips["'.a:ft.'"]["'.word.'"]')
let s:snippet = s:ChooseSnippet(&ft, word) let s:snippet = s:ChooseSnippet(a:ft, word)
elseif exists('s:multi_snips["_"]["'.word.'"]') elseif exists('s:multi_snips["_"]["'.word.'"]')
let s:snippet = s:ChooseSnippet('_', word) let s:snippet = s:ChooseSnippet('_', word)
else else