chore(mappings): add desc to all mappings
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
|
||||
-- write DEFAULT_KEYMAPS in various formats
|
||||
|
||||
local max_key_help = 0
|
||||
local max_short_help = 0
|
||||
local max_key = 0
|
||||
local max_short = 0
|
||||
local max_callback = 0
|
||||
local outs_help = {}
|
||||
|
||||
for _, m in pairs(DEFAULT_KEYMAPS) do
|
||||
@@ -13,22 +14,23 @@ for _, m in pairs(DEFAULT_KEYMAPS) do
|
||||
for _, key in ipairs(keys) do
|
||||
local out = {}
|
||||
out.key = key
|
||||
max_key_help = math.max(#out.key, max_key_help)
|
||||
max_key = math.max(#out.key, max_key)
|
||||
if first then
|
||||
out.short = m.desc.short
|
||||
max_short_help = math.max(#out.short, max_short_help)
|
||||
max_short = math.max(#out.short, max_short)
|
||||
out.long = m.desc.long
|
||||
first = false
|
||||
end
|
||||
table.insert(outs_help, out)
|
||||
end
|
||||
max_callback = math.max(#m.callback, max_callback)
|
||||
end
|
||||
|
||||
-- help
|
||||
local file = io.open("/tmp/DEFAULT_KEYMAPS.help", "w")
|
||||
io.output(file)
|
||||
io.write "\n"
|
||||
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key_help, max_key_help, max_short_help, max_short_help)
|
||||
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key, max_key, max_short, max_short)
|
||||
for _, m in pairs(outs_help) do
|
||||
if not m.short then
|
||||
io.write(string.format("%s\n", m.key))
|
||||
@@ -42,12 +44,19 @@ io.close(file)
|
||||
-- lua on_attach
|
||||
file = io.open("/tmp/DEFAULT_KEYMAPS.on_attach.lua", "w")
|
||||
io.output(file)
|
||||
io.write "local function on_attach(bufnr, mode, opts)\n"
|
||||
io.write "local Api = require('nvim-tree.api')\n"
|
||||
io.write "local Api = require('nvim-tree.api')\n\n"
|
||||
io.write "local function on_attach(bufnr)\n"
|
||||
fmt = string.format(
|
||||
" vim.keymap.set('n', %%-%d.%ds %%-%d.%ds { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = '%%s', })\n",
|
||||
max_key + 3,
|
||||
max_key + 3,
|
||||
max_callback + 1,
|
||||
max_callback + 1
|
||||
)
|
||||
for _, m in pairs(DEFAULT_KEYMAPS) do
|
||||
local keys = type(m.key) == "table" and m.key or { m.key }
|
||||
for _, key in ipairs(keys) do
|
||||
io.write(string.format(" vim.keymap.set(mode, '%s', %s, opts)\n", key, m.callback))
|
||||
io.write(string.format(fmt, "'" .. key .. "',", m.callback .. ",", m.desc.short))
|
||||
end
|
||||
end
|
||||
io.write "end\n"
|
||||
|
||||
Reference in New Issue
Block a user