|
233 | 233 | --- miniclue.setup({ |
234 | 234 | --- triggers = { |
235 | 235 | --- -- Leader triggers |
236 | | ---- { mode = 'n', keys = '<Leader>' }, |
237 | | ---- { mode = 'x', keys = '<Leader>' }, |
| 236 | +--- { mode = { 'n', 'x' }, keys = '<Leader>' }, |
238 | 237 | --- |
239 | 238 | --- -- `[` and `]` keys |
240 | 239 | --- { mode = 'n', keys = '[' }, |
|
244 | 243 | --- { mode = 'i', keys = '<C-x>' }, |
245 | 244 | --- |
246 | 245 | --- -- `g` key |
247 | | ---- { mode = 'n', keys = 'g' }, |
248 | | ---- { mode = 'x', keys = 'g' }, |
| 246 | +--- { mode = { 'n', 'x' }, keys = 'g' }, |
249 | 247 | --- |
250 | 248 | --- -- Marks |
251 | | ---- { mode = 'n', keys = "'" }, |
252 | | ---- { mode = 'n', keys = '`' }, |
253 | | ---- { mode = 'x', keys = "'" }, |
254 | | ---- { mode = 'x', keys = '`' }, |
| 249 | +--- { mode = { 'n', 'x' }, keys = "'" }, |
| 250 | +--- { mode = { 'n', 'x' }, keys = '`' }, |
255 | 251 | --- |
256 | 252 | --- -- Registers |
257 | | ---- { mode = 'n', keys = '"' }, |
258 | | ---- { mode = 'x', keys = '"' }, |
259 | | ---- { mode = 'i', keys = '<C-r>' }, |
260 | | ---- { mode = 'c', keys = '<C-r>' }, |
| 253 | +--- { mode = { 'n', 'x' }, keys = '"' }, |
| 254 | +--- { mode = { 'i', 'c' }, keys = '<C-r>' }, |
261 | 255 | --- |
262 | 256 | --- -- Window commands |
263 | 257 | --- { mode = 'n', keys = '<C-w>' }, |
264 | 258 | --- |
265 | 259 | --- -- `z` key |
266 | | ---- { mode = 'n', keys = 'z' }, |
267 | | ---- { mode = 'x', keys = 'z' }, |
| 260 | +--- { mode = { 'n', 'x' }, keys = 'z' }, |
268 | 261 | --- }, |
269 | 262 | --- |
270 | 263 | --- clues = { |
|
307 | 300 | --- require('mini.clue').setup({ |
308 | 301 | --- -- Register `<Leader>` as trigger |
309 | 302 | --- triggers = { |
310 | | ---- { mode = 'n', keys = '<Leader>' }, |
311 | | ---- { mode = 'x', keys = '<Leader>' }, |
| 303 | +--- { mode = { 'n', 'x' }, keys = '<Leader>' }, |
312 | 304 | --- }, |
313 | 305 | --- |
314 | 306 | --- -- Add descriptions for mapping groups |
|
394 | 386 | --- triggers = { |
395 | 387 | --- -- This can also set up directly `<Leader>m` as a trigger, but make |
396 | 388 | --- -- sure to not also use `<Leader>`, as they would "overlap" |
397 | | ---- { mode = 'n', keys = '<Leader>' }, |
398 | | ---- { mode = 'x', keys = '<Leader>' }, |
| 389 | +--- { mode = { 'n', 'x' }, keys = '<Leader>' }, |
399 | 390 | --- }, |
400 | 391 | --- clues = { |
401 | 392 | --- { mode = 'n', keys = '<Leader>m', desc = '+Move' }, |
402 | 393 | --- |
403 | | ---- { mode = 'n', keys = '<Leader>mh', postkeys = '<Leader>m' }, |
404 | | ---- { mode = 'n', keys = '<Leader>mj', postkeys = '<Leader>m' }, |
405 | | ---- { mode = 'n', keys = '<Leader>mk', postkeys = '<Leader>m' }, |
406 | | ---- { mode = 'n', keys = '<Leader>ml', postkeys = '<Leader>m' }, |
407 | | ---- { mode = 'x', keys = '<Leader>mh', postkeys = '<Leader>m' }, |
408 | | ---- { mode = 'x', keys = '<Leader>mj', postkeys = '<Leader>m' }, |
409 | | ---- { mode = 'x', keys = '<Leader>mk', postkeys = '<Leader>m' }, |
410 | | ---- { mode = 'x', keys = '<Leader>ml', postkeys = '<Leader>m' }, |
| 394 | +--- { mode = { 'n', 'x' }, keys = '<Leader>mh', postkeys = '<Leader>m' }, |
| 395 | +--- { mode = { 'n', 'x' }, keys = '<Leader>mj', postkeys = '<Leader>m' }, |
| 396 | +--- { mode = { 'n', 'x' }, keys = '<Leader>mk', postkeys = '<Leader>m' }, |
| 397 | +--- { mode = { 'n', 'x' }, keys = '<Leader>ml', postkeys = '<Leader>m' }, |
411 | 398 | --- }, |
412 | 399 | --- }) |
413 | 400 | --- < |
|
529 | 516 | --- - Callable (function) returning either of the previous two. |
530 | 517 | --- |
531 | 518 | --- A clue table is a table with the following fields: |
532 | | ---- - <mode> `(string)` - single character describing **single** mode short-name of |
533 | | ---- key combination as in `nvim_set_keymap()` ('n', 'x', 'i', 'o', 'c', etc.). |
| 519 | +--- - <mode> `(string|table)` - single character describing mode short-name of |
| 520 | +--- key combination as in `nvim_set_keymap()` ('n', 'x', 'i', 'o', 'c', etc.), |
| 521 | +--- or a array thereof. |
534 | 522 | --- - <keys> `(string)` - key combination for which clue will be shown. |
535 | 523 | --- "Human-readable" key names as in |key-notation| (like "<Leader>", "<Space>", |
536 | 524 | --- "<Tab>", etc.) are allowed. |
|
721 | 709 | --- |
722 | 710 | --- Contains clues for the following triggers: >lua |
723 | 711 | --- |
724 | | ---- { mode = 'n', keys = 'g' } |
725 | | ---- { mode = 'x', keys = 'g' } |
| 712 | +--- { mode = { 'n', 'x' }, keys = 'g' } |
726 | 713 | --- < |
727 | 714 | ---@return table Array of clues. |
728 | 715 | MiniClue.gen_clues.g = function() |
@@ -874,14 +861,10 @@ end |
874 | 861 | --- |
875 | 862 | --- Contains clues for the following triggers: >lua |
876 | 863 | --- |
877 | | ---- { mode = 'n', keys = "'" } |
878 | | ---- { mode = 'n', keys = "g'" } |
879 | | ---- { mode = 'n', keys = '`' } |
880 | | ---- { mode = 'n', keys = 'g`' } |
881 | | ---- { mode = 'x', keys = "'" } |
882 | | ---- { mode = 'x', keys = "g'" } |
883 | | ---- { mode = 'x', keys = '`' } |
884 | | ---- { mode = 'x', keys = 'g`' } |
| 864 | +--- { mode = { 'n', 'x' }, keys = "'" } |
| 865 | +--- { mode = { 'n', 'x' }, keys = "g'" } |
| 866 | +--- { mode = { 'n', 'x' }, keys = '`' } |
| 867 | +--- { mode = { 'n', 'x' }, keys = 'g`' } |
885 | 868 | --- < |
886 | 869 | --- Note: if you use "g" as trigger (like to enable |MiniClue.gen_clues.g()|), |
887 | 870 | --- don't add "g'" and "g`" as triggers: they already will be taken into account. |
@@ -912,28 +895,20 @@ MiniClue.gen_clues.marks = function() |
912 | 895 |
|
913 | 896 | --stylua: ignore |
914 | 897 | return { |
915 | | - -- Normal mode |
916 | | - describe_marks('n', "'"), |
917 | | - describe_marks('n', "g'"), |
918 | | - describe_marks('n', "`"), |
919 | | - describe_marks('n', "g`"), |
920 | | - |
921 | | - -- Visual mode |
922 | | - describe_marks('x', "'"), |
923 | | - describe_marks('x', "g'"), |
924 | | - describe_marks('x', "`"), |
925 | | - describe_marks('x', "g`"), |
| 898 | + -- Normal and visual mode |
| 899 | + describe_marks({ 'n', 'x' }, "'"), |
| 900 | + describe_marks({ 'n', 'x' }, "g'"), |
| 901 | + describe_marks({ 'n', 'x' }, "`"), |
| 902 | + describe_marks({ 'n', 'x' }, "g`"), |
926 | 903 | } |
927 | 904 | end |
928 | 905 |
|
929 | 906 | --- Generate clues for registers |
930 | 907 | --- |
931 | 908 | --- Contains clues for the following triggers: >lua |
932 | 909 | --- |
933 | | ---- { mode = 'n', keys = '"' } |
934 | | ---- { mode = 'x', keys = '"' } |
935 | | ---- { mode = 'i', keys = '<C-r>' } |
936 | | ---- { mode = 'c', keys = '<C-r>' } |
| 910 | +--- { mode = { 'n', 'x' }, keys = '"' } |
| 911 | +--- { mode = { 'i', 'c' }, keys = '<C-r>' } |
937 | 912 | --- < |
938 | 913 | ---@param opts table|nil Options. Possible keys: |
939 | 914 | --- - <show_contents> `(boolean)` - whether to show contents of all possible |
@@ -972,11 +947,8 @@ MiniClue.gen_clues.registers = function(opts) |
972 | 947 |
|
973 | 948 | --stylua: ignore |
974 | 949 | return { |
975 | | - -- Normal mode |
976 | | - describe_registers('n', '"'), |
977 | | - |
978 | | - -- Visual mode |
979 | | - describe_registers('x', '"'), |
| 950 | + -- Normal and Visual mode |
| 951 | + describe_registers({ 'n', 'x' }, '"'), |
980 | 952 |
|
981 | 953 | -- Insert mode |
982 | 954 | describe_registers('i', '<C-r>'), |
@@ -1084,8 +1056,7 @@ end |
1084 | 1056 | --- |
1085 | 1057 | --- Contains clues for the following triggers: >lua |
1086 | 1058 | --- |
1087 | | ---- { mode = 'n', keys = 'z' } |
1088 | | ---- { mode = 'x', keys = 'z' } |
| 1059 | +--- { mode = { 'n', 'x' }, keys = 'z' } |
1089 | 1060 | --- < |
1090 | 1061 | ---@return table Array of clues. |
1091 | 1062 | MiniClue.gen_clues.z = function() |
@@ -1328,15 +1299,21 @@ H.map_buf_triggers = function(buf_id) |
1328 | 1299 | if not H.is_valid_buf(buf_id) or H.is_disabled(buf_id) then return end |
1329 | 1300 |
|
1330 | 1301 | for _, trigger in ipairs(H.get_config(nil, buf_id).triggers) do |
1331 | | - H.map_trigger(buf_id, trigger) |
| 1302 | + local modes = type(trigger.mode) == 'table' and trigger.mode or { trigger.mode } |
| 1303 | + for _, mode in ipairs(modes) do |
| 1304 | + H.map_trigger(buf_id, { mode = mode, keys = trigger.keys }) |
| 1305 | + end |
1332 | 1306 | end |
1333 | 1307 | end |
1334 | 1308 |
|
1335 | 1309 | H.unmap_buf_triggers = function(buf_id) |
1336 | 1310 | if not H.is_valid_buf(buf_id) or H.is_disabled(buf_id) then return end |
1337 | 1311 |
|
1338 | 1312 | for _, trigger in ipairs(H.get_config(nil, buf_id).triggers) do |
1339 | | - H.unmap_trigger(buf_id, trigger) |
| 1313 | + local modes = type(trigger.mode) == 'table' and trigger.mode or { trigger.mode } |
| 1314 | + for _, mode in ipairs(modes) do |
| 1315 | + H.unmap_trigger(buf_id, { mode = mode, keys = trigger.keys }) |
| 1316 | + end |
1340 | 1317 | end |
1341 | 1318 | end |
1342 | 1319 |
|
@@ -1780,7 +1757,8 @@ H.clues_get_all = function(mode) |
1780 | 1757 |
|
1781 | 1758 | -- Order of clue precedence: config clues < buffer mappings < global mappings |
1782 | 1759 | local config_clues = H.clues_normalize(H.get_config().clues) or {} |
1783 | | - local mode_clues = vim.tbl_filter(function(x) return x.mode == mode end, config_clues) |
| 1760 | + local mode_filter = function(x) return type(x.mode) == 'table' and vim.tbl_contains(x.mode, mode) or x.mode == mode end |
| 1761 | + local mode_clues = vim.tbl_filter(mode_filter, config_clues) |
1784 | 1762 | for _, clue in ipairs(mode_clues) do |
1785 | 1763 | local lhsraw = H.replace_termcodes(clue.keys) |
1786 | 1764 |
|
@@ -1949,11 +1927,13 @@ H.make_clues_with_register_contents = function(mode, prefix) |
1949 | 1927 | end |
1950 | 1928 |
|
1951 | 1929 | -- Predicates ----------------------------------------------------------------- |
1952 | | -H.is_trigger = function(x) return type(x) == 'table' and type(x.mode) == 'string' and type(x.keys) == 'string' end |
| 1930 | +H.is_trigger = function(x) |
| 1931 | + return type(x) == 'table' and (type(x.mode) == 'string' or type(x.mode) == 'table') and type(x.keys) == 'string' |
| 1932 | +end |
1953 | 1933 |
|
1954 | 1934 | H.is_clue = function(x) |
1955 | 1935 | if type(x) ~= 'table' then return false end |
1956 | | - local mandatory = type(x.mode) == 'string' and type(x.keys) == 'string' |
| 1936 | + local mandatory = (type(x.mode) == 'string' or type(x.mode) == 'table') and type(x.keys) == 'string' |
1957 | 1937 | local extra = (x.desc == nil or type(x.desc) == 'string' or vim.is_callable(x.desc)) |
1958 | 1938 | and (x.postkeys == nil or type(x.postkeys) == 'string') |
1959 | 1939 | return mandatory and extra |
|
0 commit comments