From 9aa4608401384a59ea54e0ba800ce063775e8ae9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 20 May 2026 17:33:01 -0400 Subject: 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. --- runtime/lua/vim/pack.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/pack.lua') diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index a4f7389fda..aad11e0915 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -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 -- cgit