From 98a676f8acc1591f8224ef3f7d71dec66f1b8bb5 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Wed, 5 Feb 2014 20:26:33 +0100 Subject: [PATCH] Moved some code from __init__.py into a file of its own. --- plugin/UltiSnips/__init__.py | 53 ++--------------------------------- plugin/UltiSnips/vim_state.py | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 51 deletions(-) create mode 100755 plugin/UltiSnips/vim_state.py diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index d8f473e..e085cb8 100755 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -2,7 +2,7 @@ # encoding: utf-8 from functools import wraps -from collections import deque, defaultdict +from collections import defaultdict import glob import hashlib import os @@ -14,6 +14,7 @@ from UltiSnips._diff import diff, guess_edit from UltiSnips.geometry import Position from UltiSnips.text_objects import SnippetInstance from UltiSnips.util import IndentUtil +from UltiSnips.vim_state import VimState import UltiSnips._vim as _vim def _ask_snippets(snippets): @@ -557,56 +558,6 @@ class VisualContentPreserver(object): def mode(self): return self._mode -class _VimPosition(Position): - def __init__(self): - pos = _vim.buf.cursor - self._mode = _vim.eval("mode()") - self._visualmode = _vim.eval("visualmode()") - Position.__init__(self, pos.line, pos.col) - - @property - def mode(self): - return self._mode - - @property - def visualmode(self): - return self._visualmode - - -class VimState(object): - def __init__(self): - """ - This class caches some state information from Vim to better - guess what editing tasks the user might have done in the last step - """ - self._poss = deque(maxlen=5) - self._lvb = None - - def remember_position(self): - self._poss.append(_VimPosition()) - - def remember_buffer(self, to): - self._lvb = _vim.buf[to.start.line:to.end.line+1] - self._lvb_len = len(_vim.buf) - self.remember_position() - - @property - def diff_in_buffer_length(self): - return len(_vim.buf) - self._lvb_len - - @property - def pos(self): - return self._poss[-1] - - @property - def ppos(self): - return self._poss[-2] - - @property - def remembered_buffer(self): - return self._lvb[:] - - class SnippetManager(object): def __init__(self): self._supertab_keys = None diff --git a/plugin/UltiSnips/vim_state.py b/plugin/UltiSnips/vim_state.py new file mode 100755 index 0000000..87eb888 --- /dev/null +++ b/plugin/UltiSnips/vim_state.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from collections import deque + +from UltiSnips.geometry import Position +import UltiSnips._vim as _vim + +class VimPosition(Position): + def __init__(self): + """Represents the current position in the buffer, together with some + status variables that might change our decisions down the line. """ + pos = _vim.buf.cursor + self._mode = _vim.eval("mode()") + Position.__init__(self, pos.line, pos.col) + + @property + def mode(self): + return self._mode + +class VimState(object): + def __init__(self): + """ + This class caches some state information from Vim to better guess what + editing tasks the user might have done in the last step. + """ + self._poss = deque(maxlen=5) + self._lvb = None + + def remember_position(self): + self._poss.append(VimPosition()) + + def remember_buffer(self, to): + self._lvb = _vim.buf[to.start.line:to.end.line+1] + self._lvb_len = len(_vim.buf) + self.remember_position() + + @property + def diff_in_buffer_length(self): + return len(_vim.buf) - self._lvb_len + + @property + def pos(self): + return self._poss[-1] + + @property + def ppos(self): + return self._poss[-2] + + @property + def remembered_buffer(self): + return self._lvb[:]