diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index c09d5c3..d93e4c2 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -5,6 +5,7 @@ if exists('did_UltiSnips_autoload') || &cp || version < 700 finish endif +let did_UltiSnips_autoload=1 " Define dummy version of function called by autocommand setup in " ftdetect/UltiSnips.vim. If the function isn't defined (probably due to @@ -13,26 +14,10 @@ endif function! UltiSnips#FileTypeChanged() endfunction -if !exists("g:UltiSnipsUsePythonVersion") - let g:_uspy=":py3 " - if !has("python3") - if !has("python") - if !exists("g:UltiSnipsNoPythonWarning") - echo "UltiSnips requires py >= 2.6 or any py3" - endif - finish - endif - let g:_uspy=":py " - endif - let g:UltiSnipsUsePythonVersion = "" -else - if g:UltiSnipsUsePythonVersion == 2 - let g:_uspy=":py " - else - let g:_uspy=":py3 " - endif -endif - +call UltiSnips#bootstrap#Bootstrap() +if !exists("g:_uspy") + finish +end " FUNCTIONS {{{ function! s:compensate_for_pum() @@ -176,13 +161,3 @@ function! UltiSnips#LeavingInsertMode() exec g:_uspy "UltiSnips_Manager._leaving_insert_mode()" endfunction " }}} - -" Expand our path -exec g:_uspy "import vim, os, sys" -exec g:_uspy "new_path = os.path.abspath(os.path.join( - \ vim.eval('expand(\":h\")'), '..', 'pythonx'))" -exec g:_uspy "vim.command(\"let g:UltiSnipsPythonPath = '%s'\" % new_path)" -exec g:_uspy "if not hasattr(vim, 'VIM_SPECIAL_PATH'): sys.path.append(new_path)" -exec g:_uspy "from UltiSnips import UltiSnips_Manager" - -let did_UltiSnips_autoload=1 diff --git a/autoload/UltiSnips/variables.vim b/autoload/UltiSnips/bootstrap.vim similarity index 54% rename from autoload/UltiSnips/variables.vim rename to autoload/UltiSnips/bootstrap.vim index d5555c9..91734a2 100644 --- a/autoload/UltiSnips/variables.vim +++ b/autoload/UltiSnips/bootstrap.vim @@ -1,5 +1,40 @@ -" Kludge to make sure that this file is really run. -function! UltiSnips#variables#WasRun() +let s:SourcedFile=expand("") + +function! UltiSnips#bootstrap#Bootstrap() + if exists('did_UltiSnips_bootstrap') + return + endif + let did_UltiSnips_bootstrap=1 + + if !exists("g:UltiSnipsUsePythonVersion") + let g:_uspy=":py3 " + if !has("python3") + if !has("python") + if !exists("g:UltiSnipsNoPythonWarning") + echo "UltiSnips requires py >= 2.6 or any py3" + endif + finish + endif + let g:_uspy=":py " + endif + let g:UltiSnipsUsePythonVersion = "" + else + if g:UltiSnipsUsePythonVersion == 2 + let g:_uspy=":py " + else + let g:_uspy=":py3 " + endif + endif + + " Expand our path + exec g:_uspy "import vim, os, sys" + exec g:_uspy "sourced_file = vim.eval('s:SourcedFile')" + exec g:_uspy "while not os.path.exists(os.path.join(sourced_file, 'pythonx')): + \ sourced_file = os.path.dirname(sourced_file)" + exec g:_uspy "module_path = os.path.join(sourced_file, 'pythonx')" + exec g:_uspy "vim.command(\"let g:UltiSnipsPythonPath = '%s'\" % module_path)" + exec g:_uspy "if not hasattr(vim, 'VIM_SPECIAL_PATH'): sys.path.append(module_path)" + exec g:_uspy "from UltiSnips import UltiSnips_Manager" endfunction " The trigger used to expand a snippet. diff --git a/autoload/UltiSnips/map_keys.vim b/autoload/UltiSnips/map_keys.vim index aa0bce9..3b44aea 100644 --- a/autoload/UltiSnips/map_keys.vim +++ b/autoload/UltiSnips/map_keys.vim @@ -1,4 +1,4 @@ -call UltiSnips#variables#WasRun() +call UltiSnips#bootstrap#Bootstrap() function! UltiSnips#map_keys#MapKeys() " Map the keys correctly