Moved pyarrow overlay to overlays, cleanup

This commit is contained in:
Daniel Winkler 2026-08-12 08:49:32 +10:00
commit a4bae164c3
14 changed files with 165 additions and 589 deletions

View file

@ -119,3 +119,69 @@ Config.add = (function(pkg)
end)
Config.now_if_args = vim.fn.argc(-1) > 0 and MiniDeps.now or MiniDeps.later
-- Checkbox
local checked_character = "x"
local checked_checkbox = "%[" .. checked_character .. "%]"
local unchecked_checkbox = "%[ %]"
local line_contains_unchecked = function(line)
return line:find(unchecked_checkbox)
end
local line_contains_checked = function(line)
return line:find(checked_checkbox)
end
local line_with_checkbox = function(line)
return line:find("^%s*- " .. checked_checkbox)
or line:find("^%s*- " .. unchecked_checkbox)
or line:find("^%s*%d%. " .. checked_checkbox)
or line:find("^%s*%d%. " .. unchecked_checkbox)
end
local checkbox = {
check = function(line)
return line:gsub(unchecked_checkbox, checked_checkbox, 1)
end,
uncheck = function(line)
return line:gsub(checked_checkbox, unchecked_checkbox, 1)
end,
make_checkbox = function(line)
if not line:match("^%s*%-%s") and not line:match("^%s*%d%.%s") then
-- "xxx" -> "- [ ] xxx"
return line:gsub("(%S+)", "- [ ] %1", 1)
else
-- "- xxx" -> "- [ ] xxx", "3. xxx" -> "3. [ ] xxx"
return line:gsub("(%s*- )(.*)", "%1[ ] %2", 1):gsub("(%s*%d%. )(.*)", "%1[ ] %2", 1)
end
end,
}
Config.togglecb = function()
local bufnr = vim.api.nvim_get_current_buf()
local cursor = vim.api.nvim_win_get_cursor(0)
local start_line = cursor[1] - 1
local current_line = vim.api.nvim_buf_get_lines(bufnr, start_line, start_line + 1, false)[1] or ""
-- If the line contains a checked checkbox then uncheck it.
-- Otherwise, if it contains an unchecked checkbox, check it.
local new_line = ""
if not line_with_checkbox(current_line) then
new_line = checkbox.make_checkbox(current_line)
elseif line_contains_unchecked(current_line) then
new_line = checkbox.check(current_line)
elseif line_contains_checked(current_line) then
new_line = checkbox.uncheck(current_line)
end
vim.api.nvim_buf_set_lines(bufnr, start_line, start_line + 1, false, { new_line })
vim.api.nvim_win_set_cursor(0, cursor)
end
vim.api.nvim_create_user_command("ToggleCheckbox", Config.togglecb, {})