How can I hook into the keys handler? #891
Replies: 2 comments 2 replies
-
That can't work indeed, since once your plugin runs all those keymaps would already have been added. I also strongly dislike the way you interfer with lazy this way. Definitely not the way to do this. That part of the code is running in a limited environment and loading other plugins / requiring other Lua modules there is not always going to work as expected, since lazy startup didn't finish yet. I have to go here in a bit, but will reply later today or tomorrow with a much better way for you to get all de lazy defined keymaps. |
Beta Was this translation helpful? Give feedback.
-
This should do what you want. local Config = require("lazy.core.config")
local Handler = require("lazy.core.handler")
for _, plugin in pairs(Config.plugins) do
local keys = Handler.handlers.keys:values(plugin)
for _, keymap in pairs(keys) do
if keymap.desc and #keymap.desc > 0 then
local legendary_keymap = {
keymap[1], -- lhs
description = keymap.desc,
mode = keymap.mode, ---@type string|string[]|nil
}
require("legendary").keymap(legendary_keymap)
end
end
end |
Beta Was this translation helpful? Give feedback.
-
Hi folke, thanks for all the awesome plugins you've provided the community!
I'm trying to write an integration for legendary.nvim such that any keymaps defined on a
lazy.nvim
plugin spec via thekeys
property will be automatically loaded into thelegendary.nvim
registry.My first attempt was monkey-patching the
:_add
function inlazy.core.handlers.keys
but that doesn't seem to work, I assume because of something to do with metatables and the function being defined with a:
instead of.
, so my monkey-patch is not overwriting the implementation of the instance?Is there any way to have
legendary.nvim
easily "hook into" the key handlers oflazy.nvim
?Here's a bit of code I was playing with (that does not work):
Beta Was this translation helpful? Give feedback.
All reactions