better name for 'tab' attribute, and expand to tabstops, rather inserting 'ts' spaces
This commit is contained in:
parent
23924c3249
commit
9464f0c99c
@ -17,11 +17,21 @@ class IndentUtil(object):
|
|||||||
self.et = (vim.eval("&expandtab") == "1")
|
self.et = (vim.eval("&expandtab") == "1")
|
||||||
self.ts = int(vim.eval("&ts"))
|
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):
|
def indent_to_spaces(self, indent):
|
||||||
""" Converts indentation to spaces respecting vim settings. """
|
""" 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(" "))) * " "
|
right = (len(indent) - len(indent.rstrip(" "))) * " "
|
||||||
indent = indent.replace(" ", "")
|
indent = indent.replace(" ", "")
|
||||||
indent = indent.replace('\t', " " * self.ts)
|
indent = indent.replace('\t', " " * self.ts)
|
||||||
|
@ -359,7 +359,7 @@ class Snippet(object):
|
|||||||
line_ind = ""
|
line_ind = ""
|
||||||
else:
|
else:
|
||||||
line_ind = indent
|
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.indent_to_spaces(line_ind)
|
||||||
line_ind = self._util.spaces_to_indent(line_ind)
|
line_ind = self._util.spaces_to_indent(line_ind)
|
||||||
v.append(line_ind + line[tabs:])
|
v.append(line_ind + line[tabs:])
|
||||||
|
Loading…
Reference in New Issue
Block a user