refactor: introduce nvim_on internally #39883

Problem:
`nvim_create_autocmd` is too verbose and its `callback` requires extra
"nesting".

Solution:
Introduce `nvim_on`. Start using it internally. Then we can get a feel
for how it should look before making it public.
This commit is contained in:
Justin M. Keyes
2026-05-20 17:33:01 -04:00
committed by GitHub
parent 799cbfff85
commit 9aa4608401
32 changed files with 842 additions and 1040 deletions

View File

@@ -342,11 +342,13 @@ do
--- Initialize Progress handlers.
local function progress_init()
progress_group = vim.api.nvim_create_augroup('nvim.ui.progress_status', { clear = true })
progress_autocmd = vim.api.nvim_create_autocmd('Progress', {
group = progress_group,
desc = 'Tracks progress messages for vim.ui.progress_status()',
---@param ev {data: vim.event.progress.data}
callback = function(ev)
progress_autocmd = require('vim._core.util').nvim_on(
'Progress',
progress_group,
{
desc = 'Tracks progress messages for vim.ui.progress_status()',
}, ---@param ev {data: vim.event.progress.data}
function(ev)
if not ev.data or not ev.data.id then
return
end
@@ -362,8 +364,8 @@ do
then
progress[ev.data.id] = nil
end
end,
})
end
)
end
--- Gets a status description summarizing currently running progress messages.