From f308e96832bfaee89fc28179afad17fb6b9d3e82 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sat, 4 Jul 2009 23:01:23 +0200 Subject: [PATCH] Fixed a bug when tabstops were behind mirrors --- PySnippets/python.snippets | 25 +++++++++++++++++++++++++ plugin/PySnipEmu.py | 33 ++++++++++++++++++++++++--------- test.py | 25 +++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/PySnippets/python.snippets b/PySnippets/python.snippets index 715e53c..4c884c6 100644 --- a/PySnippets/python.snippets +++ b/PySnippets/python.snippets @@ -19,6 +19,8 @@ if __name__ == '__main__': ${1:main()}$0 endsnippet +# self. + ########################## # Try / Except / Finally # ########################## @@ -58,3 +60,26 @@ finally: ${7:pass} endsnippet +############## +# Assertions # +############## +snippet ae +self.assertEqual(${1:first},${2:second}) +endsnippet + +snippet at +self.assertTrue(${0:exp}) +endsnippet + +snippet af +self.assertFalse(${1:expression}) +endsnippet + +snippet aae +self.assertAlmostEqual(${1:first},${2:second}) +endsnippet + +snippet ar +self.assertRaises(${1:exception}, ${2:func}${3/.+/, /}${3:arguments}) +endsnippet + diff --git a/plugin/PySnipEmu.py b/plugin/PySnipEmu.py index a4d6ba1..210e40f 100644 --- a/plugin/PySnipEmu.py +++ b/plugin/PySnipEmu.py @@ -141,6 +141,12 @@ class TextObject(object): self._current_text = initial_text + def __cmp__(self, other): + s = self._start.line, self._start.col + o = other._start.line, other._start.col + + return cmp(s, o) + def _do_update(self): pass @@ -149,11 +155,14 @@ class TextObject(object): if not self._has_parsed: self._current_text = TextBuffer(self._parse(self._current_text)) - for c in self._children: + debug("In update:") + for idx,c in enumerate(self._children): + debug("Updating children:") + debug(" c: %s" % c ) oldend = Position(c.end.line, c.end.col) moved_lines, moved_cols = c.update(self._current_text) - self._move_textobjects_behind(oldend, moved_lines, moved_cols, c) + self._move_textobjects_behind(c.start, oldend, moved_lines, moved_cols, idx) self._do_update() @@ -163,18 +172,24 @@ class TextObject(object): moved_lines = new_end.line - self._end.line moved_cols = new_end.col - self._end.col + debug(" self: %s, ct: %s" % (self, self._current_text)) + debug(" new_end: %s" % (new_end)) + self._end = new_end return moved_lines, moved_cols - def _move_textobjects_behind(self, end, lines, cols, obj): + def _move_textobjects_behind(self, start, end, lines, cols, obj_idx): if lines == 0 and cols == 0: return - for m in self._children: - if m == obj: - continue + debug("In _move_textobjects_behind") + debug(" childs: %s" % self._children) + debug(" obj_idx: %i" % obj_idx) + for idx,m in enumerate(self._children[:]): + if idx == obj_idx: + continue delta_lines = 0 delta_cols_begin = 0 delta_cols_end = 0 @@ -188,8 +203,8 @@ class TextObject(object): delta_cols_begin = cols if m.start.line == m.end.line: delta_cols_end = cols - # debug(" Moving %s: %i (b: %i, e: %i)" % ( - # m, delta_lines, delta_cols_begin, delta_cols_end)) + debug(" Moving %s: %i (b: %i, e: %i)" % ( + m, delta_lines, delta_cols_begin, delta_cols_end)) m.start.line += delta_lines m.end.line += delta_lines m.start.col += delta_cols_begin @@ -291,6 +306,7 @@ class TextObject(object): def add_child(self,c): self._children.append(c) + self._children.sort() def parent(): doc = "The parent TextObject this TextObject resides in" @@ -779,7 +795,6 @@ class SnippetManager(object): return True def cursor_moved(self): - debug("Cursor moved!") self._cursor.update_position() if len(self._current_snippets) and (self._cursor.has_moved): diff --git a/test.py b/test.py index 66bac74..f4d29c9 100755 --- a/test.py +++ b/test.py @@ -474,6 +474,31 @@ class Transformation_MultipleTransformations_ECR(_VimTest): def cmd(self): self.type("test\tSomE tExt ") def runTest(self): self.check_output() +class Transformation_TabIsAtEndAndDeleted_ECR(_VimTest): + snippets = ("test", "${1/.+/is something/}${1:some}") + wanted = "hallo " + def cmd(self): + self.type("hallo test\tsome\b\b\b\b\b") + def runTest(self): self.check_output() +class Transformation_TabIsAtEndAndDeleted1_ECR(_VimTest): + snippets = ("test", "${1/.+/is something/}${1:some}") + wanted = "hallo is somethingmore" + def cmd(self): + self.type("hallo test\tsome\b\b\b\bmore") + def runTest(self): self.check_output() +class Transformation_TabIsAtEndNoTextLeave_ECR(_VimTest): + snippets = ("test", "${1/.+/is something/}${1}") + wanted = "hallo " + def cmd(self): + self.type("hallo test\t") + def runTest(self): self.check_output() +class Transformation_TabIsAtEndNoTextType_ECR(_VimTest): + snippets = ("test", "${1/.+/is something/}${1}") + wanted = "hallo is somethingb" + def cmd(self): + self.type("hallo test\tb") + def runTest(self): self.check_output() + class Transformation_Backreference_ExceptCorrectResult(_VimTest): snippets = ("test", "$1 ${1/([ab])oo/$1ull/}")