]> granicus.if.org Git - vim/commitdiff
patch 8.2.3617: ":verbose pwd" does not mention 'autochdir' was applied v8.2.3617
authorBram Moolenaar <Bram@vim.org>
Thu, 18 Nov 2021 18:53:45 +0000 (18:53 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 18 Nov 2021 18:53:45 +0000 (18:53 +0000)
Problem:    ":verbose pwd" does not mention 'autochdir' was applied.
Solution:   Remember the last chdir was done by 'autochdir'.  (issue #9142)

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

index 31f902d779705009018a8fbe75f4100419da75a7..29cfb8a993e36f993cc71a9282858f7d6339114c 100644 (file)
@@ -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
 
index 052f230dd4146d29377967b1ff9f52b5f2f9e669..aae34f90c44eaab7c5b605504dbe1457527192c9 100644 (file)
@@ -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";
index 5c54130ebd240058cbedd346ebddb18c8dc1dcbf..90998d8752ba8d4f26e536fbe90ce299aa574e16 100644 (file)
@@ -832,6 +832,7 @@ EXTERN int  stdout_isatty INIT(= TRUE);     // is stdout a terminal?
 #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()
index 450fc12b5c3a3807d58ac64fb3b01bfde3f9d644..0d7777893df441f4f2b9ad19926d96026d668b81 100644 (file)
@@ -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);
     }
index 5bd36a4ddd9a53cd48d8750cc188dc53ee37f73d..003cc531d1a01b59517242c69e8a0b8fa6be53f8 100644 (file)
@@ -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);
+    }
 }
 
 /*
index 73af6a1817f19a684ab638ac9b0bba84abc530a6..a8062a82f7db3f00d27f446a60d1ecf7909b746a 100644 (file)
@@ -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();
index d36d32609266cce2af6aaca7a423ffb54408e5c9..8a78b0de6a605008b117fc7674248bde832fc832 100644 (file)
@@ -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
index ea1644d911583d93b9730fa8c9368a3100a9493c..69193a626a43a68033bf7a0bcfcf1117b1f847ab 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3617,
 /**/
     3616,
 /**/
index 5473aaba60e374780a18387cdd1d6ff05f03003c..3f996817ee9048124bb2b4744590740aadae9452 100644 (file)
@@ -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);
     }
 }