Patch 8.2.3920

15 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 28, 2021, 8:16:06 AM12/28/21
to vim...@googlegroups.com

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 -- Br...@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 ///

John Marriott

unread,
Dec 28, 2021, 2:44:00 PM12/28/21
to vim...@googlegroups.com

On 29-Dec-2021 00:16, Bram Moolenaar wrote:
> 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
>
>
>
After this patch, mingw64 (gcc 11.2.0) spits out this error message if
FEAT_AUTOCHDIR is not defined (which is only defined if
FEAT_NETBEANS_INTG or FEAT_BIG are defined):
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD evalwindow.c -o
gobjnative/evalwindow.o
evalwindow.c: In function 'f_win_execute':
evalwindow.c:719:33: error: 'p_acd' undeclared (first use in this function)
  719 |         if (cwd_status == OK && p_acd)
      |                                 ^~~~~
evalwindow.c:719:33: note: each undeclared identifier is reported only
once for each function it appears in
make: *** [Make_cyg_ming.mak:1162: gobjnative/evalwindow.o] Error 1
</snip>

The attached patch makes the error go away but I'm not sure that it is
correct.

Cheers
John
evalwindow.c.8.2.3920.patch

Bram Moolenaar

unread,
Dec 28, 2021, 3:04:20 PM12/28/21
to vim...@googlegroups.com, John Marriott
Not quite, the directory still needs to be restored. But I can see
where the problem is.

--
All true wisdom is found on T-shirts.
Reply all
Reply to author
Forward
0 new messages