Ejemplo n.º 1
0
def goto_help(window):
    view = window.active_view()
    if not view:
        raise ValueError('view is required')

    if not view.sel():
        raise ValueError('selection is required')

    sel = view.sel()[0]

    score = view.score_selector(sel.b, 'text.neovintageous jumptag')

    # TODO goto to help for any word in a help file. See :h bar Anyway, you can
    # use CTRL-] on any word, also when it is not within |, and Vim will try to
    # find help for it.  Especially for options in single quotes, e.g.
    # 'compatible'.

    if score == 0:
        return

    subject = view.substr(view.extract_scope(sel.b))
    if not subject:
        return

    if len(subject) > 35:
        return status_message('E149: Sorry, no help found')

    # TODO Refactor ex cmd internets to this common utility
    from NeoVintageous.nv.ex_cmds import do_ex_command
    do_ex_command(window, 'help', {'subject': subject})
Ejemplo n.º 2
0
    def run(self):
        view = self.window.active_view()
        pt = view.sel()[0]
        # scope_name() needs to striped due to a bug in ST:
        # See https://github.com/SublimeTextIssues/Core/issues/657.
        scope = view.scope_name(pt.b).rstrip()

        # TODO Fix jumptags scopes (rename them to less generic scopes)
        jumptag_scopes = [
            'text.neovintageous.help string.neovintageous',
            'text.neovintageous.help support.constant.neovintageous'
        ]

        if scope not in jumptag_scopes:
            return

        subject = view.substr(view.extract_scope(pt.b))

        if len(subject) < 3:
            return message('E149: Sorry, no help for %s' % subject)

        match = re.match('^\'[a-z_]+\'|\\|[^\\s\\|]+\\|$', subject)
        if match:
            do_ex_command(self.window, 'help', {'subject': subject.strip('|')})
        else:
            return message('E149: Sorry, no help for %s' % subject)
Ejemplo n.º 3
0
def window_tab_control(window,
                       action: str,
                       count: int = 1,
                       index: int = None) -> None:
    view = window.active_view()
    if not view:
        return status_message('view not found')

    view_count = len(window.views_in_group(window.active_group()))
    group_index, view_index = window.get_view_index(view)

    if action == 'next':
        window.run_command('select_by_index',
                           {'index': (view_index + count) % view_count})

    elif action == 'previous':
        window.run_command(
            'select_by_index',
            {'index': (view_index + view_count - count) % view_count})

    elif action == 'last':
        window.run_command('select_by_index', {'index': view_count - 1})

    elif action == 'first':
        window.run_command('select_by_index', {'index': 0})

    elif action == 'goto':
        if index:
            window.run_command('select_by_index', {'index': index - 1})

    elif action == 'only':
        group_views = window.views_in_group(group_index)
        if any(view.is_dirty() for view in group_views):
            return status_message('E445: Other window contains changes')

        for group_view in group_views:
            if group_view.id() == view.id():
                continue

            window.focus_view(group_view)

            # TODO [review] Probably doesn't need use :quit (just close the view).
            from NeoVintageous.nv.ex_cmds import do_ex_command

            do_ex_command(window, 'quit')

        window.focus_view(view)

    elif action == 'close':
        window.run_command('close_by_index', {
            'group': group_index,
            'index': view_index
        })

    else:
        raise ValueError('unknown tab control action: %s' % action)
Ejemplo n.º 4
0
    def run(self):
        view = self.window.active_view()
        if not view:
            raise ValueError('view is required')

        if not view.sel():
            raise ValueError('selection is required')

        sel = view.sel()[0]

        score = view.score_selector(sel.b, 'text.neovintageous jumptag')
        # TODO ENHANCEMENT Allow goto to help for any word in a help file. See :h bar Anyway, you can use CTRL-] on any word, also when it is not within |, and Vim will try to find help for it.  Especially for options in single quotes, e.g. 'compatible'.  # noqa: E501
        if score == 0:
            return  # noop

        subject = view.substr(view.extract_scope(sel.b))
        if not subject:
            return  # noop

        if len(subject) > 35:
            return message('E149: Sorry, no help found')

        do_ex_command(self.window, 'help', {'subject': subject})