summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authordaangoossens22 <62295482+daangoossens22@users.noreply.github.com>2022-01-28 16:36:42 +0100
committerGitHub <noreply@github.com>2022-01-28 16:36:42 +0100
commit3a3c9a3c8ba3fb14121ef5c50a87173dcb969416 (patch)
tree387005c35a1ff425ec7481eca12b9afdda05ec9f /lua
parent6c275e2f6ae8c68c8bf07ca48ea14af4ced2f803 (diff)
feat (keymaps): add configuration options (#1703)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/init.lua2
-rw-r--r--lua/telescope/builtin/internal.lua24
2 files changed, 19 insertions, 7 deletions
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index de5a689..dc094b5 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -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>`
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index 4765e60..8e1c9c4 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -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)