Refresh generated neovim config
This commit is contained in:
@ -64,7 +64,7 @@ local defaults = {
|
||||
show_help = true, -- show a help message in the command line for using WhichKey
|
||||
show_keys = true, -- show the currently pressed key and its label as a message in the command line
|
||||
triggers = "auto", -- automatically setup triggers
|
||||
-- triggers = {"<leader>"} -- or specifiy a list manually
|
||||
-- triggers = {"<leader>"} -- or specify a list manually
|
||||
-- list of triggers, where WhichKey should not wait for timeoutlen and show immediately
|
||||
triggers_nowait = {
|
||||
-- marks
|
||||
@ -85,7 +85,7 @@ local defaults = {
|
||||
v = { "j", "k" },
|
||||
},
|
||||
-- disable the WhichKey popup for certain buf types and file types.
|
||||
-- Disabled by deafult for Telescope
|
||||
-- Disabled by default for Telescope
|
||||
disable = {
|
||||
buftypes = {},
|
||||
filetypes = {},
|
||||
@ -97,6 +97,9 @@ M.options = {}
|
||||
|
||||
---@param options? Options
|
||||
function M.setup(options)
|
||||
if vim.fn.has("nvim-0.9") == 0 then
|
||||
return vim.notify("WhichKey.nvim requires Neovim 0.9 or higher", vim.log.levels.ERROR)
|
||||
end
|
||||
M.options = vim.tbl_deep_extend("force", {}, defaults, options or {})
|
||||
end
|
||||
|
||||
|
||||
@ -25,11 +25,6 @@ function M.setup(options)
|
||||
schedule_load()
|
||||
end
|
||||
|
||||
function M.execute(id)
|
||||
local func = Keys.functions[id]
|
||||
return func()
|
||||
end
|
||||
|
||||
function M.show(keys, opts)
|
||||
opts = opts or {}
|
||||
if type(opts) == "string" then
|
||||
@ -98,11 +93,4 @@ function M.load()
|
||||
loaded = true
|
||||
end
|
||||
|
||||
function M.reset()
|
||||
-- local mappings = Keys.mappings
|
||||
require("plenary.reload").reload_module("which-key")
|
||||
-- require("which-key.Keys").mappings = mappings
|
||||
require("which-key").setup()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -8,10 +8,9 @@ local secret = "Þ"
|
||||
---@class Keys
|
||||
local M = {}
|
||||
|
||||
M.functions = {}
|
||||
M.operators = {}
|
||||
M.nowait = {}
|
||||
M.blacklist = {}
|
||||
M.operators = {} ---@type table<string, boolean>
|
||||
M.nowait = {} ---@type table<string, boolean>
|
||||
M.blacklist = {} ---@type table<string, table<string, boolean>>
|
||||
|
||||
function M.setup()
|
||||
local builtin_ops = require("which-key.plugins.presets").operators
|
||||
@ -39,12 +38,14 @@ function M.setup()
|
||||
end
|
||||
|
||||
function M.get_operator(prefix_i)
|
||||
local ret = { i = nil, n = nil, len = nil }
|
||||
for op_n, _ in pairs(Config.options.operators) do
|
||||
local op_i = Util.t(op_n)
|
||||
if prefix_i:sub(1, #op_i) == op_i then
|
||||
return op_i, op_n
|
||||
if prefix_i:sub(1, #op_i) == op_i and (ret.len == nil or #op_i > ret.len) then
|
||||
ret = { i = op_i, n = op_n, len = #op_i }
|
||||
end
|
||||
end
|
||||
return ret.i, ret.n
|
||||
end
|
||||
|
||||
function M.process_motions(ret, mode, prefix_i, buf)
|
||||
@ -102,11 +103,11 @@ function M.get_mappings(mode, prefix_i, buf)
|
||||
for k, child in pairs(node.children) do
|
||||
if
|
||||
child.mapping
|
||||
and child.mapping.label ~= "which_key_ignore"
|
||||
and child.mapping.desc ~= "which_key_ignore"
|
||||
and not (child.mapping.group and vim.tbl_isempty(child.children))
|
||||
then
|
||||
ret.mappings[k] = vim.tbl_deep_extend("force", {}, ret.mappings[k] or {}, child.mapping)
|
||||
local child_mapping = vim.deepcopy(child.mapping)
|
||||
ret.mappings[k] = vim.tbl_deep_extend("force", ret.mappings[k] or {}, child_mapping)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -126,19 +127,19 @@ function M.get_mappings(mode, prefix_i, buf)
|
||||
if Config.options.key_labels[value.key] then
|
||||
value.key = Config.options.key_labels[value.key]
|
||||
end
|
||||
local skip = not value.label and Config.options.ignore_missing == true
|
||||
local skip = not value.desc and Config.options.ignore_missing == true
|
||||
if Util.t(value.key) == Util.t("<esc>") then
|
||||
skip = true
|
||||
end
|
||||
if not skip then
|
||||
if value.group then
|
||||
value.label = value.label or "+prefix"
|
||||
value.label = value.label:gsub("^%+", "")
|
||||
value.label = Config.options.icons.group .. value.label
|
||||
elseif not value.label then
|
||||
value.label = value.desc or value.cmd or ""
|
||||
value.desc = value.desc or "+prefix"
|
||||
value.desc = value.desc:gsub("^%+", "")
|
||||
value.desc = Config.options.icons.group .. value.desc
|
||||
elseif not value.desc then
|
||||
value.desc = value.cmd or ""
|
||||
for _, v in ipairs(Config.options.hidden) do
|
||||
value.label = value.label:gsub(v, "")
|
||||
value.desc = value.desc:gsub(v, "")
|
||||
end
|
||||
end
|
||||
if value.value then
|
||||
@ -342,7 +343,7 @@ function M.add_hooks(mode, buf, node, secret_only)
|
||||
node.mapping = { prefix = node.prefix_n, group = true, keys = Util.parse_keys(node.prefix_n) }
|
||||
end
|
||||
if node.prefix_n ~= "" and node.mapping.group == true and not (node.mapping.cmd or node.mapping.callback) then
|
||||
-- first non-cmd level, so create hook and make all decendents secret only
|
||||
-- first non-cmd level, so create hook and make all descendents secret only
|
||||
M.hook_add(node.prefix_n, mode, buf, secret_only)
|
||||
secret_only = true
|
||||
end
|
||||
@ -360,7 +361,7 @@ function M.dump()
|
||||
---@param node Node
|
||||
function(node)
|
||||
if node.mapping then
|
||||
if node.mapping.label then
|
||||
if node.mapping.desc then
|
||||
ok[node.mapping.prefix] = true
|
||||
todo[node.mapping.prefix] = nil
|
||||
elseif not ok[node.mapping.prefix] then
|
||||
@ -374,7 +375,7 @@ function M.dump()
|
||||
end
|
||||
|
||||
---@param mode string
|
||||
---@param buf? buffer
|
||||
---@param buf? number
|
||||
function M.get_tree(mode, buf)
|
||||
if mode == "s" or mode == "x" then
|
||||
mode = "v"
|
||||
@ -411,24 +412,34 @@ function M.update_keymaps(mode, buf)
|
||||
|
||||
for _, keymap in pairs(keymaps) do
|
||||
local skip = M.is_hook(keymap.lhs, keymap.rhs)
|
||||
local is_group = false
|
||||
|
||||
if is_nop(keymap) then
|
||||
skip = true
|
||||
if not skip and is_nop(keymap) then
|
||||
if keymap.desc then
|
||||
pcall(vim.keymap.del, { mode }, keymap.lhs, { buffer = buf })
|
||||
is_group = true
|
||||
else
|
||||
skip = true
|
||||
end
|
||||
end
|
||||
|
||||
if not skip then
|
||||
---@type Mapping
|
||||
local mapping = {
|
||||
prefix = keymap.lhs,
|
||||
cmd = keymap.rhs,
|
||||
cmd = not is_group and keymap.rhs or nil,
|
||||
desc = keymap.desc,
|
||||
group = is_group,
|
||||
callback = keymap.callback,
|
||||
keys = Util.parse_keys(keymap.lhs),
|
||||
buf = buf,
|
||||
mode = mode,
|
||||
}
|
||||
-- don't include Plug keymaps
|
||||
if mapping.keys.notation[1]:lower() ~= "<plug>" then
|
||||
local node = tree:add(mapping)
|
||||
if node.mapping and node.mapping.preset and mapping.desc then
|
||||
node.mapping.label = mapping.desc
|
||||
node.mapping.desc = mapping.desc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -45,12 +45,12 @@ function Layout:trail()
|
||||
local cmd_line = { { " " } }
|
||||
for i = 1, len, 1 do
|
||||
local node = buf_path[i]
|
||||
if not (node and node.mapping and node.mapping.label) then
|
||||
if not (node and node.mapping and node.mapping.desc) then
|
||||
node = path[i]
|
||||
end
|
||||
local step = self.mapping.keys.notation[i]
|
||||
if node and node.mapping and node.mapping.label then
|
||||
step = self.options.icons.group .. node.mapping.label
|
||||
if node and node.mapping and node.mapping.desc then
|
||||
step = self.options.icons.group .. node.mapping.desc
|
||||
end
|
||||
if Config.options.key_labels[step] then
|
||||
step = Config.options.key_labels[step]
|
||||
@ -113,7 +113,7 @@ function Layout:layout(win)
|
||||
width = width - pad_right - pad_left
|
||||
|
||||
local max_key_width = self:max_width("key")
|
||||
local max_label_width = self:max_width("label")
|
||||
local max_label_width = self:max_width("desc")
|
||||
local max_value_width = self:max_width("value")
|
||||
|
||||
local intro_width = max_key_width + 2 + Text.len(self.options.icons.separator) + self.options.layout.spacing
|
||||
@ -192,7 +192,7 @@ function Layout:layout(win)
|
||||
start = start + max_value_width + 2
|
||||
end
|
||||
|
||||
local label = item.label
|
||||
local label = item.desc
|
||||
if Text.len(label) > max_label_width then
|
||||
label = vim.fn.strcharpart(label, 0, max_label_width - 2) .. " …"
|
||||
end
|
||||
|
||||
@ -134,7 +134,7 @@ function M._parse(value, mappings, opts)
|
||||
if type(list[1]) ~= "string" then
|
||||
error("Invalid mapping for " .. vim.inspect({ value = value, opts = opts }))
|
||||
end
|
||||
opts.desc = list[1]
|
||||
opts.desc = opts.desc or list[1]
|
||||
-- { cmd, desc }
|
||||
elseif #list == 2 then
|
||||
-- desc
|
||||
@ -179,7 +179,8 @@ function M.to_mapping(mapping)
|
||||
mapping.buffer = nil
|
||||
|
||||
mapping.mode = mapping.mode or "n"
|
||||
mapping.label = mapping.desc or mapping.name
|
||||
mapping.desc = mapping.desc or mapping.name
|
||||
mapping.name = nil
|
||||
mapping.keys = Util.parse_keys(mapping.prefix or "")
|
||||
|
||||
local opts = {}
|
||||
@ -187,25 +188,8 @@ function M.to_mapping(mapping)
|
||||
opts[o] = mapping[o]
|
||||
mapping[o] = nil
|
||||
end
|
||||
|
||||
if vim.fn.has("nvim-0.7.0") == 0 then
|
||||
opts.replace_keycodes = nil
|
||||
|
||||
-- Neovim < 0.7.0 doesn't support descriptions
|
||||
opts.desc = nil
|
||||
|
||||
-- use lua functions proxy for Neovim < 0.7.0
|
||||
if opts.callback then
|
||||
local functions = require("which-key.keys").functions
|
||||
table.insert(functions, opts.callback)
|
||||
if opts.expr then
|
||||
opts.cmd = string.format([[luaeval('require("which-key").execute(%d)')]], #functions)
|
||||
else
|
||||
opts.cmd = string.format([[<cmd>lua require("which-key").execute(%d)<cr>]], #functions)
|
||||
end
|
||||
opts.callback = nil
|
||||
end
|
||||
end
|
||||
-- restore desc
|
||||
mapping.desc = opts.desc
|
||||
|
||||
mapping.opts = opts
|
||||
return mapping
|
||||
|
||||
@ -55,7 +55,7 @@ function M.run(_trigger, _mode, buf)
|
||||
|
||||
table.insert(items, {
|
||||
key = key,
|
||||
label = labels[key] or file and ("file: " .. file) or "",
|
||||
desc = labels[key] or file and ("file: " .. file) or "",
|
||||
value = value,
|
||||
highlights = { { 1, 5, "Number" } },
|
||||
})
|
||||
|
||||
@ -32,6 +32,9 @@ local misc = {
|
||||
O = "Open all folds under cursor",
|
||||
c = "Close fold under cursor",
|
||||
C = "Close all folds under cursor",
|
||||
d = "Delete fold under cursor",
|
||||
D = "Delete all folds under cursor",
|
||||
E = "Delete all folds in file",
|
||||
a = "Toggle fold under cursor",
|
||||
A = "Toggle all folds under cursor",
|
||||
v = "Show cursor line",
|
||||
@ -92,6 +95,7 @@ function M.setup(wk, config)
|
||||
wk.register(mappings, { mode = "n", prefix = "", preset = true })
|
||||
end
|
||||
end
|
||||
wk.register({ ["zf"] = "Create fold from selection" }, { mode = "x", prefix = "", preset = true })
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -30,20 +30,44 @@ local labels = {
|
||||
["/"] = "last search pattern",
|
||||
}
|
||||
|
||||
-- This function makes the assumption that OSC 52 is set up per :help osc-52
|
||||
M.osc52_active = function()
|
||||
-- If no clipboard set, can't be OSC 52
|
||||
if not vim.g.clipboard then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Per the docs, OSC 52 should be set up with a name field in the table
|
||||
if vim.g.clipboard.name == "OSC 52" then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---@type Plugin
|
||||
---@return PluginItem[]
|
||||
function M.run(_trigger, _mode, _buf)
|
||||
local items = {}
|
||||
|
||||
local osc52_skip_keys = { "+", "*" }
|
||||
|
||||
for i = 1, #M.registers, 1 do
|
||||
local key = M.registers:sub(i, i)
|
||||
local ok, value = pcall(vim.fn.getreg, key, 1)
|
||||
if not ok then
|
||||
value = ""
|
||||
|
||||
local value = ""
|
||||
|
||||
if M.osc52_active() and vim.tbl_contains(osc52_skip_keys, key) then
|
||||
value = "OSC 52 detected, register not checked to maintain compatibility"
|
||||
else
|
||||
local ok, reg_value = pcall(vim.fn.getreg, key, 1)
|
||||
if ok then
|
||||
value = reg_value
|
||||
end
|
||||
end
|
||||
|
||||
if value ~= "" then
|
||||
table.insert(items, { key = key, label = labels[key] or "", value = value })
|
||||
table.insert(items, { key = key, desc = labels[key] or "", value = value })
|
||||
end
|
||||
end
|
||||
return items
|
||||
|
||||
@ -21,7 +21,7 @@ function M.run()
|
||||
|
||||
---@diagnostic disable-next-line: missing-parameter
|
||||
local cursor_word = vim.fn.expand("<cword>")
|
||||
-- get a misspellled word from under the cursor, if not found, then use the cursor_word instead
|
||||
-- get a misspelled word from under the cursor, if not found, then use the cursor_word instead
|
||||
---@diagnostic disable-next-line: redundant-parameter
|
||||
local bad = vim.fn.spellbadword(cursor_word)
|
||||
local word = bad[1]
|
||||
@ -39,9 +39,9 @@ function M.run()
|
||||
|
||||
table.insert(items, {
|
||||
key = key,
|
||||
label = label,
|
||||
desc = label,
|
||||
fn = function()
|
||||
vim.cmd("norm! ciw" .. label)
|
||||
vim.cmd('norm! "_ciw' .. label)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@ -83,7 +83,11 @@ function Tree:add(mapping, opts)
|
||||
path_i = path_i .. prefix_i[i]
|
||||
path_n = path_n .. prefix_n[i]
|
||||
if not node.children[prefix_i[i]] then
|
||||
node.children[prefix_i[i]] = { children = {}, prefix_i = path_i, prefix_n = path_n }
|
||||
node.children[prefix_i[i]] = {
|
||||
children = {},
|
||||
prefix_i = path_i,
|
||||
prefix_n = path_n,
|
||||
}
|
||||
end
|
||||
node = node.children[prefix_i[i]]
|
||||
end
|
||||
|
||||
@ -32,7 +32,6 @@
|
||||
---@class Mapping
|
||||
---@field buf number
|
||||
---@field group boolean
|
||||
---@field label string
|
||||
---@field desc string
|
||||
---@field prefix string
|
||||
---@field cmd string
|
||||
|
||||
@ -52,17 +52,13 @@ function M.show()
|
||||
|
||||
local opts = {
|
||||
relative = "editor",
|
||||
width = vim.o.columns
|
||||
- margins[2]
|
||||
- margins[4]
|
||||
- (vim.fn.has("nvim-0.6") == 0 and config.options.window.border ~= "none" and 2 or 0),
|
||||
width = vim.o.columns - margins[2] - margins[4],
|
||||
height = config.options.layout.height.min,
|
||||
focusable = false,
|
||||
anchor = "SW",
|
||||
border = config.options.window.border,
|
||||
row = vim.o.lines
|
||||
- margins[3]
|
||||
- (vim.fn.has("nvim-0.6") == 0 and config.options.window.border ~= "none" and 2 or 0)
|
||||
+ ((vim.o.laststatus == 0 or vim.o.laststatus == 1 and #wins == 1) and 1 or 0)
|
||||
- vim.o.cmdheight,
|
||||
col = margins[4],
|
||||
@ -76,18 +72,13 @@ function M.show()
|
||||
end
|
||||
M.buf = vim.api.nvim_create_buf(false, true)
|
||||
M.win = vim.api.nvim_open_win(M.buf, false, opts)
|
||||
vim.api.nvim_buf_set_option(M.buf, "filetype", "WhichKey")
|
||||
vim.api.nvim_buf_set_option(M.buf, "buftype", "nofile")
|
||||
vim.api.nvim_buf_set_option(M.buf, "bufhidden", "wipe")
|
||||
vim.api.nvim_buf_set_option(M.buf, "modifiable", true)
|
||||
|
||||
local winhl = "NormalFloat:WhichKeyFloat"
|
||||
if vim.fn.hlexists("FloatBorder") == 1 then
|
||||
winhl = winhl .. ",FloatBorder:WhichKeyBorder"
|
||||
end
|
||||
vim.api.nvim_win_set_option(M.win, "winhighlight", winhl)
|
||||
vim.api.nvim_win_set_option(M.win, "foldmethod", "manual")
|
||||
vim.api.nvim_win_set_option(M.win, "winblend", config.options.window.winblend)
|
||||
vim.bo[M.buf].filetype = "WhichKey"
|
||||
vim.bo[M.buf].buftype = "nofile"
|
||||
vim.bo[M.buf].bufhidden = "wipe"
|
||||
vim.bo[M.buf].modifiable = true
|
||||
vim.wo[M.win].winhighlight = "NormalFloat:WhichKeyFloat,FloatBorder:WhichKeyBorder"
|
||||
vim.wo[M.win].foldmethod = "manual"
|
||||
vim.wo[M.win].winblend = config.options.window.winblend
|
||||
end
|
||||
|
||||
function M.read_pending()
|
||||
@ -204,7 +195,7 @@ function M.execute(prefix_i, mode, buf)
|
||||
end
|
||||
|
||||
-- make sure we remove all WK hooks before executing the sequence
|
||||
-- this is to make existing keybindongs work and prevent recursion
|
||||
-- this is to make existing keybindings work and prevent recursion
|
||||
unhook(Keys.get_tree(mode).tree:path(prefix_i))
|
||||
if buf then
|
||||
unhook(Keys.get_tree(mode, buf).tree:path(prefix_i), buf)
|
||||
@ -256,20 +247,24 @@ function M.open(keys, opts)
|
||||
end
|
||||
|
||||
function M.is_enabled(buf)
|
||||
local buftype = vim.api.nvim_buf_get_option(buf, "buftype")
|
||||
local buftype = vim.bo[buf].buftype
|
||||
for _, bt in ipairs(config.options.disable.buftypes) do
|
||||
if bt == buftype then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local filetype = vim.api.nvim_buf_get_option(buf, "filetype")
|
||||
local filetype = vim.bo[buf].filetype
|
||||
for _, bt in ipairs(config.options.disable.filetypes) do
|
||||
if bt == filetype then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if vim.fn.getcmdwintype() ~= "" then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -333,6 +328,7 @@ end
|
||||
|
||||
---@param text Text
|
||||
function M.render(text)
|
||||
local view = vim.api.nvim_win_call(M.win, vim.fn.winsaveview)
|
||||
vim.api.nvim_buf_set_lines(M.buf, 0, -1, false, text.lines)
|
||||
local height = #text.lines
|
||||
if height > config.options.layout.height.max then
|
||||
@ -345,6 +341,9 @@ function M.render(text)
|
||||
for _, data in ipairs(text.hl) do
|
||||
highlight(M.buf, config.namespace, data.group, data.line, data.from, data.to)
|
||||
end
|
||||
vim.api.nvim_win_call(M.win, function()
|
||||
vim.fn.winrestview(view)
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user