This commit is contained in:
Scherer 2024-09-16 12:16:48 +02:00 committed by GitHub
commit 4d7785b335
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -2104,12 +2104,20 @@ char *getnextac(int c, void *cookie, int indent, bool do_concat)
char *retval;
if (ac->exec.type == CALLABLE_CB) {
AutoCmd ac_copy = *ac;
if (oneshot) {
ac->pat = NULL; // Assign NULL to prevent calling autocommand with once=true again
}
// Can potentially reallocate kvec_t data and invalidate the ac pointer
if (call_autocmd_callback(ac, apc)) {
if (call_autocmd_callback(&ac_copy, apc)) {
// If an autocommand callback returns true, delete the autocommand
oneshot = true;
}
kv_A(*acs, apc->auidx).pat = ac_copy.pat; // Restore aucmd reference
// TODO(tjdevries):
//
// Major Hack Alert:

View File

@ -250,6 +250,23 @@ describe('autocmd', function()
--- Autocommands ---]]),
fn.execute('autocmd Tabnew')
)
--
-- :autocmd should not recursively call ++once handlers.
--
exec_lua [[
vim.g.count = 0
vim.api.nvim_create_autocmd('User', {
once = true,
pattern = nil,
callback = function()
vim.g.count = vim.g.count + 1
vim.api.nvim_exec_autocmds('User', { pattern = nil })
end,
})
vim.api.nvim_exec_autocmds('User', { pattern = nil })
]]
eq(1, eval('g:count')) -- Added autocommands should not be executed
end)
it('internal `aucmd_win` window', function()