Merge remote-tracking branch 'aschrab/trailing' into trailing
This commit is contained in:
commit
d4f4c718e8
@ -552,6 +552,10 @@ The options currently supported are: >
|
|||||||
Vim settings and insert the tab characters as is. This option is useful
|
Vim settings and insert the tab characters as is. This option is useful
|
||||||
for snippets involved with tab delimited formats, for example.
|
for snippets involved with tab delimited formats, for example.
|
||||||
|
|
||||||
|
s Remove whitespace immediately before the cursor at the end of a line
|
||||||
|
before jumping to the next tabstop. This is useful if there is a
|
||||||
|
tabstop with optional text at the end of a line.
|
||||||
|
|
||||||
The end line is the 'endsnippet' keyword on a line by itself. >
|
The end line is the 'endsnippet' keyword on a line by itself. >
|
||||||
|
|
||||||
endsnippet
|
endsnippet
|
||||||
|
@ -288,6 +288,10 @@ class Snippet(object):
|
|||||||
return match
|
return match
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def has_option(self, opt):
|
||||||
|
""" Check if the named option is set """
|
||||||
|
return opt in self._opts
|
||||||
|
|
||||||
def matches(self, trigger):
|
def matches(self, trigger):
|
||||||
# If user supplies both "w" and "i", it should perhaps be an
|
# If user supplies both "w" and "i", it should perhaps be an
|
||||||
# error, but if permitted it seems that "w" should take precedence
|
# error, but if permitted it seems that "w" should take precedence
|
||||||
@ -412,11 +416,7 @@ class Snippet(object):
|
|||||||
v.append(line_ind + line[tabs:])
|
v.append(line_ind + line[tabs:])
|
||||||
v = '\n'.join(v)
|
v = '\n'.join(v)
|
||||||
|
|
||||||
if parent is None:
|
si = SnippetInstance(self, parent, indent, v, start, end, visual_content,
|
||||||
si = SnippetInstance(None, indent, v, start, end, visual_content = visual_content,
|
|
||||||
last_re = self._last_re, globals = self._globals)
|
|
||||||
else:
|
|
||||||
si = SnippetInstance(parent, indent, v, start, end, visual_content,
|
|
||||||
last_re = self._last_re, globals = self._globals)
|
last_re = self._last_re, globals = self._globals)
|
||||||
|
|
||||||
return si
|
return si
|
||||||
@ -743,6 +743,13 @@ class SnippetManager(object):
|
|||||||
if self._cs:
|
if self._cs:
|
||||||
self._ctab = self._cs.select_next_tab(backwards)
|
self._ctab = self._cs.select_next_tab(backwards)
|
||||||
if self._ctab:
|
if self._ctab:
|
||||||
|
before, after = _vim.buf.current_line_splitted
|
||||||
|
if self._cs.snippet.has_option("s"):
|
||||||
|
if after == "":
|
||||||
|
m = re.match( r'(.*?)\s+$', before )
|
||||||
|
if m:
|
||||||
|
lineno = _vim.buf.cursor.line
|
||||||
|
_vim.text_to_vim( Position(lineno,0), Position(lineno,len(before)+len(after)), m.group(1) )
|
||||||
_vim.select(self._ctab.start, self._ctab.end)
|
_vim.select(self._ctab.start, self._ctab.end)
|
||||||
jumped = True
|
jumped = True
|
||||||
if self._ctab.no == 0:
|
if self._ctab.no == 0:
|
||||||
|
@ -15,12 +15,12 @@ class SnippetInstance(EditableTextObject):
|
|||||||
also a TextObject because it has a start an end
|
also a TextObject because it has a start an end
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, parent, indent, initial_text, start, end, visual_content, last_re, globals):
|
def __init__(self, snippet, parent, indent, initial_text, start, end, visual_content, last_re, globals):
|
||||||
if start is None:
|
if start is None:
|
||||||
start = Position(0,0)
|
start = Position(0,0)
|
||||||
if end is None:
|
if end is None:
|
||||||
end = Position(0,0)
|
end = Position(0,0)
|
||||||
|
self.snippet = snippet
|
||||||
self._cts = 0
|
self._cts = 0
|
||||||
|
|
||||||
self.locals = {"match" : last_re}
|
self.locals = {"match" : last_re}
|
||||||
|
10
test.py
10
test.py
@ -2605,6 +2605,16 @@ ${0}
|
|||||||
keys = "test" + EX + JF + "sub junk {}"
|
keys = "test" + EX + JF + "sub junk {}"
|
||||||
wanted = "package c03;\nsub junk {}\n1;"
|
wanted = "package c03;\nsub junk {}\n1;"
|
||||||
# End: Folding Interaction #}}}
|
# End: Folding Interaction #}}}
|
||||||
|
# Trailing whitespace {{{#
|
||||||
|
class RemoveTrailingWhitespace(_VimTest):
|
||||||
|
snippets = ("test", """Hello\t ${1:default}\n$2""", "", "s")
|
||||||
|
wanted = """Hello\nGoodbye"""
|
||||||
|
keys = "test" + EX + BS + JF + "Goodbye"
|
||||||
|
class LeaveTrailingWhitespace(_VimTest):
|
||||||
|
snippets = ("test", """Hello \t ${1:default}\n$2""")
|
||||||
|
wanted = """Hello \t \nGoodbye"""
|
||||||
|
keys = "test" + EX + BS + JF + "Goodbye"
|
||||||
|
# End: Trailing whitespace }}}#
|
||||||
|
|
||||||
# Cursor Movement {{{#
|
# Cursor Movement {{{#
|
||||||
class CursorMovement_Multiline_ECR(_VimTest):
|
class CursorMovement_Multiline_ECR(_VimTest):
|
||||||
|
Loading…
Reference in New Issue
Block a user