summaryrefslogtreecommitdiff
path: root/lua/telescope/actions/utils.lua
diff options
context:
space:
mode:
authorfdschmidt93 <39233597+fdschmidt93@users.noreply.github.com>2021-09-01 20:11:53 +0200
committerGitHub <noreply@github.com>2021-09-01 20:11:53 +0200
commitfbe004142f69962d92eb6ede13a6721f7fdb4d50 (patch)
treeb301d26dc501f72b88ccd2c153666846fb68db96 /lua/telescope/actions/utils.lua
parent5d37c3ea08f40d8c9d3a9ebcc72bd641d366c110 (diff)
feat: show keymaps for builtin actions (#1084)
* Add default mappings `<C-/>`and `?` for insert and normal mode, respectively, to show registered keymappings (`actions.which_key`) attached to prompt buffer
Diffstat (limited to 'lua/telescope/actions/utils.lua')
-rw-r--r--lua/telescope/actions/utils.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/telescope/actions/utils.lua b/lua/telescope/actions/utils.lua
index f2abfe1..7c8a3ac 100644
--- a/lua/telescope/actions/utils.lua
+++ b/lua/telescope/actions/utils.lua
@@ -78,4 +78,26 @@ function utils.map_selections(prompt_bufnr, f)
end
end
+local findnth = function(str, nth)
+ local array = {}
+ for i in string.gmatch(str, "%d+") do
+ table.insert(array, tonumber(i))
+ end
+ return array[nth]
+end
+
+--- Utility to collect mappings of prompt buffer in array of `{mode, keybind, name}`.
+---@param prompt_bufnr number: The prompt bufnr
+function utils.get_registered_mappings(prompt_bufnr)
+ local ret = {}
+ for _, mode in ipairs { "n", "i" } do
+ local mode_mappings = vim.api.nvim_buf_get_keymap(prompt_bufnr, mode)
+ for _, mapping in ipairs(mode_mappings) do
+ local funcid = findnth(mapping.rhs, 2)
+ table.insert(ret, { mode = mode, keybind = mapping.lhs, func = __TelescopeKeymapStore[prompt_bufnr][funcid] })
+ end
+ end
+ return ret
+end
+
return utils