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

@ -25,12 +25,12 @@ describe('diff', function()
describe('parse_buffer', function()
it('parses headers and tasks', function()
local lines = {
'School',
'/1/ Do homework',
'/2/ [1] Read chapter 5',
'## School',
'/1/- [ ] Do homework',
'/2/- [!] Read chapter 5',
'',
'Errands',
'/3/ Buy groceries',
'## Errands',
'/3/- [ ] Buy groceries',
}
local result = diff.parse_buffer(lines)
assert.are.equal(6, #result)
@ -48,8 +48,8 @@ describe('diff', function()
it('handles new tasks without ids', function()
local lines = {
'Inbox',
' New task here',
'## Inbox',
'- [ ] New task here',
}
local result = diff.parse_buffer(lines)
assert.are.equal(2, #result)
@ -60,8 +60,8 @@ describe('diff', function()
it('inline cat: token overrides header category', function()
local lines = {
'Inbox',
'/1/ Buy milk cat:Work',
'## Inbox',
'/1/- [ ] Buy milk cat:Work',
}
local result = diff.parse_buffer(lines)
assert.are.equal(2, #result)
@ -71,8 +71,8 @@ describe('diff', function()
it('inline due: token is parsed', function()
local lines = {
'Inbox',
'/1/ Buy milk due:2026-03-15',
'## Inbox',
'/1/- [ ] Buy milk due:2026-03-15',
}
local result = diff.parse_buffer(lines)
assert.are.equal(2, #result)
@ -84,9 +84,9 @@ describe('diff', function()
describe('apply', function()
it('creates new tasks from buffer lines', function()
local lines = {
'Inbox',
' First task',
' Second task',
'## Inbox',
'- [ ] First task',
'- [ ] Second task',
}
diff.apply(lines)
store.unload()
@ -102,8 +102,8 @@ describe('diff', function()
store.add({ description = 'Delete me' })
store.save()
local lines = {
'Inbox',
'/1/ Keep me',
'## Inbox',
'/1/- [ ] Keep me',
}
diff.apply(lines)
store.unload()
@ -119,8 +119,8 @@ describe('diff', function()
store.add({ description = 'Original' })
store.save()
local lines = {
'Inbox',
'/1/ Renamed',
'## Inbox',
'/1/- [ ] Renamed',
}
diff.apply(lines)
store.unload()
@ -134,8 +134,8 @@ describe('diff', function()
t.modified = '2020-01-01T00:00:00Z'
store.save()
local lines = {
'Inbox',
'/1/ Renamed',
'## Inbox',
'/1/- [ ] Renamed',
}
diff.apply(lines)
store.unload()
@ -149,9 +149,9 @@ describe('diff', function()
store.add({ description = 'Original' })
store.save()
local lines = {
'Inbox',
'/1/ Original',
'/1/ Copy of original',
'## Inbox',
'/1/- [ ] Original',
'/1/- [ ] Copy of original',
}
diff.apply(lines)
store.unload()
@ -164,8 +164,8 @@ describe('diff', function()
store.add({ description = 'Moving task', category = 'Inbox' })
store.save()
local lines = {
'Work',
'/1/ Moving task',
'## Work',
'/1/- [ ] Moving task',
}
diff.apply(lines)
store.unload()
@ -178,8 +178,8 @@ describe('diff', function()
store.add({ description = 'Stable task', category = 'Inbox' })
store.save()
local lines = {
'Inbox',
'/1/ Stable task',
'## Inbox',
'/1/- [ ] Stable task',
}
diff.apply(lines)
store.unload()
@ -196,8 +196,8 @@ describe('diff', function()
store.add({ description = 'Pay bill', due = '2026-03-15' })
store.save()
local lines = {
'Inbox',
'/1/ Pay bill',
'## Inbox',
'/1/- [ ] Pay bill',
}
diff.apply(lines)
store.unload()
@ -210,8 +210,8 @@ describe('diff', function()
store.add({ description = 'Task name', priority = 1 })
store.save()
local lines = {
'Inbox',
'/1/ Task name',
'## Inbox',
'/1/- [ ] Task name',
}
diff.apply(lines)
store.unload()