예제 #1
0
 def _jump(self, backwards=False):
     jumped = False
     if self._cs:
         self._ctab = self._cs.select_next_tab(backwards)
         if self._ctab:
             before, after = _vim.buf.current_line_splitted
             if self._cs.snippet.has_option("s"):
                 if after == "":
                     m = re.match(r'(.*?)\s+$', before)
                     if m:
                         lineno = _vim.buf.cursor.line
                         _vim.text_to_vim(
                             Position(lineno, 0),
                             Position(lineno,
                                      len(before) + len(after)), m.group(1))
             _vim.select(self._ctab.start, self._ctab.end)
             jumped = True
             if self._ctab.no == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
     if jumped:
         self._vstate.remember_position()
     return jumped
예제 #2
0
 def _jump(self, backwards = False):
     jumped = False
     if self._cs:
         self._ctab = self._cs.select_next_tab(backwards)
         if self._ctab:
             before, after = _vim.buf.current_line_splitted
             if self._cs.snippet.has_option("s"):
                 if after == "":
                     m = re.match(r'(.*?)\s+$', before)
                     if m:
                         lineno = _vim.buf.cursor.line
                         _vim.text_to_vim(Position(lineno,0), Position(
                             lineno,len(before)+len(after)), m.group(1))
             _vim.select(self._ctab.start, self._ctab.end)
             jumped = True
             if self._ctab.no == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
     if jumped:
         self._vstate.remember_position()
         self._ignore_movements = True
     return jumped
예제 #3
0
 def _jump(self, backwards=False):
     """Helper method that does the actual jump."""
     jumped = False
     # If next tab has length 1 and the distance between itself and
     # self._ctab is 1 then there is 1 less CursorMove events.  We
     # cannot ignore next movement in such case.
     ntab_short_and_near = False
     if self._cs:
         ntab = self._cs.select_next_tab(backwards)
         if ntab:
             if self._cs.snippet.has_option("s"):
                 lineno = _vim.buf.cursor.line
                 _vim.buf[lineno] = _vim.buf[lineno].rstrip()
             _vim.select(ntab.start, ntab.end)
             jumped = True
             if (self._ctab is not None
                     and ntab.start - self._ctab.end == Position(0, 1)
                     and ntab.end - ntab.start == Position(0, 1)):
                 ntab_short_and_near = True
             if ntab.number == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
         self._ctab = ntab
     if jumped:
         self._vstate.remember_position()
         self._vstate.remember_unnamed_register(self._ctab.current_text)
         if not ntab_short_and_near:
             self._ignore_movements = True
     return jumped
예제 #4
0
 def _jump(self, backwards=False):
     """Helper method that does the actual jump."""
     jumped = False
     # If next tab has length 1 and the distance between itself and
     # self._ctab is 1 then there is 1 less CursorMove events.  We
     # cannot ignore next movement in such case.
     ntab_short_and_near = False
     if self._cs:
         ntab = self._cs.select_next_tab(backwards)
         if ntab:
             if self._cs.snippet.has_option("s"):
                 lineno = _vim.buf.cursor.line
                 _vim.buf[lineno] = _vim.buf[lineno].rstrip()
             _vim.select(ntab.start, ntab.end)
             jumped = True
             if (self._ctab is not None
                     and ntab.start - self._ctab.end == Position(0, 1)
                     and ntab.end - ntab.start == Position(0, 1)):
                 ntab_short_and_near = True
             if ntab.number == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
         self._ctab = ntab
     if jumped:
         self._vstate.remember_position()
         self._vstate.remember_unnamed_register(self._ctab.current_text)
         if not ntab_short_and_near:
             self._ignore_movements = True
     return jumped
예제 #5
0
    def _jump(self, backwards=False):
        # we need to set 'onemore' there, because of limitations of the vim
        # API regarding cursor movements; without that test
        # 'CanExpandAnonSnippetInJumpActionWhileSelected' will fail
        with _vim.toggle_opt('ve', 'onemore'):
            """Helper method that does the actual jump."""
            jumped = False

            # We need to remember current snippets stack here because of
            # post-jump action on the last tabstop should be able to access
            # snippet instance which is ended just now.
            stack_for_post_jump = self._csnippets[:]

            # If next tab has length 1 and the distance between itself and
            # self._ctab is 1 then there is 1 less CursorMove events.  We
            # cannot ignore next movement in such case.
            ntab_short_and_near = False

            if self._cs:
                snippet_for_action = self._cs
            elif stack_for_post_jump:
                snippet_for_action = stack_for_post_jump[-1]
            else:
                snippet_for_action = None

            if self._cs:
                ntab = self._cs.select_next_tab(backwards)
                if ntab:
                    if self._cs.snippet.has_option('s'):
                        lineno = _vim.buf.cursor.line
                        _vim.buf[lineno] = _vim.buf[lineno].rstrip()
                    _vim.select(ntab.start, ntab.end)
                    jumped = True
                    if (self._ctab is not None
                            and ntab.start - self._ctab.end == Position(0, 1)
                            and ntab.end - ntab.start == Position(0, 1)):
                        ntab_short_and_near = True
                    if ntab.number == 0:
                        self._current_snippet_is_done()
                    self._ctab = ntab
                else:
                    # This really shouldn't happen, because a snippet should
                    # have been popped when its final tabstop was used.
                    # Cleanup by removing current snippet and recursing.
                    self._current_snippet_is_done()
                    jumped = self._jump(backwards)
            if jumped:
                self._vstate.remember_position()
                self._vstate.remember_unnamed_register(self._ctab.current_text)
                if not ntab_short_and_near:
                    self._ignore_movements = True

            if len(stack_for_post_jump) > 0 and ntab is not None:
                with use_proxy_buffer(stack_for_post_jump, self._vstate):
                    snippet_for_action.snippet.do_post_jump(
                        ntab.number, -1 if backwards else 1,
                        stack_for_post_jump, snippet_for_action)

        return jumped
예제 #6
0
 def _jump(self, backwards = False):
     jumped = False
     if self._cs:
         self._ctab = self._cs.select_next_tab(backwards)
         if self._ctab:
             _vim.select(self._ctab.start, self._ctab.end)
             jumped = True
             if self._ctab.no == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
     if jumped:
         self._vstate.remember_position()
     return jumped
예제 #7
0
 def _jump(self, backwards=False):
     """Helper method that does the actual jump."""
     jumped = False
     if self._cs:
         self._ctab = self._cs.select_next_tab(backwards)
         if self._ctab:
             if self._cs.snippet.has_option("s"):
                 lineno = _vim.buf.cursor.line
                 _vim.buf[lineno] = _vim.buf[lineno].rstrip()
             _vim.select(self._ctab.start, self._ctab.end)
             jumped = True
             if self._ctab.number == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
     if jumped:
         self._vstate.remember_position()
         self._vstate.remember_unnamed_register(self._ctab.current_text)
         self._ignore_movements = True
     return jumped
예제 #8
0
 def _jump(self, backwards=False):
     """Helper method that does the actual jump."""
     jumped = False
     if self._cs:
         self._ctab = self._cs.select_next_tab(backwards)
         if self._ctab:
             if self._cs.snippet.has_option("s"):
                 lineno = _vim.buf.cursor.line
                 _vim.buf[lineno] = _vim.buf[lineno].rstrip()
             _vim.select(self._ctab.start, self._ctab.end)
             jumped = True
             if self._ctab.number == 0:
                 self._current_snippet_is_done()
         else:
             # This really shouldn't happen, because a snippet should
             # have been popped when its final tabstop was used.
             # Cleanup by removing current snippet and recursing.
             self._current_snippet_is_done()
             jumped = self._jump(backwards)
     if jumped:
         self._vstate.remember_position()
         self._vstate.remember_unnamed_register(self._ctab.current_text)
         self._ignore_movements = True
     return jumped
