UltiSnips/plugin/PySnipEmu.vim

66 lines
1.6 KiB
VimL
Raw Normal View History

"" FUNCTIONS
2009-07-04 06:15:12 -04:00
function! PyVimSnips_ExpandSnippet()
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingForward == "<s-tab>"
let SuperTabKey = "\<c-n>"
elseif g:SuperTabMappingBackward == "<s-tab>"
let SuperTabKey = "\<c-p>"
endif
endif
if pumvisible() " Update snippet if completion is used, or deal with supertab
if exists('SuperTabKey')
call feedkeys(SuperTabKey) | return ''
endif
call feedkeys("\<esc>a", 'n') " Close completion menu
call feedkeys("\<tab>") | return ''
endif
" Now, really expand something
2009-07-04 06:15:12 -04:00
py << EOF
if not PySnipSnippets.try_expand():
vim.command("""if exists('SuperTabKey')
call feedkeys(SuperTabKey)
endif
""")
2009-07-04 06:15:12 -04:00
EOF
return ""
2009-07-04 06:15:12 -04:00
endfunction
function! PyVimSnips_JumpBackwards()
py << EOF
from PySnipEmu import PySnipSnippets
PySnipSnippets.try_expand(True)
EOF
return ""
endfunction
"" STARTUP CODE
2009-07-04 06:15:12 -04:00
" Expand our path
python << EOF
import vim, os, sys
for p in vim.eval("&runtimepath").split(','):
dname = p + os.path.sep + "plugin"
if os.path.exists(dname + os.path.sep + "PySnipEmu.py"):
if dname not in sys.path:
sys.path.append(dname)
break
from PySnipEmu import PySnipSnippets
EOF
2009-07-04 06:15:12 -04:00
inoremap <Tab> <C-R>=PyVimSnips_ExpandSnippet()<cr>
snoremap <Tab> <Esc>:call PyVimSnips_ExpandSnippet()<cr>
inoremap <S-Tab> <C-R>=PyVimSnips_JumpBackwards()<cr>
snoremap <S-Tab> <Esc>:call PyVimSnips_JumpBackwards()<cr>
2009-07-04 06:15:12 -04:00
au CursorMovedI * py PySnipSnippets.cursor_moved()
au InsertEnter * py PySnipSnippets.entered_insert_mode()