feat: text objects and motions for the pending buffer (#39)
* feat: text objects and motions for the pending buffer
Problem: the pending buffer has action-button mappings but no Vim
grammar. You cannot dat to delete a task, cit to change a description,
or ]] to jump to the next category header.
Solution: add textobj.lua with at/it (a task / inner task), aC/iC
(a category / inner category), ]]/[[ (next/prev header), and ]t/[t
(next/prev task). All text objects work in operator-pending and visual
modes; motions work in normal, visual, and operator-pending. Mappings
are configurable via the keymaps table and exposed as <Plug> mappings.
* fix(textobj): escape Lua pattern hyphen, fix test expectations
Problem: inner_task_range used unescaped '-' in Lua patterns, which
acts as a lazy quantifier instead of matching a literal hyphen. The
metadata-stripping logic also tokenized the full line including the
prefix, so the rebuilt string could never be found after the prefix.
All test column expectations were off by one.
Solution: escape hyphens with %-, rewrite metadata stripping to
tokenize only the description portion after the prefix, and correct
all test assertions to match actual rendered column positions.
* feat(textobj): add debug mode, rename priority view buffer
Problem: the ]] motion reportedly lands one line past the header in
some environments, and ]t/[t may not override Neovim defaults. No
way to diagnose these at runtime. Also, pending://priority is a poor
buffer name for the flat ranked view.
Solution: add a debug config option (vim.g.pending = { debug = true })
that logs meta state, cursor positions, and mapping registration to
:messages at DEBUG level. Rename the buffer from pending://priority to
pending://queue. Internal view identifier stays 'priority'.
* docs: text objects, motions, debug mode, queue view rename
Problem: vimdoc had no documentation for the new text objects, motions,
debug config, or the pending://queue buffer rename.
Solution: add text object and motion tables to the mappings section,
document all eight <Plug> mappings, add debug field to the config
reference, update config example with new keymap defaults, rename
priority view references to queue throughout the vimdoc.
* fix(textobj): use correct config variable, raise log level
Problem: motion keymaps (]], [[, ]t, [t) were never set because
`config.get().debug` referenced an undefined `config` variable,
crashing _setup_buf_mappings before the motion loop. Debug logging
also used vim.log.levels.DEBUG which is filtered by default.
Solution: replace `config` with `cfg` (already in scope) and raise
both debug notify calls from DEBUG to INFO.
* ci: formt
This commit is contained in:
parent
f689cac70b
commit
92c2c670c5
7 changed files with 778 additions and 5 deletions
|
|
@ -88,6 +88,72 @@ function M._setup_buf_mappings(bufnr)
|
|||
vim.keymap.set('n', key --[[@as string]], fn, opts)
|
||||
end
|
||||
end
|
||||
|
||||
local textobj = require('pending.textobj')
|
||||
|
||||
---@type table<string, { modes: string[], fn: fun(count: integer), visual_fn?: fun(count: integer) }>
|
||||
local textobjs = {
|
||||
a_task = {
|
||||
modes = { 'o', 'x' },
|
||||
fn = textobj.a_task,
|
||||
visual_fn = textobj.a_task_visual,
|
||||
},
|
||||
i_task = {
|
||||
modes = { 'o', 'x' },
|
||||
fn = textobj.i_task,
|
||||
visual_fn = textobj.i_task_visual,
|
||||
},
|
||||
a_category = {
|
||||
modes = { 'o', 'x' },
|
||||
fn = textobj.a_category,
|
||||
visual_fn = textobj.a_category_visual,
|
||||
},
|
||||
i_category = {
|
||||
modes = { 'o', 'x' },
|
||||
fn = textobj.i_category,
|
||||
visual_fn = textobj.i_category_visual,
|
||||
},
|
||||
}
|
||||
|
||||
for name, spec in pairs(textobjs) do
|
||||
local key = km[name]
|
||||
if key and key ~= false then
|
||||
for _, mode in ipairs(spec.modes) do
|
||||
if mode == 'x' and spec.visual_fn then
|
||||
vim.keymap.set(mode, key --[[@as string]], function()
|
||||
spec.visual_fn(vim.v.count1)
|
||||
end, opts)
|
||||
else
|
||||
vim.keymap.set(mode, key --[[@as string]], function()
|
||||
spec.fn(vim.v.count1)
|
||||
end, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@type table<string, fun(count: integer)>
|
||||
local motions = {
|
||||
next_header = textobj.next_header,
|
||||
prev_header = textobj.prev_header,
|
||||
next_task = textobj.next_task,
|
||||
prev_task = textobj.prev_task,
|
||||
}
|
||||
|
||||
for name, fn in pairs(motions) do
|
||||
local key = km[name]
|
||||
if cfg.debug then
|
||||
vim.notify(
|
||||
('[pending] mapping motion %s → %s (buf=%d)'):format(name, key or 'nil', bufnr),
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
end
|
||||
if key and key ~= false then
|
||||
vim.keymap.set({ 'n', 'x', 'o' }, key --[[@as string]], function()
|
||||
fn(vim.v.count1)
|
||||
end, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue