|
6 | 6 |
|
7 | 7 | ---@class Utils.Treesitter.TextObject.Repeatable |
8 | 8 | ---@field repeat_last_move_opposite fun() |
9 | | ----@field repeat_last_move fun() |
| 9 | +---@field repeat_last_move fun(opts: TSTextObjects.MoveOpts?) |
10 | 10 | ---@field builtin_F_expr fun() |
11 | 11 | ---@field builtin_T_expr fun() |
12 | 12 | ---@field builtin_f_expr fun() |
|
16 | 16 | ---@field select_textobject fun(query: string, group: string) |
17 | 17 |
|
18 | 18 | local textobjects = { |
19 | | - group = "textobjects", |
20 | | - mode = { "n", "o", "x" }, |
21 | | - options = { expr = true }, |
| 19 | + group = "textobjects", |
| 20 | + mode_nox = { "n", "o", "x" }, |
| 21 | + mode_ox = { "o", "x" }, |
| 22 | + options = { expr = true }, |
22 | 23 | } |
23 | 24 |
|
| 25 | +---@see https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/795 |
| 26 | +---@param func function |
| 27 | +---@return string? |
| 28 | +function Provisional(func) |
| 29 | + local response = func() |
| 30 | + |
| 31 | + return response and vim.api.nvim_feedkeys(vim.v.count1 .. response, "n", true) |
| 32 | +end |
| 33 | + |
24 | 34 | ---@class Utils.Treesitter |
25 | 35 | M = { |
26 | | - ---@param lhs string |
27 | | - ---@param to_move Utils.Treesitter.TextObject.Move |
28 | | - ---@param query string |
29 | | - to_move_mapper = function(lhs, to_move, query) |
30 | | - vim.keymap.set(textobjects.mode, "[" .. lhs, function() |
31 | | - to_move.goto_previous_start(query, textobjects.group) |
32 | | - end) |
33 | | - vim.keymap.set(textobjects.mode, "[" .. string.upper(lhs), function() |
34 | | - to_move.goto_previous_end(query, textobjects.group) |
35 | | - end) |
36 | | - vim.keymap.set(textobjects.mode, "]" .. lhs, function() |
37 | | - to_move.goto_next_start(query, textobjects.group) |
38 | | - end) |
39 | | - vim.keymap.set(textobjects.mode, "]" .. string.upper(lhs), function() |
40 | | - to_move.goto_next_end(query, textobjects.group) |
41 | | - end) |
42 | | - end, |
43 | | - ---@param to_repeatable Utils.Treesitter.TextObject.Repeatable |
44 | | - to_repeatable_mapper = function(to_repeatable) |
45 | | - vim.keymap.set(textobjects.mode, ",", to_repeatable.repeat_last_move_opposite) |
46 | | - vim.keymap.set(textobjects.mode, ";", to_repeatable.repeat_last_move) |
47 | | - vim.keymap.set(textobjects.mode, "F", to_repeatable.builtin_F_expr, textobjects.options) |
48 | | - vim.keymap.set(textobjects.mode, "T", to_repeatable.builtin_T_expr, textobjects.options) |
49 | | - vim.keymap.set(textobjects.mode, "f", to_repeatable.builtin_f_expr, textobjects.options) |
50 | | - vim.keymap.set(textobjects.mode, "t", to_repeatable.builtin_t_expr, textobjects.options) |
51 | | - end, |
52 | | - ---@param lhs string |
53 | | - ---@param to_select Utils.Treesitter.TextObject.Select |
54 | | - ---@param query string |
55 | | - to_select_mapper = function(lhs, to_select, query) |
56 | | - vim.keymap.set(textobjects.mode, lhs, function() |
57 | | - to_select.select_textobject(query, textobjects.group) |
58 | | - end) |
59 | | - end, |
| 36 | + ---@param lhs string |
| 37 | + ---@param to_move Utils.Treesitter.TextObject.Move |
| 38 | + ---@param query string |
| 39 | + to_move_mapper = function(lhs, to_move, query) |
| 40 | + vim.keymap.set(textobjects.mode_nox, "[" .. lhs, function() |
| 41 | + to_move.goto_previous_start(query, textobjects.group) |
| 42 | + end) |
| 43 | + vim.keymap.set(textobjects.mode_nox, "[" .. string.upper(lhs), function() |
| 44 | + to_move.goto_previous_end(query, textobjects.group) |
| 45 | + end) |
| 46 | + vim.keymap.set(textobjects.mode_nox, "]" .. lhs, function() |
| 47 | + to_move.goto_next_start(query, textobjects.group) |
| 48 | + end) |
| 49 | + vim.keymap.set(textobjects.mode_nox, "]" .. string.upper(lhs), function() |
| 50 | + to_move.goto_next_end(query, textobjects.group) |
| 51 | + end) |
| 52 | + end, |
| 53 | + ---@param to_repeatable Utils.Treesitter.TextObject.Repeatable |
| 54 | + to_repeatable_mapper = function(to_repeatable) |
| 55 | + vim.keymap.set(textobjects.mode_nox, ",", function() |
| 56 | + Provisional(to_repeatable.repeat_last_move_opposite) |
| 57 | + end) |
| 58 | + vim.keymap.set(textobjects.mode_nox, ";", function() |
| 59 | + Provisional(to_repeatable.repeat_last_move) |
| 60 | + end) |
| 61 | + vim.keymap.set(textobjects.mode_nox, "F", to_repeatable.builtin_F_expr, textobjects.options) |
| 62 | + vim.keymap.set(textobjects.mode_nox, "T", to_repeatable.builtin_T_expr, textobjects.options) |
| 63 | + vim.keymap.set(textobjects.mode_nox, "f", to_repeatable.builtin_f_expr, textobjects.options) |
| 64 | + vim.keymap.set(textobjects.mode_nox, "t", to_repeatable.builtin_t_expr, textobjects.options) |
| 65 | + end, |
| 66 | + ---@param lhs string |
| 67 | + ---@param to_select Utils.Treesitter.TextObject.Select |
| 68 | + ---@param query string |
| 69 | + to_select_mapper = function(lhs, to_select, query) |
| 70 | + vim.keymap.set(textobjects.mode_ox, lhs, function() |
| 71 | + to_select.select_textobject(query, textobjects.group) |
| 72 | + end) |
| 73 | + end, |
60 | 74 | } |
61 | 75 |
|
62 | 76 | return M |
0 commit comments