$VISUAL now supports default text
This commit is contained in:
parent
8c9bf502f2
commit
13aadb5def
@ -7,7 +7,7 @@ version 2.0:
|
||||
behave more like Vim *UltiSnips-adding-snippets*
|
||||
- Backwards incompatible change: Zero Tabstop is no longer removed in
|
||||
nested snippets
|
||||
- Support for ${VISUAL} placeholder. *UltiSnips-visual-placeholder*
|
||||
- Support for ${VISUAL:default text} placeholder. *UltiSnips-visual-placeholder*
|
||||
- Improved handling of utf-8 characters in files and snippet definitions.
|
||||
- Full support for :py3. UltiSnips now works with python >= 2.6 or >= 3.2.
|
||||
- New or improved snippets: python, all
|
||||
|
@ -367,11 +367,13 @@ Snippets can contain a special placeholder called ${VISUAL}. When you select
|
||||
some text in visual mode and press the key to expand a trigger
|
||||
(see g:UltiSnipsExpandTrigger) the selected text will get deleted and you will
|
||||
drop to insert mode. The next snippet you expand will have the selected text
|
||||
in the place of the ${VISUAL}. As a small example, let's take this snippet:
|
||||
in the place of the ${VISUAL}. The place holder can also contain default text
|
||||
when there is no visual text to be selected: ${VISUAL:default text}.
|
||||
As a small example, let's take this snippet:
|
||||
|
||||
------------------- SNIP -------------------
|
||||
snippet t
|
||||
<tag>${VISUAL}</tag>
|
||||
<tag>${VISUAL:inside text}</tag>
|
||||
endsnippet
|
||||
------------------- SNAP -------------------
|
||||
And starting with this line: >
|
||||
@ -379,6 +381,9 @@ And starting with this line: >
|
||||
position the cursor on the should, then press viw (visual mode -> select inner
|
||||
word). Then press tab, type "t" and press tab again >
|
||||
-> this <tag>should</tag> be cool
|
||||
If you expand this snippet without having been in visual mode before, e.g. by
|
||||
writing in insert mode t<tab>, you will get >
|
||||
<tag>inside text</tag>
|
||||
|
||||
4.4 Interpolation *UltiSnips-interpolation*
|
||||
-----------------
|
||||
|
@ -135,16 +135,20 @@ class TabStopToken(Token):
|
||||
)
|
||||
|
||||
class VisualToken(Token):
|
||||
TOKEN = "${VISUAL}"
|
||||
CHECK = re.compile(r"^\${VISUAL[:}]")
|
||||
|
||||
@classmethod
|
||||
def starts_here(klass, stream):
|
||||
return stream.peek(len(klass.TOKEN)) == klass.TOKEN
|
||||
return klass.CHECK.match(stream.peek(10)) is not None
|
||||
|
||||
def _parse(self, stream, indent):
|
||||
for i in range(len(self.TOKEN)):
|
||||
for i in range(8): # ${VISUAL
|
||||
stream.next()
|
||||
|
||||
if stream.peek() == ":":
|
||||
stream.next()
|
||||
self.alternative_text = _parse_till_closing_brace(stream)
|
||||
|
||||
def __repr__(self):
|
||||
return "VisualToken(%r,%r)" % (
|
||||
self.start, self.end
|
||||
|
@ -25,6 +25,9 @@ class Visual(NoneditableTextObject):
|
||||
break
|
||||
except AttributeError:
|
||||
snippet = snippet._parent
|
||||
if not self._text:
|
||||
self._text = token.alternative_text
|
||||
self._mode = "v"
|
||||
|
||||
NoneditableTextObject.__init__(self, parent, token)
|
||||
|
||||
|
8
test.py
8
test.py
@ -1521,6 +1521,14 @@ class Visual_SelectOneWord(_VimTest):
|
||||
snippets = ("test", "h${VISUAL}b")
|
||||
keys = "blablub" + ESC + "0v6l" + EX + "test" + EX
|
||||
wanted = "hblablubb"
|
||||
class VisualWithDefault_ExpandWithoutVisual(_VimTest):
|
||||
snippets = ("test", "h${VISUAL:world}b")
|
||||
keys = "test" + EX + "hi"
|
||||
wanted = "hworldbhi"
|
||||
class VisualWithDefault_ExpandWithVisual(_VimTest):
|
||||
snippets = ("test", "h${VISUAL:world}b")
|
||||
keys = "blablub" + ESC + "0v6l" + EX + "test" + EX
|
||||
wanted = "hblablubb"
|
||||
|
||||
class Visual_ExpandTwice(_VimTest):
|
||||
snippets = ("test", "h${VISUAL}b")
|
||||
|
Loading…
x
Reference in New Issue
Block a user