|
1 | | ----@tag telescope.actions |
2 | | ----@config { ["module"] = "telescope.actions" } |
3 | | - |
4 | | ----@brief [[ |
| 1 | +---@brief |
5 | 2 | --- These functions are useful for people creating their own mappings. |
6 | 3 | --- |
7 | 4 | --- Actions can be either normal functions that expect the `prompt_bufnr` as |
|
10 | 7 | --- (1) The `prompt_bufnr` of a normal function denotes the identifier of your |
11 | 8 | --- picker which can be used to access the picker state. In practice, users |
12 | 9 | --- most commonly access from both picker and global state via the following: |
13 | | ---- <code> |
14 | | ---- -- for utility functions |
15 | | ---- local action_state = require "telescope.actions.state" |
| 10 | +--- ```lua |
| 11 | +--- -- for utility functions |
| 12 | +--- local action_state = require "telescope.actions.state" |
16 | 13 | --- |
17 | | ---- local actions = {} |
18 | | ---- actions.do_stuff = function(prompt_bufnr) |
19 | | ---- local current_picker = action_state.get_current_picker(prompt_bufnr) -- picker state |
20 | | ---- local entry = action_state.get_selected_entry() |
21 | | ---- end |
22 | | ---- </code> |
| 14 | +--- local actions = {} |
| 15 | +--- actions.do_stuff = function(prompt_bufnr) |
| 16 | +--- local current_picker = action_state.get_current_picker(prompt_bufnr) -- picker state |
| 17 | +--- local entry = action_state.get_selected_entry() |
| 18 | +--- end |
| 19 | +--- ``` |
23 | 20 | --- |
24 | 21 | --- See |telescope.actions.state| for more information. |
25 | 22 | --- |
26 | 23 | --- (2) To transform a module of functions into a module of "action"s, you need |
27 | 24 | --- to do the following: |
28 | | ---- <code> |
29 | | ---- local transform_mod = require("telescope.actions.mt").transform_mod |
| 25 | +--- ```lua |
| 26 | +--- local transform_mod = require("telescope.actions.mt").transform_mod |
30 | 27 | --- |
31 | | ---- local mod = {} |
32 | | ---- mod.a1 = function(prompt_bufnr) |
33 | | ---- -- your code goes here |
34 | | ---- -- You can access the picker/global state as described above in (1). |
35 | | ---- end |
| 28 | +--- local mod = {} |
| 29 | +--- mod.a1 = function(prompt_bufnr) |
| 30 | +--- -- your code goes here |
| 31 | +--- -- You can access the picker/global state as described above in (1). |
| 32 | +--- end |
36 | 33 | --- |
37 | | ---- mod.a2 = function(prompt_bufnr) |
38 | | ---- -- your code goes here |
39 | | ---- end |
40 | | ---- mod = transform_mod(mod) |
| 34 | +--- mod.a2 = function(prompt_bufnr) |
| 35 | +--- -- your code goes here |
| 36 | +--- end |
| 37 | +--- mod = transform_mod(mod) |
41 | 38 | --- |
42 | | ---- -- Now the following is possible. This means that actions a2 will be executed |
43 | | ---- -- after action a1. You can chain as many actions as you want. |
44 | | ---- local action = mod.a1 + mod.a2 |
45 | | ---- action(bufnr) |
46 | | ---- </code> |
| 39 | +--- -- Now the following is possible. This means that actions a2 will be executed |
| 40 | +--- -- after action a1. You can chain as many actions as you want. |
| 41 | +--- local action = mod.a1 + mod.a2 |
| 42 | +--- action(bufnr) |
| 43 | +--- ``` |
47 | 44 | --- |
48 | 45 | --- Another interesting thing to do is that these actions now have functions you |
49 | 46 | --- can call. These functions include `:replace(f)`, `:replace_if(f, c)`, |
50 | 47 | --- `replace_map(tbl)` and `enhance(tbl)`. More information on these functions |
51 | 48 | --- can be found in the `developers.md` and `lua/tests/automated/action_spec.lua` |
52 | 49 | --- file. |
53 | | ----@brief ]] |
54 | 50 |
|
55 | 51 | local a = vim.api |
56 | 52 |
|
@@ -156,7 +152,7 @@ actions.toggle_selection = function(prompt_bufnr) |
156 | 152 | end |
157 | 153 |
|
158 | 154 | --- Multi select all entries. |
159 | | ---- - Note: selected entries may include results not visible in the results pop up. |
| 155 | +---@note selected entries may include results not visible in the results pop up. |
160 | 156 | ---@param prompt_bufnr number: The prompt bufnr |
161 | 157 | actions.select_all = function(prompt_bufnr) |
162 | 158 | local current_picker = action_state.get_current_picker(prompt_bufnr) |
@@ -193,7 +189,7 @@ actions.drop_all = function(prompt_bufnr) |
193 | 189 | end |
194 | 190 |
|
195 | 191 | --- Toggle multi selection for all entries. |
196 | | ---- - Note: toggled entries may include results not visible in the results pop up. |
| 192 | +---@note toggled entries may include results not visible in the results pop up. |
197 | 193 | ---@param prompt_bufnr number: The prompt bufnr |
198 | 194 | actions.toggle_all = function(prompt_bufnr) |
199 | 195 | local current_picker = action_state.get_current_picker(prompt_bufnr) |
@@ -1255,8 +1251,7 @@ actions.remove_selected_picker = function(prompt_bufnr) |
1255 | 1251 | end |
1256 | 1252 |
|
1257 | 1253 | --- Display the keymaps of registered actions similar to which-key.nvim.<br> |
1258 | | ---- - Notes: |
1259 | | ---- - The defaults can be overridden via |action_generate.which_key|. |
| 1254 | +---@note The defaults can be overridden via |action_generate.which_key|. |
1260 | 1255 | ---@param prompt_bufnr number: The prompt bufnr |
1261 | 1256 | actions.which_key = function(prompt_bufnr, opts) |
1262 | 1257 | opts = opts or {} |
|
0 commit comments