Merge remote-tracking branch 'aschrab/trailing' into trailing

This commit is contained in:
Holger Rapp 2012-11-27 09:36:48 +01:00
commit d4f4c718e8
4 changed files with 29 additions and 8 deletions

View File

@ -552,6 +552,10 @@ The options currently supported are: >
Vim settings and insert the tab characters as is. This option is useful
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. >
endsnippet

View File

@ -288,6 +288,10 @@ class Snippet(object):
return match
return False
def has_option(self, opt):
""" Check if the named option is set """
return opt in self._opts
def matches(self, trigger):
# If user supplies both "w" and "i", it should perhaps be an
# error, but if permitted it seems that "w" should take precedence
@ -412,12 +416,8 @@ class Snippet(object):
v.append(line_ind + line[tabs:])
v = '\n'.join(v)
if parent is None:
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)
si = SnippetInstance(self, parent, indent, v, start, end, visual_content,
last_re = self._last_re, globals = self._globals)
return si
@ -743,6 +743,13 @@ class SnippetManager(object):
if self._cs:
self._ctab = self._cs.select_next_tab(backwards)
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)
jumped = True
if self._ctab.no == 0:

View File

@ -15,12 +15,12 @@ class SnippetInstance(EditableTextObject):
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:
start = Position(0,0)
if end is None:
end = Position(0,0)
self.snippet = snippet
self._cts = 0
self.locals = {"match" : last_re}

10
test.py
View File

@ -2605,6 +2605,16 @@ ${0}
keys = "test" + EX + JF + "sub junk {}"
wanted = "package c03;\nsub junk {}\n1;"
# 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 {{{#
class CursorMovement_Multiline_ECR(_VimTest):