]> granicus.if.org Git - vim/commitdiff
patch 8.2.0876: :pwd does not give a hint about the scope of the directory v8.2.0876
authorBram Moolenaar <Bram@vim.org>
Mon, 1 Jun 2020 14:26:19 +0000 (16:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 1 Jun 2020 14:26:19 +0000 (16:26 +0200)
Problem:    :pwd does not give a hint about the scope of the directory
Solution:   Make ":verbose pwd" show the scope. (Takuya Fujiwara, closes #5469)

runtime/doc/editing.txt
src/ex_docmd.c
src/testdir/test_cd.vim
src/version.c

index f6e3810d88984ebf13a481663d597f3453ffe4c9..f33ffb9954ea0c418a5c3a01226e594769c0a143 100644 (file)
@@ -1338,6 +1338,21 @@ present in 'cpoptions' and "!" is not used in the command.
                                                        *:pw* *:pwd* *E187*
 :pw[d]                 Print the current directory name.
                        Also see |getcwd()|.
+                                                       *:pwd-verbose*
+                       When 'verbose' is non-zero, |:pwd| will also display
+                       what scope the current directory was set. Example: >
+
+                               " Set by :cd
+                               :verbose pwd
+                               [global] /path/to/current
+
+                               " Set by :lcd
+                               :verbose pwd
+                               [window] /path/to/current
+
+                               " Set by :tcd
+                               :verbose pwd
+                               [tabpage] /path/to/current
 
 So long as no |:lcd| or |:tcd| command has been used, all windows share the
 same current directory.  Using a command to jump to another window doesn't
index 7b53e6c6a6cd09ce81616ac09e61374b787bae00..ea2763e4425e633c0e74a74d2029b3ef992ce361 100644 (file)
@@ -6619,9 +6619,10 @@ post_chdir(cdscope_T scope)
 
 /*
  * Change directory function used by :cd/:tcd/:lcd Ex commands and the
- * chdir() function. If 'winlocaldir' is TRUE, then changes the window-local
- * directory. If 'tablocaldir' is TRUE, then changes the tab-local directory.
- * Otherwise changes the global directory.
+ * chdir() function.
+ * scope == CDSCOPE_WINDOW: changes the window-local directory
+ * scope == CDSCOPE_TABPAGE: changes the tab-local directory
+ * Otherwise: changes the global directory
  * Returns TRUE if the directory is successfully changed.
  */
     int
@@ -6751,7 +6752,18 @@ ex_pwd(exarg_T *eap UNUSED)
 #ifdef BACKSLASH_IN_FILENAME
        slash_adjust(NameBuff);
 #endif
-       msg((char *)NameBuff);
+       if (p_verbose > 0)
+       {
+           char *context = "global";
+
+           if (curwin->w_localdir != NULL)
+               context = "window";
+           else if (curtab->tp_localdir != NULL)
+               context = "tabpage";
+           smsg("[%s] %s", context, (char *)NameBuff);
+       }
+       else
+           msg((char *)NameBuff);
     }
     else
        emsg(_("E187: Unknown"));
index da9ef0830fb223188f3bc634fb2baee29fd7b140..ad25f3a32e114a1c4b468702d1902baeec6607f2 100644 (file)
@@ -97,16 +97,19 @@ func Test_chdir_func()
   lcd z
 
   tabfirst
+  call assert_match('^\[global\] .*/Xdir$', trim(execute('verbose pwd')))
   call chdir('..')
   call assert_equal('y', fnamemodify(getcwd(1, 2), ':t'))
   call assert_equal('z', fnamemodify(3->getcwd(2), ':t'))
   tabnext | wincmd t
+  call assert_match('^\[tabpage\] .*/y$', trim(execute('verbose pwd')))
   eval '..'->chdir()
   call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t'))
   call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t'))
   call assert_equal('z', fnamemodify(getcwd(3, 2), ':t'))
   call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t'))
   3wincmd w
+  call assert_match('^\[window\] .*/z$', trim(execute('verbose pwd')))
   call chdir('..')
   call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t'))
   call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t'))
index 8772e75e6a1a96a28f29cefe6a850d94634b9dab..ce0e5452b100bbdeada6a5002ad14ef170adee58 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    876,
 /**/
     875,
 /**/