refactor(init): remove help popup, use config-driven keymaps
Problem: Buffer-local keymaps were hardcoded with no way for users to customize them. The g? help popup duplicated information already in the vimdoc. Solution: Remove show_help() and the g? mapping. Refactor _setup_buf_mappings to read from cfg.keymaps, letting users override or disable any buffer-local binding via vim.g.pending.
This commit is contained in:
parent
39fd4ef17a
commit
c038130a8b
1 changed files with 37 additions and 99 deletions
|
|
@ -50,37 +50,44 @@ end
|
|||
|
||||
---@param bufnr integer
|
||||
function M._setup_buf_mappings(bufnr)
|
||||
local cfg = require('pending.config').get()
|
||||
local km = cfg.keymaps
|
||||
local opts = { buffer = bufnr, silent = true }
|
||||
vim.keymap.set('n', 'q', function()
|
||||
buffer.close()
|
||||
end, opts)
|
||||
vim.keymap.set('n', '<Esc>', function()
|
||||
buffer.close()
|
||||
end, opts)
|
||||
vim.keymap.set('n', '<CR>', function()
|
||||
M.toggle_complete()
|
||||
end, opts)
|
||||
vim.keymap.set('n', '<Tab>', function()
|
||||
buffer.toggle_view()
|
||||
end, opts)
|
||||
vim.keymap.set('n', 'g?', function()
|
||||
M.show_help()
|
||||
end, opts)
|
||||
vim.keymap.set('n', '!', function()
|
||||
M.toggle_priority()
|
||||
end, opts)
|
||||
vim.keymap.set('n', 'D', function()
|
||||
M.prompt_date()
|
||||
end, opts)
|
||||
vim.keymap.set('n', 'U', function()
|
||||
M.undo_write()
|
||||
end, opts)
|
||||
vim.keymap.set('n', 'o', function()
|
||||
buffer.open_line(false)
|
||||
end, opts)
|
||||
vim.keymap.set('n', 'O', function()
|
||||
buffer.open_line(true)
|
||||
end, opts)
|
||||
|
||||
---@type table<string, fun()>
|
||||
local actions = {
|
||||
close = function()
|
||||
buffer.close()
|
||||
end,
|
||||
toggle = function()
|
||||
M.toggle_complete()
|
||||
end,
|
||||
view = function()
|
||||
buffer.toggle_view()
|
||||
end,
|
||||
priority = function()
|
||||
M.toggle_priority()
|
||||
end,
|
||||
date = function()
|
||||
M.prompt_date()
|
||||
end,
|
||||
undo = function()
|
||||
M.undo_write()
|
||||
end,
|
||||
open_line = function()
|
||||
buffer.open_line(false)
|
||||
end,
|
||||
open_line_above = function()
|
||||
buffer.open_line(true)
|
||||
end,
|
||||
}
|
||||
|
||||
for name, fn in pairs(actions) do
|
||||
local key = km[name]
|
||||
if key and key ~= false then
|
||||
vim.keymap.set('n', key --[[@as string]], fn, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
|
|
@ -334,75 +341,6 @@ function M.due()
|
|||
vim.cmd('copen')
|
||||
end
|
||||
|
||||
function M.show_help()
|
||||
local cfg = require('pending.config').get()
|
||||
local dk = cfg.date_syntax or 'due'
|
||||
local rk = cfg.recur_syntax or 'rec'
|
||||
local lines = {
|
||||
'pending.nvim keybindings',
|
||||
'',
|
||||
'<CR> Toggle complete/uncomplete',
|
||||
'<Tab> Switch category/priority view',
|
||||
'! Toggle urgent',
|
||||
'D Set due date',
|
||||
'U Undo last write',
|
||||
'o / O Add new task line',
|
||||
'dd Delete task line (on :w)',
|
||||
'p / P Paste (duplicates get new IDs)',
|
||||
'zc / zo Fold/unfold category (category view)',
|
||||
':w Save all changes',
|
||||
'',
|
||||
':Pending add <text> Quick-add task',
|
||||
':Pending add Cat: <text> Quick-add with category',
|
||||
':Pending due Show overdue/due qflist',
|
||||
':Pending sync Push to Google Calendar',
|
||||
':Pending archive [days] Purge old done tasks',
|
||||
':Pending undo Undo last write',
|
||||
'',
|
||||
'Inline metadata (on new lines before :w):',
|
||||
' ' .. dk .. ':YYYY-MM-DD Set due date',
|
||||
' cat:Name Set category',
|
||||
' ' .. rk .. ':pattern Set recurrence',
|
||||
'',
|
||||
'Due date input:',
|
||||
' today, tomorrow, yesterday, +Nd, +Nw, +Nm',
|
||||
' -Nd, -Nw, mon-sun, jan-dec, 1st-31st',
|
||||
' eod, eow, eom, eoq, eoy, sow, som, soq, soy',
|
||||
' later, someday',
|
||||
' Empty input clears due date',
|
||||
'',
|
||||
'Recurrence patterns:',
|
||||
' daily, weekdays, weekly, biweekly',
|
||||
' monthly, quarterly, yearly, Nd, Nw, Nm, Ny',
|
||||
' Prefix ! for completion-based (e.g. !weekly)',
|
||||
'',
|
||||
'Completion: <C-x><C-o> after due:, cat:, rec:',
|
||||
'',
|
||||
'Press q or <Esc> to close',
|
||||
}
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.bo[buf].bufhidden = 'wipe'
|
||||
local width = 54
|
||||
local height = #lines
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = 'editor',
|
||||
width = width,
|
||||
height = height,
|
||||
col = math.floor((vim.o.columns - width) / 2),
|
||||
row = math.floor((vim.o.lines - height) / 2),
|
||||
style = 'minimal',
|
||||
border = 'rounded',
|
||||
})
|
||||
vim.keymap.set('n', 'q', function()
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end, { buffer = buf, silent = true })
|
||||
vim.keymap.set('n', '<Esc>', function()
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end, { buffer = buf, silent = true })
|
||||
end
|
||||
|
||||
---@param args string
|
||||
function M.command(args)
|
||||
if not args or args == '' then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue