def run(self, name=None):
        state = VintageState(self.view)
        state.cancel_macro = False
        if not (name and state.latest_macro_name):
            return

        if name == '@':
            # Run the macro recorded latest.
            commands = state.macros[state.latest_macro_name]
        else:
            try:
                commands = state.macros[name]
            except KeyError:
                # TODO: Add 'delayed message' support to VintageState.
                return

        for cmd in commands:
            if state.cancel_macro:
                utils.blink()
                break
            self.view.run_command(cmd['command'], cmd['args'])
Exemple #2
0
    def run(self, name=None):
        state = VintageState(self.view)
        state.cancel_macro = False
        if not (name and state.latest_macro_name):
            return

        if name == '@':
            # Run the macro recorded latest.
            commands = state.macros[state.latest_macro_name]
        else:
            try:
                commands = state.macros[name]
            except KeyError:
                # TODO: Add 'delayed message' support to VintageState.
                return

        for cmd in commands:
            if state.cancel_macro:
                utils.blink()
                break
            self.view.run_command(cmd['command'], cmd['args'])
Exemple #3
0
    def run(self, edit, **vi_cmd_data):
        self.debug("Data in ViRunCommand:", vi_cmd_data)

        state = VintageState(self.view)

        try:
            # Always save carets just in case.
            self.save_caret_pos()

            # If we're about to jump, we need to remember the current position so we can jump back
            # here. XXX creates_jump_at_current_position might be redundant.
            # TODO: Extract method.
            if vi_cmd_data['creates_jump_at_current_position'] or vi_cmd_data['is_jump']:
                self.add_to_jump_list(vi_cmd_data)

            sels_before_motion = list(self.view.sel())

            # XXX: Fix this. When should we run the motion exactly?
            if vi_cmd_data['action']:
                # If no motion is present, we know we just have to run the action (like ctrl+w, v).
                if ((vi_cmd_data['motion']) or
                    (vi_cmd_data['motion_required'] and
                     not view.has_non_empty_selection_region())):
                        self.do_whole_motion(vi_cmd_data)

                        # The motion didn't change the selections: abort action if so required.
                        # TODO: What to do with .post_action() and .restore_original_carets_if_needed() in this event?
                        if (vi_cmd_data['mode'] in (_MODE_INTERNAL_NORMAL, MODE_VISUAL) and
                            any([(old == new) for (old, new) in zip(sels_before_motion, list(self.view.sel()))]) and
                            vi_cmd_data['cancel_action_if_motion_fails']):
                                # TODO: There should be a method that lets us do this without modifying vi_cmd_data.
                                vi_cmd_data['restore_original_carets'] = True
                                # FIXME: This is redundant: we call the same method in 'finally' clause.
                                self.restore_original_carets_if_needed(vi_cmd_data)
                                utils.blink()
                                state.cancel_macro = True
                                return

                self.reorient_begin_to_end(vi_cmd_data)
                self.do_action(vi_cmd_data)
            else:
                self.do_whole_motion(vi_cmd_data)
                if (vi_cmd_data['mode'] == MODE_NORMAL and
                    any([(old == new) for (old, new) in zip(sels_before_motion, list(self.view.sel()))])):
                        state.cancel_macro = True
                        utils.blink()

        finally:
            # XXX: post_action should be run only if do_action succeeds (?).
            self.do_post_action(vi_cmd_data)

            # TODO: Extract method.
            if vi_cmd_data['must_update_xpos']:
                state = VintageState(self.view)
                state.update_xpos()

            self.do_modify_selections(vi_cmd_data)
            self.restore_original_carets_if_needed(vi_cmd_data)

            # TODO: Extract method.
            if vi_cmd_data['scroll_into_view']:
                if vi_cmd_data['scroll_command']:
                    self.view.run_command(*vi_cmd_data['scroll_command'])
                else:
                    # TODO: If moving by lines, scroll the minimum amount to display the new sels.
                    self.view.show(self.view.sel()[0])

            # We cannot run (maybe_)mark_undo_groups_for_gluing/glue_marked_undo_groups commands
            # within a command meant to be subsumed in the group to be glued. It won't work. So
            # let's save the data we need to transtion to the next mode, which will be taken care
            # of later by VintageState.reset().
            # XXX: This code can probably be moved to VintageState.run().
            # TODO: Extract method.
            state = VintageState(self.view)
            state.next_mode = vi_cmd_data['next_mode']
            state.next_mode_command = vi_cmd_data['follow_up_mode']
