From ca63cbdf5745d615eb0a9147309e7cabd767ceaa Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sat, 21 Jan 2012 13:10:08 +0100 Subject: [PATCH] Code cleanup and fixes - Removed _add_tabstop function and move it to TabStop __init__ - replace initital text is now a function of snippet instance --- plugin/UltiSnips/TextObjects/_base.py | 3 --- plugin/UltiSnips/TextObjects/_parser.py | 18 +++--------------- .../UltiSnips/TextObjects/_snippet_instance.py | 9 +++++++++ plugin/UltiSnips/TextObjects/_tabstop.py | 2 ++ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/plugin/UltiSnips/TextObjects/_base.py b/plugin/UltiSnips/TextObjects/_base.py index dbc3258..774c167 100755 --- a/plugin/UltiSnips/TextObjects/_base.py +++ b/plugin/UltiSnips/TextObjects/_base.py @@ -336,9 +336,6 @@ class TextObject(object): except AttributeError: pass - def _add_tabstop(self, ts): # Why is tabstop not doing this in __init__? TODO - self._tabstops[ts.no] = ts - class NoneditableTextObject(TextObject): """ All passive text objects that the user can't edit by hand diff --git a/plugin/UltiSnips/TextObjects/_parser.py b/plugin/UltiSnips/TextObjects/_parser.py index e14d0ba..8ba4ace 100755 --- a/plugin/UltiSnips/TextObjects/_parser.py +++ b/plugin/UltiSnips/TextObjects/_parser.py @@ -46,9 +46,9 @@ class TOParser(object): if add_ts_zero and 0 not in seen_ts: mark = all_tokens[-1][1].end # Last token is always EndOfText m1 = Position(mark.line, mark.col) - self._parent_to._add_tabstop(TabStop(self._parent_to, 0, mark, m1)) + TabStop(self._parent_to, 0, mark, m1) - self._replace_initial_texts() + self._parent_to.replace_initital_text() ##################### # Private Functions # @@ -57,9 +57,7 @@ class TOParser(object): for parent, token in all_tokens: if isinstance(token, MirrorToken): if token.no not in seen_ts: - ts = TabStop(parent, token) - seen_ts[token.no] = ts - parent._add_tabstop(ts) + seen_ts[token.no] = TabStop(parent, token) else: Mirror(parent, seen_ts[token.no], token) @@ -70,15 +68,6 @@ class TOParser(object): raise RuntimeError("Tabstop %i is not known but is used by a Transformation" % token.no) Transformation(parent, seen_ts[token.no], token) - def _replace_initial_texts(self): - def _place_initial_text(obj): - obj.overwrite() - - for c in obj._childs: # TODO: private parts! - _place_initial_text(c) - - _place_initial_text(self._parent_to) - def _do_parse(self, all_tokens, seen_ts): tokens = list(tokenize(self._text, self._indent, self._parent_to.start)) @@ -88,7 +77,6 @@ class TOParser(object): if isinstance(token, TabStopToken): ts = TabStop(self._parent_to, token) seen_ts[token.no] = ts - self._parent_to._add_tabstop(ts) k = TOParser(ts, token.initial_text, self._indent) k._do_parse(all_tokens, seen_ts) diff --git a/plugin/UltiSnips/TextObjects/_snippet_instance.py b/plugin/UltiSnips/TextObjects/_snippet_instance.py index 273380f..d2b2961 100755 --- a/plugin/UltiSnips/TextObjects/_snippet_instance.py +++ b/plugin/UltiSnips/TextObjects/_snippet_instance.py @@ -30,6 +30,15 @@ class SnippetInstance(TextObject): self.do_edits() + def replace_initital_text(self): + def _place_initial_text(obj): + obj.overwrite() + + for c in obj._childs: + _place_initial_text(c) + + _place_initial_text(self) + def _get_tabstop(self, requester, no): # SnippetInstances are completely self contained, therefore, we do not # need to ask our parent for Tabstops diff --git a/plugin/UltiSnips/TextObjects/_tabstop.py b/plugin/UltiSnips/TextObjects/_tabstop.py index 1e5af59..09bc4e8 100755 --- a/plugin/UltiSnips/TextObjects/_tabstop.py +++ b/plugin/UltiSnips/TextObjects/_tabstop.py @@ -18,6 +18,8 @@ class TabStop(TextObject): TextObject.__init__(self, parent, token) self._no = token.no + parent._tabstops[self._no] = self + def no(self): return self._no no = property(no)