feat (keymaps): add configuration options (#1703)

This commit is contained in:
daangoossens22
2022-01-28 16:36:42 +01:00
committed by GitHub
parent 6c275e2f6a
commit 3a3c9a3c8b
3 changed files with 25 additions and 7 deletions

View File

@@ -1240,6 +1240,12 @@ builtin.keymaps({opts}) *builtin.keymaps()*
Parameters: ~
{opts} (table) options to pass to the picker
Options: ~
{modes} (table) a list of short-named keymap modes to search
(default: { "n", "i", "c", "x" })
{show_plug} (boolean) if true, the keymaps for which the lhs contains
"<Plug>" are also shown (default: true)
builtin.filetypes({opts}) *builtin.filetypes()*
Lists all available filetypes, sets currently open buffer's filetype to

View File

@@ -314,6 +314,8 @@ builtin.registers = require_on_exported_call("telescope.builtin.internal").regis
--- Lists normal mode keymappings, runs the selected keymap on `<cr>`
---@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 show_plug boolean: if true, the keymaps for which the lhs contains "<Plug>" are also shown (default: true)
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>`

View File

@@ -952,18 +952,28 @@ end
-- TODO: make filtering include the mapping and the action
internal.keymaps = function(opts)
local modes = { "n", "i", "c" }
local keymaps_table = {}
opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" })
opts.show_plug = vim.F.if_nil(opts.show_plug, true)
local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table
local keymaps_table = {}
local max_len_lhs = 0
for _, mode in pairs(modes) do
local function extract_keymaps(keymaps)
for _, keymap in pairs(keymaps) do
table.insert(keymaps_table, keymap)
max_len_lhs = math.max(max_len_lhs, string.len(keymap.lhs or ""))
-- helper function to populate keymaps_table and determine max_len_lhs
local function extract_keymaps(keymaps)
for _, keymap in pairs(keymaps) do
local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap
if not keymap_encountered[keymap_key] then
keymap_encountered[keymap_key] = true
if opts.show_plug or not string.find(keymap.lhs, "<Plug>") then
table.insert(keymaps_table, keymap)
max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs))
end
end
end
end
for _, mode in pairs(opts.modes) do
local global = vim.api.nvim_get_keymap(mode)
local buf_local = vim.api.nvim_buf_get_keymap(0, mode)
extract_keymaps(global)