예제 #1
0
    def expand_anon(self, value, trigger="", description="", options="", context=None, actions={}):
        """Expand an anonymous snippet right here."""
        before = _vim.buf.line_till_cursor
        snip = UltiSnipsSnippetDefinition(0, trigger, value, description, options, {}, "", context, actions)

        if not trigger or snip.matches(before):
            self._do_snippet(snip, before)
            return True
        else:
            return False
예제 #2
0
    def expand_anon(self, value, trigger="", description="", options=""):
        """Expand an anonymous snippet right here."""
        before = _vim.buf.line_till_cursor
        snip = UltiSnipsSnippetDefinition(0, trigger, value, description,
                                          options, {}, "")

        if not trigger or snip.matches(before):
            self._do_snippet(snip, before)
            return True
        else:
            return False
예제 #3
0
    def expand_anon(
        self, value, trigger="", description="", options="", context=None, actions=None
    ):
        """Expand an anonymous snippet right here."""
        before = vim_helper.buf.line_till_cursor
        snip = UltiSnipsSnippetDefinition(
            0, trigger, value, description, options, {}, "", context, actions
        )

        if not trigger or snip.matches(before, self._visual_content):
            self._do_snippet(snip, before)
            return True
        return False
예제 #4
0
 def add_snippet(self, trigger, value, description,
                 options, ft='all', priority=0, context=None, actions={}):
     """Add a snippet to the list of known snippets of the given 'ft'."""
     self._added_snippets_source.add_snippet(ft,
         UltiSnipsSnippetDefinition(priority, trigger, value,
                                    description, options, {}, 'added',
                                    context, actions))
예제 #5
0
파일: ultisnips.py 프로젝트: fgypas/.vim
def _handle_snippet_or_global(filename, line, lines, python_globals, priority):
    """Parses the snippet that begins at the current line."""
    start_line_index = lines.line_index
    descr = ""
    opts = ""

    # Ensure this is a snippet
    snip = line.split()[0]

    # Get and strip options if they exist
    remain = line[len(snip):].strip()
    words = remain.split()
    if len(words) > 2:
        # second to last word ends with a quote
        if '"' not in words[-1] and words[-2][-1] == '"':
            opts = words[-1]
            remain = remain[:-len(opts) - 1].rstrip()

    # Get and strip description if it exists
    remain = remain.strip()
    if len(remain.split()) > 1 and remain[-1] == '"':
        left = remain[:-1].rfind('"')
        if left != -1 and left != 0:
            descr, remain = remain[left:], remain[:left]

    # The rest is the trigger
    trig = remain.strip()
    if len(trig.split()) > 1 or "r" in opts:
        if trig[0] != trig[-1]:
            return "error", ("Invalid multiword trigger: '%s'" % trig,
                             lines.line_index)
        trig = trig[1:-1]
    end = "end" + snip
    content = ""

    found_end = False
    for line in lines:
        if line.rstrip() == end:
            content = content[:-1]  # Chomp the last newline
            found_end = True
            break
        content += line

    if not found_end:
        return "error", ("Missing 'endsnippet' for %r" % trig,
                         lines.line_index)

    if snip == "global":
        python_globals[trig].append(content)
    elif snip == "snippet":
        return "snippet", (UltiSnipsSnippetDefinition(
            priority, trig, content, descr, opts, python_globals,
            "%s:%i" % (filename, start_line_index)), )
    else:
        return "error", ("Invalid snippet type: '%s'" % snip, lines.line_index)
예제 #6
0
 def add_snippet(self,
                 trigger,
                 value,
                 description,
                 options,
                 ft="all",
                 priority=0):
     """Add a snippet to the list of known snippets of the given 'ft'."""
     self._added_snippets_source.add_snippet(
         ft,
         UltiSnipsSnippetDefinition(priority, trigger, value, description,
                                    options, {}, "added"))