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.
This commit is contained in:
parent
44fd0c704a
commit
7cd4434a99
@ -612,7 +612,7 @@ The options currently supported are: >
|
|||||||
the tab trigger start matches a word boundary and the tab trigger end
|
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
|
matches a word boundary. In other words the tab trigger must be
|
||||||
preceded and followed by non-word characters. Word characters are
|
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
|
permit expansion where the tab trigger follows punctuation without
|
||||||
expanding suffixes of larger words.
|
expanding suffixes of larger words.
|
||||||
|
|
||||||
|
@ -315,7 +315,8 @@ class Snippet(object):
|
|||||||
if match and words_prefix:
|
if match and words_prefix:
|
||||||
# Require a word boundary between prefix and suffix.
|
# Require a word boundary between prefix and suffix.
|
||||||
boundaryChars = words_prefix[-1:] + words_suffix[:1]
|
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:
|
elif "i" in self._opts:
|
||||||
match = words.endswith(self._t)
|
match = words.endswith(self._t)
|
||||||
else:
|
else:
|
||||||
@ -350,7 +351,8 @@ class Snippet(object):
|
|||||||
match = self._re_match(trigger)
|
match = self._re_match(trigger)
|
||||||
elif "w" in self._opts:
|
elif "w" in self._opts:
|
||||||
# Trim non-empty prefix up to word boundary, if present.
|
# 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)
|
match = self._t.startswith(words_suffix)
|
||||||
self._matched = words_suffix
|
self._matched = words_suffix
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user