From b065b5cf306659b68b4e1a2370cfb9c2cbcfc098 Mon Sep 17 00:00:00 2001 From: "rygwdn@gmail.com" <> Date: Fri, 17 Dec 2010 22:38:56 -0400 Subject: [PATCH] Fixes Bug #691575. Deals with the case where there are multiple matches on the line. Tries all matches until one fits! --- plugin/UltiSnips/__init__.py | 12 +++++------- test.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 36b6bda..7261c4f 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -234,17 +234,15 @@ class Snippet(object): """ Test if a the current regex trigger matches `trigger`. If so, set _last_re and _matched. """ - match = re.search(self._t, trigger) - if match: + for match in re.finditer(self._t, trigger): if match.end() != len(trigger): - match = False + continue else: self._matched = trigger[match.start():match.end()] - if match: + self._last_re = match - else: - self._last_re = None - return match + return match + return False def matches(self, trigger): # If user supplies both "w" and "i", it should perhaps be an diff --git a/test.py b/test.py index 56423f8..99173f8 100755 --- a/test.py +++ b/test.py @@ -1550,6 +1550,23 @@ class SnippetOptions_Regex_PythonBlockNoMatch(_VimTest): keys = "test cabfed" + EX wanted = "test No match" +# Tests for Bug #691575 +class SnippetOptions_Regex_SameLine_Long_End(_VimTest): + snippets = ("(test.*)", "Expand me!", "", "r") + keys = "test test abc" + EX + wanted = "Expand me!" + +class SnippetOptions_Regex_SameLine_Long_Start(_VimTest): + snippets = ("(.*test)", "Expand me!", "", "r") + keys = "abc test test" + EX + wanted = "Expand me!" + +class SnippetOptions_Regex_SameLine_Simple(_VimTest): + snippets = ("(test)", "Expand me!", "", "r") + keys = "abc test test" + EX + wanted = "abc test Expand me!" + + ####################### # MULTI-WORD SNIPPETS # #######################