예제 #9
0
    def _jump(self, backwards=False):
        """Helper method that does the actual jump."""
        if self._should_update_textobjects:
            self._should_reset_visual = False
            self._cursor_moved()

        # we need to set 'onemore' there, because of limitations of the vim
        # API regarding cursor movements; without that test
        # 'CanExpandAnonSnippetInJumpActionWhileSelected' will fail
        with _vim.toggle_opt('ve', 'onemore'):
            jumped = False

            # We need to remember current snippets stack here because of
            # post-jump action on the last tabstop should be able to access
            # snippet instance which is ended just now.
            stack_for_post_jump = self._csnippets[:]

            # If next tab has length 1 and the distance between itself and
            # self._ctab is 1 then there is 1 less CursorMove events.  We
            # cannot ignore next movement in such case.
            ntab_short_and_near = False

            if self._cs:
                snippet_for_action = self._cs
            elif stack_for_post_jump:
                snippet_for_action = stack_for_post_jump[-1]
            else:
                snippet_for_action = None

            if self._cs:
                ntab = self._cs.select_next_tab(backwards)
                if ntab:
                    if self._cs.snippet.has_option('s'):
                        lineno = _vim.buf.cursor.line
                        _vim.buf[lineno] = _vim.buf[lineno].rstrip()
                    _vim.select(ntab.start, ntab.end)
                    jumped = True
                    if (self._ctab is not None
                            and ntab.start - self._ctab.end == Position(0, 1)
                            and ntab.end - ntab.start == Position(0, 1)):
                        ntab_short_and_near = True

                    self._ctab = ntab

                    # Run interpolations again to update new placeholder
                    # values, binded to currently newly jumped placeholder.
                    self._visual_content.conserve_placeholder(self._ctab)
                    self._cs.current_placeholder = \
                        self._visual_content.placeholder
                    self._should_reset_visual = False
                    self._csnippets[0].update_textobjects()
                    self._vstate.remember_buffer(self._csnippets[0])

                    if ntab.number == 0 and self._csnippets:
                        self._current_snippet_is_done()
                else:
                    # This really shouldn't happen, because a snippet should
                    # have been popped when its final tabstop was used.
                    # Cleanup by removing current snippet and recursing.
                    self._current_snippet_is_done()
                    jumped = self._jump(backwards)

            if jumped:
                if self._ctab:
                    self._vstate.remember_position()
                    self._vstate.remember_unnamed_register(self._ctab.current_text)
                if not ntab_short_and_near:
                    self._ignore_movements = True

            if len(stack_for_post_jump) > 0 and ntab is not None:
                with use_proxy_buffer(stack_for_post_jump, self._vstate):
                    snippet_for_action.snippet.do_post_jump(
                        ntab.number,
                        -1 if backwards else 1,
                        stack_for_post_jump,
                        snippet_for_action
                    )

        return jumped
예제 #10
0
    def _jump(self, backwards=False):
        """Helper method that does the actual jump."""
        if self._should_update_textobjects:
            self._should_reset_visual = False
            self._cursor_moved()

        # we need to set 'onemore' there, because of limitations of the vim
        # API regarding cursor movements; without that test
        # 'CanExpandAnonSnippetInJumpActionWhileSelected' will fail
        with _vim.option_set_to('ve', 'onemore'):
            jumped = False

            # We need to remember current snippets stack here because of
            # post-jump action on the last tabstop should be able to access
            # snippet instance which is ended just now.
            stack_for_post_jump = self._active_snippets[:]

            # If next tab has length 1 and the distance between itself and
            # self._ctab is 1 then there is 1 less CursorMove events.  We
            # cannot ignore next movement in such case.
            ntab_short_and_near = False

            if self._current_snippet:
                snippet_for_action = self._current_snippet
            elif stack_for_post_jump:
                snippet_for_action = stack_for_post_jump[-1]
            else:
                snippet_for_action = None

            if self._current_snippet:
                ntab = self._current_snippet.select_next_tab(backwards)
                if ntab:
                    if self._current_snippet.snippet.has_option('s'):
                        lineno = _vim.buf.cursor.line
                        _vim.buf[lineno] = _vim.buf[lineno].rstrip()
                    _vim.select(ntab.start, ntab.end)
                    jumped = True
                    if (self._ctab is not None
                            and ntab.start - self._ctab.end == Position(0, 1)
                            and ntab.end - ntab.start == Position(0, 1)):
                        ntab_short_and_near = True

                    self._ctab = ntab

                    # Run interpolations again to update new placeholder
                    # values, binded to currently newly jumped placeholder.
                    self._visual_content.conserve_placeholder(self._ctab)
                    self._current_snippet.current_placeholder = \
                        self._visual_content.placeholder
                    self._should_reset_visual = False
                    self._active_snippets[0].update_textobjects(_vim.buf)
                    # Open any folds this might have created
                    _vim.command('normal! zv')
                    self._vstate.remember_buffer(self._active_snippets[0])

                    if ntab.number == 0 and self._active_snippets:
                        self._current_snippet_is_done()
                else:
                    # This really shouldn't happen, because a snippet should
                    # have been popped when its final tabstop was used.
                    # Cleanup by removing current snippet and recursing.
                    self._current_snippet_is_done()
                    jumped = self._jump(backwards)

            if jumped:
                if self._ctab:
                    self._vstate.remember_position()
                    self._vstate.remember_unnamed_register(
                        self._ctab.current_text)
                if not ntab_short_and_near:
                    self._ignore_movements = True

            if len(stack_for_post_jump) > 0 and ntab is not None:
                with use_proxy_buffer(stack_for_post_jump, self._vstate):
                    snippet_for_action.snippet.do_post_jump(
                        ntab.number, -1 if backwards else 1,
                        stack_for_post_jump, snippet_for_action)

        return jumped