Skip to content

Commit

Permalink
fix: make which-key's lazy loading work when it is also lazy-loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 5, 2021
1 parent bbfc640 commit 7d929b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lua/which-key/init.lua
Expand Up @@ -6,6 +6,11 @@ local M = {}

function M.setup(options)
require("which-key.config").setup(options)
if vim.v.vim_did_enter == 0 then
vim.cmd([[au VimEnter * ++once lua require("which-key").load()]])
else
M.load()
end
end

function M.execute(id)
Expand Down Expand Up @@ -42,7 +47,9 @@ function M.show_command(keys, mode)
mode = mode or "n"
keys = Util.t(keys)
if not Util.check_mode(mode) then
Util.error("Invalid mode passed to :WhichKey (Dont create any keymappings to trigger WhichKey. WhichKey does this automaytically)")
Util.error(
"Invalid mode passed to :WhichKey (Dont create any keymappings to trigger WhichKey. WhichKey does this automaytically)"
)
else
M.show(keys, { mode = mode })
end
Expand All @@ -63,6 +70,9 @@ end

-- Load mappings and update only once
function M.load()
if loaded then
return
end
require("which-key.plugins").setup()
require("which-key.colors").setup()
Keys.register({}, { prefix = "<leader>", mode = "n" })
Expand Down
1 change: 0 additions & 1 deletion plugin/which-key.vim
@@ -1,2 +1 @@
command! -nargs=* WhichKey lua require('which-key').show_command(<f-args>)
au VimEnter * ++once lua require("which-key").load()

0 comments on commit 7d929b9

Please sign in to comment.