From becab789a844631c49d776eccec753e7e3220e5a Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sat, 11 Jul 2015 16:17:50 +0200 Subject: [PATCH] Remove bootstrap.vim. Simplify startup. The python module is now pulled in autoload/UltiSnips.vim. This means that parsing of the .vimrc will only map the keys and set some options - very cheap. Unfortunately, the autocommands set up in plugin/UltiSnips.vim pulls in the python code basically immediately still. --- after/plugin/UltiSnips_after.vim | 13 ++-- autoload/UltiSnips.vim | 28 ++------- autoload/UltiSnips/bootstrap.vim | 93 ---------------------------- autoload/UltiSnips/map_keys.vim | 62 ++++++++++++++++--- plugin/UltiSnips.vim | 42 ++++++++++--- pythonx/UltiSnips/snippet_manager.py | 2 +- test/test_AnonymousExpansion.py | 2 +- test/test_Expand.py | 2 +- test/test_Fixes.py | 4 +- test/test_Folding.py | 4 +- test/test_Format.py | 10 +-- test/test_Interpolation.py | 8 +-- test/test_Movement.py | 2 +- test/test_Plugin.py | 8 +-- test/test_Selection.py | 6 +- test/test_SnipMate.py | 11 ++++ test/test_SnippetOptions.py | 12 ++-- test/test_UltiSnipFunc.py | 9 ++- test/vim_test_case.py | 14 ++--- 19 files changed, 145 insertions(+), 187 deletions(-) delete mode 100644 autoload/UltiSnips/bootstrap.vim diff --git a/after/plugin/UltiSnips_after.vim b/after/plugin/UltiSnips_after.vim index fe4a7d1..33ad9e0 100644 --- a/after/plugin/UltiSnips_after.vim +++ b/after/plugin/UltiSnips_after.vim @@ -1,13 +1,8 @@ -" File: UltiSnips_after.vim -" Author: Holger Rapp -" Description: Called after everything else to reclaim keys (Needed for -" Supertab) -" Last Modified: July 27, 2009 +" Called after everything else to reclaim keys (Needed for Supertab) -if exists('did_UltiSnips_after') || &cp || version < 704 - finish +if exists("b:did_after_plugin_ultisnips_after") || !exists("g:_uspy") + finish endif +let b:did_after_plugin_ultisnips_after = 1 call UltiSnips#map_keys#MapKeys() - -let did_UltiSnips_after=1 diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index 51e17ae..a96965b 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -1,28 +1,12 @@ -" File: UltiSnips.vim -" Author: Holger Rapp -" Description: The Ultimate Snippets solution for Vim - -if exists('did_UltiSnips_autoload') || &cp || version < 704 - finish +if exists("b:did_autoload_ultisnips") || !exists("g:_uspy") + finish endif -let did_UltiSnips_autoload=1 +let b:did_autoload_ultisnips = 1 -" Define dummy version of function called by autocommand setup in -" ftdetect/UltiSnips.vim and plugin/UltiSnips.vim. -" If the function isn't defined (probably due to using a copy of vim -" without python support) it would cause an error. -function! UltiSnips#FileTypeChanged() -endfunction -function! UltiSnips#CursorMoved() -endfunction -function! UltiSnips#CursorMoved() -endfunction -function! UltiSnips#LeavingBuffer() -endfunction -function! UltiSnips#LeavingInsertMode() -endfunction +" Also import vim as we expect it to be imported in many places. +exec g:_uspy "import vim" +exec g:_uspy "from UltiSnips import UltiSnips_Manager" -call UltiSnips#bootstrap#Bootstrap() if !exists("g:_uspy") " Delete the autocommands defined in plugin/UltiSnips.vim and " ftdetect/UltiSnips.vim. diff --git a/autoload/UltiSnips/bootstrap.vim b/autoload/UltiSnips/bootstrap.vim deleted file mode 100644 index 46f2e8e..0000000 --- a/autoload/UltiSnips/bootstrap.vim +++ /dev/null @@ -1,93 +0,0 @@ -let s:SourcedFile=expand("") - -function! UltiSnips#bootstrap#Bootstrap() - if exists('s:did_UltiSnips_bootstrap') - return - endif - let s:did_UltiSnips_bootstrap=1 - - if !exists("g:UltiSnipsUsePythonVersion") - let g:_uspy=":py3 " - if !has("python3") - if !has("python") - if !exists("g:UltiSnipsNoPythonWarning") - echohl WarningMsg - echom "UltiSnips requires py >= 2.7 or any py3" - echohl None - endif - unlet g:_uspy - return - endif - let g:_uspy=":py " - endif - let g:UltiSnipsUsePythonVersion = "" - else - " Use user-provided value, but check if it's available. - " This uses `has()`, because e.g. `exists(":python3")` is always 2. - if g:UltiSnipsUsePythonVersion == 2 && has('python') - let g:_uspy=":python " - elseif g:UltiSnipsUsePythonVersion == 3 && has('python3') - let g:_uspy=":python3 " - endif - if !exists('g:_uspy') - echohl WarningMsg - echom "UltiSnips: the Python version from g:UltiSnipsUsePythonVersion (".g:UltiSnipsUsePythonVersion.") is not available." - echohl None - return - endif - endif - - " Import vim as we expect it to be imported in many places. - exec g:_uspy "import vim" - exec g:_uspy "from UltiSnips import UltiSnips_Manager" -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 - -" Enable or Disable snipmate snippet expansion. -if !exists("g:UltiSnipsEnableSnipMate") - let g:UltiSnipsEnableSnipMate = 1 -endif diff --git a/autoload/UltiSnips/map_keys.vim b/autoload/UltiSnips/map_keys.vim index a60d00e..a535761 100644 --- a/autoload/UltiSnips/map_keys.vim +++ b/autoload/UltiSnips/map_keys.vim @@ -1,14 +1,60 @@ -call UltiSnips#bootstrap#Bootstrap() +if exists("b:did_autoload_ultisnips_map_keys") || !exists("g:_uspy") + finish +endif +let b:did_autoload_ultisnips_map_keys = 1 + +" 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 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 + +" Enable or Disable snipmate snippet expansion. +if !exists("g:UltiSnipsEnableSnipMate") + let g:UltiSnipsEnableSnipMate = 1 +endif function! UltiSnips#map_keys#MapKeys() - if !exists('g:_uspy') - " Do not map keys if bootstrapping failed (e.g. no Python). - return - endif - - " Map the keys correctly if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger - exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippetOrJump()" exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippetOrJump()" else diff --git a/plugin/UltiSnips.vim b/plugin/UltiSnips.vim index 4e9aab7..3558202 100644 --- a/plugin/UltiSnips.vim +++ b/plugin/UltiSnips.vim @@ -1,15 +1,7 @@ -" File: UltiSnips.vim -" Author: Holger Rapp -" Description: The Ultimate Snippets solution for Vim -" -" Testing Info: -" See directions at the top of the test.py script located one -" directory above this file. - -if exists('did_UltiSnips_plugin') || &cp +if exists('did_plugin_ultisnips') || &cp finish endif -let did_UltiSnips_plugin=1 +let did_plugin_ultisnips=1 if version < 704 echohl WarningMsg @@ -18,6 +10,36 @@ if version < 704 finish endif +if !exists("g:UltiSnipsUsePythonVersion") + let g:_uspy=":py3 " + if !has("python3") + if !has("python") + if !exists("g:UltiSnipsNoPythonWarning") + echohl WarningMsg + echom "UltiSnips requires py >= 2.7 or py3" + echohl None + endif + unlet g:_uspy + finish + endif + let g:_uspy=":py " + endif +else + " Use user-provided value, but check if it's available. + " This uses `has()`, because e.g. `exists(":python3")` is always 2. + if g:UltiSnipsUsePythonVersion == 2 && has('python') + let g:_uspy=":python " + elseif g:UltiSnipsUsePythonVersion == 3 && has('python3') + let g:_uspy=":python3 " + endif + if !exists('g:_uspy') + echohl WarningMsg + echom "UltiSnips: the Python version from g:UltiSnipsUsePythonVersion (".g:UltiSnipsUsePythonVersion.") is not available." + echohl None + finish + endif +endif + " The Commands we define. command! -bang -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit \ :call UltiSnips#Edit(, ) diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index 0c6cada..d9f95a1 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -98,7 +98,7 @@ class SnippetManager(object): self.register_snippet_source('ultisnips_files', UltiSnipsFileSource()) self.register_snippet_source('added', self._added_snippets_source) - enable_snipmate = True + enable_snipmate = '1' if _vim.eval("exists('g:UltiSnipsEnableSnipMate')") == '1': enable_snipmate = _vim.eval('g:UltiSnipsEnableSnipMate') if enable_snipmate == '1': diff --git a/test/test_AnonymousExpansion.py b/test/test_AnonymousExpansion.py index 91b47f9..f74d3ff 100644 --- a/test/test_AnonymousExpansion.py +++ b/test/test_AnonymousExpansion.py @@ -7,7 +7,7 @@ from test.constant import * class _AnonBase(_VimTest): args = '' - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('inoremap %s =UltiSnips#Anon(%s)' % (EA, self.args)) diff --git a/test/test_Expand.py b/test/test_Expand.py index 4e22ecc..d231838 100644 --- a/test/test_Expand.py +++ b/test/test_Expand.py @@ -22,7 +22,7 @@ class SimpleExpandNewLineAndBackspae_ExpectCorrectResult(_SimpleExpands): keys = 'hallo' + EX + '\nHallo Welt!\n\n\b\b\b\b\b' wanted = 'Hallo Welt!\nHallo We' - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set backspace=eol,start') diff --git a/test/test_Fixes.py b/test/test_Fixes.py index 90e4816..febb0e9 100644 --- a/test/test_Fixes.py +++ b/test/test_Fixes.py @@ -18,7 +18,7 @@ class VirtualEdit(_VimTest): keys = '\t\t\tpd' + EX + '2' wanted = '\t\t\tpadding: 2px' - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set virtualedit=all') vim_config.append('set noexpandtab') # End: 1251994 #}}} @@ -46,7 +46,7 @@ class RetainsTheUnnamedRegister_ButOnlyOnce(_VimTest): class ShiftWidthZero(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config += [ "if exists('*shiftwidth')", ' set shiftwidth=0', diff --git a/test/test_Folding.py b/test/test_Folding.py index 49bc4a4..3a31f77 100644 --- a/test/test_Folding.py +++ b/test/test_Folding.py @@ -6,7 +6,7 @@ from test.constant import * class FoldingEnabled_SnippetWithFold_ExpectNoFolding(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set foldlevel=0') vim_config.append('set foldmethod=marker') snippets = ('test', r"""Hello {{{ @@ -37,7 +37,7 @@ class Fold_DeleteMiddleLine_ECR(_VimTest): class PerlSyntaxFold(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set foldlevel=0') vim_config.append('syntax enable') vim_config.append('set foldmethod=syntax') diff --git a/test/test_Format.py b/test/test_Format.py index 78504c7..905e77e 100644 --- a/test/test_Format.py +++ b/test/test_Format.py @@ -7,7 +7,7 @@ from test.util import running_on_windows class _ExpandTabs(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set sw=3') vim_config.append('set expandtab') @@ -33,8 +33,8 @@ class RecTabStopsWithExpandtab_SpecialIndentProblem_ECR(_ExpandTabs): keys = 'm' + EX + 'm1' + EX + '\nHallo' wanted = ' Something\n Hallo' - def _extra_options_pre_init(self, vim_config): - _ExpandTabs._extra_options_pre_init(self, vim_config) + def _extra_vim_config(self, vim_config): + _ExpandTabs._extra_vim_config(self, vim_config) vim_config.append('set indentkeys=o,O,*,<>>,{,}') vim_config.append('set indentexpr=8') # End: ExpandTab #}}} @@ -59,7 +59,7 @@ class ProperIndenting_AutoIndentAndNewline_ECR(_VimTest): keys = ' test' + EX + '\n' + 'blah' wanted = ' hui\n blah' - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set autoindent') # Test for bug 1073816 @@ -99,7 +99,7 @@ class ProperIndenting_FirstLineInFileComplete_ECR( class _FormatoptionsBase(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set tw=20') vim_config.append('set fo=lrqntc') diff --git a/test/test_Interpolation.py b/test/test_Interpolation.py index 30e261a..b006355 100644 --- a/test/test_Interpolation.py +++ b/test/test_Interpolation.py @@ -283,7 +283,7 @@ i0 class PythonCode_IndentEtSw(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set sw=3') vim_config.append('set expandtab') snippets = ('test', r"""hi @@ -307,7 +307,7 @@ i0 class PythonCode_IndentEtSwOffset(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set sw=3') vim_config.append('set expandtab') snippets = ('test', r"""hi @@ -331,7 +331,7 @@ End""") class PythonCode_IndentNoetSwTs(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set sw=3') vim_config.append('set ts=4') snippets = ('test', r"""hi @@ -357,7 +357,7 @@ i0 class PythonCode_OptExists(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('let g:UStest="yes"') snippets = ( 'test', diff --git a/test/test_Movement.py b/test/test_Movement.py index a3eb589..51b0c10 100644 --- a/test/test_Movement.py +++ b/test/test_Movement.py @@ -13,7 +13,7 @@ class CursorMovement_Multiline_ECR(_VimTest): class CursorMovement_BS_InEditMode(_VimTest): - def _extra_options_pre_init(self, vim_config): + def _extra_vim_config(self, vim_config): vim_config.append('set backspace=eol,indent,start') snippets = ('\n\t$1\n\t$2\n\n$3') keys = '