From 7cd4434a99a6aa51fbbcc5104436e37bf8051e7c Mon Sep 17 00:00:00 2001 From: guns Date: Mon, 23 Dec 2013 15:36:29 -0600 Subject: [PATCH] Evaluate word boundaries with Vim, not r'\b' Certain non ALGOL-derived languages (notably LISP derivatives) do not share the alphanumeric + underscore definition of a word character. Fortunately, each language FileType has its own definition of a word character, which Vim's regex engine uses when matching against the boundary classes \< and \>. We change the word matching routine of 'w' snippets to use Vim's regex engine instead of a static pattern. --- doc/UltiSnips.txt | 2 +- plugin/UltiSnips/__init__.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index f2199d4..e4af8b0 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -612,7 +612,7 @@ The options currently supported are: > the tab trigger start matches a word boundary and the tab trigger end matches a word boundary. In other words the tab trigger must be preceded and followed by non-word characters. Word characters are - letters, digits and the underscore. Use this option, for example, to + defined by the 'iskeyword' setting. Use this option, for example, to permit expansion where the tab trigger follows punctuation without expanding suffixes of larger words. diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index be0b4ef..ea44a0c 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -315,7 +315,8 @@ class Snippet(object): if match and words_prefix: # Require a word boundary between prefix and suffix. boundaryChars = words_prefix[-1:] + words_suffix[:1] - match = re.match(r'.\b.', boundaryChars) + boundaryChars = boundaryChars.replace('"', '\\"') + match = _vim.eval('"%s" =~# "\\\\v.<."' % boundaryChars) != '0' elif "i" in self._opts: match = words.endswith(self._t) else: @@ -350,7 +351,8 @@ class Snippet(object): match = self._re_match(trigger) elif "w" in self._opts: # Trim non-empty prefix up to word boundary, if present. - words_suffix = re.sub(r'^.+\b(.+)$', r'\1', words) + qwords = words.replace('"', '\\"') + words_suffix = _vim.eval('substitute("%s", "\\\\v^.+<(.+)", "\\\\1", "")' % qwords) match = self._t.startswith(words_suffix) self._matched = words_suffix