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).
This commit is contained in:
Sean Dewar
2024-04-15 00:10:16 +01:00
committed by GitHub
parent e3fb937545
commit 7180ef6901
8 changed files with 56 additions and 48 deletions

View File

@ -735,16 +735,13 @@ static void cmd_with_count(char *cmd, char *bufp, size_t bufsize, int64_t Prenum
}
}
void win_set_buf(win_T *win, buf_T *buf, bool noautocmd, Error *err)
void win_set_buf(win_T *win, buf_T *buf, Error *err)
FUNC_ATTR_NONNULL_ALL
{
tabpage_T *tab = win_find_tabpage(win);
// no redrawing and don't set the window title
RedrawingDisabled++;
if (noautocmd) {
block_autocmds();
}
switchwin_T switchwin;
if (switch_win_noblock(&switchwin, win, tab, true) == FAIL) {
@ -770,9 +767,6 @@ void win_set_buf(win_T *win, buf_T *buf, bool noautocmd, Error *err)
cleanup:
restore_win_noblock(&switchwin, true);
if (noautocmd) {
unblock_autocmds();
}
RedrawingDisabled--;
}