TextObjects.py no longer needs the vim module. Now the VimBuffer also needs removing

This commit is contained in:
Holger Rapp 2009-07-09 10:20:25 +02:00
parent 384a8d563a
commit 130706b915
3 changed files with 18 additions and 33 deletions

View File

@ -1,16 +1,11 @@
#!/usr/bin/env python
# encoding: utf-8
# TODO: this shouldn't be here
import vim
import re
from PySnipEmu.Buffer import VimBuffer, TextBuffer
from PySnipEmu.Geometry import Range, Position
from PySnipEmu.debug import debug
__all__ = [ "Mirror", "Transformation", "SnippetInstance" ]
class TextObject(object):
@ -62,7 +57,7 @@ class TextObject(object):
if self._end.line == 0:
return ps + self._end
else:
return Position(ps.line + self._end.line, self._start.col)
return Position(ps.line + self._end.line, self._end.col)
return self._end
abs_end = property(abs_end)
@ -398,8 +393,6 @@ class SnippetInstance(TextObject):
col -= self.start.col
start = Position(delta.line, col)
end = Position(delta.line, col)
debug("Adding zero Tabstop!")
debug("start: %s, end: %s" % (start, end))
ts = TabStop(self, start, end, "")
self.add_tabstop(0,ts)
@ -415,19 +408,6 @@ class SnippetInstance(TextObject):
return None
current_tab = property(current_tab)
def update(self, buf, cur):
TextObject.update(self, buf)
cts = self._tabstops[self._cts]
cursor = self.start + cts.end
if cts.end.line != 0:
cursor.col -= self.start.col
lineno, col = cursor.line, cursor.col
vim.current.window.cursor = lineno +1, col
def has_tabs(self):
return len(self._children) > 0
@ -460,24 +440,21 @@ class SnippetInstance(TextObject):
self._tab_selected = True
return self._tabstops[self._cts]
def backspace(self,count, previous_cp):
def backspace(self,count):
cts = self._tabstops[self._cts]
cts.current_text = cts.current_text[:-count]
self.update(self._vb, previous_cp)
self.update(self._vb)
def chars_entered(self, chars, cur):
def chars_entered(self, chars):
cts = self._tabstops[self._cts]
debug("chars_entered");
if self._tab_selected:
cts.current_text = chars
debug("cts.current_text: %s" % (cts.current_text))
self._tab_selected = False
else:
cts.current_text += chars
debug("cts.current_text: %s" % (cts.current_text))
self.update(self._vb, cur)
self.update(self._vb)

View File

@ -285,6 +285,7 @@ class SnippetManager(object):
self._expect_move_wo_change = True
self._csnippet = snippet.launch(before.rstrip()[:-len(word)], after)
self._ctab = None
# TODO: this code is duplicated above
if self._csnippet is not None:
@ -334,17 +335,20 @@ class SnippetManager(object):
# user
cache_pos = vim.current.window.cursor
del vim.current.buffer[self._vstate.pos.line-1]
self._csnippet.chars_entered('\n', self._vstate)
self._csnippet.chars_entered('\n')
vim.current.window.cursor = cache_pos
elif self._vstate.moved.col < 0: # Some deleting was going on
self._csnippet.backspace(-self._vstate.moved.col,
self._vstate)
self._csnippet.backspace(-self._vstate.moved.col)
else:
line = vim.current.line
chars = line[self._vstate.pos.col - self._vstate.moved.col:
self._vstate.pos.col]
self._csnippet.chars_entered(chars, self._vstate)
self._csnippet.chars_entered(chars)
ct_end = self._ctab.abs_end
vim.current.window.cursor = ct_end.line +1, ct_end.col
self._vstate.update()
@ -364,7 +368,7 @@ class SnippetManager(object):
if self._csnippet and self._csnippet.tab_selected:
# This only happens when a default value is delted using backspace
vim.command(r'call feedkeys("i")')
self._csnippet.chars_entered('', self._vstate)
self._csnippet.chars_entered('')
self._vstate.update()
else:
vim.command(r'call feedkeys("\<BS>")')

View File

@ -145,6 +145,10 @@ class TabStopSimpleReplaceSurrounded1_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "hallo $0 a small feed")
keys = "hallo\tNase"
wanted = "hallo Nase a small feed"
class TabStopSimpleReplaceEndingWithNewline_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "Hallo Welt\n")
keys = "hallo\t\nAnd more"
wanted = "Hallo Welt\n\nAnd more"
class ExitTabStop_ExceptCorrectResult(_VimTest):