Pulled from master.

This commit is contained in:
Holger Rapp 2014-01-04 07:42:15 +01:00
commit f596d98065
3 changed files with 41 additions and 4 deletions

View File

@ -240,6 +240,11 @@ vimrc file. >
let g:UltiSnipsJumpForwardTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>" let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
Note that the default value for g:UltiSnipsJumpBackwardTrigger interferes with
the built-in complete function: |i_CTRL-X_CTRL-K|. A workaround is to add the
following to your vimrc file. >
inoremap <c-x><c-k> <c-x><c-k>
3.2.1 Using your own trigger functions *UltiSnips-trigger-functions* 3.2.1 Using your own trigger functions *UltiSnips-trigger-functions*
-------------------------------------- --------------------------------------

View File

@ -84,6 +84,12 @@ endif
if !exists("g:UltiSnipsSnippetDirectories") if !exists("g:UltiSnipsSnippetDirectories")
let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ] let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ]
endif endif
" Should UltiSnips map JumpForwardTrigger and JumpBackwardTrigger only during
" snippet expansion?
if !exists("g:UltiSnipsClearJumpTrigger")
let g:UltiSnipsClearJumpTrigger = 1
endif
" }}} " }}}
" Global Commands {{{ " Global Commands {{{
@ -204,12 +210,16 @@ function! UltiSnips_MapKeys()
else else
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips_ExpandSnippet()<cr>" exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips_ExpandSnippet()<cr>"
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips_ExpandSnippet()<cr>" exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips_ExpandSnippet()<cr>"
exec "inoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips_JumpForwards()<cr>" if g:UltiSnipsClearJumpTrigger == 0
exec "snoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips_JumpForwards()<cr>" exec "inoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips_JumpForwards()<cr>"
exec "snoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips_JumpForwards()<cr>"
endif
endif endif
exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips_SaveLastVisualSelection()<cr>gvs' exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips_SaveLastVisualSelection()<cr>gvs'
exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips_JumpBackwards()<cr>" if g:UltiSnipsClearJumpTrigger == 0
exec "snoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips_JumpBackwards()<cr>" exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips_JumpBackwards()<cr>"
exec "snoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips_JumpBackwards()<cr>"
endif
exec "inoremap <silent> " . g:UltiSnipsListSnippets . " <C-R>=UltiSnips_ListSnippets()<cr>" exec "inoremap <silent> " . g:UltiSnipsListSnippets . " <C-R>=UltiSnips_ListSnippets()<cr>"
exec "snoremap <silent> " . g:UltiSnipsListSnippets . " <Esc>:call UltiSnips_ListSnippets()<cr>" exec "snoremap <silent> " . g:UltiSnipsListSnippets . " <Esc>:call UltiSnips_ListSnippets()<cr>"
@ -217,6 +227,23 @@ function! UltiSnips_MapKeys()
snoremap <silent> <DEL> <c-g>c snoremap <silent> <DEL> <c-g>c
snoremap <silent> <c-h> <c-g>c snoremap <silent> <c-h> <c-g>c
endf endf
function! UltiSnips_MapInnerKeys()
if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger
exec "inoremap <buffer> <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips_JumpForwards()<cr>"
exec "snoremap <buffer> <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips_JumpForwards()<cr>"
endif
exec "inoremap <buffer> <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips_JumpBackwards()<cr>"
exec "snoremap <buffer> <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips_JumpBackwards()<cr>"
endf
function! UltiSnips_RestoreInnerKeys()
if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger
exec "iunmap <buffer> " . g:UltiSnipsJumpForwardTrigger
exec "sunmap <buffer> " . g:UltiSnipsJumpForwardTrigger
endif
exec "iunmap <buffer> " . g:UltiSnipsJumpBackwardTrigger
exec "sunmap <buffer> " . g:UltiSnipsJumpBackwardTrigger
endf
function! UltiSnips_CursorMoved() function! UltiSnips_CursorMoved()
exec g:_uspy "UltiSnips_Manager.cursor_moved()" exec g:_uspy "UltiSnips_Manager.cursor_moved()"

View File

@ -806,6 +806,9 @@ class SnippetManager(object):
def _current_snippet_is_done(self): def _current_snippet_is_done(self):
self._csnippets.pop() self._csnippets.pop()
if _vim.eval("g:UltiSnipsClearJumpTrigger") != "0":
if len(self._csnippets) == 0:
_vim.command("call UltiSnips_RestoreInnerKeys()")
def _jump(self, backwards = False): def _jump(self, backwards = False):
jumped = False jumped = False
@ -924,6 +927,8 @@ class SnippetManager(object):
""" Expands the given snippet, and handles everything """ Expands the given snippet, and handles everything
that needs to be done with it. that needs to be done with it.
""" """
if _vim.eval("g:UltiSnipsClearJumpTrigger") == "1":
_vim.command("call UltiSnips_MapInnerKeys()")
# Adjust before, maybe the trigger is not the complete word # Adjust before, maybe the trigger is not the complete word
text_before = before text_before = before
if snippet.matched: if snippet.matched: