~ubuntu-branches/ubuntu/vivid/vim-ultisnips/vivid

« back to all changes in this revision

Viewing changes to pythonx/UltiSnips/snippet/source/_snippet_dictionary.py

  • Committer: Package Import Robot
  • Author(s): Michael Fladischer
  • Date: 2014-10-12 18:11:54 UTC
  • Revision ID: package-import@ubuntu.com-20141012181154-1jeoj467dh2l5f2e
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# encoding: utf-8
 
3
 
 
4
"""Implements a container for parsed snippets."""
 
5
 
 
6
# TODO(sirver): This class should not keep track of extends.
 
7
class SnippetDictionary(object):
 
8
    """See module docstring."""
 
9
 
 
10
    def __init__(self):
 
11
        self._snippets = []
 
12
        self._extends = []
 
13
 
 
14
    def add_snippet(self, snippet):
 
15
        """Add 'snippet' to this dictionary."""
 
16
        self._snippets.append(snippet)
 
17
 
 
18
    def get_matching_snippets(self, trigger, potentially):
 
19
        """Returns all snippets matching the given trigger. If 'potentially' is
 
20
        true, returns all that could_match()."""
 
21
        all_snippets = self._snippets
 
22
        if not potentially:
 
23
            return [s for s in all_snippets if s.matches(trigger)]
 
24
        else:
 
25
            return [s for s in all_snippets if s.could_match(trigger)]
 
26
 
 
27
    def clear_snippets(self, triggers):
 
28
        """Remove all snippets that match each trigger in 'triggers'. When
 
29
        'triggers' is None, empties this dictionary completely."""
 
30
        if not triggers:
 
31
            self._snippets = []
 
32
            return
 
33
        for trigger in triggers:
 
34
            for snippet in self.get_matching_snippets(trigger, False):
 
35
                if snippet in self._snippets:
 
36
                    self._snippets.remove(snippet)
 
37
 
 
38
    @property
 
39
    def extends(self):
 
40
        """The list of filetypes this filetype extends."""
 
41
        return self._extends