Skip to content

Commit

Permalink
feat(builtin): implement filter for keymaps (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
bn-peters authored May 24, 2023
1 parent 19e8a8a commit 5b7cedd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,11 @@ builtin.keymaps({opts}) *telescope.builtin.keymaps()*
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)
{lhs_filter} (function) filter(lhs:string) -> boolean. true for
keymap.lhs if the keymap should be shown
(optional)
{filter} (function) filter(km:keymap) -> boolean. true for the
keymap if it should be shown (optional)


builtin.filetypes({opts}) *telescope.builtin.filetypes()*
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,6 @@ internal.registers = function(opts)
:find()
end

-- TODO: make filtering include the mapping and the action
internal.keymaps = function(opts)
opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" })
opts.show_plug = vim.F.if_nil(opts.show_plug, true)
Expand All @@ -1148,6 +1147,7 @@ internal.keymaps = function(opts)
if
(opts.show_plug or not string.find(keymap.lhs, "<Plug>"))
and (not opts.lhs_filter or opts.lhs_filter(keymap.lhs))
and (not opts.filter or opts.filter(keymap))
then
table.insert(keymaps_table, keymap)
max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs))
Expand Down
3 changes: 2 additions & 1 deletion lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ builtin.registers = require_on_exported_call("telescope.builtin.__internal").reg
---@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 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)
---@field lhs_filter function: filter(lhs:string) -> boolean. true for keymap.lhs if the keymap should be shown (optional)
---@field filter function: filter(km:keymap) -> boolean. true for the keymap if it should be shown (optional)
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>`
Expand Down

0 comments on commit 5b7cedd

Please sign in to comment.