hydra.nvim
hydra.nvim copied to clipboard
having problem when body, heads use different modes
reproduce code: (nvim 0.7.2)
local Hydra = require("hydra")
local treesitter_incsel = require("nvim-treesitter.incremental_selection")
local setup = function()
Hydra({
name = "object select",
config = {
color = "pink",
buffer = true,
invoke_on_body = true,
on_enter = function()
treesitter_incsel.init_selection()
end,
},
mode = { "n" },
body = "gs",
heads = {
{ "a", treesitter_incsel.node_incremental, { private = true, mode = "v" } },
{ "d", treesitter_incsel.node_decremental, { private = true, mode = "v" } },
},
})
end
setup()
in this usecase, i want to bind nmap gs
body trigger .init_selection
, after that function, nvim will enter visual mode, so the two heads need to be pink and vmap
.
did i do something wong here?
oh, the errors:
Error detected while processing /home/haoliang/.config/nvim/init.vim:
line 425:
E5108: Error executing lua ....config/nvim/plugged/hydra.nvim/lua/hydra/layer/init.lua:233: attempt to index a nil value
stack traceback:
....config/nvim/plugged/hydra.nvim/lua/hydra/layer/init.lua:233: in function '_constructor'
...iang/.config/nvim/plugged/hydra.nvim/lua/hydra/class.lua:14: in function 'Layer'
...liang/.config/nvim/plugged/hydra.nvim/lua/hydra/init.lua:473: in function '_setup_pink_hydra'
...liang/.config/nvim/plugged/hydra.nvim/lua/hydra/init.lua:249: in function '_constructor'
...iang/.config/nvim/plugged/hydra.nvim/lua/hydra/class.lua:14: in function 'Hydra'
/home/haoliang/.config/nvim/lua/locals/plugins/hydra.lua:7: in function 'setup'
/home/haoliang/.config/nvim/lua/locals/plugins/init.lua:19: in function 'setup'
[string ":lua"]:1: in main chunk
seems this duplicated to ~~#30~~. oops, it's #17
but, in my case, the error remains. i'm using the latest version e699886, so pardon me for reopening this
You closed this, does that mean the issue is resolved?
nope. i tried to dig into the code to reason it out, unfortunately failed; asked in neovim's matrix room and got no reply. as this issue has not received a confirmation either from you or any other in a week, i think i should close it to stop consuming community's energy, and it could be false positive. thanks for this awesome plugin, i learnt some new workflows! once i get time, i'll investigate it again.
Let keep it opened for now. I will check when I get time.
Fix attempt to index a nil value
in d58a992ae52fe19bc77e3fdf304a2c5e1b74e187
i tried to fixes this keyError, but seems there is another edge case: <cmd>lua vs :lua
(though i had not figured out how hydra sets keymap for heads).
the incremental_selection function relies on visual selection, fwik i have to use :
for it's keymap.
buf_map(bufnr, "v", "a", [[:lua require'nvim-treesitter.incremental_selection'.node_incremental()<cr>]], { silent = true, noremap = true })
that's the keymap hydra made
v a *@<Lua function 50>
i managed to know Hydra's head accept string rhs, after i changed head setting to
{ "a", [[:lua require'nvim-treesitter.incremental_selection'.node_incremental()<cr>]], { private = true, mode = "v" } },
it worked.
hi, thanks to your fix, i can confirm that error is gone. my last comment is nvim-treesitter specific, so i think this issue can be closed safely.