コード例 #1
0
def _resize_secondary(nvim: Nvim) -> None:
    tab = cur_tab(nvim)
    wins = tab_list_wins(nvim, tab=tab)
    height = nvim.options["previewheight"]

    for win in wins:
        is_preview: bool = win_get_option(nvim, win=win, key="previewwindow")
        buf = win_get_buf(nvim, win=win)
        ft = buf_filetype(nvim, buf=buf)
        if is_preview or ft == "qf":
            nvim.api.win_set_height(win, height)
コード例 #2
0
def _toggle_preview(nvim: Nvim) -> None:
    tab = cur_tab(nvim)
    wins = tab_list_wins(nvim, tab=tab)
    closed = False
    for win in wins:
        is_preview: bool = win_get_option(nvim, win=win, key="previewwindow")
        if is_preview:
            win_close(nvim, win=win)
            closed = True
    if not closed:
        nvim.command("new")
        win = cur_win(nvim)
        win_set_option(nvim, win=win, key="previewwindow", val=True)
        height = nvim.options["previewheight"]
        nvim.api.win_set_height(win, height)
コード例 #3
0
def find_windows_in_tab(nvim: Nvim, no_secondary: bool) -> Iterator[Window]:
    def key_by(win: Window) -> Tuple[int, int]:
        """
        -> sort by row, then col
        """

        row, col = nvim.funcs.win_screenpos(win.number)
        return col, row

    tab = cur_tab(nvim)
    wins = tab_list_wins(nvim, tab=tab)

    for win in sorted(wins, key=key_by):
        is_preview: bool = win_get_option(nvim, win=win, key="previewwindow")
        buf = win_get_buf(nvim, win)
        ft = buf_filetype(nvim, buf=buf)
        is_secondary = is_preview or ft == "qf"
        if not is_secondary or not no_secondary:
            yield win
コード例 #4
0
def find_windows_in_tab(nvim: Nvim, last_used: Mapping[int, None],
                        no_secondary: bool) -> Iterator[Window]:
    ordering = {win_id: idx for idx, win_id in enumerate(reversed(last_used))}

    def key_by(win: Window) -> Tuple[float, int, int]:
        """
        -> sort by last_used, then row, then col
        """

        pos = ordering.get(win.handle, inf)
        row, col = nvim.funcs.win_screenpos(win.number)
        return pos, col, row

    tab = cur_tab(nvim)
    wins = tab_list_wins(nvim, tab=tab)
    ordered = sorted(wins, key=key_by)

    for win in ordered:
        is_preview: bool = win_get_option(nvim, win=win, key="previewwindow")
        buf = win_get_buf(nvim, win)
        ft = buf_filetype(nvim, buf=buf)
        is_secondary = is_preview or ft == "qf"
        if not is_secondary or not no_secondary:
            yield win
コード例 #5
0
def initial(nvim: Nvim, specs: Sequence[RpcSpec]) -> Settings:
    win = cur_win(nvim)
    artifacts: Artifact = decode(Artifact,
                                 safe_load(ARTIFACT.read_text("UTF-8")))

    user_config = nvim.vars.get(SETTINGS_VAR, {})
    config: _UserConfig = decode(
        _UserConfig,
        merge(safe_load(CONFIG_YML.read_text("UTF-8")),
              hydrate(user_config),
              replace=True),
    )
    options, view, theme = config.options, config.view, config.theme
    win_actual_opts: Mapping[str, Union[bool, str]] = {
        opt: cast(Union[bool, str], win_get_option(nvim, win=win, key=opt))
        for opt in view.window_options
    }

    icons, hl_context = load_theme(
        nvim,
        artifact=artifacts,
        particular_mappings=theme.highlights,
        discrete_colours=theme.discrete_colour_map,
        icon_set=theme.icon_glyph_set,
        icon_colour_set=theme.icon_colour_set,
        text_colour_set=theme.text_colour_set,
    )

    view_opts = ViewOptions(
        hl_context=hl_context,
        icons=icons,
        sort_by=view.sort_by,
        use_icons=theme.icon_glyph_set is not IconGlyphSetEnum.ascii,
        time_fmt=view.time_format,
    )

    keymap = {f"CHAD{k}": v for k, v in config.keymap.items()}
    legal_keys = {name for name, _ in specs}
    extra_keys = keymap.keys() - legal_keys

    if extra_keys:
        raise DecodeError(
            path=(_UserOptions, _key_sort(legal_keys)),
            actual=None,
            missing_keys=(),
            extra_keys=_key_sort(extra_keys),
        )

    settings = Settings(
        close_on_open=options.close_on_open,
        follow=options.follow,
        ignores=config.ignore,
        keymap=keymap,
        lang=options.lang,
        mime=options.mimetypes,
        open_left=view.open_direction is _OpenDirection.left,
        page_increment=options.page_increment,
        polling_rate=float(options.polling_rate),
        session=options.session,
        show_hidden=options.show_hidden,
        version_ctl=options.version_control,
        view=view_opts,
        width=view.width,
        win_actual_opts=win_actual_opts,
        win_local_opts=view.window_options,
        xdg=config.xdg,
        profiling=config.profiling,
    )

    return settings