]> granicus.if.org Git - vim/commitdiff
patch 8.2.3780: ":cd" works differently on MS-Windows v8.2.3780
authorBakudankun <bakudankun@gmail.com>
Sat, 11 Dec 2021 12:28:08 +0000 (12:28 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 11 Dec 2021 12:28:08 +0000 (12:28 +0000)
Problem:    ":cd" works differently on MS-Windows.
Solution:   Add the 'cdhome' option. (closes #9324)

runtime/doc/editing.txt
runtime/doc/quickref.txt
runtime/optwin.vim
src/ex_docmd.c
src/option.h
src/optiondefs.h
src/testdir/runtest.vim
src/testdir/test_options.vim
src/version.c

index cea0e443d80137cc618f901b14ea6ec55cb3a5ae..34935100612125e200b493c262f2dc50aa986ecf 100644 (file)
@@ -1298,11 +1298,12 @@ Changing directory fails when the current buffer is modified, the '.' flag is
 present in 'cpoptions' and "!" is not used in the command.
 
                                                        *:cd* *E747* *E472*
-:cd[!]                 On non-Unix systems: Print the current directory
-                       name.  On Unix systems: Change the current directory
-                       to the home directory.  Use |:pwd| to print the
-                       current directory on all systems.
-                       On Unix systems: clear any window-local directory.
+:cd[!]                 On non-Unix systems when 'cdhome' is off: Print the
+                       current directory name.
+                       Otherwise: Change the current directory to the home
+                       directory.  Clear any window-local directory.
+                       Use |:pwd| to print the current directory on all
+                       systems.
 
 :cd[!] {path}          Change the current directory to {path}.
                        If {path} is relative, it is searched for in the
index f1e2ac42213857d051df28c3636a5665ab809bc0..aa5a36a331d2713fa308f9a1692db537b52ad54c 100644 (file)
@@ -635,6 +635,7 @@ Short explanation of each option:           *option-list*
 'buflisted'      'bl'      whether the buffer shows up in the buffer list
 'buftype'        'bt'      special type of buffer
 'casemap'        'cmp'     specifies how case of letters is changed
+'cdhome'         'cdh'     change directory to the home directory by ":cd"
 'cdpath'         'cd'      list of directories searched with ":cd"
 'cedit'                            key used to open the command-line window
 'charconvert'    'ccv'     expression for character encoding conversion
index 1b826c765b928236a2f1102c2bc365ebe8ce514f..38bc87ecad2aae267154a62cac478cb234fb8e13 100644 (file)
@@ -260,6 +260,10 @@ call <SID>OptionG("sect", &sect)
 call <SID>AddOption("path", gettext("list of directory names used for file searching"))
 call append("$", "\t" .. s:global_or_local)
 call <SID>OptionG("pa", &pa)
+if exists("+cdhome")
+  call <SID>AddOption("cdhome", gettext("change directory to the home directory by :cd"))
+  call <SID>BinOptionG("cdh", &cdh)
+endif
 call <SID>AddOption("cdpath", gettext("list of directory names used for :cd"))
 call <SID>OptionG("cd", &cd)
 if exists("+autochdir")
index 4d739f9a4a799504efbe1c5c0635643cd6d5ee9a..640260a630ca6e335e062a33311fe15267d3084d 100644 (file)
@@ -7402,9 +7402,13 @@ changedir_func(
     else
        prev_dir = pdir;
 
+    // For UNIX ":cd" means: go to home directory.
+    // On other systems too if 'cdhome' is set.
 #if defined(UNIX) || defined(VMS)
-    // for UNIX ":cd" means: go to home directory
     if (*new_dir == NUL)
+#else
+    if (*new_dir == NUL && p_cdh)
+#endif
     {
        // use NameBuff for home directory name
 # ifdef VMS
@@ -7420,7 +7424,6 @@ changedir_func(
 # endif
        new_dir = NameBuff;
     }
-#endif
     dir_differs = new_dir == NULL || pdir == NULL
        || pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
     if (new_dir == NULL || (dir_differs && vim_chdir(new_dir)))
@@ -7459,8 +7462,8 @@ ex_cd(exarg_T *eap)
 
     new_dir = eap->arg;
 #if !defined(UNIX) && !defined(VMS)
-    // for non-UNIX ":cd" means: print current directory
-    if (*new_dir == NUL)
+    // for non-UNIX ":cd" means: print current directory unless 'cdhome' is set
+    if (*new_dir == NUL && !p_cdh)
        ex_pwd(NULL);
     else
 #endif
index fc8124543e5be09cab145ce0e4c298cfda7cb5bd..49d869bfc72ccc5ab1cf6fa91aab1a8851617b41 100644 (file)
@@ -1094,6 +1094,7 @@ EXTERN int        p_write;        // 'write'
 EXTERN int     p_wa;           // 'writeany'
 EXTERN int     p_wb;           // 'writebackup'
 EXTERN long    p_wd;           // 'writedelay'
+EXTERN int     p_cdh;          // 'cdhome'
 
 /*
  * "indir" values for buffer-local options.
index 6a96a9f2fcc2785cb1161e63506a9597d9c2b358..c39244288b56e13c2f5e369f94af61e00d924417 100644 (file)
@@ -549,6 +549,10 @@ static struct vimoption options[] =
                            (char_u *)&p_cmp, PV_NONE,
                            {(char_u *)"internal,keepascii", (char_u *)0L}
                            SCTX_INIT},
+    {"cdhome",     "cdh",  P_BOOL|P_VI_DEF|P_VIM|P_SECURE,
+                           (char_u *)&p_cdh, PV_NONE,
+                           {(char_u *)FALSE, (char_u *)0L}
+                           SCTX_INIT},
     {"cdpath",     "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
 #ifdef FEAT_SEARCHPATH
                            (char_u *)&p_cdpath, PV_NONE,
index 28e23c0d9e0ee21d156ac69e1ebb6c8fc67f5fe6..912bc203457af1e2ef88bf38961ab2352617f2bc 100644 (file)
@@ -77,6 +77,9 @@ if has('reltime')
   let s:start_time = reltime()
 endif
 
+" Always use forward slashes.
+set shellslash
+
 " Common with all tests on all systems.
 source setup.vim
 
@@ -128,9 +131,6 @@ if has('gui_running') && exists('did_install_default_menus')
   source $VIMRUNTIME/menu.vim
 endif
 
-" Always use forward slashes.
-set shellslash
-
 let s:srcdir = expand('%:p:h:h')
 
 if has('win32')
index 6fc45642241a775a842a55568739c6f05032adf5..2265894399d0f4ec737d2487628c22dfb5918f30 100644 (file)
@@ -1199,4 +1199,25 @@ func Test_opt_scrolljump()
   bw
 endfunc
 
+" Test for the 'cdhome' option
+func Test_opt_cdhome()
+  if has('unix') || has('vms')
+    throw 'Skipped: only works on non-Unix'
+  endif
+
+  set cdhome&
+  call assert_equal(0, &cdhome)
+  set cdhome
+
+  " This paragraph is copied from Test_cd_no_arg().
+  let path = getcwd()
+  cd
+  call assert_equal($HOME, getcwd())
+  call assert_notequal(path, getcwd())
+  exe 'cd ' .. fnameescape(path)
+  call assert_equal(path, getcwd())
+
+  set cdhome&
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 25669afa1e9e0e38aaf33d4a8f35958b9e480093..680cce2a52a2531338e9caad12dc9b4621cb0ca3 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3780,
 /**/
     3779,
 /**/