mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
vim-patch:8.2.3618: getcwd() is unclear about how 'autochdir' is used
Problem: getcwd() is unclear about how 'autochdir' is used.
Solution: Update the help for getcwd(). Without any arguments always return
the actual current directory. (closes vim/vim#9142)
851c7a699a
This commit is contained in:
parent
54e9cce612
commit
3d504f27a0
@ -5001,11 +5001,11 @@ getcurpos() Get the position of the cursor. This is like getpos('.'), but
|
||||
getcwd([{winnr}[, {tabnr}]]) *getcwd()*
|
||||
With no arguments, returns the name of the effective
|
||||
|current-directory|. With {winnr} or {tabnr} the working
|
||||
directory of that scope is returned.
|
||||
directory of that scope is returned, and 'autochdir' is
|
||||
ignored.
|
||||
Tabs and windows are identified by their respective numbers,
|
||||
0 means current tab or window. Missing argument implies 0.
|
||||
0 means current tab or window. Missing tab number implies 0.
|
||||
Thus the following are equivalent: >
|
||||
getcwd()
|
||||
getcwd(0)
|
||||
getcwd(0, 0)
|
||||
< If {winnr} is -1 it is ignored, only the tab is resolved.
|
||||
|
@ -3485,11 +3485,6 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
}
|
||||
}
|
||||
|
||||
// If the user didn't specify anything, default to window scope
|
||||
if (scope == kCdScopeInvalid) {
|
||||
scope = MIN_CD_SCOPE;
|
||||
}
|
||||
|
||||
// Find the tabpage by number
|
||||
if (scope_number[kCdScopeTabpage] > 0) {
|
||||
tp = find_tabpage(scope_number[kCdScopeTabpage]);
|
||||
@ -3535,12 +3530,13 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
case kCdScopeGlobal:
|
||||
if (globaldir) { // `globaldir` is not always set.
|
||||
from = globaldir;
|
||||
} else if (os_dirname(cwd, MAXPATHL) == FAIL) { // Get the OS CWD.
|
||||
break;
|
||||
}
|
||||
FALLTHROUGH; // In global directory, just need to get OS CWD.
|
||||
case kCdScopeInvalid: // If called without any arguments, get OS CWD.
|
||||
if (os_dirname(cwd, MAXPATHL) == FAIL) {
|
||||
from = (char_u *)""; // Return empty string on failure.
|
||||
}
|
||||
break;
|
||||
case kCdScopeInvalid: // We should never get here
|
||||
abort();
|
||||
}
|
||||
|
||||
if (from) {
|
||||
|
@ -233,4 +233,24 @@ func Test_cd_unknown_dir()
|
||||
call delete('Xa', 'rf')
|
||||
endfunc
|
||||
|
||||
func Test_getcwd_actual_dir()
|
||||
CheckFunction test_autochdir
|
||||
let startdir = getcwd()
|
||||
call mkdir('Xactual')
|
||||
call test_autochdir()
|
||||
set autochdir
|
||||
edit Xactual/file.txt
|
||||
call assert_match('testdir.Xactual$', getcwd())
|
||||
lcd ..
|
||||
call assert_match('testdir$', getcwd())
|
||||
edit
|
||||
call assert_match('testdir.Xactual$', getcwd())
|
||||
call assert_match('testdir$', getcwd(win_getid()))
|
||||
|
||||
set noautochdir
|
||||
bwipe!
|
||||
call chdir(startdir)
|
||||
call delete('Xactual', 'rf')
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@ -294,7 +294,16 @@ describe("getcwd()", function ()
|
||||
command('set autochdir')
|
||||
command('edit ' .. directories.global .. '/foo')
|
||||
eq(curdir .. pathsep .. directories.global, cwd())
|
||||
eq(curdir, wcwd())
|
||||
call('mkdir', 'bar')
|
||||
command('edit ' .. 'bar/foo')
|
||||
eq(curdir .. pathsep .. directories.global .. pathsep .. 'bar', cwd())
|
||||
eq(curdir, wcwd())
|
||||
command('lcd ..')
|
||||
eq(curdir .. pathsep .. directories.global, cwd())
|
||||
eq(curdir .. pathsep .. directories.global, wcwd())
|
||||
command('edit')
|
||||
eq(curdir .. pathsep .. directories.global .. pathsep .. 'bar', cwd())
|
||||
eq(curdir .. pathsep .. directories.global, wcwd())
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user