aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2021-11-19 20:07:04 +0800
committerzeertzjq <zeertzjq@outlook.com>2021-11-19 20:07:04 +0800
commit4785cad8ee808d166a9cbc9d7ab5761da70d0563 (patch)
treef757646ccce3ddf29fe77288ddd095c876165f8c /src
parent0f58ba10e264697e4bb330a17b41cd9a0ceb8b1e (diff)
downloadrneovim-4785cad8ee808d166a9cbc9d7ab5761da70d0563.tar.gz
rneovim-4785cad8ee808d166a9cbc9d7ab5761da70d0563.tar.bz2
rneovim-4785cad8ee808d166a9cbc9d7ab5761da70d0563.zip
vim-patch:8.2.3617: ":verbose pwd" does not mention 'autochdir' was applied
Problem: ":verbose pwd" does not mention 'autochdir' was applied. Solution: Remember the last chdir was done by 'autochdir'. (issue vim/vim#9142) https://github.com/vim/vim/commit/0526815c15170a5926e1008600ec29d42d8b64c2
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c1
-rw-r--r--src/nvim/ex_docmd.c5
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/testdir/test_autochdir.vim30
-rw-r--r--src/nvim/window.c2
5 files changed, 39 insertions, 1 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 88938d5099..89e237a517 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1588,6 +1588,7 @@ void do_autochdir(void)
&& curbuf->b_ffname != NULL
&& vim_chdirfile(curbuf->b_ffname, kCdCauseAuto) == OK) {
post_chdir(kCdScopeGlobal, false);
+ last_chdir_reason = "autochdir";
shorten_fnames(true);
}
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index e622a2a68f..ae868bd1cf 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -7753,6 +7753,7 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
abort();
}
+ last_chdir_reason = NULL;
shorten_fnames(true);
if (trigger_dirchanged) {
@@ -7870,7 +7871,9 @@ static void ex_pwd(exarg_T *eap)
#endif
if (p_verbose > 0) {
char *context = "global";
- if (curwin->w_localdir != NULL) {
+ if (last_chdir_reason != NULL) {
+ context = last_chdir_reason;
+ } else if (curwin->w_localdir != NULL) {
context = "window";
} else if (curtab->tp_localdir != NULL) {
context = "tabpage";
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index e2d3378402..8a273e37f6 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -789,6 +789,8 @@ extern char_u *compiled_sys;
// directory is not a local directory, globaldir is NULL.
EXTERN char_u *globaldir INIT(= NULL);
+EXTERN char *last_chdir_reason INIT(= NULL);
+
// Whether 'keymodel' contains "stopsel" and "startsel".
EXTERN bool km_stopsel INIT(= false);
EXTERN bool km_startsel INIT(= false);
diff --git a/src/nvim/testdir/test_autochdir.vim b/src/nvim/testdir/test_autochdir.vim
index 0b76828dd7..e172d0cb9a 100644
--- a/src/nvim/testdir/test_autochdir.vim
+++ b/src/nvim/testdir/test_autochdir.vim
@@ -26,4 +26,34 @@ func Test_set_filename()
call delete('samples/Xtest')
endfunc
+func Test_verbose_pwd()
+ CheckFunction test_autochdir
+ let cwd = getcwd()
+ call test_autochdir()
+
+ edit global.txt
+ call assert_match('\[global\].*testdir$', execute('verbose pwd'))
+
+ call mkdir('Xautodir')
+ split Xautodir/local.txt
+ lcd Xautodir
+ call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
+
+ set acd
+ wincmd w
+ call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
+ wincmd w
+ call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
+ set noacd
+ call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
+ wincmd w
+ call assert_match('\[global\].*testdir', execute('verbose pwd'))
+ wincmd w
+ call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
+
+ bwipe!
+ call chdir(cwd)
+ call delete('Xautodir', 'rf')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 9f6481f5de..c6e32827e7 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -4592,6 +4592,7 @@ void fix_current_dir(void)
do_autocmd_dirchanged(new_dir, curwin->w_localdir
? kCdScopeWindow : kCdScopeTabpage, kCdCauseWindow);
}
+ last_chdir_reason = NULL;
shorten_fnames(true);
}
} else if (globaldir != NULL) {
@@ -4603,6 +4604,7 @@ void fix_current_dir(void)
}
}
XFREE_CLEAR(globaldir);
+ last_chdir_reason = NULL;
shorten_fnames(true);
}
}