mirror of
https://github.com/neovim/neovim.git
synced 2025-12-03 15:33:03 +00:00
vim-patch:7.4.1126
Problem: Can only get the directory of the current window.
Solution: Add window and tab arguments to getcwd() and haslocaldir().
(Thinca, Hirohito Higashi)
c970330676
This commit is contained in:
@@ -1890,7 +1890,7 @@ getcmdpos() Number return cursor position in command-line
|
|||||||
getcmdtype() String return current command-line type
|
getcmdtype() String return current command-line type
|
||||||
getcmdwintype() String return current command-line window type
|
getcmdwintype() String return current command-line window type
|
||||||
getcurpos() List position of the cursor
|
getcurpos() List position of the cursor
|
||||||
getcwd([{scope}]) String the current working directory
|
getcwd([{winnr} [, {tabnr}]]) String the current working directory
|
||||||
getfontname([{name}]) String name of font being used
|
getfontname([{name}]) String name of font being used
|
||||||
getfperm({fname}) String file permissions of file {fname}
|
getfperm({fname}) String file permissions of file {fname}
|
||||||
getfsize({fname}) Number size in bytes of file {fname}
|
getfsize({fname}) Number size in bytes of file {fname}
|
||||||
@@ -1921,7 +1921,8 @@ globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
|
|||||||
String do glob({expr}) for all dirs in {path}
|
String do glob({expr}) for all dirs in {path}
|
||||||
has({feature}) Number TRUE if feature {feature} supported
|
has({feature}) Number TRUE if feature {feature} supported
|
||||||
has_key({dict}, {key}) Number TRUE if {dict} has entry {key}
|
has_key({dict}, {key}) Number TRUE if {dict} has entry {key}
|
||||||
haslocaldir() Number TRUE if current window executed |:lcd|
|
haslocaldir([{winnr} [, {tabnr}]])
|
||||||
|
Number TRUE if current window executed |:lcd|
|
||||||
hasmapto({what} [, {mode} [, {abbr}]])
|
hasmapto({what} [, {mode} [, {abbr}]])
|
||||||
Number TRUE if mapping to {what} exists
|
Number TRUE if mapping to {what} exists
|
||||||
histadd({history}, {item}) String add an item to a history
|
histadd({history}, {item}) String add an item to a history
|
||||||
@@ -3598,17 +3599,17 @@ getcurpos() Get the position of the cursor. This is like getpos('.'), but
|
|||||||
MoveTheCursorAround
|
MoveTheCursorAround
|
||||||
call setpos('.', save_cursor)
|
call setpos('.', save_cursor)
|
||||||
<
|
<
|
||||||
getcwd([{window}[, {tab}]]) *getcwd()*
|
getcwd([{winnr}[, {tabnr}]]) *getcwd()*
|
||||||
With no arguments the result is a String, which is the name of
|
With no arguments the result is a String, which is the name of
|
||||||
the current effective working directory. With {window} or
|
the current effective working directory. With {winnr} or
|
||||||
{tab} the working directory of that scope is returned.
|
{tabnr} the working directory of that scope is returned.
|
||||||
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 argument implies 0.
|
||||||
Thus the following are equivalent: >
|
Thus the following are equivalent: >
|
||||||
getcwd()
|
getcwd()
|
||||||
getcwd(0)
|
getcwd(0)
|
||||||
getcwd(0, 0)
|
getcwd(0, 0)
|
||||||
< If {window} is -1 it is ignored, only the tab is resolved.
|
< If {winnr} is -1 it is ignored, only the tab is resolved.
|
||||||
|
|
||||||
|
|
||||||
getfsize({fname}) *getfsize()*
|
getfsize({fname}) *getfsize()*
|
||||||
@@ -3947,7 +3948,7 @@ has_key({dict}, {key}) *has_key()*
|
|||||||
The result is a Number, which is 1 if |Dictionary| {dict} has
|
The result is a Number, which is 1 if |Dictionary| {dict} has
|
||||||
an entry with key {key}. Zero otherwise.
|
an entry with key {key}. Zero otherwise.
|
||||||
|
|
||||||
haslocaldir([{window}[, {tab}]]) *haslocaldir()*
|
haslocaldir([{winnr}[, {tabnr}]]) *haslocaldir()*
|
||||||
The result is a Number, which is 1 when the specified tabpage
|
The result is a Number, which is 1 when the specified tabpage
|
||||||
or window has a local path set via |:lcd| or |:tcd|, and
|
or window has a local path set via |:lcd| or |:tcd|, and
|
||||||
0 otherwise.
|
0 otherwise.
|
||||||
@@ -3958,7 +3959,7 @@ haslocaldir([{window}[, {tab}]]) *haslocaldir()*
|
|||||||
haslocaldir()
|
haslocaldir()
|
||||||
haslocaldir(0)
|
haslocaldir(0)
|
||||||
haslocaldir(0, 0)
|
haslocaldir(0, 0)
|
||||||
< If {window} is -1 it is ignored, only the tab is resolved.
|
< If {winnr} is -1 it is ignored, only the tab is resolved.
|
||||||
|
|
||||||
hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
|
hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
|
||||||
The result is a Number, which is 1 if there is a mapping that
|
The result is a Number, which is 1 if there is a mapping that
|
||||||
|
|||||||
@@ -7541,25 +7541,9 @@ static void f_argidx(typval_T *argvars, typval_T *rettv)
|
|||||||
static void f_arglistid(typval_T *argvars, typval_T *rettv)
|
static void f_arglistid(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
if (argvars[0].v_type != VAR_UNKNOWN) {
|
win_T *wp = find_tabwin(&argvars[0], &argvars[1]);
|
||||||
tabpage_T *tp = NULL;
|
if (wp != NULL) {
|
||||||
if (argvars[1].v_type != VAR_UNKNOWN) {
|
rettv->vval.v_number = wp->w_alist->id;
|
||||||
long n = get_tv_number(&argvars[1]);
|
|
||||||
if (n >= 0) {
|
|
||||||
tp = find_tabpage(n);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tp = curtab;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tp != NULL) {
|
|
||||||
win_T *wp = find_win_by_nr(&argvars[0], tp);
|
|
||||||
if (wp != NULL) {
|
|
||||||
rettv->vval.v_number = wp->w_alist->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rettv->vval.v_number = curwin->w_alist->id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10473,9 +10457,33 @@ find_win_by_nr (
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Find window specified by "wvp" in tabpage "tvp".
|
||||||
* "getwinvar()" function
|
static win_T *find_tabwin(typval_T *wvp, typval_T *tvp)
|
||||||
*/
|
{
|
||||||
|
win_T *wp = NULL;
|
||||||
|
tabpage_T *tp = NULL;
|
||||||
|
|
||||||
|
if (wvp->v_type != VAR_UNKNOWN) {
|
||||||
|
if (tvp->v_type != VAR_UNKNOWN) {
|
||||||
|
long n = get_tv_number(tvp);
|
||||||
|
if (n >= 0) {
|
||||||
|
tp = find_tabpage(n);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tp = curtab;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tp != NULL) {
|
||||||
|
wp = find_win_by_nr(wvp, tp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wp = curwin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "getwinvar()" function
|
||||||
static void f_getwinvar(typval_T *argvars, typval_T *rettv)
|
static void f_getwinvar(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
getwinvar(argvars, rettv, 0);
|
getwinvar(argvars, rettv, 0);
|
||||||
|
|||||||
@@ -567,7 +567,7 @@ static int included_patches[] = {
|
|||||||
// 1129 NA
|
// 1129 NA
|
||||||
// 1128 NA
|
// 1128 NA
|
||||||
// 1127 NA
|
// 1127 NA
|
||||||
// 1126,
|
1126,
|
||||||
// 1125 NA
|
// 1125 NA
|
||||||
// 1124 NA
|
// 1124 NA
|
||||||
1123,
|
1123,
|
||||||
|
|||||||
86
test/functional/legacy/getcwd_spec.lua
Normal file
86
test/functional/legacy/getcwd_spec.lua
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
-- Tests for getcwd(), haslocaldir(), and :lcd
|
||||||
|
|
||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
local eq, eval, source = helpers.eq, helpers.eval, helpers.source
|
||||||
|
local call, clear, execute = helpers.call, helpers.clear, helpers.execute
|
||||||
|
|
||||||
|
describe('getcwd', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
helpers.rmdir('Xtopdir')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('is working', function()
|
||||||
|
source([[
|
||||||
|
function! GetCwdInfo(win, tab)
|
||||||
|
let tab_changed = 0
|
||||||
|
let mod = ":t"
|
||||||
|
if a:tab > 0 && a:tab != tabpagenr()
|
||||||
|
let tab_changed = 1
|
||||||
|
exec "tabnext " . a:tab
|
||||||
|
endif
|
||||||
|
let bufname = fnamemodify(bufname(winbufnr(a:win)), mod)
|
||||||
|
if tab_changed
|
||||||
|
tabprevious
|
||||||
|
endif
|
||||||
|
if a:win == 0 && a:tab == 0
|
||||||
|
let dirname = fnamemodify(getcwd(), mod)
|
||||||
|
let lflag = haslocaldir()
|
||||||
|
elseif a:tab == 0
|
||||||
|
let dirname = fnamemodify(getcwd(a:win), mod)
|
||||||
|
let lflag = haslocaldir(a:win)
|
||||||
|
else
|
||||||
|
let dirname = fnamemodify(getcwd(a:win, a:tab), mod)
|
||||||
|
let lflag = haslocaldir(a:win, a:tab)
|
||||||
|
endif
|
||||||
|
return bufname . ' ' . dirname . ' ' . lflag
|
||||||
|
endfunction
|
||||||
|
]])
|
||||||
|
execute('new')
|
||||||
|
execute('let cwd=getcwd()')
|
||||||
|
call('mkdir', 'Xtopdir')
|
||||||
|
execute('silent cd Xtopdir')
|
||||||
|
call('mkdir', 'Xdir1')
|
||||||
|
call('mkdir', 'Xdir2')
|
||||||
|
call('mkdir', 'Xdir3')
|
||||||
|
execute('new a')
|
||||||
|
execute('new b')
|
||||||
|
execute('new c')
|
||||||
|
execute('3wincmd w')
|
||||||
|
execute('silent lcd Xdir1')
|
||||||
|
eq('a Xdir1 1', eval('GetCwdInfo(0, 0)'))
|
||||||
|
execute('wincmd W')
|
||||||
|
eq('b Xtopdir 0', eval('GetCwdInfo(0, 0)'))
|
||||||
|
execute('wincmd W')
|
||||||
|
execute('silent lcd Xdir3')
|
||||||
|
eq('c Xdir3 1', eval('GetCwdInfo(0, 0)'))
|
||||||
|
eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), 0)'))
|
||||||
|
eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), 0)'))
|
||||||
|
eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), 0)'))
|
||||||
|
execute('wincmd W')
|
||||||
|
eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), tabpagenr())'))
|
||||||
|
eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), tabpagenr())'))
|
||||||
|
eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), tabpagenr())'))
|
||||||
|
|
||||||
|
execute('tabnew x')
|
||||||
|
execute('new y')
|
||||||
|
execute('new z')
|
||||||
|
execute('3wincmd w')
|
||||||
|
eq('x Xtopdir 0', eval('GetCwdInfo(0, 0)'))
|
||||||
|
execute('wincmd W')
|
||||||
|
execute('silent lcd Xdir2')
|
||||||
|
eq('y Xdir2 1', eval('GetCwdInfo(0, 0)'))
|
||||||
|
execute('wincmd W')
|
||||||
|
execute('silent lcd Xdir3')
|
||||||
|
eq('z Xdir3 1', eval('GetCwdInfo(0, 0)'))
|
||||||
|
eq('x Xtopdir 0', eval('GetCwdInfo(bufwinnr("x"), 0)'))
|
||||||
|
eq('y Xdir2 1', eval('GetCwdInfo(bufwinnr("y"), 0)'))
|
||||||
|
eq('z Xdir3 1', eval('GetCwdInfo(bufwinnr("z"), 0)'))
|
||||||
|
execute('let tp_nr = tabpagenr()')
|
||||||
|
execute('tabrewind')
|
||||||
|
eq('x Xtopdir 0', eval('GetCwdInfo(3, tp_nr)'))
|
||||||
|
eq('y Xdir2 1', eval('GetCwdInfo(2, tp_nr)'))
|
||||||
|
eq('z Xdir3 1', eval('GetCwdInfo(1, tp_nr)'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user