Remove Span class

It was not really in much use
This commit is contained in:
Holger Rapp 2012-01-22 13:26:36 +01:00
parent f8d6285e49
commit 400ac852d2
4 changed files with 20 additions and 60 deletions

View File

@ -23,7 +23,7 @@ class TextBuffer(object):
new_end = Position(start.line + len(text)-1, len(text[-1]))
return new_end
def to_vim(self, start, end): # TODO: better take a span
def to_vim(self, start, end):
buf = vim.current.buffer
# Open any folds this might have created

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
__all__ = [ "Position", "Span" ]
__all__ = [ "Position" ]
class Position(object):
def __init__(self, line, col):
@ -80,33 +80,6 @@ class Position(object):
def __repr__(self):
return "(%i,%i)" % (self._line, self._col)
class Span(object):
def __init__(self, start, end):
self._s = start
self._e = end
def __contains__(self, pos):
return self._s <= pos <= self._e
def start():
def fget(self):
return self._s
def fset(self, value):
self._s = value
return locals()
start = property(**start())
def end():
def fget(self):
return self._e
def fset(self, value):
self._e = value
return locals()
end = property(**end())
def __repr__(self):
return "(%s -> %s)" % (self._s, self._e)
import unittest
class _MPBase(object):

View File

@ -5,7 +5,7 @@ import vim
from UltiSnips.Buffer import TextBuffer
from UltiSnips.Compatibility import as_unicode
from UltiSnips.Geometry import Span, Position
from UltiSnips.Geometry import Position
__all__ = ["TextObject", "EditableTextObject", "NoneditableTextObject"]
@ -66,22 +66,17 @@ class TextObject(object):
##############
@property
def current_text(self):
_span = self.span
buf = vim.current.buffer
if _span.start.line == _span.end.line:
return as_unicode(buf[_span.start.line])[_span.start.col:_span.end.col]
if self._start.line == self._end.line:
return as_unicode(buf[self._start.line])[self._start.col:self._end.col]
else:
lines = []
lines.append(as_unicode(buf[_span.start.line])[_span.start.col:])
lines.extend(map(as_unicode, buf[_span.start.line+1:_span.end.line]))
lines.append(as_unicode(buf[_span.end.line])[:_span.end.col])
lines.append(as_unicode(buf[self._start.line])[self._start.col:])
lines.extend(map(as_unicode, buf[self._start.line+1:self._end.line]))
lines.append(as_unicode(buf[self._end.line])[:self._end.col])
return as_unicode('\n').join(lines)
def span(self):
return Span(self._start, self._end)
span = property(span)
def start(self):
return self._start
start = property(start)
@ -119,8 +114,6 @@ class EditableTextObject(TextObject):
# Public Functions #
####################
def find_parent_for_new_to(self, pos):
assert(pos in self.span)
for c in self._editable_childs:
if (c._start <= pos < c._end):
return c.find_parent_for_new_to(pos)

View File

@ -3,6 +3,7 @@
# TODO: Currently Caches whole buffer. Is this really needed?
# TODO: Currently searches whole buffer. Is this really needed?
# TODO: hijack two marks instead of running through the whole buffer
import edit_distance
from debug import debug, echo_to_hierarchy
@ -16,7 +17,7 @@ import traceback
import vim
from UltiSnips.Geometry import Position, Span
from UltiSnips.Geometry import Position
from UltiSnips.Compatibility import make_suitable_for_vim, set_vim_cursor, vim_cursor
from UltiSnips.TextObjects import *
from UltiSnips.Buffer import TextBuffer
@ -68,11 +69,11 @@ def echom(mes, *args):
# TODO: all the vim wrapper functions should go into one module
# TODO: this function should be moved
def select_span(r):
def select(start, end):
_unmap_select_mode_mapping()
delta = r.end - r.start
lineno, col = r.start.line, r.start.col
delta = end - start
lineno, col = start.line, start.col
set_vim_cursor(lineno + 1, col)
@ -114,14 +115,14 @@ def select_span(r):
# one column less since Vim's visual selection is including the
# ending while Python slicing is excluding the ending.
inclusive = "inclusive" in vim.eval("&selection")
if r.end.col == 0:
if end.col == 0:
# Selecting should end at beginning of line -> Select the
# previous line till its end
do_select = "k$"
if not inclusive:
do_select += "j0"
elif r.end.col > 1:
do_select = "0%il" % (r.end.col-1 if inclusive else r.end.col)
elif end.col > 1:
do_select = "0%il" % (end.col-1 if inclusive else end.col)
else:
do_select = "0" if inclusive else "0l"
@ -829,14 +830,11 @@ class SnippetManager(object):
self._vstate.update()
debug("vim.eval('mode()'): %r" % (vim.eval('mode()')))
debug("in cursor_moved self._vstate.pos: %r" % (self._vstate.pos))
# TODO: hijack two marks instead of running through the whole buffer
if vim.eval("mode()") not in 'in':
return
# TODO: really necessary?
if self._ignore_movements:
debug("Ignored")
self._ignore_movements = False
return
@ -884,7 +882,7 @@ class SnippetManager(object):
debug("Before edits!")
echo_to_hierarchy(self._csnippets[-1])
self._csnippets[0].update_textobjects()
self._lvb = TextBuffer('\n'.join(vim.current.buffer)) # TODO: no need to cache everything and not on every movement?
self._lvb = TextBuffer('\n'.join(vim.current.buffer))
self._vstate.update()
def leaving_window(self):
@ -923,10 +921,7 @@ class SnippetManager(object):
def _check_if_still_inside_snippet(self):
# Did we leave the snippet with this movement?
if self._cs:
debug("self._cs.span: %r" % (self._cs.span))
debug("self._vstate.pos: %r" % (self._vstate.pos))
if self._cs and not (self._vstate.pos in self._cs.span):
if self._cs and not self._cs.start <= self._vstate.pos <= self._cs.end:
self._current_snippet_is_done()
self._reinit()
@ -945,7 +940,7 @@ class SnippetManager(object):
if self._cs:
self._ctab = self._cs.select_next_tab(backwards)
if self._ctab:
select_span(self._ctab.span)
select(self._ctab.start, self._ctab.end)
jumped = True
if self._ctab.no == 0:
self._current_snippet_is_done()
@ -1067,7 +1062,6 @@ class SnippetManager(object):
start = Position(lineno-1, len(text_before))
end = Position(lineno-1, len(before))
# TODO: private parts? maybe handle this in add_child
si = snippet.launch(text_before, self._visual_content,
self._cs.find_parent_for_new_to(start), start, end)
self._visual_content.reset()
@ -1080,7 +1074,7 @@ class SnippetManager(object):
self._visual_content.reset()
self._ignore_movements = True
self._lvb = TextBuffer('\n'.join(vim.current.buffer)) # TODO: no need to cache everything
self._lvb = TextBuffer('\n'.join(vim.current.buffer))
self._jump()