Merge pull request #16618 from zeertzjq/vim-8.2.3780

vim-patch:8.2.{3780,3784}: ":cd" works differently on MS-Windows
This commit is contained in:
Jan Edmund Lazo 2021-12-25 21:10:44 -05:00 committed by GitHub
commit 1dcdf86849
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 13 deletions

View File

@ -1253,10 +1253,12 @@ working directory. If a local working directory (tab or window) does not
exist, the next-higher scope in the hierarchy applies.
*: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.
: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

View File

@ -1159,6 +1159,14 @@ A jump table for the options with a short description can be found at |Q_op|.
case mapping, the current locale is not effective.
This probably only matters for Turkish.
*'cdhome'* *'cdh'*
'cdhome' 'cdh' boolean (default: off)
global
When on, |:cd|, |:tcd| and |:lcd| without an argument changes the
current working directory to the |$HOME| directory like in Unix.
When off, those commands just print the current directory name.
On Unix this option has no effect.
*'cdpath'* *'cd'* *E344* *E346*
'cdpath' 'cd' string (default: equivalent to $CDPATH or ",,")
global

View File

@ -629,6 +629,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

View File

@ -1,7 +1,7 @@
" These commands create the option window.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2020 Oct 27
" Last Change: 2021 Dec 12
" If there already is an option window, jump to that one.
let buf = bufnr('option-window')
@ -261,6 +261,8 @@ call <SID>OptionG("sect", &sect)
call append("$", "path\tlist of directory names used for file searching")
call append("$", "\t(global or local to buffer)")
call <SID>OptionG("pa", &pa)
call <SID>AddOption("cdhome", ":cd without argument goes to the home directory")
call <SID>BinOptionG("cdh", &cdh)
call append("$", "cdpath\tlist of directory names used for :cd")
call <SID>OptionG("cd", &cd)
if exists("+autochdir")

View File

@ -7807,14 +7807,17 @@ bool changedir_func(char_u *new_dir, CdScope scope)
prev_dir = pdir;
}
// For UNIX ":cd" means: go to home directory.
// On other systems too if 'cdhome' is set.
#if defined(UNIX)
// On 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.
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
new_dir = NameBuff;
}
#endif
bool dir_differs = new_dir == NULL || pdir == NULL
|| pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
@ -7834,9 +7837,9 @@ void ex_cd(exarg_T *eap)
{
char_u *new_dir;
new_dir = eap->arg;
#if !defined(UNIX) && !defined(VMS)
// for non-UNIX ":cd" means: print current directory
if (*new_dir == NUL) {
#if !defined(UNIX)
// for non-UNIX ":cd" means: print current directory unless 'cdhome' is set
if (*new_dir == NUL && !p_cdh) {
ex_pwd(NULL);
} else
#endif

View File

@ -743,6 +743,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'
EXTERN int p_force_on; ///< options that cannot be turned off.
EXTERN int p_force_off; ///< options that cannot be turned on.

View File

@ -274,6 +274,14 @@ return {
varname='p_cmp',
defaults={if_true="internal,keepascii"}
},
{
full_name='cdhome', abbreviation='cdh',
short_desc=N_(":cd without argument goes to the home directory"),
type='bool', scope={'global'},
secure=true,
varname='p_cdh',
defaults={if_true=false}
},
{
full_name='cdpath', abbreviation='cd',
short_desc=N_("list of directories searched with \":cd\""),

View File

@ -64,6 +64,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
@ -104,9 +107,6 @@ lang mess C
" Nvim: append runtime from build dir, which contains the generated doc/tags.
let &runtimepath .= ','.expand($BUILD_DIR).'/runtime/'
" Always use forward slashes.
set shellslash
let s:t_bold = &t_md
let s:t_normal = &t_me
if has('win32')

View File

@ -732,4 +732,25 @@ func Test_opt_reset_scroll()
call delete('Xscroll')
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