add option to not expand tabs in snippet

This commit is contained in:
rygwdn@gmail.com 2010-11-22 10:14:47 -04:00
parent eff5ec2c66
commit fbb339d03e
3 changed files with 84 additions and 1 deletions

View File

@ -250,6 +250,11 @@ snippet on. The options currently supported are >
trigger (see above) even if it doesn't have any spaces. The resulting
match is also passed to any python code blocks in your snippet
definition as the local variable "match".
t Don't expand tabs - By default, UltiSnips tries to expand leading tabs
in a snippet to match the results of automatic indentation. If this
option is set, UltiSnips will not try to do this expansion, and will
leave the tabs alone. This can be useful for snippets dealing with
tab delimited formats, etc..
4.2 Plaintext Snippets *UltiSnips-plaintext-snippets*
----------------------

View File

@ -354,11 +354,16 @@ class Snippet(object):
v = []
for line_num, line in enumerate(lines[0:]):
tabs = len(self._TABS.match(line).group(0))
if "t" in self._opts:
tabs = 0
else:
tabs = len(self._TABS.match(line).group(0))
if line_num == 0:
line_ind = ""
else:
line_ind = indent
line_ind += tabs * self._util.sw * " "
line_ind = self._util.indent_to_spaces(line_ind)
line_ind = self._util.spaces_to_indent(line_ind)

73
test.py
View File

@ -1438,6 +1438,79 @@ class SnippetOptions_ExpandWordSnippets_ExpandSuffix3(
keys = "[[test" + EX
wanted = "[[Expand me!"
####################
# NO TAB EXPANSION #
####################
class _No_Tab_Expand(_VimTest):
snippets = ("test", "\t\tExpand\tme!\t", "", "t")
class No_Tab_Expand_Simple(_No_Tab_Expand):
keys = "test" + EX
wanted = "\t\tExpand\tme!\t"
class No_Tab_Expand_Leading_Spaces(_No_Tab_Expand):
keys = " test" + EX
wanted = " \t\tExpand\tme!\t"
class No_Tab_Expand_Leading_Tabs(_No_Tab_Expand):
keys = "\ttest" + EX
wanted = "\t\t\tExpand\tme!\t"
class No_Tab_Expand_No_TS(_No_Tab_Expand):
def _options_on(self):
self.send(":set sw=3\n")
self.send(":set sts=3\n")
def _options_off(self):
self.send(":set sw=8\n")
self.send(":set sts=0\n")
keys = "test" + EX
wanted = "\t\tExpand\tme!\t"
class No_Tab_Expand_ET(_No_Tab_Expand):
def _options_on(self):
self.send(":set sw=3\n")
self.send(":set expandtab\n")
def _options_off(self):
self.send(":set sw=8\n")
self.send(":set noexpandtab\n")
keys = "test" + EX
wanted = "\t\tExpand\tme!\t"
class No_Tab_Expand_ET_Leading_Spaces(_No_Tab_Expand):
def _options_on(self):
self.send(":set sw=3\n")
self.send(":set expandtab\n")
def _options_off(self):
self.send(":set sw=8\n")
self.send(":set noexpandtab\n")
keys = " test" + EX
wanted = " \t\tExpand\tme!\t"
class No_Tab_Expand_ET_SW(_No_Tab_Expand):
def _options_on(self):
self.send(":set sw=8\n")
self.send(":set expandtab\n")
def _options_off(self):
self.send(":set sw=8\n")
self.send(":set noexpandtab\n")
keys = "test" + EX
wanted = "\t\tExpand\tme!\t"
class No_Tab_Expand_ET_SW_TS(_No_Tab_Expand):
def _options_on(self):
self.send(":set sw=3\n")
self.send(":set sts=3\n")
self.send(":set ts=3\n")
self.send(":set expandtab\n")
def _options_off(self):
self.send(":set sw=8\n")
self.send(":set ts=8\n")
self.send(":set sts=0\n")
self.send(":set noexpandtab\n")
keys = "test" + EX
wanted = "\t\tExpand\tme!\t"
#################
# REGEX MATCHES #
#################