nvimtools / hydra.nvim

Create custom submodes and menus
MIT License
143 stars 8 forks source link

foreign_keys and exit options do not overwrite color as noted in README #37

Open mintelm opened 6 months ago

mintelm commented 6 months ago

Hello everyone,

there's a sentence in the README that describes that foreign_keys and exit configuration options actually overwrite the behavior specified by a color. At least I could not get it working.

What is my problem? I want to create a DAP hydra that has the policy of an amaranth hydra. However, since DAP stepping/continuing is asynchronous, I have to use a pink hydra. When using a pink hydra and specifying { foreign_keys = 'warn', exit = true }, the behavior of the hydra does not change, i.e. it still processes inputs that are not mapped to a head.

What would solve my problem?

Example code:

    function cmd(command, suffix)
        suffix = suffix or ''
        return '<cmd>' .. command .. '<CR>' .. suffix
    end

    hydra({
        name = 'Debugging',
        config = { color = 'pink', foreign_keys = 'warn', exit = true },
        hint = hints.dap,
        mode = 'n',
        body = '<Leader>d',
        heads = {
            { 'b',     cmd('DapToggleBreakpoint') },
            { 'c',     cmd('DapContinue') },
            { 's',     cmd('DapStepOver') },
            { 'i',     cmd('DapStepInto') },
            { 'o',     cmd('DapStepOut') },
            { 'r',     cmd('DapToggleRepl') },
            { 'u',     function() require('dapui').toggle({ reset = true }) end },
            { 'w',     function() require('dapui').elements.watches.add() end },
            { '<Esc>', nil,                                                     { exit = true, nowait = true, desc = false }, },
        },
    })
benlubas commented 5 months ago

https://github.com/benlubas/hydra.nvim/blob/eb68396f4f3185e000d64711419c71f67b23bb1d/lua/hydra/init.lua#L126

It seems like there's an inconsistency between the docs and the code here.

benlubas commented 5 months ago

going back to when that code was written, the docs said the same thing. Guess it just slipped through at the time and hasn't been caught since.

However, I'm not sure fixing this will even fix the problem you're having. color and exit/foreign_keys do have to be reconciled one way or the other, so you currently can't have a Pink hydra that behaves like an Amaranth one, that would just be made into an Amaranth hydra.

edit. I guess in this case, 'warn' + exit = true would give you a Teal Hydra.

mintelm commented 5 months ago

ahh okay, makes sense that it does not work how I expect it to if the documentation is inconsistent.

Okay, if I understood you correctly: with the current implementation it is basically not possible to have an -- I'll use a different terminology here -- async hydra (pink) that uses foreign_keys = 'warn'?

benlubas commented 5 months ago

Yeah currently impossible. I'd be open to changing it though (at the very least I will update the docs). I'm not sure how hard it would be to do though.

mintelm commented 5 months ago

I mean sure, I am keen on this feature, so I'd be glad if you tried it.