diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-06-09 19:51:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-09 19:51:03 +0200 |
| commit | 618e0e6075b4215e43c6a848daa37ef4e354b5dc (patch) | |
| tree | 1d14ef2c80c4b919ea2b516788ed515d9ed49b7c /lua/telescope/mappings.lua | |
| parent | feaed4b6e23bd56906089154f293f2b1ecb68c7e (diff) | |
feat: set defaults for each picker in telescope setup (#883)
This allows easier picker configuration for example:
```lua
require("telescope").setup {
pickers = {
buffers = {
show_all_buffers = true,
sort_lastused = true,
theme = "dropdown",
previewer = false,
mappings = {
i = {
["<c-q>"] = "smart_send_to_qflist",
}
}
}
}
}
```
This configuration will be applied when running `:Telescope buffers`
Diffstat (limited to 'lua/telescope/mappings.lua')
| -rw-r--r-- | lua/telescope/mappings.lua | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index d6ebe04..bfc153c 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -111,51 +111,60 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts) if opts.silent == nil then opts.silent = true end if type(key_func) == "string" then - a.nvim_buf_set_keymap( + key_func = actions[key_func] + elseif type(key_func) == "table" then + if key_func.type == "command" then + a.nvim_buf_set_keymap( + prompt_bufnr, + mode, + key_bind, + key_func[1], + opts or { + silent = true + } + ) + return + elseif key_func.type == "action_key" then + key_func = actions[key_func[1]] + elseif key_func.type == "action" then + key_func = key_func[1] + end + end + + local key_id = assign_function(prompt_bufnr, key_func) + local prefix + + local map_string + if opts.expr then + map_string = string.format( + [[luaeval("require('telescope.mappings').execute_keymap(%s, %s)")]], prompt_bufnr, - mode, - key_bind, - key_func, - opts or { - silent = true - } + key_id ) else - local key_id = assign_function(prompt_bufnr, key_func) - local prefix - - local map_string - if opts.expr then - map_string = string.format( - [[luaeval("require('telescope.mappings').execute_keymap(%s, %s)")]], - prompt_bufnr, - key_id - ) + if mode == "i" and not opts.expr then + prefix = "<cmd>" + elseif mode == "n" then + prefix = ":<C-U>" else - if mode == "i" and not opts.expr then - prefix = "<cmd>" - elseif mode == "n" then - prefix = ":<C-U>" - else - prefix = ":" - end - - map_string = string.format( - "%slua require('telescope.mappings').execute_keymap(%s, %s)<CR>", - prefix, - prompt_bufnr, - key_id - ) + prefix = ":" end - a.nvim_buf_set_keymap( + map_string = string.format( + "%slua require('telescope.mappings').execute_keymap(%s, %s)<CR>", + prefix, prompt_bufnr, - mode, - key_bind, - map_string, - opts + key_id ) end + + a.nvim_buf_set_keymap( + prompt_bufnr, + mode, + key_bind, + map_string, + opts + ) end mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap) |
