From 7d5e92743a9a0dd73bdea0b9efd538d2fb44fc81 Mon Sep 17 00:00:00 2001 From: "rygwdn@gmail.com" <> Date: Wed, 27 Apr 2011 23:13:26 -0300 Subject: [PATCH] track manually added snippets differently --- plugin/UltiSnips/__init__.py | 42 +++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index c04e501..cbc1f4b 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -65,19 +65,28 @@ def echom(mes, *args): class _SnippetDictionary(object): def __init__(self, *args, **kwargs): - self._snippets = [] - self._extends = [] - self._files = {} + self._added = [] + self.reset() - def add_snippet(self, s): - self._snippets.append(s) + def add_snippet(self, s, fn=None): + if fn: + self._snippets.append(s) + + if fn not in self.files: + self.addfile(fn) + else: + self._added.append(s) def get_matching_snippets(self, trigger, potentially): """Returns all snippets matching the given trigger.""" if not potentially: - return [ s for s in self._snippets if s.matches(trigger) ] + return [ s for s in self.snippets if s.matches(trigger) ] else: - return [ s for s in self._snippets if s.could_match(trigger) ] + return [ s for s in self.snippets if s.could_match(trigger) ] + + def snippets(self): + return self._added + self._snippets + snippets = property(snippets) def clear_snippets(self, triggers=[]): """Remove all snippets that match each trigger in triggers. @@ -86,14 +95,23 @@ class _SnippetDictionary(object): if triggers: for t in triggers: for s in self.get_matching_snippets(t, potentially=False): - self._snippets.remove(s) + if s in self._snippets: + self._snippets.remove(s) + if s in self._added: + self._added.remove(s) else: self._snippets = [] + self._added = [] def files(self): return self._files files = property(files) + def reset(self): + self._snippets = [] + self._extends = [] + self._files = {} + def _hash(self, path): if not os.path.isfile(path): @@ -233,7 +251,7 @@ class _SnippetsFileParser(object): self._globals[trig] = [] self._globals[trig].append(cv) elif snip == "snippet": - self._sm.add_snippet(trig, cv, desc, opts, self._ft, self._globals) + self._sm.add_snippet(trig, cv, desc, opts, self._ft, self._globals, fn=self._fn) else: self._error("Invalid snippet type: '%s'" % snip) @@ -694,9 +712,9 @@ class SnippetManager(object): return self._snippets[ft] @err_to_scratch_buffer - def add_snippet(self, trigger, value, descr, options, ft = "all", globals = None): + def add_snippet(self, trigger, value, descr, options, ft = "all", globals = None, fn=None): l = self.snippet_dict(ft).add_snippet( - Snippet(trigger, value, descr, options, globals or {}) + Snippet(trigger, value, descr, options, globals or {}), fn ) @err_to_scratch_buffer @@ -1200,7 +1218,7 @@ class SnippetManager(object): # Loading def _load_snippets_for(self, ft): - self._snippets[ft] = _SnippetDictionary() + self.snippet_dict(ft).reset() for fn in self.base_snippet_files_for(ft): self._parse_snippets(ft, fn)