diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index 5bd4538..95973a0 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -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* ---------------------- diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 2669c0c..36b6bda 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -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) diff --git a/test.py b/test.py index ec42f29..56423f8 100755 --- a/test.py +++ b/test.py @@ -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 # #################