To: vim_dev@googlegroups.com Subject: Patch 8.2.3920 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3920 Problem: Restoring directory after using another window is inefficient. Solution: Only restore the directory for win_execute(). Apply 'autochdir' only when needed. Files: src/evalwindow.c, src/testdir/test_autochdir.vim *** ../vim-8.2.3919/src/evalwindow.c 2021-12-20 21:35:55.314175835 +0000 --- src/evalwindow.c 2021-12-28 13:13:08.477118501 +0000 *************** *** 707,712 **** --- 707,727 ---- if (wp != NULL && tp != NULL) { pos_T curpos = wp->w_cursor; + char_u cwd[MAXPATHL]; + int cwd_status; + char_u autocwd[MAXPATHL]; + int apply_acd = FALSE; + + cwd_status = mch_dirname(cwd, MAXPATHL); + + // If 'acd' is set, check we are using that directory. If yes, then + // apply 'acd' afterwards, otherwise restore the current directory. + if (cwd_status == OK && p_acd) + { + do_autochdir(); + apply_acd = mch_dirname(autocwd, MAXPATHL) == OK + && STRCMP(cwd, autocwd) == 0; + } if (switch_win_noblock(&save_curwin, &save_curtab, wp, tp, TRUE) == OK) { *************** *** 714,719 **** --- 729,738 ---- execute_common(argvars, rettv, 1); } restore_win_noblock(save_curwin, save_curtab, TRUE); + if (apply_acd) + do_autochdir(); + else if (cwd_status == OK) + mch_chdir((char *)cwd); // Update the status line if the cursor moved. if (win_valid(wp) && !EQUAL_POS(curpos, wp->w_cursor)) *************** *** 1316,1324 **** // to the first valid window. win_goto(firstwin); # endif - - // If called by win_execute() and executing the command changed the - // directory, it now has to be restored. - fix_current_dir(); } #endif --- 1335,1339 ---- *** ../vim-8.2.3919/src/testdir/test_autochdir.vim 2021-12-05 13:39:57.624815980 +0000 --- src/testdir/test_autochdir.vim 2021-12-28 12:17:38.450766408 +0000 *************** *** 51,56 **** --- 51,76 ---- endtry endfunc + func Test_acd_win_execute() + let cwd = getcwd() + set acd + call test_autochdir() + + call mkdir('Xfile') + let winid = win_getid() + new Xfile/file + call assert_match('testdir.Xfile$', getcwd()) + cd .. + call assert_match('testdir$', getcwd()) + call win_execute(winid, 'echo') + call assert_match('testdir$', getcwd()) + + bwipe! + set noacd + call chdir(cwd) + call delete('Xfile', 'rf') + endfunc + func Test_verbose_pwd() let cwd = getcwd() call test_autochdir() *** ../vim-8.2.3919/src/version.c 2021-12-28 11:24:44.636994380 +0000 --- src/version.c 2021-12-28 12:50:41.287915926 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3920, /**/ -- The difference between theory and practice, is that in theory, there is no difference between theory and practice. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///