aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2026-09-10 03:42:20 +0800
committerGitHub <noreply@github.com>2026-09-09 15:42:20 -0400
commit08dd3adffb60ae6c031f9b8310febd65bb14604e (patch)
tree4c692cc37fa752ec0c6c4735865286f43cf756d6 /src/nvim/api
parentac167f943a905669b29f337f18d22a1efefeca92 (diff)
downloadrneovim-08dd3adffb60ae6c031f9b8310febd65bb14604e.tar.gz
rneovim-08dd3adffb60ae6c031f9b8310febd65bb14604e.tar.bz2
rneovim-08dd3adffb60ae6c031f9b8310febd65bb14604e.zip
feat(api): add ev.win to autocmd callback args #39826
Problem: Autocmd callbacks currently have to rely on curwin, which may already have changed by the time they run. This is especially noticeable for WinNew, WinClosed, WinResized and WinScrolled. Solution: Track the window in the autocmd context and expose it as ev.win. Pass it explicitly for the window events that need it.
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/autocmd.c11
-rw-r--r--src/nvim/api/win_config.c2
2 files changed, 7 insertions, 6 deletions
diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c
index f3b5aa780a..62fb5da9e4 100644
--- a/src/nvim/api/autocmd.c
+++ b/src/nvim/api/autocmd.c
@@ -373,13 +373,14 @@ cleanup:
/// - callback (`function|string?`) Lua function (or Vimscript function name, if string)
/// called when the event(s) is triggered. Lua callback can return |lua-truthy| to delete
/// the autocommand. Callback receives one argument, a table with keys: [event-args]()
-/// - buf: (`number`) [<abuf>]
+/// - buf: (`integer`) [<abuf>]
/// - data: (`any`) Arbitrary data passed from [nvim_exec_autocmds()] [event-data]()
/// - event: (`vim.api.keyset.events`) Name of the triggered event |autocmd-events|
/// - file: (`string`) [<afile>] (not expanded to a full path)
-/// - group: (`number?`) Group id, if any
-/// - id: (`number`) Autocommand id
+/// - group: (`integer?`) Group id, if any
+/// - id: (`integer`) Autocommand id
/// - match: (`string`) [<amatch>] (expanded to a full path)
+/// - win: (`integer`) id of the window for the event, see |window-ID|
/// - command (string?) Vim command executed on event. Not allowed with {callback}.
/// - desc (`string?`) Description (for documentation and troubleshooting).
/// - group (`string|integer?`) Group name or id to match against.
@@ -764,8 +765,8 @@ void nvim_exec_autocmds(Object event, Dict(exec_autocmds) *opts, Arena *arena, E
FOREACH_ITEM(patterns, pat, {
char *fname = !has_buf ? pat.data.string.data : NULL;
- did_aucmd |= apply_autocmds_group(event_nr, fname, NULL, true, au_group, b, NULL, data,
- has_buf);
+ did_aucmd |= apply_autocmds_group(event_nr, fname, NULL, true, au_group, b, curwin, NULL,
+ data, has_buf);
})
})
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index c7f3047a64..12ee0ccb61 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -299,7 +299,7 @@ Window nvim_open_win(Buffer buf, Boolean enter, Dict(win_config) *config, Error
const bool result = ctx_switch(&switchwin, wp, tp, NULL, kCtxNoDisplay);
assert(result);
(void)result;
- if (apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf)) {
+ if (apply_autocmds_win(EVENT_WINNEW, NULL, NULL, false, curbuf, wp)) {
tp = win_find_tabpage(wp);
}
ctx_restore(&switchwin);