From ba772b0d14163e02de8efedf732bbcdfb917f3f1 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Mon, 17 Feb 2014 08:15:04 +0100 Subject: [PATCH] after script maps Keys again. Needed some refactorings. This fixes supertab integration and closes #212. --- after/plugin/UltiSnips_after.vim | 4 +- autoload/UltiSnips.vim | 87 +--------------------------- autoload/ultisnips/map_keys.vim | 38 ++++++++++++ autoload/ultisnips/variables.vim | 48 +++++++++++++++ plugin/UltiSnips.vim | 2 +- pythonx/UltiSnips/__init__.py | 2 +- pythonx/UltiSnips/snippet_manager.py | 4 +- 7 files changed, 93 insertions(+), 92 deletions(-) create mode 100644 autoload/ultisnips/map_keys.vim create mode 100644 autoload/ultisnips/variables.vim diff --git a/after/plugin/UltiSnips_after.vim b/after/plugin/UltiSnips_after.vim index 5b2f90a..ca885a6 100644 --- a/after/plugin/UltiSnips_after.vim +++ b/after/plugin/UltiSnips_after.vim @@ -4,10 +4,10 @@ " Supertab) " Last Modified: July 27, 2009 -if exists('did_UltiSnips_after') || &cp || version < 700 || !exists("did_UltiSnips_vim") || !has("python") +if exists('did_UltiSnips_after') || &cp || version < 700 finish endif -call UltiSnips#MapKeys() +call UltiSnips#map_keys#MapKeys() let did_UltiSnips_after=1 diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index 6e958ad..16f6903 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -15,7 +15,7 @@ endfunction " Kludge to make sure that if the python module is loaded first, all of this " initialization in this file is indeed done. -function! UltiSnips#EnsureAutoloadScriptWasRun() +function! UltiSnips#WasRun() endfunction if !exists("g:UltiSnipsUsePythonVersion") @@ -38,54 +38,6 @@ else endif endif -" Global Variables {{{ - -" The trigger used to expand a snippet. -" NOTE: expansion and forward jumping can, but needn't be the same trigger -if !exists("g:UltiSnipsExpandTrigger") - let g:UltiSnipsExpandTrigger = "" -endif - -" The trigger used to display all triggers that could possible -" match in the current position. -if !exists("g:UltiSnipsListSnippets") - let g:UltiSnipsListSnippets = "" -endif - -" The trigger used to jump forward to the next placeholder. -" NOTE: expansion and forward jumping can, but needn't be the same trigger -if !exists("g:UltiSnipsJumpForwardTrigger") - let g:UltiSnipsJumpForwardTrigger = "" -endif - -" The trigger to jump backward inside a snippet -if !exists("g:UltiSnipsJumpBackwardTrigger") - let g:UltiSnipsJumpBackwardTrigger = "" -endif - -" Should UltiSnips unmap select mode mappings automagically? -if !exists("g:UltiSnipsRemoveSelectModeMappings") - let g:UltiSnipsRemoveSelectModeMappings = 1 -end - -" If UltiSnips should remove Mappings, which should be ignored -if !exists("g:UltiSnipsMappingsToIgnore") - let g:UltiSnipsMappingsToIgnore = [] -endif - -" UltiSnipsEdit will use this variable to decide if a new window -" is opened when editing. default is "normal", allowed are also -" "vertical", "horizontal" -if !exists("g:UltiSnipsEditSplit") - let g:UltiSnipsEditSplit = 'normal' -endif - -" A list of directory names that are searched for snippets. -if !exists("g:UltiSnipsSnippetDirectories") - let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ] -endif -" }}} - " FUNCTIONS {{{ function! s:compensate_for_pum() @@ -138,43 +90,6 @@ function! UltiSnips#FileTypeComplete(arglead, cmdline, cursorpos) return sort(keys(ret)) endfunction -function! UltiSnips#MapKeys() - " Map the keys correctly - if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger - - exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippetOrJump()" - exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippetOrJump()" - else - exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippet()" - exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippet()" - endif - exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips#SaveLastVisualSelection()gvs' - exec "inoremap " . g:UltiSnipsListSnippets . " =UltiSnips#ListSnippets()" - exec "snoremap " . g:UltiSnipsListSnippets . " :call UltiSnips#ListSnippets()" - - snoremap c - snoremap c - snoremap c -endf - -function! UltiSnips#MapInnerKeys() - if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger - exec "inoremap " . g:UltiSnipsJumpForwardTrigger . " =UltiSnips#JumpForwards()" - exec "snoremap " . g:UltiSnipsJumpForwardTrigger . " :call UltiSnips#JumpForwards()" - endif - exec "inoremap " . g:UltiSnipsJumpBackwardTrigger . " =UltiSnips#JumpBackwards()" - exec "snoremap " . g:UltiSnipsJumpBackwardTrigger . " :call UltiSnips#JumpBackwards()" -endf - -function! UltiSnips#RestoreInnerKeys() - if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger - exec "iunmap " . g:UltiSnipsJumpForwardTrigger - exec "sunmap " . g:UltiSnipsJumpForwardTrigger - endif - exec "iunmap " . g:UltiSnipsJumpBackwardTrigger - exec "sunmap " . g:UltiSnipsJumpBackwardTrigger -endf - function! UltiSnips#ExpandSnippet() exec g:_uspy "UltiSnips_Manager.expand()" return "" diff --git a/autoload/ultisnips/map_keys.vim b/autoload/ultisnips/map_keys.vim new file mode 100644 index 0000000..aa0bce9 --- /dev/null +++ b/autoload/ultisnips/map_keys.vim @@ -0,0 +1,38 @@ +call UltiSnips#variables#WasRun() + +function! UltiSnips#map_keys#MapKeys() + " Map the keys correctly + if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger + + exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippetOrJump()" + exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippetOrJump()" + else + exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippet()" + exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippet()" + endif + exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips#SaveLastVisualSelection()gvs' + exec "inoremap " . g:UltiSnipsListSnippets . " =UltiSnips#ListSnippets()" + exec "snoremap " . g:UltiSnipsListSnippets . " :call UltiSnips#ListSnippets()" + + snoremap c + snoremap c + snoremap c +endf + +function! UltiSnips#map_keys#MapInnerKeys() + if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger + exec "inoremap " . g:UltiSnipsJumpForwardTrigger . " =UltiSnips#JumpForwards()" + exec "snoremap " . g:UltiSnipsJumpForwardTrigger . " :call UltiSnips#JumpForwards()" + endif + exec "inoremap " . g:UltiSnipsJumpBackwardTrigger . " =UltiSnips#JumpBackwards()" + exec "snoremap " . g:UltiSnipsJumpBackwardTrigger . " :call UltiSnips#JumpBackwards()" +endf + +function! UltiSnips#map_keys#RestoreInnerKeys() + if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger + exec "iunmap " . g:UltiSnipsJumpForwardTrigger + exec "sunmap " . g:UltiSnipsJumpForwardTrigger + endif + exec "iunmap " . g:UltiSnipsJumpBackwardTrigger + exec "sunmap " . g:UltiSnipsJumpBackwardTrigger +endf diff --git a/autoload/ultisnips/variables.vim b/autoload/ultisnips/variables.vim new file mode 100644 index 0000000..d5555c9 --- /dev/null +++ b/autoload/ultisnips/variables.vim @@ -0,0 +1,48 @@ +" Kludge to make sure that this file is really run. +function! UltiSnips#variables#WasRun() +endfunction + +" The trigger used to expand a snippet. +" NOTE: expansion and forward jumping can, but needn't be the same trigger +if !exists("g:UltiSnipsExpandTrigger") + let g:UltiSnipsExpandTrigger = "" +endif + +" The trigger used to display all triggers that could possible +" match in the current position. +if !exists("g:UltiSnipsListSnippets") + let g:UltiSnipsListSnippets = "" +endif + +" The trigger used to jump forward to the next placeholder. +" NOTE: expansion and forward jumping can, but needn't be the same trigger +if !exists("g:UltiSnipsJumpForwardTrigger") + let g:UltiSnipsJumpForwardTrigger = "" +endif + +" The trigger to jump backward inside a snippet +if !exists("g:UltiSnipsJumpBackwardTrigger") + let g:UltiSnipsJumpBackwardTrigger = "" +endif + +" Should UltiSnips unmap select mode mappings automagically? +if !exists("g:UltiSnipsRemoveSelectModeMappings") + let g:UltiSnipsRemoveSelectModeMappings = 1 +end + +" If UltiSnips should remove Mappings, which should be ignored +if !exists("g:UltiSnipsMappingsToIgnore") + let g:UltiSnipsMappingsToIgnore = [] +endif + +" UltiSnipsEdit will use this variable to decide if a new window +" is opened when editing. default is "normal", allowed are also +" "vertical", "horizontal" +if !exists("g:UltiSnipsEditSplit") + let g:UltiSnipsEditSplit = 'normal' +endif + +" A list of directory names that are searched for snippets. +if !exists("g:UltiSnipsSnippetDirectories") + let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ] +endif diff --git a/plugin/UltiSnips.vim b/plugin/UltiSnips.vim index c38731c..a5f0842 100644 --- a/plugin/UltiSnips.vim +++ b/plugin/UltiSnips.vim @@ -50,7 +50,7 @@ au CursorMoved * call UltiSnips#CursorMoved() au BufLeave * call UltiSnips#LeavingBuffer() au InsertLeave * call UltiSnips#LeavingInsertMode() -call UltiSnips#MapKeys() +call UltiSnips#map_keys#MapKeys() let did_UltiSnips_plugin=1 diff --git a/pythonx/UltiSnips/__init__.py b/pythonx/UltiSnips/__init__.py index 69aa204..7818a03 100644 --- a/pythonx/UltiSnips/__init__.py +++ b/pythonx/UltiSnips/__init__.py @@ -7,7 +7,7 @@ import vim # pylint:disable=import-error from UltiSnips.snippet_manager import SnippetManager -vim.command("call UltiSnips#EnsureAutoloadScriptWasRun()") +vim.command("call UltiSnips#WasRun()") UltiSnips_Manager = SnippetManager( # pylint:disable=invalid-name vim.eval('g:UltiSnipsExpandTrigger'), diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index dcd98c6..bc8bf21 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -328,7 +328,7 @@ class SnippetManager(object): """The current snippet should be terminated.""" self._csnippets.pop() if not self._csnippets: - _vim.command("call UltiSnips#RestoreInnerKeys()") + _vim.command("call UltiSnips#map_keys#RestoreInnerKeys()") def _jump(self, backwards=False): """Helper method that does the actual jump.""" @@ -408,7 +408,7 @@ class SnippetManager(object): def _do_snippet(self, snippet, before): """Expands the given snippet, and handles everything that needs to be done with it.""" - _vim.command("call UltiSnips#MapInnerKeys()") + _vim.command("call UltiSnips#map_keys#MapInnerKeys()") # Adjust before, maybe the trigger is not the complete word text_before = before