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)
0526815c15
This commit is contained in:
zeertzjq 2021-11-19 20:07:04 +08:00
parent 0f58ba10e2
commit 4785cad8ee
6 changed files with 65 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -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";

View File

@ -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);

View File

@ -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

View File

@ -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);
}
}

View File

@ -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)