smoka7 / multicursors.nvim

A multi cursor plugin for Neovim.
MIT License
444 stars 15 forks source link

Potential Custom Hint Schema #6

Closed vsedov closed 1 year ago

vsedov commented 1 year ago

Thank you for this plugin. It is quite interesting. I was wondering if it would be possible to have custom hint schemes for the hydra, to allow for better readability.

smoka7 commented 1 year ago

It's a good idea, but right now it's not high on my priority list. If you want to submit a PR for this I will help you.

vsedov commented 1 year ago

Hi,

So ive been working around this issue, as ive worked around with custom hydra hint schemes/ auto schemas before.

        local normal_binds = {
            Navigation = {
                'k',
                'j',
                'K',
                'J',
                'N',
                'n',
                '{',
                '}',
                '[',
                ']',
                'q',
                'Q',
            },

            Text_Manipulation = {
                'p',
                'P',
                'y',
                'Y',
                'yy',
                'd',
                'D',
                'dd',
                ':',
            },

            Alignment = {
                'z',
                'Z',
            },
            Select_Control = {
                '.',
                ',',
                'b',
                '@',
            },
            End_Table = {
                '<esc>',
                'i',
                'c',
                'a',
                'e',
            },
        }

        local headers_lookup = {}
        for _, header in ipairs(heads) do
            headers_lookup[header[1]] = header[3].desc
        end

         local category_order = {
              'Navigation',
              'Text_Manipulation',
              'Alignment',
              'Select_Control',
              'End_Table',
         }

        local str = ''
        for _, category in ipairs(category_order) do
            local keys = normal_binds[category]
            category = string.gsub(category, '_', ' ')
            str = str .. category .. '\n'
            str = str
                .. '▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n'
            for _, key in ipairs(keys) do
                local description = headers_lookup[key]
                str = str .. '_' .. key .. '_: ' .. description .. '\n'
            end
            str = str .. '\n'
        end
        return str

The rather odd question i have is the user would have the ability to change up the binds, and wondering if I should just refer from config.normal_keys and use that exact ordering for the hydra keys instead, wondering if that would be more ideal ? This is more so a proof of concept ofcourse, wanted to know your opinions on the ordering system idea. Without the normal_binds, the binds were in random order . Which was slightly annoying.

Now ofcourse i could be over engineering this .

Such that if we wanted to follow the principle of justing using the config.[key_type] order it self it would need to be refactored as

    { key = 'w', method = E.w_method }

So was wondering if there is another way of doing this ? Perhaps user defined ? Hydra instead ?

smoka7 commented 1 year ago

Thanks for putting in the effort. Since we have a lot of keys and there will be more in the future. Hints gonna take a lot of space and I think most users want to disable it so having a simple hint will be good enough. Grouping the hint are hard because we merge default config with user's and that could easily break the ordering. Having a config value for the user to provide their own hint and having a default generated like this

config.hints = {
    normal_mode = [[hints]],
    insert_mode = [[hints]],
    extend_mode = [[hints]],
}
---@param config Config
local function generate_hints(config)
    if config.hints.normal_mode then
        return config.hints.normal_mode
    end
--- ...
    for key, value in pairs(config.normal_keys) do
        str = str .. '_' .. key .. '_: ' .. value.desc .. '\n'
    end
--- ...
end

If you want to work on this please open a pr, review is easier over there. 🙏🙏