Exemple #4
0
    def run(self, edit, **vi_cmd_data):
        self.debug("Data in ViRunCommand:", vi_cmd_data)

        state = VintageState(self.view)

        try:
            # Always save carets just in case.
            self.save_caret_pos()

            # If we're about to jump, we need to remember the current position so we can jump back
            # here. XXX creates_jump_at_current_position might be redundant.
            # TODO: Extract method.
            if vi_cmd_data['creates_jump_at_current_position'] or vi_cmd_data[
                    'is_jump']:
                self.add_to_jump_list(vi_cmd_data)

            sels_before_motion = list(self.view.sel())

            # XXX: Fix this. When should we run the motion exactly?
            if vi_cmd_data['action']:
                # If no motion is present, we know we just have to run the action (like ctrl+w, v).
                if ((vi_cmd_data['motion'])
                        or (vi_cmd_data['motion_required']
                            and not view.has_non_empty_selection_region())):
                    self.do_whole_motion(vi_cmd_data)

                    # The motion didn't change the selections: abort action if so required.
                    # TODO: What to do with .post_action() and .restore_original_carets_if_needed() in this event?
                    if (vi_cmd_data['mode']
                            in (_MODE_INTERNAL_NORMAL, MODE_VISUAL)
                            and any([(old == new) for (old, new) in zip(
                                sels_before_motion, list(self.view.sel()))])
                            and vi_cmd_data['cancel_action_if_motion_fails']):
                        # TODO: There should be a method that lets us do this without modifying vi_cmd_data.
                        vi_cmd_data['restore_original_carets'] = True
                        # FIXME: This is redundant: we call the same method in 'finally' clause.
                        self.restore_original_carets_if_needed(vi_cmd_data)
                        utils.blink()
                        state.cancel_macro = True
                        return

                self.do_action(vi_cmd_data)
            else:
                self.do_whole_motion(vi_cmd_data)
                if (vi_cmd_data['mode'] == MODE_NORMAL
                        and any([(old == new) for (old, new) in zip(
                            sels_before_motion, list(self.view.sel()))])):
                    state.cancel_macro = True
                    utils.blink()

        finally:
            # XXX: post_action should be run only if do_action succeeds (?).
            self.do_post_action(vi_cmd_data)

            # TODO: Extract method.
            if vi_cmd_data['must_update_xpos']:
                state = VintageState(self.view)
                state.update_xpos()

            self.do_modify_selections(vi_cmd_data)
            self.restore_original_carets_if_needed(vi_cmd_data)

            # TODO: Extract method.
            if vi_cmd_data['scroll_into_view']:
                if vi_cmd_data['scroll_command']:
                    self.view.run_command(*vi_cmd_data['scroll_command'])
                else:
                    # TODO: If moving by lines, scroll the minimum amount to display the new sels.
                    self.view.show(self.view.sel()[0])

            # We cannot run (maybe_)mark_undo_groups_for_gluing/glue_marked_undo_groups commands
            # within a command meant to be subsumed in the group to be glued. It won't work. So
            # let's save the data we need to transtion to the next mode, which will be taken care
            # of later by VintageState.reset().
            # XXX: This code can probably be moved to VintageState.run().
            # TODO: Extract method.
            state = VintageState(self.view)
            state.next_mode = vi_cmd_data['next_mode']
            state.next_mode_command = vi_cmd_data['follow_up_mode']