- 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:
parent
274ef83833
commit
8fb1412791
@ -1,3 +1,5 @@
|
|||||||
|
- UltiSnips now adheres to expandtab and tabstop options of vim
|
||||||
|
|
||||||
version 1.1:
|
version 1.1:
|
||||||
- Made triggers configurable. You can also use the same trigger for
|
- Made triggers configurable. You can also use the same trigger for
|
||||||
expanding and tabbing. The TextMate configuration <tab> and <s-tab> is now
|
expanding and tabbing. The TextMate configuration <tab> and <s-tab> is now
|
||||||
|
@ -11,8 +11,6 @@ from UltiSnips.Geometry import Position
|
|||||||
from UltiSnips.TextObjects import *
|
from UltiSnips.TextObjects import *
|
||||||
from UltiSnips.Buffer import VimBuffer
|
from UltiSnips.Buffer import VimBuffer
|
||||||
|
|
||||||
from UltiSnips.debug import debug
|
|
||||||
|
|
||||||
class Snippet(object):
|
class Snippet(object):
|
||||||
_INDENT = re.compile(r"^[ \t]*")
|
_INDENT = re.compile(r"^[ \t]*")
|
||||||
|
|
||||||
@ -51,6 +49,10 @@ class Snippet(object):
|
|||||||
v += os.linesep + \
|
v += os.linesep + \
|
||||||
os.linesep.join([indent + l for l in lines[1:]])
|
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:
|
if parent is None:
|
||||||
return SnippetInstance(StartMarker(start), indent, v)
|
return SnippetInstance(StartMarker(start), indent, v)
|
||||||
else:
|
else:
|
||||||
@ -242,11 +244,21 @@ class SnippetManager(object):
|
|||||||
|
|
||||||
# Another thing that might have happened is that a word
|
# Another thing that might have happened is that a word
|
||||||
# wrapped, in this case the last line is shortened and we must
|
# 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)
|
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
|
user_didnt_enter_newline = len(lline) != self._vstate.ppos.col
|
||||||
|
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:
|
if line_was_shortened and user_didnt_enter_newline:
|
||||||
cline = vim.current.buffer[self._vstate.pos.line]
|
|
||||||
self._backspace(len(self._vstate.last_line)-len(lline))
|
self._backspace(len(self._vstate.last_line)-len(lline))
|
||||||
self._chars_entered('\n' + cline, 1)
|
self._chars_entered('\n' + cline, 1)
|
||||||
else:
|
else:
|
||||||
|
39
test.py
39
test.py
@ -457,10 +457,44 @@ class TabStop_VimScriptInterpolation_SimpleExample(_VimTest):
|
|||||||
wanted = " hi 4 End"
|
wanted = " hi 4 End"
|
||||||
|
|
||||||
# TODO: pasting with <C-R> while mirroring, also multiline
|
# 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: Multiline text pasting
|
||||||
# TODO: option to avoid snippet expansion when not only indent in front
|
# 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 #
|
# Recursive (Nested) Snippets #
|
||||||
@ -629,8 +663,6 @@ class RecTabStops_MirroredZeroTS_ECR(_VimTest):
|
|||||||
JF + "three" + JF + "end"
|
JF + "three" + JF + "end"
|
||||||
wanted = "[ [ hi two ] three ]end"
|
wanted = "[ [ hi two ] three ]end"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###########
|
###########
|
||||||
# MIRRORS #
|
# MIRRORS #
|
||||||
###########
|
###########
|
||||||
@ -977,7 +1009,6 @@ class ProperIndenting_AutoIndentAndNewline_ECR(_VimTest):
|
|||||||
self.send(":set autoindent\n")
|
self.send(":set autoindent\n")
|
||||||
def _options_off(self):
|
def _options_off(self):
|
||||||
self.send(":set noautoindent\n")
|
self.send(":set noautoindent\n")
|
||||||
_VimTest.tearDown(self)
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# COMPLETION TESTS #
|
# COMPLETION TESTS #
|
||||||
|
Loading…
x
Reference in New Issue
Block a user