Overwrite all snippets with lower priority on expansion.

Fixes #233.
This commit is contained in:
Holger Rapp 2014-03-23 17:30:44 +01:00
parent 5116001246
commit 4b4ee48858
2 changed files with 26 additions and 8 deletions

View File

@ -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

12
test.py
View File

@ -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):