refactor(mini.ai): improved descriptions for mini.ai

This commit is contained in:
Folke Lemaitre 2023-02-10 17:06:01 +01:00
parent fd0a0e829d
commit f5d232b79c
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -173,40 +173,50 @@ return {
} }
end, end,
config = function(_, opts) config = function(_, opts)
require("mini.ai").setup(opts)
-- register all text objects with which-key -- register all text objects with which-key
if require("lazyvim.util").has("which-key.nvim") then if require("lazyvim.util").has("which-key.nvim") then
local text_objects = { ---@type table<string, string|table>
t = "tag", local i = {
b = "balanced ), ], }", [" "] = "Whitespace",
f = "function", ['"'] = 'Balanced "',
c = "class", ["'"] = "Balanced '",
o = "block, conditional, loop", ["`"] = "Balanced `",
a = "argument", ["("] = "Balanced (",
q = "quote `, \", '", [")"] = "Balanced ) including white-space",
["?"] = "user Prompt", [">"] = "Balanced > including white-space",
["_"] = "underscore", ["<lt>"] = "Balanced <",
[" "] = "whitespace", ["]"] = "Balanced ] including white-space",
["["] = "Balanced [",
["}"] = "Balanced } including white-space",
["{"] = "Balanced {",
["?"] = "User Prompt",
_ = "Underscore",
a = "Argument",
b = "Balanced ), ], }",
c = "Class",
f = "Function",
o = "Block, conditional, loop",
q = "Quote `, \", '",
t = "Tag",
} }
for _, o in ipairs({ "(", ")", "[", "]", "{", "}", ">", "<", "'", "`", '"' }) do local a = vim.deepcopy(i)
local desc = "balanced " .. o for k, v in pairs(a) do
if vim.tbl_contains({ ")", "]", "}", ">" }, o) then a[k] = v:gsub(" including.*", "")
desc = desc .. " with inner space"
end end
text_objects[o == "<" and "<lt>" or o] = desc
end local ic = vim.deepcopy(i)
local text_objects_copy = vim.deepcopy(text_objects) local ac = vim.deepcopy(a)
for key, name in pairs({ n = "Next", l = "Last" }) do for key, name in pairs({ n = "Next", l = "Last" }) do
---@diagnostic disable-next-line: assign-type-mismatch i[key] = vim.tbl_extend("force", { name = "Inside " .. name .. " textobject" }, ic)
text_objects[key] = vim.tbl_extend("force", { name = name }, text_objects_copy) a[key] = vim.tbl_extend("force", { name = "Around " .. name .. " textobject" }, ac)
end end
require("which-key").register({ require("which-key").register({
mode = { "o", "x" }, mode = { "o", "x" },
i = text_objects, i = i,
a = text_objects, a = a,
}) })
end end
require("mini.ai").setup(opts)
end, end,
}, },
} }