Use noe-tree api commands outside of config mappings? #763
-
He, I'm trying to write Hydra config for neo-tree (it allows u to draw popup with keys - legend, and execute command on key press). It seems neo-tree expect some variables to be passed to commands eg. state, etc. , which are automatically set in netTree mappings function. local state = require("neo-tree.sources.manager").get_state("filesystem") But then using: { "n", function() state.commands.add(state) end, { silent = true } }, In Hydra gives error about state missing config. And other commands require passing multiple variables... |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Take a peek at my dotfiles, I do this exact thing. Consider using the available vim commands for this, that is what they are meant for. {"f", cmd 'Neotree filesystem reveal right', {desc = "Opens Neotree File Explorer", silent = true}}, |
Beta Was this translation helpful? Give feedback.
-
Thx @miversen33 but what it try to do is to add individual NeoTree commands to hydra - not just opening the NeoTree buffer. My idea is to show NeoTree commands popup when NeoTree buffer is focused. Here is my current setup for NvimTree. |
Beta Was this translation helpful? Give feedback.
-
On the one hand, you already have the state part figured out with: local state = require("neo-tree.sources.manager").get_state("filesystem") which will work fine for a sidebar style file system tree. The extra config argument that is added can just be an empty table if you don't want to use any configuration. That means all you need to do to make the example work is to append
You should really do that on every command invocation instead of treating state like a global variable. I would create a function like this: local build_command = function(command_name)
local fn = function()
local cmds = require("neo-tree.sources.filesystem.commands")
local state = require("neo-tree.sources.manager").get_state("filesystem")
state.config = {}
cmds[command_name](state)
end
return fn
end
local Hydra = require "hydra"
local function spawn_nvim_tree_hydra()
nvim_tree_hydra = Hydra {
name = "NeoTree",
hint = hint,
config = {
color = "pink",
invoke_on_body = true,
buffer = 0, -- only for active buffer
hint = {
position = "bottom",
border = "rounded",
},
},
mode = "n",
body = "H",
heads = {
{ "w", "", { silent = true } },
{ "c", "", { silent = true } },
{ "/", build_command("filter"), { silent = true } },
{ "y", build_command("copy_to_clipboard"), { silent = true } },
...
},
}
nvim_tree_hydra:activate()
end That code is completely untested. It may have bugs, but you get the idea. |
Beta Was this translation helpful? Give feedback.
On the one hand, you already have the state part figured out with:
which will work fine for a sidebar style file system tree.
The extra config argument that is added can just be an empty table if you don't want to use any configuration. That means all you need to do to make the example work is to append
You should really do that on every command invocation instead of treating state like a global variable. I would create a function like this: