diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-12-28 13:15:05 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-28 13:15:05 +0000 |
commit | 90c317f2246a7fb4bd4e3feb0778b53627bc9fad (patch) | |
tree | 0f765598411fe6bab0519ddb7f1ee4daebb80c67 /src/evalwindow.c | |
parent | 8b6256f6ec075cca40341e61ebc9f538b4902dd1 (diff) | |
download | vim-git-90c317f2246a7fb4bd4e3feb0778b53627bc9fad.tar.gz |
patch 8.2.3920: restoring directory after using another window is inefficientv8.2.3920
Problem: Restoring directory after using another window is inefficient.
Solution: Only restore the directory for win_execute(). Apply 'autochdir'
only when needed.
Diffstat (limited to 'src/evalwindow.c')
-rw-r--r-- | src/evalwindow.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/evalwindow.c b/src/evalwindow.c index 794d6aa0b..ebab85614 100644 --- a/src/evalwindow.c +++ b/src/evalwindow.c @@ -707,6 +707,21 @@ f_win_execute(typval_T *argvars, typval_T *rettv) 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,6 +729,10 @@ f_win_execute(typval_T *argvars, typval_T *rettv) 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,9 +1335,5 @@ restore_win_noblock( // 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 |