Support for m (trim) snippet option.

This commit is contained in:
Holger Rapp 2015-02-14 14:20:03 +01:00
commit 09876e0084
3 changed files with 19 additions and 1 deletions

View File

@ -649,6 +649,11 @@ The options currently supported are: >
before jumping to the next tabstop. This is useful if there is a
tabstop with optional text at the end of a line.
m Trim all whitespaces from right side of snippet lines. Useful when
snippet contains empty lines which should remain empty after expanding.
Without this option empty lines in snippets definition will have
indentation too.
The end line is the 'endsnippet' keyword on a line by itself. >
endsnippet

View File

@ -228,7 +228,10 @@ class SnippetDefinition(object):
if line_num != 0:
line_ind = indent + line_ind
initial_text.append(line_ind + line[tabs:])
result_line = line_ind + line[tabs:]
if 'm' in self._opts:
result_line = result_line.rstrip()
initial_text.append(result_line)
initial_text = '\n'.join(initial_text)
snippet_instance = SnippetInstance(

View File

@ -47,6 +47,16 @@ class RemoveTrailingWhitespace(_VimTest):
wanted = """Hello\nGoodbye"""
keys = 'test' + EX + BS + JF + 'Goodbye'
class TrimSpacesAtEndOfLines(_VimTest):
snippets = ('test', """next line\n\nshould be empty""", '', 'm')
wanted = """\tnext line\n\n\tshould be empty"""
keys = '\ttest' + EX
class DoNotTrimSpacesAtEndOfLinesByDefault(_VimTest):
snippets = ('test', """next line\n\nshould be empty""", '', '')
wanted = """\tnext line\n\t\n\tshould be empty"""
keys = '\ttest' + EX
class LeaveTrailingWhitespace(_VimTest):
snippets = ('test', """Hello \t ${1:default}\n$2""")