To: vim_dev@googlegroups.com Subject: Patch 8.0.0405 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0405 Problem: v:progpath may become invalid after ":cd". Solution: Turn v:progpath into a full path if needed. Files: src/main.c, src/testdir/test_startup.vim, runtime/doc/eval.txt *** ../vim-8.0.0404/src/main.c 2017-02-25 14:59:29.906090427 +0100 --- src/main.c 2017-03-04 14:33:21.034707076 +0100 *************** *** 57,62 **** --- 57,65 ---- # if defined(HAS_SWAP_EXISTS_ACTION) static void check_swap_exists_action(void); # endif + # ifdef FEAT_EVAL + static void set_progpath(char_u *argv0); + # endif # if defined(FEAT_CLIENTSERVER) || defined(PROTO) static void exec_on_server(mparm_T *parmp); static void prepare_server(mparm_T *parmp); *************** *** 1694,1700 **** #ifdef FEAT_EVAL set_vim_var_string(VV_PROGNAME, initstr, -1); ! set_vim_var_string(VV_PROGPATH, (char_u *)parmp->argv[0], -1); #endif if (TOLOWER_ASC(initstr[0]) == 'r') --- 1697,1703 ---- #ifdef FEAT_EVAL set_vim_var_string(VV_PROGNAME, initstr, -1); ! set_progpath((char_u *)parmp->argv[0]); #endif if (TOLOWER_ASC(initstr[0]) == 'r') *************** *** 3417,3423 **** } #endif ! #endif #if defined(STARTUPTIME) || defined(PROTO) static void time_diff(struct timeval *then, struct timeval *now); --- 3420,3426 ---- } #endif ! #endif /* NO_VIM_MAIN */ #if defined(STARTUPTIME) || defined(PROTO) static void time_diff(struct timeval *then, struct timeval *now); *************** *** 3525,3530 **** --- 3528,3557 ---- #endif + #ifndef NO_VIM_MAIN + static void + set_progpath(char_u *argv0) + { + char_u *val = argv0; + char_u buf[MAXPATHL]; + + /* A relative path containing a "/" will become invalid when using ":cd", + * turn it into a full path. + * On MS-Windows "vim.exe" is found in the current directory, thus also do + * it when there is no path and the file exists. */ + if ( !mch_isFullName(argv0) + # ifdef WIN32 + && mch_can_exe(argv0, NULL, TRUE) + # else + && gettail(argv0) != argv0 + # endif + && vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL) + val = buf; + set_vim_var_string(VV_PROGPATH, val, -1); + } + + #endif /* NO_VIM_MAIN */ + #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) /* *** ../vim-8.0.0404/src/testdir/test_startup.vim 2016-08-09 22:44:21.000000000 +0200 --- src/testdir/test_startup.vim 2017-03-04 14:28:29.700635631 +0100 *************** *** 183,185 **** --- 183,199 ---- endif call delete('Xtestout') endfunc + + func Test_progpath() + " Tests normally run with "./vim" or "../vim", these must have been expanded + " to a full path. + if has('unix') + call assert_equal('/', v:progpath[0]) + elseif has('win32') + call assert_equal(':', v:progpath[1]) + call assert_match('[/\\]', v:progpath[2]) + endif + + " Only expect "vim" to appear in v:progname. + call assert_match('vim\c', v:progname) + endfunc *** ../vim-8.0.0404/runtime/doc/eval.txt 2017-03-01 20:32:40.135105362 +0100 --- runtime/doc/eval.txt 2017-03-04 14:35:18.241915232 +0100 *************** *** 1788,1795 **** |--remote-expr|. To get the full path use: > echo exepath(v:progpath) ! < NOTE: This does not work when the command is a relative path ! and the current directory has changed. Read-only. *v:register* *register-variable* --- 1789,1799 ---- |--remote-expr|. To get the full path use: > echo exepath(v:progpath) ! < If the path is relative it will be expanded to the full path, ! so that it still works after `:cd`. Thus starting "./vim" ! results in "/home/user/path/to/vim/src/vim". ! On MS-Windows the executable may be called "vim.exe", but the ! ".exe" is not added to v:progpath. Read-only. *v:register* *register-variable* *** ../vim-8.0.0404/src/version.c 2017-03-04 13:47:08.248946851 +0100 --- src/version.c 2017-03-04 14:29:03.184412579 +0100 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 405, /**/ -- I started out with nothing, and I still have most of it. -- Michael Davis -- "Tonight Show" /// 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 ///