예제 #1
0
def plugin_loaded():

    # Enable sublime debug information if in DEBUG mode.
    if bool(os.getenv('SUBLIME_NEOVINTAGEOUS_DEBUG')):
        sublime.log_input(True)
        sublime.log_commands(True)

    # Some setting defaults are changing! To avoid impacting users in a later
    # update, this patch sets the current value to whatever is currently used.
    # See Roadmap: https://github.com/NeoVintageous/NeoVintageous/issues/404.
    preferences = sublime.load_settings('Preferences.sublime-settings')
    build_version = preferences.get('neovintageous_build_version',
                                    0)  # type: int
    if not build_version or int(build_version) < 11000:
        preferences.set('neovintageous_build_version', 11000)
        preferences.set('vintageous_use_ctrl_keys',
                        preferences.get('vintageous_use_ctrl_keys'))
        preferences.set('vintageous_use_super_keys',
                        preferences.get('vintageous_use_super_keys'))
        sublime.save_settings('Preferences.sublime-settings')

    loading_exeption = None

    pc_event = None

    try:
        from package_control import events
        if events.install('NeoVintageous'):
            pc_event = 'install'
        if events.post_upgrade('NeoVintageous'):
            pc_event = 'post_upgrade'
    except ImportError:
        pass  # Package Control isn't available (PC is not required)
    except Exception as e:
        import traceback
        traceback.print_exc()
        loading_exeption = e

    try:
        _update_ignored_packages()
    except Exception as e:
        import traceback
        traceback.print_exc()
        loading_exeption = e

    try:
        from NeoVintageous.nv import rc
        rc.load()
    except Exception as e:
        import traceback
        traceback.print_exc()
        loading_exeption = e

    if _startup_exception or loading_exeption:

        try:
            _cleanup_views()
        except Exception:
            import traceback
            traceback.print_exc()

        if isinstance(_startup_exception, ImportError) or isinstance(
                loading_exeption, ImportError):
            if pc_event == 'post_upgrade':
                message = "Failed to load some modules trying to upgrade NeoVintageous. "\
                          "Please restart Sublime Text to finish the upgrade."
            else:
                message = "Failed to load some NeoVintageous modules. "\
                          "Please restart Sublime Text."
        else:
            if pc_event == 'post_upgrade':
                message = "An error occurred trying to upgrade NeoVintageous. "\
                          "Please restart Sublime Text to finish the upgrade."
            else:
                message = "An error occurred trying to load NeoVintageous. "\
                          "Please restart Sublime Text."

        print('NeoVintageous: ERROR', message)
        sublime.message_dialog(message)
