docs(api): nvim_exec_autocmds() default "pattern"

Problem: nvim_exec_autocmds() documentation incorrectly describes the default
for "pattern" as *, when it's actually the current file name (like :doautocmd).

Solution: correct it. Add a test.
This commit is contained in:
Sean Dewar
2026-04-07 09:34:00 +01:00
parent cc0a4a653c
commit b28e5e4898
4 changed files with 12 additions and 4 deletions

View File

@@ -2227,8 +2227,8 @@ nvim_exec_autocmds({event}, {opts}) *nvim_exec_autocmds()*
• {opts} (`vim.api.keyset.exec_autocmds`) Optional filters:
• group (`string|integer?`) Group name or id to match
against. |autocmd-groups|.
• pattern (`string|array?`, default: "*") |autocmd-pattern|.
Not allowed with {buffer}.
• pattern (`string|array?`, default: current file name)
|autocmd-pattern|. Not allowed with {buffer}.
• buffer (`integer?`) Buffer id |autocmd-buflocal|. Not
allowed with {pattern}.
• modeline (`boolean?`, default: true) Process the modeline

View File

@@ -1224,7 +1224,7 @@ function vim.api.nvim_exec2(src, opts) end
--- @param event vim.api.keyset.events|vim.api.keyset.events[] Event(s) to execute.
--- @param opts vim.api.keyset.exec_autocmds Optional filters:
--- - group (`string|integer?`) Group name or id to match against. `autocmd-groups`.
--- - pattern (`string|array?`, default: "*") `autocmd-pattern`. Not allowed with {buffer}.
--- - pattern (`string|array?`, default: current file name) `autocmd-pattern`. Not allowed with {buffer}.
--- - buffer (`integer?`) Buffer id `autocmd-buflocal`. Not allowed with {pattern}.
--- - modeline (`boolean?`, default: true) Process the modeline after the autocommands
--- [<nomodeline>].

View File

@@ -657,7 +657,7 @@ void nvim_del_augroup_by_name(String name, Error *err)
/// @param event Event(s) to execute.
/// @param opts Optional filters:
/// - group (`string|integer?`) Group name or id to match against. |autocmd-groups|.
/// - pattern (`string|array?`, default: "*") |autocmd-pattern|. Not allowed with {buffer}.
/// - pattern (`string|array?`, default: current file name) |autocmd-pattern|. Not allowed with {buffer}.
/// - buffer (`integer?`) Buffer id |autocmd-buflocal|. Not allowed with {pattern}.
/// - modeline (`boolean?`, default: true) Process the modeline after the autocommands
/// [<nomodeline>].

View File

@@ -1053,6 +1053,14 @@ describe('autocmd api', function()
api.nvim_exec_autocmds('BufReadPre', { pattern = { 'foo', 'bar', 'baz', 'frederick' } })
eq(22, api.nvim_get_var('autocmd_executed'))
eq('', api.nvim_buf_get_name(0))
api.nvim_exec_autocmds({ 'BufReadPre', 'BufReadPost' }, {})
eq(23, api.nvim_get_var('autocmd_executed'))
api.nvim_buf_set_name(0, 'bar')
api.nvim_exec_autocmds({ 'BufReadPre', 'BufReadPost' }, {})
eq(34, api.nvim_get_var('autocmd_executed'))
end)
it('can pass the buffer', function()