Skip to content

Commit 0526815

Browse files
committed
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 #9142)
1 parent 3cad470 commit 0526815

File tree

9 files changed

+51
-4
lines changed

9 files changed

+51
-4
lines changed

src/buffer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,10 @@ do_autochdir(void)
18991899
if ((starting == 0 || test_autochdir)
19001900
&& curbuf->b_ffname != NULL
19011901
&& vim_chdirfile(curbuf->b_ffname, "auto") == OK)
1902+
{
19021903
shorten_fnames(TRUE);
1904+
last_chdir_reason = "autochdir";
1905+
}
19031906
}
19041907
#endif
19051908

src/ex_docmd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7390,6 +7390,7 @@ changedir_func(
73907390

73917391
if (dir_differs)
73927392
{
7393+
last_chdir_reason = NULL;
73937394
if (scope == CDSCOPE_WINDOW)
73947395
acmd_fname = (char_u *)"window";
73957396
else if (scope == CDSCOPE_TABPAGE)
@@ -7453,7 +7454,9 @@ ex_pwd(exarg_T *eap UNUSED)
74537454
{
74547455
char *context = "global";
74557456

7456-
if (curwin->w_localdir != NULL)
7457+
if (last_chdir_reason != NULL)
7458+
context = last_chdir_reason;
7459+
else if (curwin->w_localdir != NULL)
74577460
context = "window";
74587461
else if (curtab->tp_localdir != NULL)
74597462
context = "tabpage";

src/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ EXTERN int stdout_isatty INIT(= TRUE); // is stdout a terminal?
832832
#if defined(FEAT_AUTOCHDIR)
833833
EXTERN int test_autochdir INIT(= FALSE);
834834
#endif
835+
EXTERN char *last_chdir_reason INIT(= NULL);
835836
#if defined(EXITFREE)
836837
EXTERN int entered_free_all_mem INIT(= FALSE);
837838
// TRUE when in or after free_all_mem()

src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ main
275275
* Hint: to avoid this when typing a command use a forward slash.
276276
* If the cd fails, it doesn't matter.
277277
*/
278-
(void)vim_chdirfile(params.fname, "drop");
278+
if (vim_chdirfile(params.fname, "drop") == OK)
279+
last_chdir_reason = "drop";
279280
if (start_dir != NULL)
280281
mch_dirname(start_dir, MAXPATHL);
281282
}

src/netbeans.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,10 @@ netbeans_file_opened(buf_T *bufp)
26562656

26572657
nb_send(buffer, "netbeans_file_opened");
26582658
if (p_acd && vim_chdirfile(bufp->b_ffname, "auto") == OK)
2659+
{
2660+
last_chdir_reason = "netbeans";
26592661
shorten_fnames(TRUE);
2662+
}
26602663
}
26612664

26622665
/*

src/os_win32.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7783,8 +7783,9 @@ fix_arg_enc(void)
77837783
if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL)
77847784
{
77857785
do_cmdline_cmd((char_u *)":rewind");
7786-
if (GARGCOUNT == 1 && used_file_full_path)
7787-
(void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop");
7786+
if (GARGCOUNT == 1 && used_file_full_path
7787+
&& vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK)
7788+
last_chdir_reason = "drop";
77887789
}
77897790

77907791
set_alist_count();

src/testdir/test_autochdir.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,33 @@ func Test_set_filename()
2525
call delete('samples/Xtest')
2626
endfunc
2727

28+
func Test_verbose_pwd()
29+
let cwd = getcwd()
30+
call test_autochdir()
31+
32+
edit global.txt
33+
call assert_match('\[global\].*testdir$', execute('verbose pwd'))
34+
35+
call mkdir('Xautodir')
36+
split Xautodir/local.txt
37+
lcd Xautodir
38+
call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
39+
40+
set acd
41+
wincmd w
42+
call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
43+
wincmd w
44+
call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
45+
set noacd
46+
call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
47+
wincmd w
48+
call assert_match('\[global\].*testdir', execute('verbose pwd'))
49+
wincmd w
50+
call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
51+
52+
bwipe!
53+
call chdir(cwd)
54+
call delete('Xautodir', 'rf')
55+
endfunc
56+
2857
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ static char *(features[]) =
757757

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
3617,
760762
/**/
761763
3616,
762764
/**/

src/window.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,14 +4873,18 @@ fix_current_dir(void)
48734873
dirname = curtab->tp_localdir;
48744874

48754875
if (mch_chdir((char *)dirname) == 0)
4876+
{
4877+
last_chdir_reason = NULL;
48764878
shorten_fnames(TRUE);
4879+
}
48774880
}
48784881
else if (globaldir != NULL)
48794882
{
48804883
// Window doesn't have a local directory and we are not in the global
48814884
// directory: Change to the global directory.
48824885
vim_ignored = mch_chdir((char *)globaldir);
48834886
VIM_CLEAR(globaldir);
4887+
last_chdir_reason = NULL;
48844888
shorten_fnames(TRUE);
48854889
}
48864890
}

0 commit comments

Comments
 (0)