aboutsummaryrefslogtreecommitdiff
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
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
-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
-rw-r--r--test/functional/legacy/autochdir_spec.lua29
6 files changed, 65 insertions, 4 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);
}
}
diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua
index 466e3ed830..9bb13c1954 100644
--- a/test/functional/legacy/autochdir_spec.lua
+++ b/test/functional/legacy/autochdir_spec.lua
@@ -1,10 +1,11 @@
local lfs = require('lfs')
local helpers = require('test.functional.helpers')(after_each)
-local clear, eq = helpers.clear, helpers.eq
-local eval, command = helpers.eval, helpers.command
+local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches
+local eval, command, call = helpers.eval, helpers.command, helpers.call
+local exec_capture = helpers.exec_capture
describe('autochdir behavior', function()
- local dir = 'Xtest-functional-legacy-autochdir'
+ local dir = 'Xtest_functional_legacy_autochdir'
before_each(function()
lfs.mkdir(dir)
@@ -23,4 +24,26 @@ describe('autochdir behavior', function()
eq('Xtest', eval("expand('%')"))
eq(dir, eval([[substitute(getcwd(), '.*[/\\]\(\k*\)', '\1', '')]]))
end)
+
+ it(':verbose pwd shows whether autochdir is used', function()
+ local subdir = 'Xautodir'
+ command('cd '..dir)
+ command('edit global.txt')
+ matches('%[global%].*'..dir, exec_capture('verbose pwd'))
+ call('mkdir', subdir)
+ command('split '..subdir..'/local.txt')
+ command('lcd '..subdir)
+ matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
+ command('set autochdir')
+ command('wincmd w')
+ matches('%[autochdir%].*'..dir, exec_capture('verbose pwd'))
+ command('wincmd w')
+ matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
+ command('set noautochdir')
+ matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
+ command('wincmd w')
+ matches('%[global%].*'..dir, exec_capture('verbose pwd'))
+ command('wincmd w')
+ matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
+ end)
end)