mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 15:28:17 +00:00
Merge pull request #16362 from zeertzjq/vim-8.2.3617
vim-patch:8.2.{3468,3617,3618,3622}: some other CWD related patches
This commit is contained in:
@@ -5001,11 +5001,11 @@ getcurpos() Get the position of the cursor. This is like getpos('.'), but
|
|||||||
getcwd([{winnr}[, {tabnr}]]) *getcwd()*
|
getcwd([{winnr}[, {tabnr}]]) *getcwd()*
|
||||||
With no arguments, returns the name of the effective
|
With no arguments, returns the name of the effective
|
||||||
|current-directory|. With {winnr} or {tabnr} the working
|
|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,
|
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: >
|
Thus the following are equivalent: >
|
||||||
getcwd()
|
|
||||||
getcwd(0)
|
getcwd(0)
|
||||||
getcwd(0, 0)
|
getcwd(0, 0)
|
||||||
< If {winnr} is -1 it is ignored, only the tab is resolved.
|
< If {winnr} is -1 it is ignored, only the tab is resolved.
|
||||||
|
@@ -1587,7 +1587,7 @@ void do_autochdir(void)
|
|||||||
if (starting == 0
|
if (starting == 0
|
||||||
&& curbuf->b_ffname != NULL
|
&& curbuf->b_ffname != NULL
|
||||||
&& vim_chdirfile(curbuf->b_ffname, kCdCauseAuto) == OK) {
|
&& vim_chdirfile(curbuf->b_ffname, kCdCauseAuto) == OK) {
|
||||||
post_chdir(kCdScopeGlobal, false);
|
last_chdir_reason = "autochdir";
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3487,11 +3487,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
|
// Find the tabpage by number
|
||||||
if (scope_number[kCdScopeTabpage] > 0) {
|
if (scope_number[kCdScopeTabpage] > 0) {
|
||||||
tp = find_tabpage(scope_number[kCdScopeTabpage]);
|
tp = find_tabpage(scope_number[kCdScopeTabpage]);
|
||||||
@@ -3537,12 +3532,13 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
case kCdScopeGlobal:
|
case kCdScopeGlobal:
|
||||||
if (globaldir) { // `globaldir` is not always set.
|
if (globaldir) { // `globaldir` is not always set.
|
||||||
from = globaldir;
|
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.
|
from = (char_u *)""; // Return empty string on failure.
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case kCdScopeInvalid: // We should never get here
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from) {
|
if (from) {
|
||||||
|
@@ -7753,6 +7753,7 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_chdir_reason = NULL;
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
|
|
||||||
if (trigger_dirchanged) {
|
if (trigger_dirchanged) {
|
||||||
@@ -7870,7 +7871,9 @@ static void ex_pwd(exarg_T *eap)
|
|||||||
#endif
|
#endif
|
||||||
if (p_verbose > 0) {
|
if (p_verbose > 0) {
|
||||||
char *context = "global";
|
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";
|
context = "window";
|
||||||
} else if (curtab->tp_localdir != NULL) {
|
} else if (curtab->tp_localdir != NULL) {
|
||||||
context = "tabpage";
|
context = "tabpage";
|
||||||
|
@@ -789,6 +789,8 @@ extern char_u *compiled_sys;
|
|||||||
// directory is not a local directory, globaldir is NULL.
|
// directory is not a local directory, globaldir is NULL.
|
||||||
EXTERN char_u *globaldir INIT(= NULL);
|
EXTERN char_u *globaldir INIT(= NULL);
|
||||||
|
|
||||||
|
EXTERN char *last_chdir_reason INIT(= NULL);
|
||||||
|
|
||||||
// Whether 'keymodel' contains "stopsel" and "startsel".
|
// Whether 'keymodel' contains "stopsel" and "startsel".
|
||||||
EXTERN bool km_stopsel INIT(= false);
|
EXTERN bool km_stopsel INIT(= false);
|
||||||
EXTERN bool km_startsel INIT(= false);
|
EXTERN bool km_startsel INIT(= false);
|
||||||
|
@@ -2245,11 +2245,17 @@ int path_full_dir_name(char *directory, char *buffer, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (os_chdir(directory) != SUCCESS) {
|
if (os_chdir(directory) != SUCCESS) {
|
||||||
// Do not return immediately since we may be in the wrong directory.
|
// Path does not exist (yet). For a full path fail,
|
||||||
retval = FAIL;
|
// will use the path as-is. For a relative path use
|
||||||
}
|
// the current directory and append the file name.
|
||||||
|
if (path_is_absolute((const char_u *)directory)) {
|
||||||
if (retval == FAIL || os_dirname((char_u *)buffer, len) == FAIL) {
|
// Do not return immediately since we may be in the wrong directory.
|
||||||
|
retval = FAIL;
|
||||||
|
} else {
|
||||||
|
xstrlcpy(buffer, old_dir, len);
|
||||||
|
append_path(buffer, directory, len);
|
||||||
|
}
|
||||||
|
} else if (os_dirname((char_u *)buffer, len) == FAIL) {
|
||||||
// Do not return immediately since we are in the wrong directory.
|
// Do not return immediately since we are in the wrong directory.
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
|
@@ -26,4 +26,42 @@ func Test_set_filename()
|
|||||||
call delete('samples/Xtest')
|
call delete('samples/Xtest')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_verbose_pwd()
|
||||||
|
CheckFunction test_autochdir
|
||||||
|
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'))
|
||||||
|
execute 'lcd' cwd
|
||||||
|
call assert_match('\[window\].*testdir$', execute('verbose pwd'))
|
||||||
|
execute 'tcd' cwd
|
||||||
|
call assert_match('\[tabpage\].*testdir$', execute('verbose pwd'))
|
||||||
|
execute 'cd' cwd
|
||||||
|
call assert_match('\[global\].*testdir$', execute('verbose pwd'))
|
||||||
|
edit
|
||||||
|
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
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -215,3 +215,42 @@ func Test_cd_from_non_existing_dir()
|
|||||||
cd -
|
cd -
|
||||||
call assert_equal(saveddir, getcwd())
|
call assert_equal(saveddir, getcwd())
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_cd_unknown_dir()
|
||||||
|
call mkdir('Xa')
|
||||||
|
cd Xa
|
||||||
|
call writefile(['text'], 'Xb.txt')
|
||||||
|
edit Xa/Xb.txt
|
||||||
|
let first_buf = bufnr()
|
||||||
|
cd ..
|
||||||
|
edit
|
||||||
|
call assert_equal(first_buf, bufnr())
|
||||||
|
edit Xa/Xb.txt
|
||||||
|
call assert_notequal(first_buf, bufnr())
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
exe "bwipe! " .. first_buf
|
||||||
|
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
|
||||||
|
@@ -4592,6 +4592,7 @@ void fix_current_dir(void)
|
|||||||
do_autocmd_dirchanged(new_dir, curwin->w_localdir
|
do_autocmd_dirchanged(new_dir, curwin->w_localdir
|
||||||
? kCdScopeWindow : kCdScopeTabpage, kCdCauseWindow);
|
? kCdScopeWindow : kCdScopeTabpage, kCdCauseWindow);
|
||||||
}
|
}
|
||||||
|
last_chdir_reason = NULL;
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
}
|
}
|
||||||
} else if (globaldir != NULL) {
|
} else if (globaldir != NULL) {
|
||||||
@@ -4603,6 +4604,7 @@ void fix_current_dir(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
XFREE_CLEAR(globaldir);
|
XFREE_CLEAR(globaldir);
|
||||||
|
last_chdir_reason = NULL;
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -294,7 +294,16 @@ describe("getcwd()", function ()
|
|||||||
command('set autochdir')
|
command('set autochdir')
|
||||||
command('edit ' .. directories.global .. '/foo')
|
command('edit ' .. directories.global .. '/foo')
|
||||||
eq(curdir .. pathsep .. directories.global, cwd())
|
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)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local clear, eq = helpers.clear, helpers.eq
|
local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches
|
||||||
local eval, command = helpers.eval, helpers.command
|
local eval, command, call = helpers.eval, helpers.command, helpers.call
|
||||||
|
local exec_capture = helpers.exec_capture
|
||||||
|
|
||||||
describe('autochdir behavior', function()
|
describe('autochdir behavior', function()
|
||||||
local dir = 'Xtest-functional-legacy-autochdir'
|
local dir = 'Xtest_functional_legacy_autochdir'
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
lfs.mkdir(dir)
|
lfs.mkdir(dir)
|
||||||
@@ -23,4 +24,35 @@ describe('autochdir behavior', function()
|
|||||||
eq('Xtest', eval("expand('%')"))
|
eq('Xtest', eval("expand('%')"))
|
||||||
eq(dir, eval([[substitute(getcwd(), '.*[/\\]\(\k*\)', '\1', '')]]))
|
eq(dir, eval([[substitute(getcwd(), '.*[/\\]\(\k*\)', '\1', '')]]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it(':verbose pwd shows whether autochdir is used', function()
|
||||||
|
local subdir = 'Xautodir'
|
||||||
|
command('cd '..dir)
|
||||||
|
local cwd = eval('getcwd()')
|
||||||
|
command('edit global.txt')
|
||||||
|
matches('%[global%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
call('mkdir', subdir)
|
||||||
|
command('split '..subdir..'/local.txt')
|
||||||
|
command('lcd '..subdir)
|
||||||
|
matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
|
||||||
|
command('set autochdir')
|
||||||
|
command('wincmd w')
|
||||||
|
matches('%[autochdir%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
command('lcd '..cwd)
|
||||||
|
matches('%[window%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
command('tcd '..cwd)
|
||||||
|
matches('%[tabpage%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
command('cd '..cwd)
|
||||||
|
matches('%[global%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
command('edit')
|
||||||
|
matches('%[autochdir%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
command('wincmd w')
|
||||||
|
matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
|
||||||
|
command('set noautochdir')
|
||||||
|
matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
|
||||||
|
command('wincmd w')
|
||||||
|
matches('%[global%].*'..dir, exec_capture('verbose pwd'))
|
||||||
|
command('wincmd w')
|
||||||
|
matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
@@ -29,7 +29,7 @@ describe('filename modifiers', function()
|
|||||||
call assert_equal('test.out', fnamemodify('test.out', ':.'))
|
call assert_equal('test.out', fnamemodify('test.out', ':.'))
|
||||||
call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':.'))
|
call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':.'))
|
||||||
call assert_equal(fnamemodify(tmpdir, ':~').'/test.out', fnamemodify('test.out', ':~'))
|
call assert_equal(fnamemodify(tmpdir, ':~').'/test.out', fnamemodify('test.out', ':~'))
|
||||||
call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':~'))
|
call assert_equal(fnamemodify(tmpdir, ':~').'/../testdir/a', fnamemodify('../testdir/a', ':~'))
|
||||||
call assert_equal('a', fnamemodify('../testdir/a', ':t'))
|
call assert_equal('a', fnamemodify('../testdir/a', ':t'))
|
||||||
call assert_equal('', fnamemodify('.', ':p:t'))
|
call assert_equal('', fnamemodify('.', ':p:t'))
|
||||||
call assert_equal('test.out', fnamemodify('test.out', ':p:t'))
|
call assert_equal('test.out', fnamemodify('test.out', ':p:t'))
|
||||||
|
@@ -143,8 +143,8 @@ describe('URI methods', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('uri_to_fname returns non-file scheme URI without authority unchanged', function()
|
it('uri_to_fname returns non-file scheme URI without authority unchanged', function()
|
||||||
eq('zipfile:/path/to/archive.zip%3A%3Afilename.txt', exec_lua [[
|
eq('zipfile:///path/to/archive.zip%3A%3Afilename.txt', exec_lua [[
|
||||||
return vim.uri_to_fname('zipfile:/path/to/archive.zip%3A%3Afilename.txt')
|
return vim.uri_to_fname('zipfile:///path/to/archive.zip%3A%3Afilename.txt')
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
@@ -186,7 +186,7 @@ describe('URI methods', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority', function()
|
it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority', function()
|
||||||
local uri = 'zipfile:/path/to/archive.zip%3A%3Afilename.txt'
|
local uri = 'zipfile:///path/to/archive.zip%3A%3Afilename.txt'
|
||||||
local test_case = string.format([[
|
local test_case = string.format([[
|
||||||
local uri = '%s'
|
local uri = '%s'
|
||||||
return vim.uri_from_bufnr(vim.uri_to_bufnr(uri))
|
return vim.uri_from_bufnr(vim.uri_to_bufnr(uri))
|
||||||
|
@@ -54,15 +54,21 @@ describe('path.c', function()
|
|||||||
eq(lfs.currentdir(), (ffi.string(buffer)))
|
eq(lfs.currentdir(), (ffi.string(buffer)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
itp('fails if the given directory does not exist', function()
|
|
||||||
eq(FAIL, path_full_dir_name('does_not_exist', buffer, length))
|
|
||||||
end)
|
|
||||||
|
|
||||||
itp('works with a normal relative dir', function()
|
itp('works with a normal relative dir', function()
|
||||||
local result = path_full_dir_name('unit-test-directory', buffer, length)
|
local result = path_full_dir_name('unit-test-directory', buffer, length)
|
||||||
eq(lfs.currentdir() .. '/unit-test-directory', (ffi.string(buffer)))
|
eq(lfs.currentdir() .. '/unit-test-directory', (ffi.string(buffer)))
|
||||||
eq(OK, result)
|
eq(OK, result)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
itp('works with a non-existing relative dir', function()
|
||||||
|
local result = path_full_dir_name('does-not-exist', buffer, length)
|
||||||
|
eq(lfs.currentdir() .. '/does-not-exist', (ffi.string(buffer)))
|
||||||
|
eq(OK, result)
|
||||||
|
end)
|
||||||
|
|
||||||
|
itp('fails with a non-existing absolute dir', function()
|
||||||
|
eq(FAIL, path_full_dir_name('/does_not_exist', buffer, length))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('path_full_compare', function()
|
describe('path_full_compare', function()
|
||||||
|
Reference in New Issue
Block a user