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

having problem when body, heads use different modes

Open haolian9 opened this issue 2 years ago • 7 comments

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

haolian9 avatar Jul 27 '22 03:07 haolian9

seems this duplicated to ~~#30~~. oops, it's #17

haolian9 avatar Jul 27 '22 03:07 haolian9

but, in my case, the error remains. i'm using the latest version e699886, so pardon me for reopening this

haolian9 avatar Jul 27 '22 03:07 haolian9

You closed this, does that mean the issue is resolved?

bew avatar Aug 02 '22 01:08 bew

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.

haolian9 avatar Aug 02 '22 02:08 haolian9

Let keep it opened for now. I will check when I get time.

anuvyklack avatar Aug 03 '22 18:08 anuvyklack

Fix attempt to index a nil value in d58a992ae52fe19bc77e3fdf304a2c5e1b74e187

anuvyklack avatar Aug 03 '22 20:08 anuvyklack

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.

haolian9 avatar Aug 03 '22 23:08 haolian9

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.

haolian9 avatar Sep 14 '22 07:09 haolian9