Applied Michael Henrys patch for w option
This commit is contained in:
commit
4948c5f7f7
@ -1,3 +1,4 @@
|
|||||||
|
- added support for option w which is a little more strict than i.
|
||||||
- added support for listing of valid triggers. Defaults to <c-tab>.
|
- added support for listing of valid triggers. Defaults to <c-tab>.
|
||||||
- added support for option i (inword expansion)
|
- added support for option i (inword expansion)
|
||||||
- extends keyword is now supported on the first line of snippet files. This makes it easy to
|
- extends keyword is now supported on the first line of snippet files. This makes it easy to
|
||||||
|
@ -180,9 +180,15 @@ snippet on. The options currently supported are >
|
|||||||
of the cursor). Default is to expand snippets at every position, even
|
of the cursor). Default is to expand snippets at every position, even
|
||||||
mitten in the line. Most of my snippets have this option set, it keeps
|
mitten in the line. Most of my snippets have this option set, it keeps
|
||||||
UltiSnips out of the way.
|
UltiSnips out of the way.
|
||||||
i Inword expansion - normally, triggers need whitespace before them to be
|
i Inword expansion - Normally, triggers need whitespace before them to be
|
||||||
expanded. With this option, triggers are also expanded in the middle of
|
expanded. With this option, triggers are also expanded in the middle of
|
||||||
a word.
|
a word.
|
||||||
|
w Word boundary - Normally, triggers need whitespace before them to be
|
||||||
|
expanded. With this option, the trigger will be expanded at a "word"
|
||||||
|
boundary as well, where word characters are letters, digits, and the
|
||||||
|
underscore character ('_'). This enables expansion of a trigger that
|
||||||
|
adjoins punctuation (for example) without expanding suffixes of larger
|
||||||
|
words.
|
||||||
|
|
||||||
4.2 Plaintext snippets *UltiSnips-plaintext-snippets*
|
4.2 Plaintext snippets *UltiSnips-plaintext-snippets*
|
||||||
----------------------
|
----------------------
|
||||||
|
@ -96,14 +96,42 @@ class Snippet(object):
|
|||||||
return "Snippet(%s,%s,%s)" % (self._t,self._d,self._opts)
|
return "Snippet(%s,%s,%s)" % (self._t,self._d,self._opts)
|
||||||
|
|
||||||
def matches(self, trigger):
|
def matches(self, trigger):
|
||||||
if "i" not in self._opts:
|
# If user supplies both "w" and "i", it should perhaps be an
|
||||||
return trigger == self._t
|
# error, but if permitted it seems that "w" should take precedence
|
||||||
return trigger.endswith(self._t)
|
# (since matching at word boundary and within a word == matching at word
|
||||||
|
# boundary).
|
||||||
|
if "w" in self._opts:
|
||||||
|
trigger_len = len(self._t)
|
||||||
|
trigger_prefix = trigger[:-trigger_len]
|
||||||
|
trigger_suffix = trigger[-trigger_len:]
|
||||||
|
match = (trigger_suffix == self._t)
|
||||||
|
if match and trigger_prefix:
|
||||||
|
# Require a word boundary between prefix and suffix.
|
||||||
|
boundaryChars = trigger_prefix[-1:] + trigger_suffix[:1]
|
||||||
|
match = re.match(r'.\b.', boundaryChars)
|
||||||
|
elif "i" in self._opts:
|
||||||
|
match = trigger.endswith(self._t)
|
||||||
|
else:
|
||||||
|
match = (trigger == self._t)
|
||||||
|
return match
|
||||||
|
|
||||||
def could_match(self, trigger):
|
def could_match(self, trigger):
|
||||||
# it i hard to define when a inword snippet could match
|
if "w" in self._opts:
|
||||||
# therefore we do not specially look for it
|
# Trim non-empty prefix up to word boundary, if present.
|
||||||
return self._t.startswith(trigger)
|
trigger_suffix = re.sub(r'^.+\b(.+)$', r'\1', trigger)
|
||||||
|
match = self._t.startswith(trigger_suffix)
|
||||||
|
|
||||||
|
# TODO: list_snippets() function cannot handle partial-trigger
|
||||||
|
# matches yet, so for now fail if we trimmed the prefix.
|
||||||
|
if trigger_suffix != trigger:
|
||||||
|
match = False
|
||||||
|
elif "i" in self._opts:
|
||||||
|
# TODO: It is hard to define when a inword snippet could match,
|
||||||
|
# therefore we check only for full-word trigger.
|
||||||
|
match = self._t.startswith(trigger)
|
||||||
|
else:
|
||||||
|
match = self._t.startswith(trigger)
|
||||||
|
return match
|
||||||
|
|
||||||
def overwrites_previous(self):
|
def overwrites_previous(self):
|
||||||
return "!" in self._opts
|
return "!" in self._opts
|
||||||
|
22
test.py
22
test.py
@ -1107,6 +1107,28 @@ class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand3(_VimTest):
|
|||||||
keys = "ätest" + EX
|
keys = "ätest" + EX
|
||||||
wanted = "äExpand me!"
|
wanted = "äExpand me!"
|
||||||
|
|
||||||
|
class _SnippetOptions_ExpandWordSnippets(_VimTest):
|
||||||
|
snippets = (("test", "Expand me!", "", "w"), )
|
||||||
|
class SnippetOptions_ExpandWordSnippets_NormalExpand(
|
||||||
|
_SnippetOptions_ExpandWordSnippets):
|
||||||
|
keys = "test" + EX
|
||||||
|
wanted = "Expand me!"
|
||||||
|
class SnippetOptions_ExpandWordSnippets_NoExpand(
|
||||||
|
_SnippetOptions_ExpandWordSnippets):
|
||||||
|
keys = "atest" + EX
|
||||||
|
wanted = "atest" + EX
|
||||||
|
class SnippetOptions_ExpandWordSnippets_ExpandSuffix(
|
||||||
|
_SnippetOptions_ExpandWordSnippets):
|
||||||
|
keys = "a-test" + EX
|
||||||
|
wanted = "a-Expand me!"
|
||||||
|
class SnippetOptions_ExpandWordSnippets_ExpandSuffix2(
|
||||||
|
_SnippetOptions_ExpandWordSnippets):
|
||||||
|
keys = "a(test" + EX
|
||||||
|
wanted = "a(Expand me!"
|
||||||
|
class SnippetOptions_ExpandWordSnippets_ExpandSuffix3(
|
||||||
|
_SnippetOptions_ExpandWordSnippets):
|
||||||
|
keys = "[[test" + EX
|
||||||
|
wanted = "[[Expand me!"
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user