From a4f8e12c248c1bf3918acd49f936032a0387bfaa Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 22 Jan 2012 19:02:31 +0100 Subject: [PATCH] VimBuffer.cursor.line is no 0 based --- plugin/UltiSnips/__init__.py | 13 +++++-------- plugin/UltiSnips/_vim.py | 15 +++++++++------ .../UltiSnips/text_objects/_snippet_instance.py | 5 ++--- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 05df326..1cc30b2 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -676,9 +676,8 @@ class SnippetManager(object): def _check_if_still_inside_snippet(self): # Did we leave the snippet with this movement? - line, col = _vim.buf.cursor if self._cs and ( - not self._cs.start <= Position(line - 1, col) <= self._cs.end + not self._cs.start <= _vim.buf.cursor <= self._cs.end ): self._current_snippet_is_done() self._reinit() @@ -789,9 +788,7 @@ class SnippetManager(object): """ Expands the given snippet, and handles everything that needs to be done with it. """ - lineno, col = _vim.buf.cursor # Adjust before, maybe the trigger is not the complete word - text_before = before if snippet.matched: text_before = before[:-len(snippet.matched)] @@ -799,8 +796,8 @@ class SnippetManager(object): self._unset_offending_vim_options(snippet) if self._cs: - start = Position(lineno-1, len(text_before)) - end = Position(lineno-1, len(before)) + start = Position(_vim.buf.cursor.line, len(text_before)) + end = Position(_vim.buf.cursor.line, len(before)) si = snippet.launch(text_before, self._visual_content, self._cs.find_parent_for_new_to(start), start, end) @@ -808,8 +805,8 @@ class SnippetManager(object): self._csnippets.append(si) else: - start = Position(lineno-1, len(text_before)) - end = Position(lineno-1, len(before)) + start = Position(_vim.buf.cursor.line, len(text_before)) + end = Position(_vim.buf.cursor.line, len(before)) self._csnippets.append(snippet.launch(text_before, self._visual_content, None, start, end)) self._visual_content.reset() diff --git a/plugin/UltiSnips/_vim.py b/plugin/UltiSnips/_vim.py index 245aa0c..981e410 100755 --- a/plugin/UltiSnips/_vim.py +++ b/plugin/UltiSnips/_vim.py @@ -42,14 +42,17 @@ class VimBuffer(object): return before, after def cursor(): - """The current windows cursor""" + """ + The current windows cursor. Note that this is 0 based in col and 0 + based in line which is different from Vim's cursor. + """ def fget(self): - return vim_cursor() - def fset(self, value): - set_vim_cursor(*value) + line, col = vim_cursor() + return Position(line - 1, col) + def fset(self, pos): + set_vim_cursor(pos.line + 1, pos.col) return locals() cursor = property(**cursor()) - buf = VimBuffer() @@ -195,7 +198,7 @@ def text_to_vim(start, end, text): # Open any folds this might have created debug("start: %r" % (start)) - buf.cursor = start.line + 1, start.col + buf.cursor = start vim.command("normal zv") new_end = _calc_end(lines, start) diff --git a/plugin/UltiSnips/text_objects/_snippet_instance.py b/plugin/UltiSnips/text_objects/_snippet_instance.py index 6a379b1..056e275 100755 --- a/plugin/UltiSnips/text_objects/_snippet_instance.py +++ b/plugin/UltiSnips/text_objects/_snippet_instance.py @@ -116,12 +116,11 @@ class _VimCursor(NoneditableTextObject): """Helper class to keep track of the Vim Cursor""" def __init__(self, parent): - line, col = _vim.buf.cursor NoneditableTextObject.__init__( - self, parent, Position(line-1, col), Position(line-1, col) + self, parent, _vim.buf.cursor, _vim.buf.cursor ) def to_vim(self): assert(self._start == self._end) - _vim.buf.cursor = self._start.line + 1, self._start.col + _vim.buf.cursor = self._start