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

@@ -232,6 +232,7 @@ local api = vim.api
local uv = vim.uv
local async = require('vim._async')
local util = require('vim._core.util')
local nvim_on = util.nvim_on
local N_ = vim.fn.gettext
local M = {}
@@ -1199,7 +1200,7 @@ local function show_confirm_buf(lines, on_finish)
delete_buffer()
end
-- - Use `nested` to allow other events (useful for statuslines)
api.nvim_create_autocmd('BufWriteCmd', { buf = bufnr, nested = true, callback = finish })
nvim_on('BufWriteCmd', nil, { buf = bufnr, nested = true }, finish)
-- Define action to cancel confirm
--- @type integer
@@ -1211,7 +1212,7 @@ local function show_confirm_buf(lines, on_finish)
pcall(api.nvim_del_autocmd, cancel_au_id)
delete_buffer()
end
cancel_au_id = api.nvim_create_autocmd('WinClosed', { nested = true, callback = on_cancel })
cancel_au_id = nvim_on('WinClosed', nil, { nested = true }, on_cancel)
-- Set buffer-local options last (so that user autocmmands could override)
vim.bo[bufnr].modified = false