feat(snacks)!: use snacks.scope indent objects in favor of custom mini.ai indent objects

This commit is contained in:
Folke Lemaitre 2024-12-12 07:09:09 +01:00
parent 1a1a48497c
commit d904a1ef47
3 changed files with 2 additions and 42 deletions

View file

@ -160,7 +160,6 @@ return {
{ "%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]" }, { "%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]" },
"^().*()$", "^().*()$",
}, },
i = LazyVim.mini.ai_indent, -- indent
g = LazyVim.mini.ai_buffer, -- buffer g = LazyVim.mini.ai_buffer, -- buffer
u = ai.gen_spec.function_call(), -- u for "Usage" u = ai.gen_spec.function_call(), -- u for "Usage"
U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- without dot in function name U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- without dot in function name

View file

@ -35,6 +35,7 @@ return {
quickfile = { enabled = true }, quickfile = { enabled = true },
statuscolumn = { enabled = false }, -- we set this in options.lua statuscolumn = { enabled = false }, -- we set this in options.lua
scroll = { enabled = true }, scroll = { enabled = true },
scope = { enabled = true },
indent = { enabled = true }, indent = { enabled = true },
terminal = { terminal = {
win = { win = {

View file

@ -1,47 +1,6 @@
---@class lazyvim.util.mini ---@class lazyvim.util.mini
local M = {} local M = {}
---@alias Mini.ai.loc {line:number, col:number}
---@alias Mini.ai.region {from:Mini.ai.loc, to:Mini.ai.loc}
-- Mini.ai indent text object
-- For "a", it will include the non-whitespace line surrounding the indent block.
-- "a" is line-wise, "i" is character-wise.
function M.ai_indent(ai_type)
local spaces = (" "):rep(vim.o.tabstop)
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local indents = {} ---@type {line: number, indent: number, text: string}[]
for l, line in ipairs(lines) do
if not line:find("^%s*$") then
indents[#indents + 1] = { line = l, indent = #line:gsub("\t", spaces):match("^%s*"), text = line }
end
end
local ret = {} ---@type (Mini.ai.region | {indent: number})[]
for i = 1, #indents do
if i == 1 or indents[i - 1].indent < indents[i].indent then
local from, to = i, i
for j = i + 1, #indents do
if indents[j].indent < indents[i].indent then
break
end
to = j
end
from = ai_type == "a" and from > 1 and from - 1 or from
to = ai_type == "a" and to < #indents and to + 1 or to
ret[#ret + 1] = {
indent = indents[i].indent,
from = { line = indents[from].line, col = ai_type == "a" and 1 or indents[from].indent + 1 },
to = { line = indents[to].line, col = #indents[to].text },
}
end
end
return ret
end
-- taken from MiniExtra.gen_ai_spec.buffer -- taken from MiniExtra.gen_ai_spec.buffer
function M.ai_buffer(ai_type) function M.ai_buffer(ai_type)
local start_line, end_line = 1, vim.fn.line("$") local start_line, end_line = 1, vim.fn.line("$")
@ -92,6 +51,7 @@ function M.ai_whichkey(opts)
{ "}", desc = "{} with ws" }, { "}", desc = "{} with ws" },
} }
---@type wk.Spec[]
local ret = { mode = { "o", "x" } } local ret = { mode = { "o", "x" } }
---@type table<string, string> ---@type table<string, string>
local mappings = vim.tbl_extend("force", {}, { local mappings = vim.tbl_extend("force", {}, {