예제 #2
0
def init_state(view, new_session=False):
    # type: (...) -> None
    # Initialise view state.
    #
    # Runs at startup and every time a view gets activated, loaded, etc.
    #
    # Args:
    #   :view (sublime.View):
    #   :new_session (bool): Whether we're starting up Sublime Text. If so,
    #       volatile data must be wiped, and vintageousrc file must be loaded.

    if not is_view(view):
        # Abort if we got a console, widget, panel...
        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')
        except Exception:
            # TODO [review] Exception handling
            _log.debug('error initialising irregular view i.e. console, widget, panel, etc.')
        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 (NORMAL, UNKNOWN)):
        return

    # If we have no selections, add one.
    if len(state.view.sel()) == 0:
        _log.debug('no selection, adding one at 0...')
        state.view.sel().add(Region(0))

    if state.mode in (VISUAL, 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 (INSERT, 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 != 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_state.
        state.mode = VISUAL
    else:
        # This may be run when we're coming from cmdline mode.
        pseudo_visual = view.has_non_empty_selection_region()
        mode = 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()
        rc.load()

        # TODO is setting the cwd for cmdline necessary?
        cmdline_cd = os.path.dirname(view.file_name()) if view.file_name() else os.getcwd()
        state.settings.vi['_cmdline_cd'] = cmdline_cd
예제 #3
0
def plugin_loaded():

    # Enable sublime debug information if in DEBUG mode.
    if _DEBUG:
        sublime.log_input(True)
        sublime.log_commands(True)

    _init_backwards_compat_patches()

    loading_exeption = None

    pc_event = None

    try:
        from package_control import events
        if events.install('NeoVintageous'):
            pc_event = 'install'
        if events.post_upgrade('NeoVintageous'):
            pc_event = 'post_upgrade'
    except ImportError:
        pass  # Package Control isn't available (PC is not required)
    except Exception as e:
        import traceback
        traceback.print_exc()
        loading_exeption = e

    try:
        _update_ignored_packages()
    except Exception as e:
        import traceback
        traceback.print_exc()
        loading_exeption = e

    try:
        from NeoVintageous.nv import rc
        rc.load()
    except Exception as e:
        import traceback
        traceback.print_exc()
        loading_exeption = e

    if _startup_exception or loading_exeption:

        try:
            _cleanup_views()
        except Exception:
            import traceback
            traceback.print_exc()

        if isinstance(_startup_exception, ImportError) or isinstance(
                loading_exeption, ImportError):
            if pc_event == 'post_upgrade':
                message = "Failed to load some modules trying to upgrade NeoVintageous. "\
                          "Please restart Sublime Text to finish the upgrade."
            else:
                message = "Failed to load some NeoVintageous modules. "\
                          "Please restart Sublime Text."
        else:
            if pc_event == 'post_upgrade':
                message = "An error occurred trying to upgrade NeoVintageous. "\
                          "Please restart Sublime Text to finish the upgrade."
            else:
                message = "An error occurred trying to load NeoVintageous. "\
                          "Please restart Sublime Text."

        print('NeoVintageous: ERROR', message)
        sublime.message_dialog(message)
예제 #4
0
def plugin_loaded():

    # Enable sublime debug information if in DEBUG mode.
    if bool(os.getenv('SUBLIME_NEOVINTAGEOUS_DEBUG')):
        sublime.log_input(True)
        sublime.log_commands(True)

    pc_event = None

    try:
        from package_control import events
        if events.install('NeoVintageous'):
            pc_event = 'install'
        if events.post_upgrade('NeoVintageous'):
            pc_event = 'post_upgrade'
    except ImportError:
        pass  # Package Control isn't available (PC is not required)
    except Exception:
        import traceback
        traceback.print_exc()

    try:
        _update_ignored_packages()
    except Exception:
        import traceback
        traceback.print_exc()

    try:
        _loading_exeption = None

        from NeoVintageous.nv import rc

        rc.load()

        window = sublime.active_window()
        if window:
            # Hack to correctly set the current woring directory. The way
            # settings are handled needs to be completley overhauled.
            def set_window_cwd(window):
                settings = window.settings().get('vintage')

                if not isinstance(settings, dict):
                    settings = {}

                variables = window.extract_variables()
                if 'folder' in variables:
                    settings['_cmdline_cd'] = variables['folder']

                window.settings().set('vintage', settings)

            set_window_cwd(window)

    except Exception as e:
        import traceback
        traceback.print_exc()
        _loading_exeption = e

    if _startup_exception or _loading_exeption:

        try:
            _cleanup_views()
        except Exception:
            import traceback
            traceback.print_exc()

        if isinstance(_startup_exception, ImportError) or isinstance(_loading_exeption, ImportError):
            if pc_event == 'post_upgrade':
                message = "Failed to load some modules trying to upgrade NeoVintageous. "\
                          "Please restart Sublime Text to finish the upgrade."
            else:
                message = "Failed to load some NeoVintageous modules. "\
                          "Please restart Sublime Text."
        else:
            if pc_event == 'post_upgrade':
                message = "An error occurred trying to upgrade NeoVintageous. "\
                          "Please restart Sublime Text to finish the upgrade."
            else:
                message = "An error occurred trying to load NeoVintageous. "\
                          "Please restart Sublime Text."

        print('NeoVintageous: ERROR', message)
        sublime.message_dialog(message)