Beispiel #1
0
    def launch(self, text_before, visual_content, parent, start, end):
        indent = self._INDENT.match(text_before).group(0)
        lines = (self._v + "\n").splitlines()
        ind_util = IndentUtil()

        # Replace leading tabs in the snippet definition via proper indenting
        v = []
        for line_num, line in enumerate(lines):
            if "t" in self._opts:
                tabs = 0
            else:
                tabs = len(self._TABS.match(line).group(0))

            line_ind = ind_util.ntabs_to_proper_indent(tabs)

            if line_num != 0:
                line_ind = indent + line_ind

            v.append(line_ind + line[tabs:])
        v = '\n'.join(v)

        if parent is None:
            si = SnippetInstance(None, indent, v, start, end, visual_content = visual_content,
                    last_re = self._last_re, globals = self._globals)
        else:
            si = SnippetInstance(parent, indent, v, start, end, visual_content,
                    last_re = self._last_re, globals = self._globals)

        return si
Beispiel #2
0
    def launch(self, text_before, visual_content, parent, start, end):
        """Launch this snippet, overwriting the text 'start' to 'end' and
        keeping the 'text_before' on the launch line. 'Parent' is the parent
        snippet instance if any."""
        indent = self._INDENT.match(text_before).group(0)
        lines = (self._value + "\n").splitlines()
        ind_util = IndentUtil()

        # Replace leading tabs in the snippet definition via proper indenting
        initial_text = []
        for line_num, line in enumerate(lines):
            if "t" in self._opts:
                tabs = 0
            else:
                tabs = len(self._TABS.match(line).group(0))
            line_ind = ind_util.ntabs_to_proper_indent(tabs)
            if line_num != 0:
                line_ind = indent + line_ind

            initial_text.append(line_ind + line[tabs:])
        initial_text = '\n'.join(initial_text)

        snippet_instance = SnippetInstance(
                self, parent, initial_text, start, end, visual_content,
                last_re=self._last_re, globals=self._globals)
        self.instantiate(snippet_instance, initial_text, indent)

        snippet_instance.update_textobjects()
        return snippet_instance