示例#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)

        si = SnippetInstance(self,
                             parent,
                             indent,
                             v,
                             start,
                             end,
                             visual_content,
                             last_re=self._last_re,
                             globals=self._globals)

        return si
示例#2
0
    def __init__(self, initial_indent, vmode, vtext):
        self._ind = IndentUtil()
        self._visual = _VisualContent(vmode, vtext)

        self._initial_indent = self._ind.indent_to_spaces(initial_indent)

        self._reset("")
示例#3
0
    def _update(self, done, not_done):
        if self._mode != "v":
            # Keep the indent for Line/Block Selection
            text_before = _vim.buf[self.start.line][:self.start.col]
            indent = self.__REPLACE_NON_WS.sub(" ", text_before)
            iu = IndentUtil()
            indent = iu.indent_to_spaces(indent)
            indent = iu.spaces_to_indent(indent)
            text = ""
            for idx, line in enumerate(self._text.splitlines(True)):
                if idx != 0:
                    text += indent
                text += line
            text = text[:-1]  # Strip final '\n'
        else:
            text = self._text

        text = self._transform(text)
        self.overwrite(text)
        self._parent._del_child(self)

        return True