Something went wrong. Try again.
A simple nvim task manager plugin for markdown
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990Name = "Task Manager"Description = "A plugin to manage task files"
require("shared.utils")
local M = {}
local task_status = { todo = "- [ ] ", done = "- [x] ",}
local task_pattern = "^(%s*)-%s%[(.)]%s(.*)$"
local toggle_task = function (input) local prefix, checkbox, content = input:match(task_pattern) local status = task_status.done
print(input)
if prefix and checkbox and content then if checkbox == "x" then status = task_status.todo end
print("is task") return prefix .. status .. content end
-- not a task, make it one status = task_status.todo
local content_pattern = "^(%s+)(.*)$" prefix, content = input:match(content_pattern)
if prefix and content then return prefix .. status .. content end
return status .. inputend
local delete_task = function (input) local prefix, checkbox, content = input:match(task_pattern)
if prefix and checkbox and content then return prefix .. content end
return inputend
local modes = { toggle = 'toggle', remove = 'remove'}
local mode_handler = { [modes.toggle] = toggle_task, [modes.remove] = delete_task,}
local command = function (opts) local mode = opts.mode or modes.toggle
return function () local handler = mode_handler[mode] if handler == nil then return end
local content = vim.api.nvim_get_current_line() local line = handler(content)
vim.api.nvim_set_current_line(line) endend
function M.setup() vim.keymap.set("n", "<leader><leader>t", command({ mode = modes.toggle })) vim.keymap.set("n", "<leader><leader>T", command({ mode = modes.remove }))
-- reload setup vim.keymap.set("n", "<leader><leader>tr", function () R('tasks').setup() end)end
return M