aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/autocmd.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-08 06:25:22 +0800
committerGitHub <noreply@github.com>2024-04-08 06:25:22 +0800
commitd188b929d46d74ca6a93e15c39cf06896a53fbf7 (patch)
tree66c0fb1f7576877c648b16cf0f7e98c734da44f7 /src/nvim/autocmd.c
parentd32cbef59551a1808caea2ddaeac323fdc18d6b6 (diff)
downloadrneovim-d188b929d46d74ca6a93e15c39cf06896a53fbf7.tar.gz
rneovim-d188b929d46d74ca6a93e15c39cf06896a53fbf7.tar.bz2
rneovim-d188b929d46d74ca6a93e15c39cf06896a53fbf7.zip
vim-patch:9.1.0272: autocmd may change cwd after :tcd and :lcd (#28223)
Problem: Autocommand may change currect directory after :tcd and :lcd. Solution: Also clear tp_localdir and w_localdir when using aucmd_win. (zeertzjq) closes: vim/vim#14435 https://github.com/vim/vim/commit/9d956ee8eab64a0d412b045305fde5bc03d95d4a
Diffstat (limited to 'src/nvim/autocmd.c')
-rw-r--r--src/nvim/autocmd.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index c2cc8bd9b8..e9db4abf9b 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -1325,9 +1325,11 @@ void aucmd_prepbuf(aco_save_T *aco, buf_T *buf)
buf->b_nwindows++;
win_init_empty(auc_win); // set cursor and topline to safe values
- // Make sure w_localdir and globaldir are NULL to avoid a chdir() in
- // win_enter_ext().
+ // Make sure w_localdir, tp_localdir and globaldir are NULL to avoid a
+ // chdir() in win_enter_ext().
XFREE_CLEAR(auc_win->w_localdir);
+ aco->tp_localdir = curtab->tp_localdir;
+ curtab->tp_localdir = NULL;
aco->globaldir = globaldir;
globaldir = NULL;
@@ -1427,6 +1429,13 @@ win_found:
vars_clear(&awp->w_vars->dv_hashtab); // free all w: variables
hash_init(&awp->w_vars->dv_hashtab); // re-use the hashtab
+ // If :lcd has been used in the autocommand window, correct current
+ // directory before restoring tp_localdir and globaldir.
+ if (awp->w_localdir != NULL) {
+ win_fix_current_dir();
+ }
+ xfree(curtab->tp_localdir);
+ curtab->tp_localdir = aco->tp_localdir;
xfree(globaldir);
globaldir = aco->globaldir;