Remove Span class
It was not really in much use
This commit is contained in:
parent
f8d6285e49
commit
400ac852d2
@ -23,7 +23,7 @@ class TextBuffer(object):
|
|||||||
new_end = Position(start.line + len(text)-1, len(text[-1]))
|
new_end = Position(start.line + len(text)-1, len(text[-1]))
|
||||||
return new_end
|
return new_end
|
||||||
|
|
||||||
def to_vim(self, start, end): # TODO: better take a span
|
def to_vim(self, start, end):
|
||||||
buf = vim.current.buffer
|
buf = vim.current.buffer
|
||||||
|
|
||||||
# Open any folds this might have created
|
# Open any folds this might have created
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
__all__ = [ "Position", "Span" ]
|
__all__ = [ "Position" ]
|
||||||
|
|
||||||
class Position(object):
|
class Position(object):
|
||||||
def __init__(self, line, col):
|
def __init__(self, line, col):
|
||||||
@ -80,33 +80,6 @@ class Position(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "(%i,%i)" % (self._line, self._col)
|
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
|
import unittest
|
||||||
|
|
||||||
class _MPBase(object):
|
class _MPBase(object):
|
||||||
|
@ -5,7 +5,7 @@ import vim
|
|||||||
|
|
||||||
from UltiSnips.Buffer import TextBuffer
|
from UltiSnips.Buffer import TextBuffer
|
||||||
from UltiSnips.Compatibility import as_unicode
|
from UltiSnips.Compatibility import as_unicode
|
||||||
from UltiSnips.Geometry import Span, Position
|
from UltiSnips.Geometry import Position
|
||||||
|
|
||||||
__all__ = ["TextObject", "EditableTextObject", "NoneditableTextObject"]
|
__all__ = ["TextObject", "EditableTextObject", "NoneditableTextObject"]
|
||||||
|
|
||||||
@ -66,22 +66,17 @@ class TextObject(object):
|
|||||||
##############
|
##############
|
||||||
@property
|
@property
|
||||||
def current_text(self):
|
def current_text(self):
|
||||||
_span = self.span
|
|
||||||
buf = vim.current.buffer
|
buf = vim.current.buffer
|
||||||
|
|
||||||
if _span.start.line == _span.end.line:
|
if self._start.line == self._end.line:
|
||||||
return as_unicode(buf[_span.start.line])[_span.start.col:_span.end.col]
|
return as_unicode(buf[self._start.line])[self._start.col:self._end.col]
|
||||||
else:
|
else:
|
||||||
lines = []
|
lines = []
|
||||||
lines.append(as_unicode(buf[_span.start.line])[_span.start.col:])
|
lines.append(as_unicode(buf[self._start.line])[self._start.col:])
|
||||||
lines.extend(map(as_unicode, buf[_span.start.line+1:_span.end.line]))
|
lines.extend(map(as_unicode, buf[self._start.line+1:self._end.line]))
|
||||||
lines.append(as_unicode(buf[_span.end.line])[:_span.end.col])
|
lines.append(as_unicode(buf[self._end.line])[:self._end.col])
|
||||||
return as_unicode('\n').join(lines)
|
return as_unicode('\n').join(lines)
|
||||||
|
|
||||||
def span(self):
|
|
||||||
return Span(self._start, self._end)
|
|
||||||
span = property(span)
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
return self._start
|
return self._start
|
||||||
start = property(start)
|
start = property(start)
|
||||||
@ -119,8 +114,6 @@ class EditableTextObject(TextObject):
|
|||||||
# Public Functions #
|
# Public Functions #
|
||||||
####################
|
####################
|
||||||
def find_parent_for_new_to(self, pos):
|
def find_parent_for_new_to(self, pos):
|
||||||
assert(pos in self.span)
|
|
||||||
|
|
||||||
for c in self._editable_childs:
|
for c in self._editable_childs:
|
||||||
if (c._start <= pos < c._end):
|
if (c._start <= pos < c._end):
|
||||||
return c.find_parent_for_new_to(pos)
|
return c.find_parent_for_new_to(pos)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# TODO: Currently Caches whole buffer. Is this really needed?
|
# TODO: Currently Caches whole buffer. Is this really needed?
|
||||||
# TODO: Currently searches 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
|
import edit_distance
|
||||||
from debug import debug, echo_to_hierarchy
|
from debug import debug, echo_to_hierarchy
|
||||||
@ -16,7 +17,7 @@ import traceback
|
|||||||
|
|
||||||
import vim
|
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.Compatibility import make_suitable_for_vim, set_vim_cursor, vim_cursor
|
||||||
from UltiSnips.TextObjects import *
|
from UltiSnips.TextObjects import *
|
||||||
from UltiSnips.Buffer import TextBuffer
|
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: all the vim wrapper functions should go into one module
|
||||||
# TODO: this function should be moved
|
# TODO: this function should be moved
|
||||||
def select_span(r):
|
def select(start, end):
|
||||||
_unmap_select_mode_mapping()
|
_unmap_select_mode_mapping()
|
||||||
|
|
||||||
delta = r.end - r.start
|
delta = end - start
|
||||||
lineno, col = r.start.line, r.start.col
|
lineno, col = start.line, start.col
|
||||||
|
|
||||||
set_vim_cursor(lineno + 1, 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
|
# one column less since Vim's visual selection is including the
|
||||||
# ending while Python slicing is excluding the ending.
|
# ending while Python slicing is excluding the ending.
|
||||||
inclusive = "inclusive" in vim.eval("&selection")
|
inclusive = "inclusive" in vim.eval("&selection")
|
||||||
if r.end.col == 0:
|
if end.col == 0:
|
||||||
# Selecting should end at beginning of line -> Select the
|
# Selecting should end at beginning of line -> Select the
|
||||||
# previous line till its end
|
# previous line till its end
|
||||||
do_select = "k$"
|
do_select = "k$"
|
||||||
if not inclusive:
|
if not inclusive:
|
||||||
do_select += "j0"
|
do_select += "j0"
|
||||||
elif r.end.col > 1:
|
elif end.col > 1:
|
||||||
do_select = "0%il" % (r.end.col-1 if inclusive else r.end.col)
|
do_select = "0%il" % (end.col-1 if inclusive else end.col)
|
||||||
else:
|
else:
|
||||||
do_select = "0" if inclusive else "0l"
|
do_select = "0" if inclusive else "0l"
|
||||||
|
|
||||||
@ -829,14 +830,11 @@ class SnippetManager(object):
|
|||||||
self._vstate.update()
|
self._vstate.update()
|
||||||
debug("vim.eval('mode()'): %r" % (vim.eval('mode()')))
|
debug("vim.eval('mode()'): %r" % (vim.eval('mode()')))
|
||||||
debug("in cursor_moved self._vstate.pos: %r" % (self._vstate.pos))
|
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':
|
if vim.eval("mode()") not in 'in':
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO: really necessary?
|
|
||||||
if self._ignore_movements:
|
if self._ignore_movements:
|
||||||
debug("Ignored")
|
|
||||||
self._ignore_movements = False
|
self._ignore_movements = False
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -884,7 +882,7 @@ class SnippetManager(object):
|
|||||||
debug("Before edits!")
|
debug("Before edits!")
|
||||||
echo_to_hierarchy(self._csnippets[-1])
|
echo_to_hierarchy(self._csnippets[-1])
|
||||||
self._csnippets[0].update_textobjects()
|
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()
|
self._vstate.update()
|
||||||
|
|
||||||
def leaving_window(self):
|
def leaving_window(self):
|
||||||
@ -923,10 +921,7 @@ class SnippetManager(object):
|
|||||||
|
|
||||||
def _check_if_still_inside_snippet(self):
|
def _check_if_still_inside_snippet(self):
|
||||||
# Did we leave the snippet with this movement?
|
# Did we leave the snippet with this movement?
|
||||||
if self._cs:
|
if self._cs and not self._cs.start <= self._vstate.pos <= self._cs.end:
|
||||||
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):
|
|
||||||
self._current_snippet_is_done()
|
self._current_snippet_is_done()
|
||||||
|
|
||||||
self._reinit()
|
self._reinit()
|
||||||
@ -945,7 +940,7 @@ class SnippetManager(object):
|
|||||||
if self._cs:
|
if self._cs:
|
||||||
self._ctab = self._cs.select_next_tab(backwards)
|
self._ctab = self._cs.select_next_tab(backwards)
|
||||||
if self._ctab:
|
if self._ctab:
|
||||||
select_span(self._ctab.span)
|
select(self._ctab.start, self._ctab.end)
|
||||||
jumped = True
|
jumped = True
|
||||||
if self._ctab.no == 0:
|
if self._ctab.no == 0:
|
||||||
self._current_snippet_is_done()
|
self._current_snippet_is_done()
|
||||||
@ -1067,7 +1062,6 @@ class SnippetManager(object):
|
|||||||
start = Position(lineno-1, len(text_before))
|
start = Position(lineno-1, len(text_before))
|
||||||
end = Position(lineno-1, len(before))
|
end = Position(lineno-1, len(before))
|
||||||
|
|
||||||
# TODO: private parts? maybe handle this in add_child
|
|
||||||
si = snippet.launch(text_before, self._visual_content,
|
si = snippet.launch(text_before, self._visual_content,
|
||||||
self._cs.find_parent_for_new_to(start), start, end)
|
self._cs.find_parent_for_new_to(start), start, end)
|
||||||
self._visual_content.reset()
|
self._visual_content.reset()
|
||||||
@ -1080,7 +1074,7 @@ class SnippetManager(object):
|
|||||||
self._visual_content.reset()
|
self._visual_content.reset()
|
||||||
|
|
||||||
self._ignore_movements = True
|
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()
|
self._jump()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user