aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/buffer.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-16 20:57:01 +0800
committerGitHub <noreply@github.com>2024-04-16 20:57:01 +0800
commit5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98 (patch)
tree8d058733804bed0990c1a8e6836663f7b2460d5d /src/nvim/api/buffer.c
parent2fc2343728831d890a043def5d9d714947737cf6 (diff)
downloadrneovim-5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98.tar.gz
rneovim-5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98.tar.bz2
rneovim-5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98.zip
fix(api): ignore 'autochdir' when renaming other buf (#28376)
Problem: Renaming non-current buffer changes working directory when 'autochdir' is set. Solution: Temporarily disable 'autochdir'. Add more tests for the win_set_buf change.
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r--src/nvim/api/buffer.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index b32159dc96..452ba49e04 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -39,6 +39,7 @@
#include "nvim/memory_defs.h"
#include "nvim/move.h"
#include "nvim/ops.h"
+#include "nvim/option_vars.h"
#include "nvim/pos_defs.h"
#include "nvim/state_defs.h"
#include "nvim/types_defs.h"
@@ -984,12 +985,23 @@ void nvim_buf_set_name(Buffer buffer, String name, Error *err)
try_start();
+ const bool is_curbuf = buf == curbuf;
+ const int save_acd = p_acd;
+ if (!is_curbuf) {
+ // Temporarily disable 'autochdir' when setting file name for another buffer.
+ p_acd = false;
+ }
+
// Using aucmd_*: autocommands will be executed by rename_buffer
aco_save_T aco;
aucmd_prepbuf(&aco, buf);
int ren_ret = rename_buffer(name.data);
aucmd_restbuf(&aco);
+ if (!is_curbuf) {
+ p_acd = save_acd;
+ }
+
if (try_end(err)) {
return;
}