feat(builtin.keymaps): display noremap/buffer indicators and add lhs filter (#2246)
This commit is contained in:
@@ -1343,10 +1343,14 @@ builtin.keymaps({opts}) *telescope.builtin.keymaps()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{modes} (table) a list of short-named keymap modes to search
|
{modes} (table) a list of short-named keymap modes to search
|
||||||
(default: { "n", "i", "c", "x" })
|
(default: { "n", "i", "c", "x" })
|
||||||
{show_plug} (boolean) if true, the keymaps for which the lhs contains
|
{show_plug} (boolean) if true, the keymaps for which the lhs contains
|
||||||
"<Plug>" are also shown (default: true)
|
"<Plug>" are also shown (default: true)
|
||||||
|
{only_buf} (boolean) if true, only show the buffer-local keymaps
|
||||||
|
(default: false)
|
||||||
|
{lhs_filter} (function) filter(lhs:string) -> boolean. true if the
|
||||||
|
keymap should be shown (optional)
|
||||||
|
|
||||||
|
|
||||||
builtin.filetypes({opts}) *telescope.builtin.filetypes()*
|
builtin.filetypes({opts}) *telescope.builtin.filetypes()*
|
||||||
|
|||||||
@@ -1115,6 +1115,7 @@ end
|
|||||||
internal.keymaps = function(opts)
|
internal.keymaps = function(opts)
|
||||||
opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" })
|
opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" })
|
||||||
opts.show_plug = vim.F.if_nil(opts.show_plug, true)
|
opts.show_plug = vim.F.if_nil(opts.show_plug, true)
|
||||||
|
opts.only_buf = vim.F.if_nil(opts.only_buf, false)
|
||||||
|
|
||||||
local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table
|
local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table
|
||||||
local keymaps_table = {}
|
local keymaps_table = {}
|
||||||
@@ -1126,7 +1127,10 @@ internal.keymaps = function(opts)
|
|||||||
local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap
|
local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap
|
||||||
if not keymap_encountered[keymap_key] then
|
if not keymap_encountered[keymap_key] then
|
||||||
keymap_encountered[keymap_key] = true
|
keymap_encountered[keymap_key] = true
|
||||||
if opts.show_plug or not string.find(keymap.lhs, "<Plug>") then
|
if
|
||||||
|
(opts.show_plug or not string.find(keymap.lhs, "<Plug>"))
|
||||||
|
and (not opts.lhs_filter or opts.lhs_filter(keymap.lhs))
|
||||||
|
then
|
||||||
table.insert(keymaps_table, keymap)
|
table.insert(keymaps_table, keymap)
|
||||||
max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs))
|
max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs))
|
||||||
end
|
end
|
||||||
@@ -1137,7 +1141,9 @@ internal.keymaps = function(opts)
|
|||||||
for _, mode in pairs(opts.modes) do
|
for _, mode in pairs(opts.modes) do
|
||||||
local global = vim.api.nvim_get_keymap(mode)
|
local global = vim.api.nvim_get_keymap(mode)
|
||||||
local buf_local = vim.api.nvim_buf_get_keymap(0, mode)
|
local buf_local = vim.api.nvim_buf_get_keymap(0, mode)
|
||||||
extract_keymaps(global)
|
if not opts.only_buf then
|
||||||
|
extract_keymaps(global)
|
||||||
|
end
|
||||||
extract_keymaps(buf_local)
|
extract_keymaps(buf_local)
|
||||||
end
|
end
|
||||||
opts.width_lhs = max_len_lhs + 1
|
opts.width_lhs = max_len_lhs + 1
|
||||||
|
|||||||
@@ -331,6 +331,8 @@ builtin.registers = require_on_exported_call("telescope.builtin.__internal").reg
|
|||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field modes table: a list of short-named keymap modes to search (default: { "n", "i", "c", "x" })
|
---@field modes table: a list of short-named keymap modes to search (default: { "n", "i", "c", "x" })
|
||||||
---@field show_plug boolean: if true, the keymaps for which the lhs contains "<Plug>" are also shown (default: true)
|
---@field show_plug boolean: if true, the keymaps for which the lhs contains "<Plug>" are also shown (default: true)
|
||||||
|
---@field only_buf boolean: if true, only show the buffer-local keymaps (default: false)
|
||||||
|
---@field lhs_filter function: filter(lhs:string) -> boolean. true if the keymap should be shown (optional)
|
||||||
builtin.keymaps = require_on_exported_call("telescope.builtin.__internal").keymaps
|
builtin.keymaps = require_on_exported_call("telescope.builtin.__internal").keymaps
|
||||||
|
|
||||||
--- Lists all available filetypes, sets currently open buffer's filetype to selected filetype in Telescope on `<cr>`
|
--- Lists all available filetypes, sets currently open buffer's filetype to selected filetype in Telescope on `<cr>`
|
||||||
|
|||||||
@@ -827,11 +827,23 @@ function make_entry.gen_from_keymaps(opts)
|
|||||||
return utils.display_termcodes(entry.lhs)
|
return utils.display_termcodes(entry.lhs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_attr(entry)
|
||||||
|
local ret = ""
|
||||||
|
if entry.value.noremap ~= 0 then
|
||||||
|
ret = ret .. "*"
|
||||||
|
end
|
||||||
|
if entry.value.buffer ~= 0 then
|
||||||
|
ret = ret .. "@"
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
local displayer = require("telescope.pickers.entry_display").create {
|
local displayer = require("telescope.pickers.entry_display").create {
|
||||||
separator = "▏",
|
separator = "▏",
|
||||||
items = {
|
items = {
|
||||||
{ width = 2 },
|
{ width = 3 },
|
||||||
{ width = opts.width_lhs },
|
{ width = opts.width_lhs },
|
||||||
|
{ width = 2 },
|
||||||
{ remaining = true },
|
{ remaining = true },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -839,6 +851,7 @@ function make_entry.gen_from_keymaps(opts)
|
|||||||
return displayer {
|
return displayer {
|
||||||
entry.mode,
|
entry.mode,
|
||||||
get_lhs(entry),
|
get_lhs(entry),
|
||||||
|
get_attr(entry),
|
||||||
get_desc(entry),
|
get_desc(entry),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user