better name for 'tab' attribute, and expand to tabstops, rather inserting 'ts' spaces

This commit is contained in:
rygwdn@gmail.com 2010-11-18 14:00:36 -04:00
parent 23924c3249
commit 9464f0c99c
2 changed files with 13 additions and 3 deletions

View File

@ -17,11 +17,21 @@ class IndentUtil(object):
self.et = (vim.eval("&expandtab") == "1")
self.ts = int(vim.eval("&ts"))
self.tab = self.sts or self.ts
# The amount added when pressing tab in insert mode
self.ind_len = self.sts or self.ts
def _strip_tabs(self, indent, ts):
new_ind = []
for ch in indent:
if ch == '\t':
new_ind.append(" " * (ts - (len(new_ind) % ts)))
else:
new_ind.append(ch)
return "".join(new_ind)
def indent_to_spaces(self, indent):
""" Converts indentation to spaces respecting vim settings. """
indent = indent.replace(" " * self.ts, "\t")
indent = self._strip_tabs(indent, self.ts)
right = (len(indent) - len(indent.rstrip(" "))) * " "
indent = indent.replace(" ", "")
indent = indent.replace('\t', " " * self.ts)

View File

@ -359,7 +359,7 @@ class Snippet(object):
line_ind = ""
else:
line_ind = indent
line_ind += tabs * self._util.tab * " "
line_ind += tabs * self._util.ind_len * " "
line_ind = self._util.indent_to_spaces(line_ind)
line_ind = self._util.spaces_to_indent(line_ind)
v.append(line_ind + line[tabs:])