Ejemplo n.º 1
0
    def update(self):
        line, col = vim_cursor()
        line -= 1
        abs_pos = Position(line,col)
        if self._abs_pos:
            self._moved = abs_pos - self._abs_pos
        self._abs_pos = abs_pos

        # Update buffer infos
        cols = len(as_unicode(vim.current.buffer[line]))
        if self._cols:
            self._dcols = cols - self._cols
        self._cols = cols

        lines = len(vim.current.buffer)
        if self._lines:
            self._dlines = lines - self._lines
        self._lines = lines

        # Check if the buffer has changed in any ways
        self._text_changed = False
        # does it have more lines?
        if self._dlines:
            self._text_changed = True
        # did we stay in the same line and it has more columns now?
        elif not self.moved.line and self._dcols:
            self._text_changed = True
        # If the length didn't change but we moved a column, check if
        # the char under the cursor has changed (might be one char tab).
        elif self.moved.col == 1:
            self._text_changed = self._cline != as_unicode(vim.current.buffer[line])
        self._lline = self._cline
        self._cline = as_unicode(vim.current.buffer[line])
Ejemplo n.º 2
0
    def _do_snippet(self, snippet, before, after):
        """ Expands the given snippet, and handles everything
        that needs to be done with it. 'before' and 'after' should
        come from _get_before_after.
        """
        lineno, col = vim_cursor()
        # Adjust before, maybe the trigger is not the complete word

        text_before = before
        if snippet.matched:
            text_before = before[:-len(snippet.matched)]

        self._unset_offending_vim_options(snippet)

        self._expect_move_wo_change = True
        if self._cs:
            # Determine position
            pos = self._vstate.pos
            p_start = self._ctab.abs_start

            if pos.line == p_start.line:
                end = Position(0, pos.col - p_start.col)
            else:
                end = Position(pos.line - p_start.line, pos.col)
            start = Position(end.line, end.col - len(snippet.matched))

            si = snippet.launch(text_before, self._visual_content, self._ctab, start, end)
            self._visual_content = ""

            self._update_vim_buffer()

            if si.has_tabs:
                self._csnippets.append(si)
                self._jump()
        else:
            self._vb = VimBuffer(text_before, after)

            start = Position(lineno-1, len(text_before))
            self._csnippets.append(snippet.launch(text_before, self._visual_content, None, start))
            self._visual_content = ""

            self._vb.replace_lines(lineno-1, lineno-1,
                       self._cs._current_text)

            self._jump()