From f40c3ac5e055056d4099b293985a1f1a02fa0ccb Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sat, 15 Mar 2014 15:55:03 +0100 Subject: [PATCH] Made UltiSnipsEdit! more consistent with multiple filetypes. --- autoload/UltiSnips.vim | 2 +- pythonx/UltiSnips/snippet_manager.py | 43 ++++++++++++++++------------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index d9ba063..f1b2f15 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -34,7 +34,7 @@ function! UltiSnips#Edit(bang, ...) if a:0 == 1 && a:1 != '' let type = a:1 else - exec g:_uspy "vim.command(\"let type = '%s'\" % UltiSnips_Manager._primary_filetype)" + let type = "" endif exec g:_uspy "vim.command(\"let file = '%s'\" % UltiSnips_Manager._file_to_edit(vim.eval(\"type\"), vim.eval('a:bang')))" diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index ee4299d..eeb35cd 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -527,16 +527,10 @@ class SnippetManager(object): return None return self._csnippets[-1] - @property - def _primary_filetype(self): - """This filetype will be edited when UltiSnipsEdit is called without - any arguments.""" - return self._buffer_filetypes[_vim.buf.number][0] - - def _file_to_edit(self, ft, bang): # pylint: disable=no-self-use - """Returns a file to be edited for the given ft. If 'bang' is empty - only private files in g:UltiSnipsSnippetsDir are considered, otherwise - all files are considered and the user gets to choose. + def _file_to_edit(self, requested_ft, bang): # pylint: disable=no-self-use + """Returns a file to be edited for the given requested_ft. If 'bang' is + empty only private files in g:UltiSnipsSnippetsDir are considered, + otherwise all files are considered and the user gets to choose. """ # This method is not using self, but is called by UltiSnips.vim and is # therefore in this class because it is the facade to Vim. @@ -551,11 +545,22 @@ class SnippetManager(object): else: snippet_dir = os.path.join(_vim.eval("$HOME"), ".vim", "UltiSnips") - potentials.update(find_snippet_files(ft, snippet_dir)) - potentials.add(os.path.join(snippet_dir, ft + '.snippets')) - if bang: - potentials.update(find_all_snippet_files(ft)) + filetypes = [] + if requested_ft: + filetypes.append(requested_ft) + else: + if bang: + filetypes.extend(self._buffer_filetypes[_vim.buf.number]) + else: + filetypes.append(self._buffer_filetypes[_vim.buf.number][0]) + + for ft in filetypes: + potentials.update(find_snippet_files(ft, snippet_dir)) + potentials.add(os.path.join(snippet_dir, + ft + '.snippets')) + if bang: + potentials.update(find_all_snippet_files(ft)) potentials = set(os.path.realpath(os.path.expanduser(p)) for p in potentials) @@ -564,13 +569,13 @@ class SnippetManager(object): files = sorted(potentials) formatted = [as_unicode('%i: %s') % (i, fn) for i, fn in enumerate(files, 1)] - edit = _ask_user(files, formatted) - if edit is None: + file_to_edit = _ask_user(files, formatted) + if file_to_edit is None: return "" else: - edit = potentials.pop() + file_to_edit = potentials.pop() - dirname = os.path.dirname(edit) + dirname = os.path.dirname(file_to_edit) if not os.path.exists(dirname): os.makedirs(dirname) - return edit + return file_to_edit