From 7180ef690180cf92d1d49811820c46dd60e4d1c6 Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Mon, 15 Apr 2024 00:10:16 +0100 Subject: feat(api)!: nvim_open_win: noautocmd blocks all autocmds #28192 Problem: noautocmd is confusing; despite its name, it doesn't block all autocommands (instead it blocks only those related to setting the buffer), and is commonly used by plugins to open windows while producing minimal side-effects. Solution: be consistent and block all autocommands when noautocmd is set. This includes WinNew (again), plus autocommands from entering the window (if enter is set) like WinEnter, WinLeave, TabEnter, .etc. See the discussion at https://github.com/neovim/neovim/pull/14659#issuecomment-2040029517 for more information. Remove win_set_buf's noautocmd argument, as it's no longer needed. NOTE: pum_create_float_preview sets noautocmd for win_set_buf, but all its callers already use block_autocmds. Despite that, pum_create_float_preview doesn't actually properly handle autocommands (it has no checks for whether those from win_enter or nvim_create_buf free the window). For now, ensure autocommands are blocked within it for correctness (in case it's ever called outside of a block_autocmds context; the function seems to have been refactored in #26739 anyway). --- src/nvim/popupmenu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index bed0a8df4a..73e019bc50 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -666,6 +666,7 @@ void pum_redraw(void) } /// create a floating preview window for info +/// Autocommands are blocked for the duration of the call. /// @return NULL when no enough room to show static win_T *pum_create_float_preview(bool enter) { @@ -690,6 +691,9 @@ static win_T *pum_create_float_preview(bool enter) config.height = pum_height; config.style = kWinStyleMinimal; config.hide = true; + + block_autocmds(); + Error err = ERROR_INIT; win_T *wp = win_new_float(NULL, true, config, &err); // TODO(glepnir): remove win_enter usage @@ -701,6 +705,7 @@ static win_T *pum_create_float_preview(bool enter) Buffer b = nvim_create_buf(false, true, &err); if (!b) { win_free(wp, NULL); + unblock_autocmds(); return NULL; } buf_T *buf = find_buffer_by_handle(b, &err); @@ -709,7 +714,9 @@ static win_T *pum_create_float_preview(bool enter) wp->w_float_is_info = true; wp->w_p_diff = false; buf->b_p_bl = false; - win_set_buf(wp, buf, true, &err); + win_set_buf(wp, buf, &err); + + unblock_autocmds(); return wp; } -- cgit