To: vim_dev@googlegroups.com Subject: Patch 8.0.1489 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1489 Problem: There is no easy way to get the global directory, esp. if some windows have a local directory. Solution: Make getcwd(-1) return the global directory. (Andy Massimino, closes #2606) Files: runtime/doc/eval.txt, src/evalfunc.c, src/testdir/test_getcwd.vim *** ../vim-8.0.1488/runtime/doc/eval.txt 2018-01-28 17:45:41.509504168 +0100 --- runtime/doc/eval.txt 2018-02-09 20:42:53.334824536 +0100 *************** *** 4472,4481 **** Without arguments, for the current window. With {winnr} return the local current directory of this window ! in the current tab page. With {winnr} and {tabnr} return the local current directory of the window in the specified tab page. - {winnr} can be the window number or the |window-ID|. Return an empty string if the arguments are invalid. getfsize({fname}) *getfsize()* --- 4484,4496 ---- Without arguments, for the current window. With {winnr} return the local current directory of this window ! in the current tab page. {winnr} can be the window number or ! the |window-ID|. ! If {winnr} is -1 return the name of the global working ! directory. See also |haslocaldir()|. ! With {winnr} and {tabnr} return the local current directory of the window in the specified tab page. Return an empty string if the arguments are invalid. getfsize({fname}) *getfsize()* *** ../vim-8.0.1488/src/evalfunc.c 2018-02-09 12:27:57.008455532 +0100 --- src/evalfunc.c 2018-02-09 20:40:03.724035874 +0100 *************** *** 4613,4628 **** { win_T *wp = NULL; char_u *cwd; rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; ! wp = find_tabwin(&argvars[0], &argvars[1]); ! if (wp != NULL) { ! if (wp->w_localdir != NULL) ! rettv->vval.v_string = vim_strsave(wp->w_localdir); ! else if (globaldir != NULL) rettv->vval.v_string = vim_strsave(globaldir); else { --- 4613,4633 ---- { win_T *wp = NULL; char_u *cwd; + int global = FALSE; rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; ! if (argvars[0].v_type == VAR_NUMBER && argvars[0].vval.v_number == -1) ! global = TRUE; ! else ! wp = find_tabwin(&argvars[0], &argvars[1]); ! ! if (wp != NULL && wp->w_localdir != NULL) ! rettv->vval.v_string = vim_strsave(wp->w_localdir); ! else if (wp != NULL || global) { ! if (globaldir != NULL) rettv->vval.v_string = vim_strsave(globaldir); else { *** ../vim-8.0.1488/src/testdir/test_getcwd.vim 2017-07-11 21:45:26.617831206 +0200 --- src/testdir/test_getcwd.vim 2018-02-09 20:40:03.724035874 +0100 *************** *** 37,42 **** --- 37,43 ---- new call mkdir('Xtopdir') cd Xtopdir + let g:topdir = getcwd() call mkdir('Xdir1') call mkdir('Xdir2') call mkdir('Xdir3') *************** *** 56,91 **** --- 57,100 ---- 3wincmd w lcd Xdir1 call assert_equal("a Xdir1 1", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) wincmd W call assert_equal("b Xtopdir 0", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) wincmd W lcd Xdir3 call assert_equal("c Xdir3 1", GetCwdInfo(0, 0)) call assert_equal("a Xdir1 1", GetCwdInfo(bufwinnr("a"), 0)) call assert_equal("b Xtopdir 0", GetCwdInfo(bufwinnr("b"), 0)) call assert_equal("c Xdir3 1", GetCwdInfo(bufwinnr("c"), 0)) + call assert_equal(g:topdir, getcwd(-1)) wincmd W call assert_equal("a Xdir1 1", GetCwdInfo(bufwinnr("a"), tabpagenr())) call assert_equal("b Xtopdir 0", GetCwdInfo(bufwinnr("b"), tabpagenr())) call assert_equal("c Xdir3 1", GetCwdInfo(bufwinnr("c"), tabpagenr())) + call assert_equal(g:topdir, getcwd(-1)) tabnew x new y new z 3wincmd w call assert_equal("x Xtopdir 0", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) wincmd W lcd Xdir2 call assert_equal("y Xdir2 1", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) wincmd W lcd Xdir3 call assert_equal("z Xdir3 1", GetCwdInfo(0, 0)) call assert_equal("x Xtopdir 0", GetCwdInfo(bufwinnr("x"), 0)) call assert_equal("y Xdir2 1", GetCwdInfo(bufwinnr("y"), 0)) call assert_equal("z Xdir3 1", GetCwdInfo(bufwinnr("z"), 0)) + call assert_equal(g:topdir, getcwd(-1)) let tp_nr = tabpagenr() tabrewind call assert_equal("x Xtopdir 0", GetCwdInfo(3, tp_nr)) call assert_equal("y Xdir2 1", GetCwdInfo(2, tp_nr)) call assert_equal("z Xdir3 1", GetCwdInfo(1, tp_nr)) + call assert_equal(g:topdir, getcwd(-1)) endfunc *** ../vim-8.0.1488/src/version.c 2018-02-09 19:25:24.213735174 +0100 --- src/version.c 2018-02-09 20:43:01.758764154 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1489, /**/ -- MORTICIAN: Bring out your dead! [clang] Bring out your dead! [clang] Bring out your dead! CUSTOMER: Here's one -- nine pence. DEAD PERSON: I'm not dead! The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///