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
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()