From 4f4911ff95bc35438a2b8dd2d058b15f105f2ff1 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 16 May 2024 18:56:54 +0200 Subject: [PATCH] feat(coding)!: move `mini.ai` to an extra --- lua/lazyvim/plugins/coding.lua | 96 ------------------- lua/lazyvim/plugins/extras/coding/mini-ai.lua | 95 ++++++++++++++++++ 2 files changed, 95 insertions(+), 96 deletions(-) create mode 100644 lua/lazyvim/plugins/extras/coding/mini-ai.lua diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 30331e10..a2a36581 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -208,100 +208,4 @@ return { end end, }, - - -- Better text-objects - { - "echasnovski/mini.ai", - -- keys = { - -- { "a", mode = { "x", "o" } }, - -- { "i", mode = { "x", "o" } }, - -- }, - event = "VeryLazy", - opts = function() - local ai = require("mini.ai") - return { - n_lines = 500, - custom_textobjects = { - o = ai.gen_spec.treesitter({ - a = { "@block.outer", "@conditional.outer", "@loop.outer" }, - i = { "@block.inner", "@conditional.inner", "@loop.inner" }, - }, {}), - f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}), - c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }, {}), - t = { "<([%p%w]-)%f[^<%w][^<>]->.-", "^<.->().*()$" }, - d = { "%f[%d]%d+" }, -- digits - e = { -- Word with case - { - "%u[%l%d]+%f[^%l%d]", - "%f[%S][%l%d]+%f[^%l%d]", - "%f[%P][%l%d]+%f[^%l%d]", - "^[%l%d]+%f[^%l%d]", - }, - "^().*()$", - }, - g = function() -- Whole buffer, similar to `gg` and 'G' motion - local from = { line = 1, col = 1 } - local to = { - line = vim.fn.line("$"), - col = math.max(vim.fn.getline("$"):len(), 1), - } - return { from = from, to = to } - end, - u = ai.gen_spec.function_call(), -- u for "Usage" - U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- without dot in function name - }, - } - end, - config = function(_, opts) - require("mini.ai").setup(opts) - -- register all text objects with which-key - LazyVim.on_load("which-key.nvim", function() - ---@type table - local i = { - [" "] = "Whitespace", - ['"'] = 'Balanced "', - ["'"] = "Balanced '", - ["`"] = "Balanced `", - ["("] = "Balanced (", - [")"] = "Balanced ) including white-space", - [">"] = "Balanced > including white-space", - [""] = "Balanced <", - ["]"] = "Balanced ] including white-space", - ["["] = "Balanced [", - ["}"] = "Balanced } including white-space", - ["{"] = "Balanced {", - ["?"] = "User Prompt", - _ = "Underscore", - a = "Argument", - b = "Balanced ), ], }", - c = "Class", - d = "Digit(s)", - e = "Word in CamelCase & snake_case", - f = "Function", - g = "Entire file", - o = "Block, conditional, loop", - q = "Quote `, \", '", - t = "Tag", - u = "Use/call function & method", - U = "Use/call without dot in name", - } - local a = vim.deepcopy(i) - for k, v in pairs(a) do - a[k] = v:gsub(" including.*", "") - end - - local ic = vim.deepcopy(i) - local ac = vim.deepcopy(a) - for key, name in pairs({ n = "Next", l = "Last" }) do - i[key] = vim.tbl_extend("force", { name = "Inside " .. name .. " textobject" }, ic) - a[key] = vim.tbl_extend("force", { name = "Around " .. name .. " textobject" }, ac) - end - require("which-key").register({ - mode = { "o", "x" }, - i = i, - a = a, - }) - end) - end, - }, } diff --git a/lua/lazyvim/plugins/extras/coding/mini-ai.lua b/lua/lazyvim/plugins/extras/coding/mini-ai.lua new file mode 100644 index 00000000..b97c248e --- /dev/null +++ b/lua/lazyvim/plugins/extras/coding/mini-ai.lua @@ -0,0 +1,95 @@ +-- Better text-objects +return { + "echasnovski/mini.ai", + -- keys = { + -- { "a", mode = { "x", "o" } }, + -- { "i", mode = { "x", "o" } }, + -- }, + event = "VeryLazy", + opts = function() + local ai = require("mini.ai") + return { + n_lines = 500, + custom_textobjects = { + o = ai.gen_spec.treesitter({ + a = { "@block.outer", "@conditional.outer", "@loop.outer" }, + i = { "@block.inner", "@conditional.inner", "@loop.inner" }, + }, {}), + f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}), + c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }, {}), + t = { "<([%p%w]-)%f[^<%w][^<>]->.-", "^<.->().*()$" }, + d = { "%f[%d]%d+" }, -- digits + e = { -- Word with case + { + "%u[%l%d]+%f[^%l%d]", + "%f[%S][%l%d]+%f[^%l%d]", + "%f[%P][%l%d]+%f[^%l%d]", + "^[%l%d]+%f[^%l%d]", + }, + "^().*()$", + }, + g = function() -- Whole buffer, similar to `gg` and 'G' motion + local from = { line = 1, col = 1 } + local to = { + line = vim.fn.line("$"), + col = math.max(vim.fn.getline("$"):len(), 1), + } + return { from = from, to = to } + end, + u = ai.gen_spec.function_call(), -- u for "Usage" + U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- without dot in function name + }, + } + end, + config = function(_, opts) + require("mini.ai").setup(opts) + -- register all text objects with which-key + LazyVim.on_load("which-key.nvim", function() + ---@type table + local i = { + [" "] = "Whitespace", + ['"'] = 'Balanced "', + ["'"] = "Balanced '", + ["`"] = "Balanced `", + ["("] = "Balanced (", + [")"] = "Balanced ) including white-space", + [">"] = "Balanced > including white-space", + [""] = "Balanced <", + ["]"] = "Balanced ] including white-space", + ["["] = "Balanced [", + ["}"] = "Balanced } including white-space", + ["{"] = "Balanced {", + ["?"] = "User Prompt", + _ = "Underscore", + a = "Argument", + b = "Balanced ), ], }", + c = "Class", + d = "Digit(s)", + e = "Word in CamelCase & snake_case", + f = "Function", + g = "Entire file", + o = "Block, conditional, loop", + q = "Quote `, \", '", + t = "Tag", + u = "Use/call function & method", + U = "Use/call without dot in name", + } + local a = vim.deepcopy(i) + for k, v in pairs(a) do + a[k] = v:gsub(" including.*", "") + end + + local ic = vim.deepcopy(i) + local ac = vim.deepcopy(a) + for key, name in pairs({ n = "Next", l = "Last" }) do + i[key] = vim.tbl_extend("force", { name = "Inside " .. name .. " textobject" }, ic) + a[key] = vim.tbl_extend("force", { name = "Around " .. name .. " textobject" }, ac) + end + require("which-key").register({ + mode = { "o", "x" }, + i = i, + a = a, + }) + end) + end, +}