Empty lines do not end a snippet for snipMate.

This commit is contained in:
Holger Rapp 2014-02-25 23:17:05 +01:00
parent 14fca85231
commit c690a36102
2 changed files with 32 additions and 28 deletions

View File

@ -78,9 +78,14 @@ def _parse_snippet(line, lines):
content = "" content = ""
while True: while True:
next_line = lines.peek() next_line = lines.peek()
if next_line is None or not next_line.startswith('\t'): if next_line is None:
break break
content += next(lines)[1:] # strip first tab if next_line.strip() and not next_line.startswith('\t'):
break
line = next(lines)
if line[0] == '\t':
line = line[1:]
content += line
content = content[:-1] # Chomp the last newline content = content[:-1] # Chomp the last newline
return "snippet", (SnipMateSnippetDefinition( return "snippet", (SnipMateSnippetDefinition(
trigger, content, description),) trigger, content, description),)

51
test.py
View File

@ -3106,15 +3106,13 @@ class snipMate_SimpleSnippet(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet hello snippet hello
\tThis is a test snippet \tThis is a test snippet
\t# With a comment \t# With a comment"""}
"""}
keys = "hello" + EX keys = "hello" + EX
wanted = "This is a test snippet\n# With a comment" wanted = "This is a test snippet\n# With a comment"
class snipMate_OtherFiletype(_VimTest): class snipMate_OtherFiletype(_VimTest):
files = { "snippets/blubi.snippets": """ files = { "snippets/blubi.snippets": """
snippet hello snippet hello
\tworked \tworked"""}
"""}
keys = "hello" + EX + ESC + ":set ft=blubi\nohello" + EX keys = "hello" + EX + ESC + ":set ft=blubi\nohello" + EX
wanted = "hello" + EX + "\nworked" wanted = "hello" + EX + "\nworked"
class snipMate_MultiMatches(_VimTest): class snipMate_MultiMatches(_VimTest):
@ -3122,15 +3120,13 @@ class snipMate_MultiMatches(_VimTest):
snippet hello The first snippet." snippet hello The first snippet."
\tone \tone
snippet hello The second snippet. snippet hello The second snippet.
\ttwo \ttwo"""}
"""}
keys = "hello" + EX + "2\n" keys = "hello" + EX + "2\n"
wanted = "two" wanted = "two"
class snipMate_SimpleSnippetSubDirectory(_VimTest): class snipMate_SimpleSnippetSubDirectory(_VimTest):
files = { "snippets/_/blub.snippets": """ files = { "snippets/_/blub.snippets": """
snippet hello snippet hello
\tThis is a test snippet \tThis is a test snippet"""}
"""}
keys = "hello" + EX keys = "hello" + EX
wanted = "This is a test snippet" wanted = "This is a test snippet"
class snipMate_SimpleSnippetInSnippetFile(_VimTest): class snipMate_SimpleSnippetInSnippetFile(_VimTest):
@ -3144,15 +3140,13 @@ class snipMate_SimpleSnippetInSnippetFile(_VimTest):
class snipMate_Interpolation(_VimTest): class snipMate_Interpolation(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet test snippet test
\tla`printf('c%02d', 3)`lu \tla`printf('c%02d', 3)`lu"""}
"""}
keys = "test" + EX keys = "test" + EX
wanted = "lac03lu" wanted = "lac03lu"
class snipMate_InterpolationWithSystem(_VimTest): class snipMate_InterpolationWithSystem(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet test snippet test
\tla`system('echo -ne öäü')`lu \tla`system('echo -ne öäü')`lu"""}
"""}
keys = "test" + EX keys = "test" + EX
wanted = "laöäülu" wanted = "laöäülu"
class snipMate_TestMirrors(_VimTest): class snipMate_TestMirrors(_VimTest):
@ -3160,50 +3154,55 @@ class snipMate_TestMirrors(_VimTest):
snippet for snippet for
\tfor (${2:i}; $2 < ${1:count}; $1++) { \tfor (${2:i}; $2 < ${1:count}; $1++) {
\t\t${4} \t\t${4}
\t} \t}"""}
"""}
keys = "for" + EX + "blub" + JF + "j" + JF + "hi" keys = "for" + EX + "blub" + JF + "j" + JF + "hi"
wanted = "for (j; j < blub; blub++) {\n\thi\n}" wanted = "for (j; j < blub; blub++) {\n\thi\n}"
class snipMate_TestMirrorsInPlaceholders(_VimTest): class snipMate_TestMirrorsInPlaceholders(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet opt snippet opt
\t<option value="${1:option}">${2:$1}</option> \t<option value="${1:option}">${2:$1}</option>"""}
"""}
keys = "opt" + EX + "some" + JF + JF + "ende" keys = "opt" + EX + "some" + JF + JF + "ende"
wanted = """<option value="some">some</option>ende""" wanted = """<option value="some">some</option>ende"""
class snipMate_TestMirrorsInPlaceholders_Overwrite(_VimTest): class snipMate_TestMirrorsInPlaceholders_Overwrite(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet opt snippet opt
\t<option value="${1:option}">${2:$1}</option> \t<option value="${1:option}">${2:$1}</option>"""}
"""}
keys = "opt" + EX + "some" + JF + "not" + JF + "ende" keys = "opt" + EX + "some" + JF + "not" + JF + "ende"
wanted = """<option value="some">not</option>ende""" wanted = """<option value="some">not</option>ende"""
class snipMate_Visual_Simple(_VimTest): class snipMate_Visual_Simple(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet v snippet v
\th${VISUAL}b \th${VISUAL}b"""}
"""}
keys = "blablub" + ESC + "0v6l" + EX + "v" + EX keys = "blablub" + ESC + "0v6l" + EX + "v" + EX
wanted = "hblablubb" wanted = "hblablubb"
class snipMate_NoNestedTabstops(_VimTest): class snipMate_NoNestedTabstops(_VimTest):
files = { "snippets/_.snippets": """ files = { "snippets/_.snippets": """
snippet test snippet test
\th$${1:${2:blub}}$$ \th$${1:${2:blub}}$$"""}
"""}
keys = "test" + EX + JF + "hi" keys = "test" + EX + JF + "hi"
wanted = "h$${2:blub}$$hi" wanted = "h$${2:blub}$$hi"
class snipMate_Extends(_VimTest): class snipMate_Extends(_VimTest):
files = { "snippets/a.snippets": """ files = { "snippets/a.snippets": """
extends b extends b
snippet test snippet test
\tblub \tblub""", "snippets/b.snippets": """
""", "snippets/b.snippets": """
snippet test1 snippet test1
\tblah \tblah"""
"""
} }
keys = ESC + ":set ft=a\n" + "itest1" + EX keys = ESC + ":set ft=a\n" + "itest1" + EX
wanted = "blah" wanted = "blah"
class snipMate_EmptyLinesContinueSnippets(_VimTest):
files = { "snippets/_.snippets": """
snippet test
\tblub
\tblah
snippet test1
\ta"""
}
keys = "test" + EX
wanted = "blub\n\nblah\n"
# End: snipMate support #}}} # End: snipMate support #}}}