Beispiel #1
0
def plugin_loaded():
    if _DEBUG:  # pragma: no cover
        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'):  # pragma: no cover
            pc_event = 'install'
        if events.post_upgrade('NeoVintageous'):  # pragma: no cover
            pc_event = 'post_upgrade'
    except ImportError:  # pragma: no cover
        pass  # Package Control isn't available (PC is not required)
    except Exception as e:  # pragma: no cover
        traceback.print_exc()
        loading_exeption = e

    try:
        _update_ignored_packages()
    except Exception as e:  # pragma: no cover
        traceback.print_exc()
        loading_exeption = e

    try:
        load_session()
        load_rc()
    except Exception as e:  # pragma: no cover
        traceback.print_exc()
        loading_exeption = e

    if _startup_exception or loading_exeption:  # pragma: no cover

        clean_views()

        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)
Beispiel #2
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)
Beispiel #3
0
def plugin_loaded():

    try:
        pc_event = None
        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:
        _exception = None

        view = sublime.active_window().active_view()
        # We can't expect a valid view to be returned from active_view(),
        # especially at startup e.g. at startup if the active view is an image
        # then active_view() returns None, because images are not *views*, they
        # are *sheets* (they can be retrieved via active_sheet()).
        # See https://github.com/SublimeTextIssues/Core/issues/2116.
        # TODO [review] Is it necessary to initialise the active view in plugin_loaded()? Doesn't the on_activated() event initialize activated views?  # noqa: E501
        if view:
            init_state(view, new_session=True)

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

    if _EXCEPTION or _exception:

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

        if isinstance(_EXCEPTION, ImportError) or isinstance(
                _exception, 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)
Beispiel #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)