Skip to content

Handling window-specific options (e.g., wo[1002] notation) #284

@stv17

Description

@stv17

Hi, this is kind of a follow up to this other issue I opened: #283

Once again, great plugin, thank you.

Problem

I started with the <plug>leap-anywhere plug mapping, and jumping to any visible part of the screen is great. I have, however, noticed the following:

  • When I have multiple window splits sometimes buffer contents "move" when I start leap-mode. This can be disorienting.
  • It has to do with the vim.wo.conceallevel of the window and how it can be set to a different value while leaping.
  • I would like to "preserve" the conceal level of EACH window once I enter leap mode, to prevent contents from hiding/unhiding.

The problem with setting a different default value for the vim_opts['wo.conceallevel'] is that it applies to ALL windows, and if some have different conceal levels this option cannot be set the same for all of them if you wish to preserve their current conceal level.

Consider this scenario:

  • 2 windows split
  • One with an Oil buffer that has vim.wo.conceallevel = 3
  • Another with a markdown file with vim.wo.conceallevel = 0

No matter from which window I start the leap the other will always have a different conceal level value, causing content to be shown/hidden and the buffer to move.

I thought I could patch this up with runtime configs. Initially I attempted using LeapPre to provide each window with the value to use (their current value) using "wo[xyz].notation" but I believe this is unsupported. Something like this:

require("leap").leap({
    windows = { 0, 1002, 1003 },
    opts = {
        vim_opts = {
            ['wo[1002].conceallevel'] = vim.wo[1002].conceallevel,
            ['wo[1003].conceallevel'] = vim.wo[1003].conceallevel,
        },
    },
}

NOTES:

Research

Looking at the file lua/leap/main.lua @ function manage_vim_opts() I see that the option is only set for windows if the scope matches the "wo" string, ignoring the "wo[xyz]" notation case.

I took a stab at this and managed to get my use case working, I think. Because I don't know the first thing about fennel I'll just leave two patches atop the lua files here in case it's useful:

To make it work, besides those changes to leap.nvim, I have these configs:

vim.keymap.set('n', 'gl', '<Plug>(leap-anywhere)')

-- Remove this default option. I handle conceal level in LeapPre autocmd and it clases with the wo[1000] scope.
opts.vim_opts['wo.conceallevel'] = nil

vim.api.nvim_create_autocmd('User', {
    pattern = 'LeapEnter',
    callback = function(_)
        local leap_args = require('leap').state.args
        -- Preserve all window's current conceal level while leaping
        local custom_opts = { opts = { vim_opts = {} }, }
        for _,win in pairs(leap_args.windows) do
            local win_key = "wo[" .. win .. "].conceallevel"
            custom_opts.opts.vim_opts[win_key] = vim.wo[win].conceallevel
        end
        require('leap').state.args = vim.tbl_deep_extend('force', leap_args, custom_opts)
        -- PrintObject(require('leap').state.args)
    end
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions