Load snippets as soon as filetype is set. This avoids a delay in the first expansion in a file

This commit is contained in:
Holger Rapp 2012-02-21 21:47:12 +01:00
parent 874cb89401
commit 8a7af50154
2 changed files with 10 additions and 4 deletions

View File

@ -77,7 +77,7 @@ if !exists("g:UltiSnipsSnippetDirectories")
endif
" }}}
"" Global Commands {{{
" Global Commands {{{
function! UltiSnipsEdit(...)
if a:0 == 1 && a:1 != ''
let type = a:1
@ -101,7 +101,7 @@ endfunction
command! -nargs=? UltiSnipsEdit :call UltiSnipsEdit(<q-args>)
"" }}}
"" FUNCTIONS {{{
" FUNCTIONS {{{
function! CompensateForPUM()
""" The CursorMovedI event is not triggered while the popup-menu is visible,
""" and it's by this event that UltiSnips updates its vim-state. The fix is
@ -144,6 +144,11 @@ function! UltiSnips_JumpForwards()
return ""
endfunction
function! UltiSnips_FileTypeChanged()
exec g:_uspy "UltiSnips_Manager.ensure_snippets_loaded()"
return ""
endfunction
function! UltiSnips_AddSnippet(trigger, value, descr, options, ...)
" Takes the same arguments as SnippetManager.add_snippet:
" (trigger, value, descr, options, ft = "all", globals = None)
@ -210,6 +215,7 @@ exec g:_uspy "UltiSnips_Manager.backward_trigger = vim.eval('g:UltiSnipsJumpBack
au CursorMovedI * call UltiSnips_CursorMoved()
au CursorMoved * call UltiSnips_CursorMoved()
au WinLeave * call UltiSnips_LeavingWindow()
au FileType * call UltiSnips_FileTypeChanged()
call UltiSnips_MapKeys()

View File

@ -780,7 +780,7 @@ class SnippetManager(object):
before the cursor. If possible is True, then get all
possible matches.
"""
filetypes = self._ensure_snippets_loaded()
filetypes = self.ensure_snippets_loaded()
found_snippets = []
for ft in filetypes:
@ -1027,7 +1027,7 @@ class SnippetManager(object):
self._ensure_loaded(parent, checked)
def _ensure_snippets_loaded(self):
def ensure_snippets_loaded(self):
""" Checks for changes in the list of snippet files or the contents
of the snippet files and reloads them if necessary.
"""