Moved some code from __init__.py into a file of its own.

This commit is contained in:
Holger Rapp 2014-02-05 20:26:33 +01:00
parent a408ba5ce9
commit 98a676f8ac
2 changed files with 54 additions and 51 deletions

View File

@ -2,7 +2,7 @@
# encoding: utf-8 # encoding: utf-8
from functools import wraps from functools import wraps
from collections import deque, defaultdict from collections import defaultdict
import glob import glob
import hashlib import hashlib
import os import os
@ -14,6 +14,7 @@ from UltiSnips._diff import diff, guess_edit
from UltiSnips.geometry import Position from UltiSnips.geometry import Position
from UltiSnips.text_objects import SnippetInstance from UltiSnips.text_objects import SnippetInstance
from UltiSnips.util import IndentUtil from UltiSnips.util import IndentUtil
from UltiSnips.vim_state import VimState
import UltiSnips._vim as _vim import UltiSnips._vim as _vim
def _ask_snippets(snippets): def _ask_snippets(snippets):
@ -557,56 +558,6 @@ class VisualContentPreserver(object):
def mode(self): def mode(self):
return self._mode 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): class SnippetManager(object):
def __init__(self): def __init__(self):
self._supertab_keys = None self._supertab_keys = None

52
plugin/UltiSnips/vim_state.py Executable file
View File

@ -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[:]