From 4b4ee488580f7586e82a76bb392e4f79027ce049 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 23 Mar 2014 17:30:44 +0100 Subject: [PATCH] Overwrite all snippets with lower priority on expansion. Fixes #233. --- pythonx/UltiSnips/snippet_manager.py | 22 ++++++++++++++-------- test.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index a4ed344..0488c8f 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -440,27 +440,33 @@ class SnippetManager(object): elif feedkey: _vim.command("return %s" % _vim.escape(feedkey)) - def _snips(self, before, possible): - """ Returns all the snippets for the given text - before the cursor. If possible is True, then get all - possible matches. - """ + def _snips(self, before, partial): + """Returns all the snippets for the given text before the cursor. If + partial is True, then get also return partial matches. """ filetypes = self._buffer_filetypes[_vim.buf.number][::-1] matching_snippets = defaultdict(list) for _, source in self._snippet_sources: - for snippet in source.get_snippets(filetypes, before, possible): + for snippet in source.get_snippets(filetypes, before, partial): matching_snippets[snippet.trigger].append(snippet) if not matching_snippets: return [] # Now filter duplicates and only keep the one with the highest - # priority. Only keep the snippets with the highest priority. + # priority. snippets = [] for snippets_with_trigger in matching_snippets.values(): highest_priority = max(s.priority for s in snippets_with_trigger) snippets.extend(s for s in snippets_with_trigger if s.priority == highest_priority) - return snippets + + # For partial matches we are done, but if we want to expand a snippet, + # we have to go over them again and only keep those with the maximum + # priority. + if partial: + return snippets + + highest_priority = max(s.priority for s in snippets) + return [s for s in snippets if s.priority == highest_priority] def _do_snippet(self, snippet, before): """Expands the given snippet, and handles everything diff --git a/test.py b/test.py index 32662f9..0e1de5c 100755 --- a/test.py +++ b/test.py @@ -3282,6 +3282,18 @@ snippet test1 } keys = "test" + EX wanted = "blub\n\nblah\n" +class snipMate_OverwrittenByRegExpTrigger(_VimTest): + files = { "snippets/_.snippets": """ +snippet def +\tsnipmate +""", + "us/all.snippets": r""" +snippet "(de)?f" "blub" r +ultisnips +endsnippet +""" } + keys = "def" + EX + wanted = "ultisnips" # End: snipMate support #}}} # SnippetsInCurrentScope {{{# class VerifyVimDict1(_VimTest):