Beispiel #1
0
    def run(self, initial_text=':', cmd_line=''):
        if cmd_line:
            # The caller has provided a command, to we're not in interactive
            # mode -- just run the command.
            ViColonInput.interactive_call = False
            self.on_done(cmd_line)
            return
        else:
            ViColonInput.interactive_call = True

        FsCompletion.invalidate()

        v = mark_as_widget(
            show_ipanel(self.window,
                        initial_text=self.adjust_initial_text(initial_text),
                        on_done=self.on_done,
                        on_change=self.on_change))

        v.set_syntax_file(
            'Packages/NeoVintageous/res/Command-line mode.sublime-syntax')
        v.settings().set('gutter', False)
        v.settings().set('rulers', [])
        v.settings().set('auto_match_enabled', False)

        state = State(self.window.active_view())
        state.reset_during_init = False
Beispiel #2
0
    def on_text_command(self, view, command, args):
        if command == 'drag_select':
            state = State(view)

            if state.mode in (_VISUAL_MODE, _VISUAL_LINE_MODE,
                              _VISUAL_BLOCK_MODE):
                if (args.get('extend') or (args.get('by') == 'words')
                        or args.get('additive')):
                    return
                elif not args.get('extend'):
                    return ('sequence', {
                        'commands':
                        [['drag_select', args],
                         ['_enter_normal_mode', {
                             'mode': state.mode
                         }]]
                    })

            elif state.mode == _NORMAL_MODE:
                # TODO(guillermooo): Dragging the mouse does not seem to
                # fire a different event than simply clicking. This makes it
                # hard to update the xpos.
                if args.get('extend') or (args.get('by') == 'words'):
                    return ('sequence', {
                        'commands':
                        [['drag_select', args],
                         ['_enter_visual_mode', {
                             'mode': state.mode
                         }]]
                    })
Beispiel #3
0
    def run(self, edit):
        if self.view.score_selector(0, 'text.excmdline') == 0:
            return

        state = State(self.view)
        FsCompletion.frozen_dir = (FsCompletion.frozen_dir or
                                   (state.settings.vi['_cmdline_cd'] + '/'))

        cmd, prefix, only_dirs = parse(self.view.substr(self.view.line(0)))
        if not cmd:
            return

        if not (FsCompletion.prefix or FsCompletion.items) and prefix:
            FsCompletion.prefix = prefix
            FsCompletion.is_stale = True

        if prefix == '..':
            FsCompletion.prefix = '../'
            self.view.run_command('write_fs_completion', {
                'cmd': cmd,
                'completion': '../'
            })

        if prefix == '~':
            path = os.path.expanduser(prefix) + '/'
            FsCompletion.prefix = path
            self.view.run_command('write_fs_completion', {
                'cmd': cmd,
                'completion': path
            })

            return

        if (not FsCompletion.items) or FsCompletion.is_stale:
            FsCompletion.items = iter_paths(from_dir=FsCompletion.frozen_dir,
                                            prefix=FsCompletion.prefix,
                                            only_dirs=only_dirs)
            FsCompletion.is_stale = False

        try:
            self.view.run_command('write_fs_completion', {
                'cmd': cmd,
                'completion': next(FsCompletion.items)
            })
        except StopIteration:
            FsCompletion.items = iter_paths(prefix=FsCompletion.prefix,
                                            from_dir=FsCompletion.frozen_dir,
                                            only_dirs=only_dirs)

            self.view.run_command('write_fs_completion', {
                'cmd': cmd,
                'completion': FsCompletion.prefix
            })
Beispiel #4
0
    def handle_counts(self, key, repeat_count):
        """Return `True` if the processing of the current key needs to stop."""
        state = State(self.window.active_view())
        if not state.action and key.isdigit():
            if not repeat_count and (key != '0' or state.action_count):
                _logger.debug('[press_key] action count digit \'%s\'', key)
                state.action_count += key
                return True

        if (state.action and (state.mode == modes.OPERATOR_PENDING) and key.isdigit()):
            if not repeat_count and (key != '0' or state.motion_count):
                _logger.debug('[press_key] motion count digit \'%s\'', key)
                state.motion_count += key
                return True
