-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
which-key.lua
63 lines (42 loc) · 1.53 KB
/
which-key.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local table = _tl_compat and _tl_compat.table or table; require('legendary.types')
local M = {}
local function wk_to_legendary(wk)
local legendary = {}
legendary[1] = wk.prefix
if wk.cmd then
legendary[2] = wk.cmd
end
legendary.description = wk.label
legendary.opts = wk.opts or {}
return legendary
end
function M.parse_whichkey(which_key_tbls, which_key_opts)
local wk_parsed = ((_G['require']('which-key.keys')).parse_mappings)(
{},
which_key_tbls,
which_key_opts and (which_key_opts.prefix) or '')
local legendary_tbls = {}
vim.tbl_map(function(wk)
if not wk.label or ((type(wk.group) == 'boolean' and not wk.group) or (#(tostring(wk.group) or '') > 0)) or wk.buf ~= nil then
goto continue
end
table.insert(legendary_tbls, wk_to_legendary(wk))
::continue::
end, wk_parsed)
return legendary_tbls
end
function M.bind_whichkey(wk_tbls, wk_opts)
local legendary_tbls = M.parse_whichkey(wk_tbls, wk_opts)
require('legendary.bindings').bind_keymaps(legendary_tbls)
end
function M.whichkey_listen()
local wk = (_G['require']('which-key'))
local original = wk.register
local listener = function(whichkey_tbls, whichkey_opts)
M.bind_whichkey(whichkey_tbls, whichkey_opts)
original(whichkey_tbls, whichkey_opts)
end
wk.register = listener
return true
end
return M