- fixed a bug related to indentexpr. vim just has too many options

- expandtab and ts options are now taken into consideration when expanding tabs
This commit is contained in:
Holger Rapp 2009-07-29 09:49:44 +02:00
parent 274ef83833
commit 8fb1412791
3 changed files with 53 additions and 8 deletions

View File

@ -1,3 +1,5 @@
- UltiSnips now adheres to expandtab and tabstop options of vim
version 1.1:
- Made triggers configurable. You can also use the same trigger for
expanding and tabbing. The TextMate configuration <tab> and <s-tab> is now

View File

@ -11,8 +11,6 @@ from UltiSnips.Geometry import Position
from UltiSnips.TextObjects import *
from UltiSnips.Buffer import VimBuffer
from UltiSnips.debug import debug
class Snippet(object):
_INDENT = re.compile(r"^[ \t]*")
@ -51,6 +49,10 @@ class Snippet(object):
v += os.linesep + \
os.linesep.join([indent + l for l in lines[1:]])
if vim.eval("&expandtab") == '1':
ts = int(vim.eval("&ts"))
v = v.expandtabs(ts)
if parent is None:
return SnippetInstance(StartMarker(start), indent, v)
else:
@ -242,11 +244,21 @@ class SnippetManager(object):
# Another thing that might have happened is that a word
# wrapped, in this case the last line is shortened and we must
# delete what vim deleted there
# delete what Vim deleted there
line_was_shortened = len(self._vstate.last_line) > len(lline)
# Another thing that might have happened is that vim has
# adjusted the indent of the last line and therefore the line
# effectivly got longer. This means a newline was entered and
# we quite definitivly do not want the indent that vim added
line_was_lengthened = len(lline) > len(self._vstate.last_line)
user_didnt_enter_newline = len(lline) != self._vstate.ppos.col
if line_was_shortened and user_didnt_enter_newline:
cline = vim.current.buffer[self._vstate.pos.line]
if line_was_lengthened:
this_entered = vim.current.line[:self._vstate.pos.col]
self._chars_entered('\n' + cline + this_entered, 1)
if line_was_shortened and user_didnt_enter_newline:
self._backspace(len(self._vstate.last_line)-len(lline))
self._chars_entered('\n' + cline, 1)
else:

39
test.py
View File

@ -457,10 +457,44 @@ class TabStop_VimScriptInterpolation_SimpleExample(_VimTest):
wanted = " hi 4 End"
# TODO: pasting with <C-R> while mirroring, also multiline
# TODO: expandtab and therelikes
# TODO: check for noexpandtab and indentexpr alone when
# there is no tab in the snippet
# TODO: Multiline text pasting
# TODO: option to avoid snippet expansion when not only indent in front
#############
# EXPANDTAB #
#############
class _ExpandTabs(_VimTest):
def _options_on(self):
self.send(":set ts=3\n")
self.send(":set expandtab\n")
def _options_off(self):
self.send(":set ts=8\n")
self.send(":set noexpandtab\n")
class RecTabStopsWithExpandtab_SimpleExample_ECR(_ExpandTabs):
snippets = ("m", "\tBlaahblah \t\t ")
keys = "m" + EX
wanted = " Blaahblah "
class RecTabStopsWithExpandtab_SpecialIndentProblem_ECR(_ExpandTabs):
snippets = (
("m1", "Something"),
("m", "\t$0"),
)
keys = "m" + EX + "m1" + EX + '\nHallo'
wanted = " Something\n Hallo"
def _options_on(self):
_ExpandTabs._options_on(self)
self.send(":set indentkeys=o,O,*<Return>,<>>,{,}\n")
self.send(":set indentexpr=8\n")
def _options_off(self):
_ExpandTabs._options_off(self)
self.send(":set indentkeys=\n")
self.send(":set indentexpr=\n")
###############################
# Recursive (Nested) Snippets #
@ -629,8 +663,6 @@ class RecTabStops_MirroredZeroTS_ECR(_VimTest):
JF + "three" + JF + "end"
wanted = "[ [ hi two ] three ]end"
###########
# MIRRORS #
###########
@ -977,7 +1009,6 @@ class ProperIndenting_AutoIndentAndNewline_ECR(_VimTest):
self.send(":set autoindent\n")
def _options_off(self):
self.send(":set noautoindent\n")
_VimTest.tearDown(self)
####################
# COMPLETION TESTS #