From 34a59e30dbe23bab59bc6b39a4b235c5b2862e60 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Fri, 6 Mar 2026 19:34:47 +0100 Subject: [PATCH] docs(api): clarify nvim_win_set_buf documentation #37201 --- runtime/doc/api.txt | 5 ++++- runtime/lua/vim/_meta/api.lua | 3 ++- src/nvim/api/window.c | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 00aebd1866..dd8dfa5f19 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -4156,7 +4156,10 @@ nvim_win_is_valid({window}) *nvim_win_is_valid()* (`boolean`) true if the window is valid, false otherwise nvim_win_set_buf({window}, {buffer}) *nvim_win_set_buf()* - Sets the current buffer in a window, without side effects + Sets the current buffer in a window. + + Note: As a side-effect, this executes |BufEnter| and |BufLeave| + autocommands. Attributes: ~ not allowed when |textlock| is active diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua index b9cf341403..e3f99dc539 100644 --- a/runtime/lua/vim/_meta/api.lua +++ b/runtime/lua/vim/_meta/api.lua @@ -2484,8 +2484,9 @@ function vim.api.nvim_win_hide(window) end --- @return boolean # true if the window is valid, false otherwise function vim.api.nvim_win_is_valid(window) end ---- Sets the current buffer in a window, without side effects +--- Sets the current buffer in a window. --- +--- Note: As a side-effect, this executes `BufEnter` and `BufLeave` autocommands. --- @param window integer `window-ID`, or 0 for current window --- @param buffer integer Buffer id function vim.api.nvim_win_set_buf(window, buffer) end diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index e3f080c407..bacd2fb67c 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -45,8 +45,9 @@ Buffer nvim_win_get_buf(Window window, Error *err) return win->w_buffer->handle; } -/// Sets the current buffer in a window, without side effects +/// Sets the current buffer in a window. /// +/// Note: As a side-effect, this executes |BufEnter| and |BufLeave| autocommands. /// @param window |window-ID|, or 0 for current window /// @param buffer Buffer id /// @param[out] err Error details, if any