aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt17
-rw-r--r--src/nvim/eval.c52
-rw-r--r--src/nvim/version.c2
-rw-r--r--test/functional/legacy/getcwd_spec.lua86
4 files changed, 126 insertions, 31 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 869fcf0078..71a7682f15 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1890,7 +1890,7 @@ getcmdpos() Number return cursor position in command-line
getcmdtype() String return current command-line type
getcmdwintype() String return current command-line window type
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
getfperm({fname}) String file permissions 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}
has({feature}) Number TRUE if feature {feature} supported
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}]])
Number TRUE if mapping to {what} exists
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
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
- the current effective working directory. With {window} or
- {tab} the working directory of that scope is returned.
+ the current effective working directory. With {winnr} or
+ {tabnr} the working directory of that scope is returned.
Tabs and windows are identified by their respective numbers,
0 means current tab or window. Missing argument implies 0.
Thus the following are equivalent: >
getcwd()
getcwd(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()*
@@ -3947,7 +3948,7 @@ has_key({dict}, {key}) *has_key()*
The result is a Number, which is 1 if |Dictionary| {dict} has
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
or window has a local path set via |:lcd| or |:tcd|, and
0 otherwise.
@@ -3958,7 +3959,7 @@ haslocaldir([{window}[, {tab}]]) *haslocaldir()*
haslocaldir()
haslocaldir(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()*
The result is a Number, which is 1 if there is a mapping that
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 111105fa37..915484ebfb 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7541,25 +7541,9 @@ static void f_argidx(typval_T *argvars, typval_T *rettv)
static void f_arglistid(typval_T *argvars, typval_T *rettv)
{
rettv->vval.v_number = -1;
- if (argvars[0].v_type != VAR_UNKNOWN) {
- tabpage_T *tp = NULL;
- if (argvars[1].v_type != VAR_UNKNOWN) {
- 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;
+ win_T *wp = find_tabwin(&argvars[0], &argvars[1]);
+ if (wp != NULL) {
+ rettv->vval.v_number = wp->w_alist->id;
}
}
@@ -10473,9 +10457,33 @@ find_win_by_nr (
return NULL;
}
-/*
- * "getwinvar()" function
- */
+/// Find window specified by "wvp" in tabpage "tvp".
+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)
{
getwinvar(argvars, rettv, 0);
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 04a6f63451..c2e17b7377 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -567,7 +567,7 @@ static int included_patches[] = {
// 1129 NA
// 1128 NA
// 1127 NA
- // 1126,
+ 1126,
// 1125 NA
// 1124 NA
1123,
diff --git a/test/functional/legacy/getcwd_spec.lua b/test/functional/legacy/getcwd_spec.lua
new file mode 100644
index 0000000000..3bb9930b74
--- /dev/null
+++ b/test/functional/legacy/getcwd_spec.lua
@@ -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)