diff options
author | Karel Kočí <cynerd@email.cz> | 2016-06-30 16:03:25 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2016-06-30 16:03:25 +0200 |
commit | e573b3020c032400eed60b649a2cbf55266e6bb0 (patch) | |
tree | 8f572394ac8433529c7a8e70d160a2fbe8268b4e /vim/bundle/vim-snipmate/autoload/snipMate_python_demo.vim | |
parent | b8c667bd64b3edd38d56c63c5bd1db53a23b4499 (diff) | |
download | myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.tar.gz myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.tar.bz2 myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.zip |
Add current configurations from old repository
Diffstat (limited to 'vim/bundle/vim-snipmate/autoload/snipMate_python_demo.vim')
-rw-r--r-- | vim/bundle/vim-snipmate/autoload/snipMate_python_demo.vim | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/vim/bundle/vim-snipmate/autoload/snipMate_python_demo.vim b/vim/bundle/vim-snipmate/autoload/snipMate_python_demo.vim new file mode 100644 index 0000000..de495d2 --- /dev/null +++ b/vim/bundle/vim-snipmate/autoload/snipMate_python_demo.vim @@ -0,0 +1,47 @@ +" This file demonstrates +" - how to register your own snippet sources (call snipMate_python_demo#Activate() in ftplugin/python.vim) +" - implents a source which creates snippets based on python function +" definitions found in the current file +" +" Example: +" +" def abc(a,b,c=None) +" will create a snippet on the fly which looks like this: +" abc(${1:a}, ${2:b}, ${3:c=None}) + +fun! snipMate_python_demo#Activate() abort + if !exists('g:snipMateSources') + let g:snipMateSources = {} + endif + + let g:snipMateSources['python'] = funcref#Function('snipMate_python_demo#FunctionsFromCurrentFileAndTags') +endf + +fun! s:Add(dict, line, source, trigger) abort + let matched = matchlist(a:line,'def\s\+\([^( \t]\+\)[ \t]*(\([^)]*\)') + if len(matched) > 2 + let name = matched[1] + " TODO: is this a glob? + if name !~ a:trigger | return | endif + let a:dict[name] = get(a:dict, name, {}) + let sd = a:dict[name] + let args = [] + let nr=1 + for arg in split(matched[2], '\s*,\s*') + call add(args, '${'.nr.':'.arg.'}') + let nr+=1 + endfor + let sd[a:source] = name.'('.join(args,', ').')' + endif +endf +fun! snipMate_python_demo#FunctionsFromCurrentFileAndTags(scopes, trigger, result) abort + " getting all might be too much + if a:trigger == '*' | return | endif + if index(a:scopes, 'python') < 0 | return | endif + for t in taglist('^'.a:trigger) + call s:Add(a:result, t.cmd, 'tags-' . t.filename, a:trigger) + endfor + for l in getline(0, line('$')) + call s:Add(a:result, l, 'current-file', a:trigger) + endfor +endf |