More linting.
This commit is contained in:
parent
a669654466
commit
63021206cd
1
pylintrc
1
pylintrc
@ -44,6 +44,7 @@ disable=
|
||||
too-few-public-methods,
|
||||
too-many-branches,
|
||||
too-many-statements,
|
||||
too-many-locals,
|
||||
|
||||
|
||||
[REPORTS]
|
||||
|
@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
__all__ = [ "debug", "echo_to_hierarchy", "print_stack" ]
|
||||
|
||||
import sys
|
||||
|
||||
from UltiSnips.compatibility import as_unicode
|
||||
@ -36,4 +34,3 @@ def print_stack():
|
||||
import traceback
|
||||
with open(dump_filename, "ab") as dump_file:
|
||||
traceback.print_stack(file=dump_file)
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
__all__ = [ "Position" ]
|
||||
|
||||
class Position(object):
|
||||
def __init__(self, line, col):
|
||||
self.line = line
|
||||
@ -79,4 +77,3 @@ class Position(object):
|
||||
|
||||
def __repr__(self):
|
||||
return "(%i,%i)" % (self._line, self._col)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
"""Public facing classes for TextObjects."""
|
||||
|
||||
from ._snippet_instance import SnippetInstance
|
||||
|
||||
__all__ = [ "SnippetInstance" ]
|
||||
|
||||
|
@ -6,8 +6,6 @@
|
||||
import UltiSnips._vim as _vim
|
||||
from UltiSnips.geometry import Position
|
||||
|
||||
__all__ = ["TextObject", "EditableTextObject", "NoneditableTextObject"]
|
||||
|
||||
def _calc_end(text, start):
|
||||
"""Calculate the end position of the 'text' starting at 'start."""
|
||||
if len(text) == 1:
|
||||
@ -39,7 +37,9 @@ def _text_to_vim(start, end, text):
|
||||
|
||||
return new_end
|
||||
|
||||
|
||||
# These classes use their subclasses a lot and we really do not want to expose
|
||||
# their functions more globally.
|
||||
# pylint: disable=protected-access
|
||||
class TextObject(object):
|
||||
"""Represents any object in the text that has a span in any ways."""
|
||||
|
||||
@ -129,6 +129,13 @@ class TextObject(object):
|
||||
self._end.diff(old_end)
|
||||
)
|
||||
|
||||
def _update(self, done):
|
||||
"""Update this object inside the Vim Buffer.
|
||||
|
||||
Return False if you need to be called again for this edit cycle.
|
||||
Otherwise return True.
|
||||
"""
|
||||
raise NotImplementedError("Must be implemented by subclasses.")
|
||||
|
||||
class EditableTextObject(TextObject):
|
||||
"""
|
||||
@ -137,16 +144,20 @@ class EditableTextObject(TextObject):
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
TextObject.__init__(self, *args, **kwargs)
|
||||
|
||||
self._childs = []
|
||||
self._tabstops = {}
|
||||
|
||||
##############
|
||||
# Properties #
|
||||
##############
|
||||
@property
|
||||
def childs(self):
|
||||
"""List of all childs."""
|
||||
return self._childs
|
||||
|
||||
@property
|
||||
def _editable_childs(self):
|
||||
"""All childs that are EditableTextObject s"""
|
||||
"""List of all childs that are EditableTextObjects"""
|
||||
return [child for child in self._childs if
|
||||
isinstance(child, EditableTextObject)]
|
||||
|
||||
@ -229,7 +240,8 @@ class EditableTextObject(TextObject):
|
||||
# We have to handle this ourselves
|
||||
delta = Position(1, 0) if text == "\n" else Position(0, len(text))
|
||||
if ctype == "D":
|
||||
if self._start == self._end: # Makes no sense to delete in empty textobject
|
||||
# Makes no sense to delete in empty textobject
|
||||
if self._start == self._end:
|
||||
return
|
||||
delta.line *= -1
|
||||
delta.col *= -1
|
||||
@ -323,11 +335,6 @@ class EditableTextObject(TextObject):
|
||||
return self._parent._get_tabstop(self, number)
|
||||
|
||||
def _update(self, done):
|
||||
"""Update this object inside the Vim Buffer.
|
||||
|
||||
Return False if you need to be called again for this edit cycle.
|
||||
Otherwise return True.
|
||||
"""
|
||||
if all((child in done) for child in self._childs):
|
||||
assert self not in done
|
||||
done.add(self)
|
||||
|
@ -12,12 +12,6 @@ import re
|
||||
from UltiSnips.geometry import Position
|
||||
from UltiSnips.compatibility import as_unicode
|
||||
|
||||
__all__ = [
|
||||
"tokenize", "EscapeCharToken", "VisualToken", "TransformationToken",
|
||||
"TabStopToken", "MirrorToken", "PythonCodeToken", "VimLCodeToken",
|
||||
"ShellCodeToken"
|
||||
]
|
||||
|
||||
class _TextIterator(object):
|
||||
"""Helper class to make iterating over text easier."""
|
||||
|
||||
|
@ -14,8 +14,6 @@ from UltiSnips.text_objects._transformation import Transformation
|
||||
from UltiSnips.text_objects._viml_code import VimLCode
|
||||
from UltiSnips.text_objects._visual import Visual
|
||||
|
||||
__all__ = ["TOParser"]
|
||||
|
||||
class TOParser(object):
|
||||
TOKEN2TO = {
|
||||
EscapeCharToken: EscapedChar,
|
||||
@ -47,7 +45,7 @@ class TOParser(object):
|
||||
m1 = Position(mark.line, mark.col)
|
||||
TabStop(self._parent_to, 0, mark, m1)
|
||||
|
||||
self._parent_to.replace_initital_text()
|
||||
self._parent_to.replace_initial_text()
|
||||
|
||||
#####################
|
||||
# Private Functions #
|
||||
|
@ -1,25 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
"""A Snippet instance is an instance of a Snippet Definition. That is, when the
|
||||
user expands a snippet, a SnippetInstance is created to keep track of the
|
||||
corresponding TextObjects. The Snippet itself is also a TextObject. """
|
||||
|
||||
from UltiSnips.geometry import Position
|
||||
import UltiSnips._vim as _vim
|
||||
|
||||
from UltiSnips.text_objects._base import EditableTextObject, NoneditableTextObject
|
||||
from UltiSnips.text_objects._base import EditableTextObject, \
|
||||
NoneditableTextObject
|
||||
from UltiSnips.text_objects._parser import TOParser
|
||||
|
||||
class SnippetInstance(EditableTextObject):
|
||||
"""
|
||||
A Snippet instance is an instance of a Snippet Definition. That is,
|
||||
when the user expands a snippet, a SnippetInstance is created to
|
||||
keep track of the corresponding TextObjects. The Snippet itself is
|
||||
also a TextObject because it has a start an end
|
||||
"""
|
||||
"""See module docstring."""
|
||||
|
||||
def __init__(self, snippet, parent, indent, initial_text, start, end, visual_content, last_re, globals):
|
||||
def __init__(self, snippet, parent, indent, initial_text,
|
||||
start, end, visual_content, last_re, globals):
|
||||
if start is None:
|
||||
start = Position(0,0)
|
||||
start = Position(0, 0)
|
||||
if end is None:
|
||||
end = Position(0,0)
|
||||
end = Position(0, 0)
|
||||
self.snippet = snippet
|
||||
self._cts = 0
|
||||
|
||||
@ -33,14 +34,14 @@ class SnippetInstance(EditableTextObject):
|
||||
|
||||
self.update_textobjects()
|
||||
|
||||
def replace_initital_text(self):
|
||||
def replace_initial_text(self):
|
||||
"""Puts the initial text of all text elements into Vim."""
|
||||
def _place_initial_text(obj):
|
||||
"""recurses on the childs to do the work."""
|
||||
obj.overwrite()
|
||||
|
||||
if isinstance(obj, EditableTextObject):
|
||||
for c in obj._childs:
|
||||
_place_initial_text(c)
|
||||
|
||||
for child in obj._childs:
|
||||
_place_initial_text(child)
|
||||
_place_initial_text(self)
|
||||
|
||||
def replay_user_edits(self, cmds):
|
||||
@ -54,13 +55,13 @@ class SnippetInstance(EditableTextObject):
|
||||
the users edits have been replayed. This might also move the Cursor
|
||||
"""
|
||||
vc = _VimCursor(self)
|
||||
|
||||
done = set()
|
||||
not_done = set()
|
||||
def _find_recursive(obj):
|
||||
"""Finds all text objects and puts them into 'not_done'."""
|
||||
if isinstance(obj, EditableTextObject):
|
||||
for c in obj._childs:
|
||||
_find_recursive(c)
|
||||
for child in obj._childs:
|
||||
_find_recursive(child)
|
||||
not_done.add(obj)
|
||||
_find_recursive(self)
|
||||
|
||||
@ -71,7 +72,7 @@ class SnippetInstance(EditableTextObject):
|
||||
if obj._update(done):
|
||||
done.add(obj)
|
||||
counter -= 1
|
||||
if counter == 0:
|
||||
if not counter:
|
||||
raise RuntimeError(
|
||||
"The snippets content did not converge: Check for Cyclic "
|
||||
"dependencies or random strings in your snippet. You can use "
|
||||
@ -80,7 +81,8 @@ class SnippetInstance(EditableTextObject):
|
||||
vc.to_vim()
|
||||
self._del_child(vc)
|
||||
|
||||
def select_next_tab(self, backwards = False):
|
||||
def select_next_tab(self, backwards=False):
|
||||
"""Selects the next tabstop or the previous if 'backwards' is True."""
|
||||
if self._cts is None:
|
||||
return
|
||||
|
||||
@ -107,22 +109,23 @@ class SnippetInstance(EditableTextObject):
|
||||
def _get_tabstop(self, requester, no):
|
||||
# SnippetInstances are completely self contained, therefore, we do not
|
||||
# need to ask our parent for Tabstops
|
||||
p = self._parent
|
||||
cached_parent = self._parent
|
||||
self._parent = None
|
||||
rv = EditableTextObject._get_tabstop(self, requester, no)
|
||||
self._parent = p
|
||||
|
||||
self._parent = cached_parent
|
||||
return rv
|
||||
|
||||
|
||||
class _VimCursor(NoneditableTextObject):
|
||||
"""Helper class to keep track of the Vim Cursor"""
|
||||
"""Helper class to keep track of the Vim Cursor when text objects expand
|
||||
and move."""
|
||||
|
||||
def __init__(self, parent):
|
||||
NoneditableTextObject.__init__(
|
||||
self, parent, _vim.buf.cursor, _vim.buf.cursor, tiebreaker = Position(-1,-1),
|
||||
)
|
||||
self, parent, _vim.buf.cursor, _vim.buf.cursor,
|
||||
tiebreaker=Position(-1, -1))
|
||||
|
||||
def to_vim(self):
|
||||
assert(self._start == self._end)
|
||||
"""Moves the cursor in the Vim to our position."""
|
||||
assert self._start == self._end
|
||||
_vim.buf.cursor = self._start
|
||||
|
@ -1,28 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
"""This is the most important TextObject. A TabStop is were the cursor
|
||||
comes to rest when the user taps through the Snippet."""
|
||||
|
||||
from UltiSnips.text_objects._base import EditableTextObject
|
||||
|
||||
__all__ = ['EditableTextObject']
|
||||
|
||||
class TabStop(EditableTextObject):
|
||||
"""
|
||||
This is the most important TextObject. A TabStop is were the cursor
|
||||
comes to rest when the user taps through the Snippet.
|
||||
"""
|
||||
def __init__(self, parent, token, start = None, end = None):
|
||||
"""See module docstring."""
|
||||
|
||||
def __init__(self, parent, token, start=None, end=None):
|
||||
if start is not None:
|
||||
self._number = token
|
||||
EditableTextObject.__init__(self, parent, start, end)
|
||||
else:
|
||||
self._number = token.number
|
||||
EditableTextObject.__init__(self, parent, token)
|
||||
parent._tabstops[self._number] = self
|
||||
parent._tabstops[self._number] = self # pylint:disable=protected-access
|
||||
|
||||
@property
|
||||
def number(self):
|
||||
"""The tabstop number."""
|
||||
return self._number
|
||||
|
||||
@property
|
||||
def is_killed(self):
|
||||
"""True if this tabstop has been typed over and the user therefore can
|
||||
no longer jump to it."""
|
||||
return self._parent is None
|
||||
|
Loading…
Reference in New Issue
Block a user