changeset 26171:fa8161b003f6 v8.2.3617

patch 8.2.3617: ":verbose pwd" does not mention 'autochdir' was applied Commit: https://github.com/vim/vim/commit/0526815c15170a5926e1008600ec29d42d8b64c2 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 18 18:53:45 2021 +0000 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 https://github.com/vim/vim/issues/9142)
author Bram Moolenaar <Bram@vim.org>
date Thu, 18 Nov 2021 20:00:06 +0100
parents 3e5f506a2165
children b35f5fdc951b
files src/buffer.c src/ex_docmd.c src/globals.h src/main.c src/netbeans.c src/os_win32.c src/testdir/test_autochdir.vim src/version.c src/window.c
diffstat 9 files changed, 51 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1899,7 +1899,10 @@ do_autochdir(void)
     if ((starting == 0 || test_autochdir)
 	    && curbuf->b_ffname != NULL
 	    && vim_chdirfile(curbuf->b_ffname, "auto") == OK)
+    {
 	shorten_fnames(TRUE);
+	last_chdir_reason = "autochdir";
+    }
 }
 #endif
 
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -7390,6 +7390,7 @@ changedir_func(
 
 	if (dir_differs)
 	{
+	    last_chdir_reason = NULL;
 	    if (scope == CDSCOPE_WINDOW)
 		acmd_fname = (char_u *)"window";
 	    else if (scope == CDSCOPE_TABPAGE)
@@ -7453,7 +7454,9 @@ ex_pwd(exarg_T *eap UNUSED)
 	{
 	    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";
--- a/src/globals.h
+++ b/src/globals.h
@@ -832,6 +832,7 @@ EXTERN int	stdout_isatty INIT(= TRUE);	/
 #if defined(FEAT_AUTOCHDIR)
 EXTERN int	test_autochdir INIT(= FALSE);
 #endif
+EXTERN char	*last_chdir_reason INIT(= NULL);
 #if defined(EXITFREE)
 EXTERN int	entered_free_all_mem INIT(= FALSE);
 				// TRUE when in or after free_all_mem()
--- a/src/main.c
+++ b/src/main.c
@@ -275,7 +275,8 @@ main
 	 * Hint: to avoid this when typing a command use a forward slash.
 	 * If the cd fails, it doesn't matter.
 	 */
-	(void)vim_chdirfile(params.fname, "drop");
+	if (vim_chdirfile(params.fname, "drop") == OK)
+	    last_chdir_reason = "drop";
 	if (start_dir != NULL)
 	    mch_dirname(start_dir, MAXPATHL);
     }
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -2656,7 +2656,10 @@ netbeans_file_opened(buf_T *bufp)
 
     nb_send(buffer, "netbeans_file_opened");
     if (p_acd && vim_chdirfile(bufp->b_ffname, "auto") == OK)
+    {
+	last_chdir_reason = "netbeans";
 	shorten_fnames(TRUE);
+    }
 }
 
 /*
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -7783,8 +7783,9 @@ fix_arg_enc(void)
     if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL)
     {
 	do_cmdline_cmd((char_u *)":rewind");
-	if (GARGCOUNT == 1 && used_file_full_path)
-	    (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop");
+	if (GARGCOUNT == 1 && used_file_full_path
+		&& vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK)
+	    last_chdir_reason = "drop";
     }
 
     set_alist_count();
--- a/src/testdir/test_autochdir.vim
+++ b/src/testdir/test_autochdir.vim
@@ -25,4 +25,33 @@ func Test_set_filename()
   call delete('samples/Xtest')
 endfunc
 
+func Test_verbose_pwd()
+  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
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3617,
+/**/
     3616,
 /**/
     3615,
--- a/src/window.c
+++ b/src/window.c
@@ -4873,7 +4873,10 @@ fix_current_dir(void)
 	    dirname = curtab->tp_localdir;
 
 	if (mch_chdir((char *)dirname) == 0)
+	{
+	    last_chdir_reason = NULL;
 	    shorten_fnames(TRUE);
+	}
     }
     else if (globaldir != NULL)
     {
@@ -4881,6 +4884,7 @@ fix_current_dir(void)
 	// directory: Change to the global directory.
 	vim_ignored = mch_chdir((char *)globaldir);
 	VIM_CLEAR(globaldir);
+	last_chdir_reason = NULL;
 	shorten_fnames(TRUE);
     }
 }