Beispiel #5
0
def _init_vintageous(view, new_session=False):
    """
    Initializes global data. Runs at startup and every time a view gets
    activated, loaded, etc.

    @new_session
      Whether we're starting up Sublime Text. If so, volatile data must be
      wiped.
    """

    _logger.debug("running init for view %d", view.id())

    if not is_view(view):
        # Abort if we got a widget, panel...
        _logger.info(
            '[_init_vintageous] ignoring view: {0}'.format(
                view.name() or view.file_name() or '<???>'))
        try:
            # XXX: All this seems to be necessary here.
            if not is_ignored_but_command_mode(view):
                view.settings().set('command_mode', False)
                view.settings().set('inverse_caret_state', False)
            view.settings().erase('vintage')
            if is_ignored(view):
                # Someone has intentionally disabled NeoVintageous, so let the user know.
                sublime.status_message(
                    'NeoVintageous: Vim emulation disabled for the current view')
        except AttributeError:
            _logger.info(
                '[_init_vintageous] probably received the console view')
        except Exception:
            _logger.error('[_init_vintageous] error initializing view')
        finally:
            return

    state = State(view)

    if not state.reset_during_init:
        # Probably exiting from an input panel, like when using '/'. Don't
        # reset the global state, as it may contain data needed to complete
        # the command that's being built.
        state.reset_during_init = True
        return

    # Non-standard user setting.
    reset = state.settings.view['vintageous_reset_mode_when_switching_tabs']
    # XXX: If the view was already in normal mode, we still need to run the
    # init code. I believe this is due to Sublime Text (intentionally) not
    # serializing the inverted caret state and the command_mode setting when
    # first loading a file.
    # If the mode is unknown, it might be a new file. Let normal mode setup
    # continue.
    if not reset and (state.mode not in (modes.NORMAL, modes.UNKNOWN)):
        return

    # If we have no selections, add one.
    if len(state.view.sel()) == 0:
        state.view.sel().add(sublime.Region(0))

    state.logger.info('[_init_vintageous] running init')

    if state.mode in (modes.VISUAL, modes.VISUAL_LINE):
        # TODO: Don't we need to pass a mode here?
        view.window().run_command('_enter_normal_mode', {'from_init': True})

    elif state.mode in (modes.INSERT, modes.REPLACE):
        # TODO: Don't we need to pass a mode here?
        view.window().run_command('_enter_normal_mode', {'from_init': True})

    elif (view.has_non_empty_selection_region() and
          state.mode != modes.VISUAL):
            # Runs, for example, when we've performed a search via ST3 search
            # panel and we've pressed 'Find All'. In this case, we want to
            # ensure a consistent state for multiple selections.
            # TODO: We could end up with multiple selections in other ways
            #       that bypass _init_vintageous.
            state.mode = modes.VISUAL

    else:
        # This may be run when we're coming from cmdline mode.
        pseudo_visual = view.has_non_empty_selection_region()
        mode = modes.VISUAL if pseudo_visual else state.mode
        # TODO: Maybe the above should be handled by State?
        state.enter_normal_mode()
        view.window().run_command('_enter_normal_mode', {'mode': mode,
                                                         'from_init': True})

    state.reset_command_data()
    if new_session:
        state.reset_volatile_data()

        # Load settings.
        DotFile.from_user().run()
Beispiel #6
0
 def create_state(self):
     return State(self.view)
Beispiel #7
0
    def on_post_save(self, view):
        modeline(view)

        # Ensure the carets are within valid bounds. For instance, this is a
        # concern when 'trim_trailing_white_space_on_save' is set to true.
        view.run_command('_vi_adjust_carets', {'mode': State(view).mode})
Beispiel #8
0
 def adjust_initial_text(self, text):
     state = State(self.window.active_view())
     if state.mode in (modes.VISUAL, modes.VISUAL_LINE):
         text = ":'<,'>" + text[1:]
     return text
Beispiel #9
0
def plugin_loaded():
    v = sublime.active_window().active_view()
    state = State(v)
    d = os.path.dirname(v.file_name()) if v.file_name() else os.getcwd()
    state.settings.vi['_cmdline_cd'] = d
Beispiel #10
0
 def run(self, key=None):
     state = State(self.window.active_view())
     state.motion = cmd_defs.ViSearchBackwardImpl()
     state.last_buffer_search = (state.motion._inp or state.last_buffer_search)
Beispiel #11
0
 def state(self):
     return State(self._view)
Beispiel #12
0
 def on_query_context(self, view, key, operator, operand, match_all):
     vintage_state = State(view)
     return vintage_state.context.check(key, operator, operand, match_all)