hydra.nvim icon indicating copy to clipboard operation
hydra.nvim copied to clipboard

Cannot use `_` as a head

Open andrewferrier opened this issue 3 years ago • 3 comments

It appears that a single _ character cannot be used as a head.

Example:

hydra({
    config = {
        exit = true,
    },
    name = "Change case",
    mode = "n",
    body = "gyc",
    heads = {
        {"_", function() require("textcase").operator("to_snake_case") end },
        {"-", function() require("textcase").operator("to_dash_case") end },

        { "<Esc>", nil, { exit = true } },
    },
})

... fails, as soon as gyc is typed, an error is shown:

E5108: Error executing lua: ...vim/site/pack/packer/start/hydra.nvim/lua/hydra/init.lua:648: attempt to index a nil value
stack traceback:
        ...vim/site/pack/packer/start/hydra.nvim/lua/hydra/init.lua:648: in function '_make_hint_buffer'
        ...vim/site/pack/packer/start/hydra.nvim/lua/hydra/init.lua:482: in function '_show_hint'
        ...vim/site/pack/packer/start/hydra.nvim/lua/hydra/init.lua:424: in function '_enter'
        ...vim/site/pack/packer/start/hydra.nvim/lua/hydra/init.lua:212: in function <...vim/site/pack/packer/start/hydra.nvim/lua/hydra/init.
lua:212>

Changing it to this:

hydra({
    config = {
        exit = true,
    },
    name = "Change case",
    mode = "n",
    body = "gyc",
    heads = {
        {"x", function() require("textcase").operator("to_snake_case") end },
        {"-", function() require("textcase").operator("to_dash_case") end },

        { "<Esc>", nil, { exit = true } },
    },
})

works (x and - can now be used as expected as heads).

Thanks for your hard work on this great plugin!

andrewferrier avatar Jul 01 '22 15:07 andrewferrier

Actually, I suspect this might be an auto-hint generation issue. The same bug occurs if _ is anywhere in the desc attached to a head.

andrewferrier avatar Jul 01 '22 15:07 andrewferrier

I seem to be able to use _ as one of my hydra heads. However, I get a runtime error when I try to create a hint table for it.

rsurasin avatar May 07 '23 16:05 rsurasin

Workaround is to set desc = false for that head and won't try to add it to the hint.

ironsigma avatar Sep 25 '23 21:09 ironsigma