diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index b31b31e..7e4830d 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -1,11 +1,4 @@ if exists("b:did_autoload_ultisnips") || !exists("g:_uspy") - " Define no-op function, called via ftdetect/UltiSnips.vim. - " TODO(sirver): Add a test for that using a bad g:UltiSnipsPythonVersion - " setting. Without this fix moving the cursor will spam errors, with this - " it should not. - function! UltiSnips#FileTypeChanged(...) - endfunction - finish endif let b:did_autoload_ultisnips = 1 @@ -53,7 +46,7 @@ function! UltiSnips#Edit(bang, ...) endfunction function! UltiSnips#AddFiletypes(filetypes) - exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . a:filetypes . ".all')" + exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . a:filetypes . "')" return "" endfunction @@ -116,13 +109,6 @@ function! UltiSnips#JumpForwards() return "" endfunction -function! UltiSnips#FileTypeChanged(...) - exec g:_uspy "UltiSnips_Manager.reset_buffer_filetypes()" - exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . (a:0 ? a:1 : &ft) . "')" - return "" -endfunction - - function! UltiSnips#AddSnippetWithPriority(trigger, value, description, options, filetype, priority) exec g:_uspy "trigger = vim.eval(\"a:trigger\")" exec g:_uspy "value = vim.eval(\"a:value\")" diff --git a/ftdetect/UltiSnips.vim b/ftdetect/UltiSnips.vim deleted file mode 100644 index 81af3a1..0000000 --- a/ftdetect/UltiSnips.vim +++ /dev/null @@ -1,17 +0,0 @@ -" This has to be called before ftplugins are loaded. Therefore -" it is here in ftdetect though it maybe shouldn't - -" This is necessary to prevent errors when using vim as a pager. -if exists("vimpager") - finish -endif - -if has("autocmd") && &loadplugins - augroup UltiSnipsFileType - autocmd! - autocmd FileType * call UltiSnips#FileTypeChanged() - augroup END - - " restore 'filetypedetect' group declaration - augroup filetypedetect -endif diff --git a/pythonx/UltiSnips/_vim.py b/pythonx/UltiSnips/_vim.py index 568da3a..1b0f752 100644 --- a/pythonx/UltiSnips/_vim.py +++ b/pythonx/UltiSnips/_vim.py @@ -51,6 +51,10 @@ class VimBuffer(object): """The bufnr() of the current buffer.""" return vim.current.buffer.number + @property + def filetypes(self): + return [ft for ft in vim.eval('&filetype').split('.') if ft] + @property def cursor(self): # pylint:disable=no-self-use """The current windows cursor. diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index aed93fa..331500e 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -71,7 +71,7 @@ class SnippetManager(object): self._supertab_keys = None self._csnippets = [] - self._buffer_filetypes = defaultdict(lambda: ['all']) + self._added_buffer_filetypes = defaultdict(lambda: []) self._vstate = VimState() self._visual_content = VisualContentPreserver() @@ -255,15 +255,12 @@ class SnippetManager(object): self._snippet_sources[index + 1:] break - def reset_buffer_filetypes(self): - """Reset the filetypes for the current buffer.""" - if _vim.buf.number in self._buffer_filetypes: - del self._buffer_filetypes[_vim.buf.number] + def get_buffer_filetypes(self): + return (self._added_buffer_filetypes[_vim.buf.number] + + _vim.buf.filetypes + ['all']) def add_buffer_filetypes(self, ft): - """Checks for changes in the list of snippet files or the contents of - the snippet files and reloads them if necessary.""" - buf_fts = self._buffer_filetypes[_vim.buf.number] + buf_fts = self._added_buffer_filetypes[_vim.buf.number] idx = -1 for ft in ft.split('.'): ft = ft.strip() @@ -272,7 +269,7 @@ class SnippetManager(object): try: idx = buf_fts.index(ft) except ValueError: - self._buffer_filetypes[_vim.buf.number].insert(idx + 1, ft) + self._added_buffer_filetypes[_vim.buf.number].insert(idx + 1, ft) idx += 1 @err_to_scratch_buffer.wrap @@ -570,7 +567,7 @@ class SnippetManager(object): If partial is True, then get also return partial matches. """ - filetypes = self._buffer_filetypes[_vim.buf.number][::-1] + filetypes = self.get_buffer_filetypes()[::-1] matching_snippets = defaultdict(list) clear_priority = None cleared = {} @@ -792,9 +789,9 @@ class SnippetManager(object): filetypes.append(requested_ft) else: if bang: - filetypes.extend(self._buffer_filetypes[_vim.buf.number]) + filetypes.extend(self.get_buffer_filetypes()) else: - filetypes.append(self._buffer_filetypes[_vim.buf.number][0]) + filetypes.append(self.get_buffer_filetypes()[0]) for ft in filetypes: potentials.update(find_snippet_files(ft, snippet_dir))