From 2ad6ad4493d787abc1e8a8dd5ee74633343d202d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 9 Apr 2014 19:04:08 +0200 Subject: [PATCH 1/5] Fix E168: :finish used outside of a sourced file --- autoload/UltiSnips/bootstrap.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/UltiSnips/bootstrap.vim b/autoload/UltiSnips/bootstrap.vim index 50375b1..d5c865c 100644 --- a/autoload/UltiSnips/bootstrap.vim +++ b/autoload/UltiSnips/bootstrap.vim @@ -14,7 +14,7 @@ function! UltiSnips#bootstrap#Bootstrap() echo "UltiSnips requires py >= 2.6 or any py3" endif unlet g:_uspy - finish + return endif let g:_uspy=":py " endif From c57c717e336d4e66e2bdf174eb63ea3473503b14 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 9 Apr 2014 19:04:30 +0200 Subject: [PATCH 2/5] Delete autocommands when Bootstrap failed When bootstrapping fails to setup `g:_uspy` (e.g. without Python), the functions used in the autocommands are not being defined. Since it makes no sense to have autocommands defined for UltiSnips in this case, this patch deletes them (via a new augroup 'UltiSnips'). --- autoload/UltiSnips.vim | 4 ++++ plugin/UltiSnips.vim | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index f1b2f15..55da863 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -16,6 +16,10 @@ endfunction call UltiSnips#bootstrap#Bootstrap() if !exists("g:_uspy") + " Delete the autocommands defined in plugin/UltiSnips.vim. + augroup UltiSnips + au! + augroup END finish end diff --git a/plugin/UltiSnips.vim b/plugin/UltiSnips.vim index bad9016..26ac44b 100644 --- a/plugin/UltiSnips.vim +++ b/plugin/UltiSnips.vim @@ -57,10 +57,13 @@ function! UltiSnips_Anon(...) return call(function('UltiSnips#Anon'), a:000) endfunction -au CursorMovedI * call UltiSnips#CursorMoved() -au CursorMoved * call UltiSnips#CursorMoved() -au BufLeave * call UltiSnips#LeavingBuffer() -au InsertLeave * call UltiSnips#LeavingInsertMode() +augroup UltiSnips + au! + au CursorMovedI * call UltiSnips#CursorMoved() + au CursorMoved * call UltiSnips#CursorMoved() + au BufLeave * call UltiSnips#LeavingBuffer() + au InsertLeave * call UltiSnips#LeavingInsertMode() +augroup END call UltiSnips#map_keys#MapKeys() From 3208654c4e3d3513cd974a96e15ba2146b7cbb0d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 9 Apr 2014 19:30:00 +0200 Subject: [PATCH 3/5] Do not map keys if 'g:_uspy' could not be set --- autoload/UltiSnips/map_keys.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autoload/UltiSnips/map_keys.vim b/autoload/UltiSnips/map_keys.vim index 44e4082..eb570ba 100644 --- a/autoload/UltiSnips/map_keys.vim +++ b/autoload/UltiSnips/map_keys.vim @@ -1,6 +1,11 @@ call UltiSnips#bootstrap#Bootstrap() 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 From 7da9dbe2af95b4d13dd90bf3f136630f8d6d3637 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 9 Apr 2014 19:31:00 +0200 Subject: [PATCH 4/5] Add UltiSnipsFileType augroup and unset it if UltiSnips is disabled --- autoload/UltiSnips.vim | 6 +++++- ftdetect/UltiSnips.vim | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index 55da863..4f1a381 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -16,10 +16,14 @@ endfunction call UltiSnips#bootstrap#Bootstrap() if !exists("g:_uspy") - " Delete the autocommands defined in plugin/UltiSnips.vim. + " Delete the autocommands defined in plugin/UltiSnips.vim and + " ftdetect/UltiSnips.vim. augroup UltiSnips au! augroup END + augroup UltiSnipsFileType + au! + augroup END finish end diff --git a/ftdetect/UltiSnips.vim b/ftdetect/UltiSnips.vim index 9ec5b7b..e5df595 100644 --- a/ftdetect/UltiSnips.vim +++ b/ftdetect/UltiSnips.vim @@ -1,5 +1,8 @@ " This has to be called before ftplugins are loaded. Therefore " it is here in ftdetect though it maybe shouldn't if has("autocmd") - autocmd FileType * call UltiSnips#FileTypeChanged() + augroup UltiSnipsFileType + au! + autocmd FileType * call UltiSnips#FileTypeChanged() + augroup END endif From 210304884ade8da3b5fb2f293b99caa185470857 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 9 Apr 2014 19:32:26 +0200 Subject: [PATCH 5/5] Define all/other dummy functions used in autocommands --- autoload/UltiSnips.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index 4f1a381..5f18569 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -8,11 +8,19 @@ 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 -" using a copy of vim without python support) it will cause an error anytime a -" new file is opened. +" 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 call UltiSnips#bootstrap#Bootstrap() if !exists("g:_uspy")