Implemented i option (inword snippet expansion) along the line of the patch by jceb, also added his test cases
This commit is contained in:
parent
f5610ae451
commit
cd0b859b62
@ -29,7 +29,7 @@ ${4/.+/(?0:\n)/}${4/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=[^,]*)?(,\s*
|
||||
${2/object$|(.+)/(?1: $0.__init__\(self\)\n\n)/}${4/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=[^,]*)?(,\s*|$)/(?2: self._$2 = $2\n)/g}
|
||||
endsnippet
|
||||
|
||||
snippet .
|
||||
snippet . "self." i
|
||||
self.
|
||||
endsnippet
|
||||
|
||||
|
@ -178,6 +178,9 @@ snippet on. The options currently supported are >
|
||||
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
|
||||
UltiSnips out of the way.
|
||||
i Inword expansion - normally, triggers need whitespace before them to be
|
||||
expanded. With this option, triggers are also expanded in the middle of
|
||||
a word.
|
||||
|
||||
4.2 Plaintext snippets *UltiSnips-plaintext-snippets*
|
||||
----------------------
|
||||
|
@ -11,12 +11,24 @@ from UltiSnips.Geometry import Position
|
||||
from UltiSnips.TextObjects import *
|
||||
from UltiSnips.Buffer import VimBuffer
|
||||
|
||||
# TODO: it doesn't make sense to have
|
||||
# this as a baseclass of a dict, since we have
|
||||
# to run through all snippets anyway
|
||||
class _SnippetDictionary(dict):
|
||||
def __init__(self, *args, **kwargs):
|
||||
dict.__init__(self, *args, **kwargs)
|
||||
|
||||
self._extends = []
|
||||
|
||||
def get_matching_snippets(self, trigger):
|
||||
"""Returns all snippets matching the given trigger."""
|
||||
rv = []
|
||||
for l in self.values():
|
||||
for snip in l:
|
||||
if snip.matches(trigger):
|
||||
rv.append(snip)
|
||||
return rv
|
||||
|
||||
def extends():
|
||||
def fget(self):
|
||||
return self._extends
|
||||
@ -86,6 +98,11 @@ class Snippet(object):
|
||||
def __repr__(self):
|
||||
return "Snippet(%s,%s,%s)" % (self._t,self._d,self._opts)
|
||||
|
||||
def matches(self, trigger):
|
||||
if "i" not in self._opts:
|
||||
return trigger == self._t
|
||||
return trigger.endswith(self._t)
|
||||
|
||||
def overwrites_previous(self):
|
||||
return "!" in self._opts
|
||||
overwrites_previous = property(overwrites_previous)
|
||||
@ -489,6 +506,9 @@ class SnippetManager(object):
|
||||
return True
|
||||
raise
|
||||
|
||||
# Adjust before, maybe the trigger is not the complete word
|
||||
text_before += word[:-len(snippet.trigger)]
|
||||
|
||||
self._expect_move_wo_change = True
|
||||
|
||||
if self._cs:
|
||||
@ -590,7 +610,7 @@ class SnippetManager(object):
|
||||
parent_results = reduce( lambda a,b: a+b,
|
||||
[ self._find_snippets(p, trigger) for p in snips.extends ], [])
|
||||
|
||||
return parent_results + snips.get(trigger, [])
|
||||
return parent_results + snips.get_matching_snippets(trigger)
|
||||
|
||||
|
||||
UltiSnips_Manager = SnippetManager()
|
||||
|
24
test.py
24
test.py
@ -1075,6 +1075,30 @@ class SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWOChoose(_VimTest):
|
||||
keys = " test" + EX + "1\n"
|
||||
wanted = " Expand me!"
|
||||
|
||||
|
||||
class SnippetOptions_ExpandInwordSnippets_SimpleExpand(_VimTest):
|
||||
snippets = (("test", "Expand me!", "", "i"), )
|
||||
keys = "atest" + EX
|
||||
wanted = "aExpand me!"
|
||||
class SnippetOptions_ExpandInwordSnippets_ExpandSingle(_VimTest):
|
||||
snippets = (("test", "Expand me!", "", "i"), )
|
||||
keys = "test" + EX
|
||||
wanted = "Expand me!"
|
||||
class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand(_VimTest):
|
||||
snippets = (("test", "Expand me!", "", "i"), )
|
||||
keys = "$test" + EX
|
||||
wanted = "$Expand me!"
|
||||
class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand2(_VimTest):
|
||||
snippets = (("test", "Expand me!", "", "i"), )
|
||||
keys = "-test" + EX
|
||||
wanted = "-Expand me!"
|
||||
class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand3(_VimTest):
|
||||
snippets = (("test", "Expand me!", "", "i"), )
|
||||
keys = "ätest" + EX
|
||||
wanted = "äExpand me!"
|
||||
|
||||
|
||||
|
||||
######################
|
||||
# SELECTING MULTIPLE #
|
||||
######################
|
||||
|
Loading…
x
Reference in New Issue
Block a user