Only one critical known bug remaining in recursive expansion
This commit is contained in:
parent
118045a24a
commit
3f760eaebf
@ -156,18 +156,20 @@ class VimState(object):
|
|||||||
|
|
||||||
class SnippetManager(object):
|
class SnippetManager(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self._vstate = VimState()
|
||||||
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
self._vstate = VimState()
|
|
||||||
self._ctab = None
|
|
||||||
|
|
||||||
self._expect_move_wo_change = False
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._snippets = {}
|
self._snippets = {}
|
||||||
self._csnippets = []
|
self._csnippets = []
|
||||||
|
self._reinit()
|
||||||
|
|
||||||
|
def _reinit(self):
|
||||||
self._ctab = None
|
self._ctab = None
|
||||||
self._span_selected = None
|
self._span_selected = None
|
||||||
|
self._expect_move_wo_change = False
|
||||||
|
|
||||||
|
|
||||||
def add_snippet(self, trigger, value, descr):
|
def add_snippet(self, trigger, value, descr):
|
||||||
@ -179,8 +181,10 @@ class SnippetManager(object):
|
|||||||
|
|
||||||
def jump(self, backwards = False):
|
def jump(self, backwards = False):
|
||||||
if self._cs:
|
if self._cs:
|
||||||
|
debug("jump: self._cs: %s" % (self._cs))
|
||||||
self._expect_move_wo_change = True
|
self._expect_move_wo_change = True
|
||||||
self._ctab = self._cs.select_next_tab(backwards)
|
self._ctab = self._cs.select_next_tab(backwards)
|
||||||
|
debug(" self._ctab: %s" % (self._ctab))
|
||||||
if self._ctab:
|
if self._ctab:
|
||||||
self._vstate.select_span(self._ctab.abs_span)
|
self._vstate.select_span(self._ctab.abs_span)
|
||||||
self._span_selected = self._ctab.abs_span
|
self._span_selected = self._ctab.abs_span
|
||||||
@ -300,17 +304,25 @@ class SnippetManager(object):
|
|||||||
else:
|
else:
|
||||||
vim.command(r'call feedkeys("\<BS>")')
|
vim.command(r'call feedkeys("\<BS>")')
|
||||||
|
|
||||||
|
def _check_if_still_inside_snippet(self):
|
||||||
|
# Cursor moved without input.
|
||||||
|
self._ctab = None
|
||||||
|
|
||||||
|
# Did we leave the snippet with this movement?
|
||||||
|
if self._cs and not (self._vstate.pos in self._cs.abs_span):
|
||||||
|
debug("popping: self._cs: %s" % (self._cs))
|
||||||
|
debug(" self._csni: %s" % (self._csnippets))
|
||||||
|
self._csnippets.pop()
|
||||||
|
|
||||||
|
self._reinit()
|
||||||
|
|
||||||
|
self._check_if_still_inside_snippet()
|
||||||
|
|
||||||
def cursor_moved(self):
|
def cursor_moved(self):
|
||||||
self._vstate.update()
|
self._vstate.update()
|
||||||
|
|
||||||
if not self._vstate.buf_changed and not self._expect_move_wo_change:
|
if not self._vstate.buf_changed and not self._expect_move_wo_change:
|
||||||
# Cursor moved without input.
|
self._check_if_still_inside_snippet()
|
||||||
self._ctab = None
|
|
||||||
|
|
||||||
# Did we leave the snippet with this movement?
|
|
||||||
if self._cs and not \
|
|
||||||
(self._vstate.pos in self._cs.abs_span):
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
if not self._ctab:
|
if not self._ctab:
|
||||||
return
|
return
|
||||||
@ -356,7 +368,8 @@ class SnippetManager(object):
|
|||||||
def entered_insert_mode(self):
|
def entered_insert_mode(self):
|
||||||
self._vstate.update()
|
self._vstate.update()
|
||||||
if self._cs and self._vstate.has_moved:
|
if self._cs and self._vstate.has_moved:
|
||||||
self.reset()
|
self._reinit()
|
||||||
|
self._csnippets = []
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# Private/Protect Functions Below #
|
# Private/Protect Functions Below #
|
||||||
|
42
test.py
42
test.py
@ -42,7 +42,7 @@ class _VimTest(unittest.TestCase):
|
|||||||
text_after = " --- some text after --- "
|
text_after = " --- some text after --- "
|
||||||
wanted = ""
|
wanted = ""
|
||||||
keys = ""
|
keys = ""
|
||||||
sleeptime = 0.01
|
sleeptime = 0.03
|
||||||
|
|
||||||
def send(self,s):
|
def send(self,s):
|
||||||
send(s, self.session)
|
send(s, self.session)
|
||||||
@ -227,7 +227,7 @@ class TabStopUsingBackspaceToDeleteDefaultValue_ECR(_VimTest):
|
|||||||
keys = "test" + EX + BS
|
keys = "test" + EX + BS
|
||||||
wanted = "snip "
|
wanted = "snip "
|
||||||
class TabStopUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest):
|
class TabStopUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest):
|
||||||
sleeptime = 0.05 # Do this very slowly
|
sleeptime = 0.09 # Do this very slowly
|
||||||
snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
|
||||||
"${1:default} ${2:def}")
|
"${1:default} ${2:def}")
|
||||||
keys = "test" + EX + BS + JF + "hi"
|
keys = "test" + EX + BS + JF + "hi"
|
||||||
@ -374,7 +374,7 @@ class TabStop_Shell_TextInNextLine(_VimTest):
|
|||||||
keys = "test" + EX + "and more"
|
keys = "test" + EX + "and more"
|
||||||
wanted = "hi hallo\nWeiterand more"
|
wanted = "hi hallo\nWeiterand more"
|
||||||
class TabStop_Shell_InDefValue_Leave(_VimTest):
|
class TabStop_Shell_InDefValue_Leave(_VimTest):
|
||||||
sleeptime = 0.05 # Do this very slowly
|
sleeptime = 0.09 # Do this very slowly
|
||||||
snippets = ("test", "Hallo ${1:now `echo fromecho`} end")
|
snippets = ("test", "Hallo ${1:now `echo fromecho`} end")
|
||||||
keys = "test" + EX + JF + "and more"
|
keys = "test" + EX + JF + "and more"
|
||||||
wanted = "Hallo now fromecho endand more"
|
wanted = "Hallo now fromecho endand more"
|
||||||
@ -384,7 +384,7 @@ class TabStop_Shell_InDefValue_Overwrite(_VimTest):
|
|||||||
wanted = "Hallo overwrite endand more"
|
wanted = "Hallo overwrite endand more"
|
||||||
|
|
||||||
class TabStop_Shell_ShebangPython(_VimTest):
|
class TabStop_Shell_ShebangPython(_VimTest):
|
||||||
sleeptime = 0.05 # Do this very slowly
|
sleeptime = 0.09 # Do this very slowly
|
||||||
snippets = ("test", """Hallo ${1:now `#!/usr/bin/env python
|
snippets = ("test", """Hallo ${1:now `#!/usr/bin/env python
|
||||||
print "Hallo Welt"
|
print "Hallo Welt"
|
||||||
`} end""")
|
`} end""")
|
||||||
@ -420,10 +420,6 @@ class TabStop_VimScriptInterpolation_SimpleExample(_VimTest):
|
|||||||
# TODO: Multiline text pasting
|
# TODO: Multiline text pasting
|
||||||
|
|
||||||
|
|
||||||
print "Recursive Tabstops: TODO: this will still take some time"
|
|
||||||
# TODO: leaving all nested snippets at onec
|
|
||||||
# TODO: only leaving one nested snippet
|
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
# Recursive (Nested) Snippets #
|
# Recursive (Nested) Snippets #
|
||||||
###############################
|
###############################
|
||||||
@ -530,6 +526,36 @@ class RecTabStops_InNewlineInTabstopNotAtBeginOfLine_ECR(_VimTest):
|
|||||||
# keys = "m" + EX + "m" + EX
|
# keys = "m" + EX + "m" + EX
|
||||||
# wanted = "M START\n M START\n"
|
# wanted = "M START\n M START\n"
|
||||||
|
|
||||||
|
print "Recursive Tabstops: TODO: this will still take some time"
|
||||||
|
|
||||||
|
class RecTabStops_BarelyNotLeavingInner_ECR(_VimTest):
|
||||||
|
snippets = (
|
||||||
|
("m", "[ ${1:first} ${2:sec} ]"),
|
||||||
|
)
|
||||||
|
keys = "m" + EX + "m" + EX + "a" + 3*ARR_L + JF + "hallo" + \
|
||||||
|
JF + "world" + JF + "end"
|
||||||
|
wanted = "[ [ a hallo ] world ]end"
|
||||||
|
class RecTabStops_LeavingInner_ECR(_VimTest):
|
||||||
|
snippets = (
|
||||||
|
("m", "[ ${1:first} ${2:sec} ]"),
|
||||||
|
)
|
||||||
|
keys = "m" + EX + "m" + EX + "a" + 4*ARR_L + JF + "hallo" + \
|
||||||
|
JF + "world"
|
||||||
|
wanted = "[ [ a sec ] hallo ]world"
|
||||||
|
class RecTabStops_LeavingInnerInner_ECR(_VimTest):
|
||||||
|
snippets = (
|
||||||
|
("m", "[ ${1:first} ${2:sec} ]"),
|
||||||
|
)
|
||||||
|
keys = "m" + EX + "m" + EX + "m" + EX + "a" + 4*ARR_L + JF + "hallo" + \
|
||||||
|
JF + "world" + JF + "end"
|
||||||
|
wanted = "[ [ [ a sec ] hallo ] world ]end"
|
||||||
|
class RecTabStops_LeavingInnerInnerTwo_ECR(_VimTest):
|
||||||
|
snippets = (
|
||||||
|
("m", "[ ${1:first} ${2:sec} ]"),
|
||||||
|
)
|
||||||
|
keys = "m" + EX + "m" + EX + "m" + EX + "a" + 6*ARR_L + JF + "hallo" + \
|
||||||
|
JF + "end"
|
||||||
|
wanted = "[ [ [ a sec ] sec ] hallo ]end"
|
||||||
|
|
||||||
|
|
||||||
class RecTabStops_IgnoreZeroTS_ECR(_VimTest):
|
class RecTabStops_IgnoreZeroTS_ECR(_VimTest):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user