refactor: adopt markdown-style checkbox buffer format (#20)

* refactor(config): change default category from Inbox to Todo

* refactor(views): adopt markdown checkbox line format

Problem: task lines used an opaque /ID/  [N] prefix format that was
hard to read and inconsistent between category and priority views.
Header lines had no visual marker distinguishing them from tasks.

Solution: render headers as '## Cat', task lines as
'/ID/- [x|!| ] description'. State encoding: [x]=done, [!]=urgent,
[ ]=pending. Both views use the same construction.

* refactor(diff): parse and reconcile markdown checkbox format

Problem: parse_buffer matched the old '  text' indent pattern and
detected headers via '^%S'. Priority was read from a '[N] ' prefix.
apply() never reconciled status changes written into the buffer.

Solution: match '- [.] text' for tasks and '^## ' for headers.
Extract state char to derive priority (! -> 1) and status (x -> done).
apply() now reconciles status from the buffer, setting/clearing 'end'
timestamps — enabling the oil-style edit-checkbox-then-:w workflow.

* refactor(buffer): update syntax, extmarks, and render for checkbox format

Problem: syntax patterns matched the old indent/[N] format; right_align
virtual text produced a broken layout in narrow windows; the done
strikethrough skipped past the '  ' indent leaving '- [x] ' unstyled;
render() added undo history entries so 'u' could undo a re-render.

Solution: update taskHeader/taskLine patterns for '## '/'- [.]'; rename
taskPriority -> taskCheckbox matching '[!]'; switch virt_text_pos to
'eol'; drop the +2 col_start offset so strikethrough covers '- [x] ';
guard nvim_buf_set_lines with undolevels=-1 so renders are not undoable.
Also fix open_line to insert '- [ ] ' and position cursor at col 6.

* refactor(init): replace multi-level priority with binary toggle

Problem: <C-a>/<C-x> overrode Vim's native number increment and the
visual g<C-a>/g<C-x> variants added complexity for marginal value.
toggle_complete() left the cursor on the wrong line after re-render.

Solution: remove change_priority/change_priority_visual; add
toggle_priority() (0<->1) mapped to '!', with cursor-follow after
render matching the pattern already used in priority toggle. Add
cursor-follow to toggle_complete() for the same reason. Update plugin
plugs (priority-up/down -> priority) and add 'due'/'undo' to the
:Pending completion list. Update help text accordingly.

* feat(buffer): reflect current view in buffer name

Problem: no way to tell at a glance which view (category vs priority)
is active — the buffer was always named 'pending://'.

Solution: update the buffer name to 'pending://category' or
'pending://priority' on every render, so the view is visible in
the statusline/tabline without any extra UI.
This commit is contained in:
Barrett Ruth 2026-02-24 23:21:55 -05:00
parent 114048298b
commit e04440bb3d
10 changed files with 101 additions and 130 deletions

View file

@ -52,17 +52,8 @@ function M._setup_buf_mappings(bufnr)
vim.keymap.set('n', 'g?', function()
M.show_help()
end, opts)
vim.keymap.set('n', '<C-a>', function()
M.change_priority(1)
end, opts)
vim.keymap.set('n', '<C-x>', function()
M.change_priority(-1)
end, opts)
vim.keymap.set('v', 'g<C-a>', function()
M.change_priority_visual(1)
end, opts)
vim.keymap.set('v', 'g<C-x>', function()
M.change_priority_visual(-1)
vim.keymap.set('n', '!', function()
M.toggle_priority()
end, opts)
vim.keymap.set('n', 'D', function()
M.prompt_date()
@ -126,10 +117,15 @@ function M.toggle_complete()
end
store.save()
buffer.render(bufnr)
for lnum, m in ipairs(buffer.meta()) do
if m.id == id then
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
break
end
end
end
---@param delta integer
function M.change_priority(delta)
function M.toggle_priority()
local bufnr = buffer.bufnr()
if not bufnr then
return
@ -147,7 +143,7 @@ function M.change_priority(delta)
if not task then
return
end
local new_priority = math.max(0, task.priority + delta)
local new_priority = task.priority > 0 and 0 or 1
store.update(id, { priority = new_priority })
store.save()
buffer.render(bufnr)
@ -159,33 +155,6 @@ function M.change_priority(delta)
end
end
---@param delta integer
function M.change_priority_visual(delta)
local bufnr = buffer.bufnr()
if not bufnr then
return
end
local start_row = vim.fn.line("'<")
local end_row = vim.fn.line("'>")
local meta = buffer.meta()
local changed = false
for row = start_row, end_row do
local m = meta[row]
if m and m.type == 'task' and m.id then
local task = store.get(m.id)
if task then
local new_priority = math.max(0, task.priority + delta)
store.update(m.id, { priority = new_priority })
changed = true
end
end
end
if changed then
store.save()
buffer.render(bufnr)
end
end
function M.prompt_date()
local bufnr = buffer.bufnr()
if not bufnr then
@ -342,10 +311,7 @@ function M.show_help()
'',
'<CR> Toggle complete/uncomplete',
'<Tab> Switch category/priority view',
'<C-a> Raise priority level',
'<C-x> Lower priority level',
'g<C-a> Raise priority for visual selection',
'g<C-x> Lower priority for visual selection',
'! Toggle urgent',
'D Set due date',
'U Undo last write',
'o / O Add new task line',
@ -371,7 +337,7 @@ function M.show_help()
'',
'Highlights:',
' PendingOverdue overdue tasks (red)',
' PendingPriority [N] priority prefix',
' PendingPriority [!] urgent tasks',
'',
'Press q or <Esc> to close',
}