summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-11-14 11:41:31 +0000
committerBram Moolenaar <Bram@vim.org>2021-11-14 11:41:31 +0000
commit7f13b24ab6aca808262e68680d8fe5f082670ebd (patch)
treea6fc626ad6115ec983c0d682489ccc1397741f87
parent6a950a6007f27d9d0ce32ef8dcaf5c9d0f1b5aab (diff)
patch 8.2.3593: directory is wrong after executing "lcd" with win_execute()v8.2.3593
Problem: Directory is wrong after executing "lcd" with win_execute(). Solution: Correct the directory when going back to the original window. (closes #9132)
-rw-r--r--src/evalwindow.c4
-rw-r--r--src/proto/window.pro1
-rw-r--r--src/testdir/test_execute_func.vim12
-rw-r--r--src/version.c2
-rw-r--r--src/window.c69
5 files changed, 58 insertions, 30 deletions
diff --git a/src/evalwindow.c b/src/evalwindow.c
index f043c6f4d7..c90571557d 100644
--- a/src/evalwindow.c
+++ b/src/evalwindow.c
@@ -1311,5 +1311,9 @@ 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
diff --git a/src/proto/window.pro b/src/proto/window.pro
index c10b61dba4..93264e1ad2 100644
--- a/src/proto/window.pro
+++ b/src/proto/window.pro
@@ -43,6 +43,7 @@ tabpage_T *win_find_tabpage(win_T *win);
win_T *win_vert_neighbor(tabpage_T *tp, win_T *wp, int up, long count);
win_T *win_horz_neighbor(tabpage_T *tp, win_T *wp, int left, long count);
void win_enter(win_T *wp, int undo_sync);
+void fix_current_dir(void);
win_T *buf_jump_open_win(buf_T *buf);
win_T *buf_jump_open_tab(buf_T *buf);
void win_free_popup(win_T *win);
diff --git a/src/testdir/test_execute_func.vim b/src/testdir/test_execute_func.vim
index 2652ba170a..2a84706ad5 100644
--- a/src/testdir/test_execute_func.vim
+++ b/src/testdir/test_execute_func.vim
@@ -105,6 +105,18 @@ func Test_win_execute()
call win_gotoid(otherwin)
bwipe!
+
+ " check :lcd in another window does not change directory
+ let curid = win_getid()
+ let curdir = getcwd()
+ split Xother
+ lcd ..
+ " Use :pwd to get the actual current directory
+ let otherdir = execute('pwd')
+ call win_execute(curid, 'lcd testdir')
+ call assert_equal(otherdir, execute('pwd'))
+ bwipe!
+ execute 'cd ' .. curdir
endfunc
func Test_win_execute_update_ruler()
diff --git a/src/version.c b/src/version.c
index c0acd4b676..1664f21c30 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3593,
+/**/
3592,
/**/
3591,
diff --git a/src/window.c b/src/window.c
index 226d6c1a40..5473aaba60 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4796,36 +4796,7 @@ win_enter_ext(win_T *wp, int flags)
}
#endif
- if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL)
- {
- char_u *dirname;
-
- // Window or tab has a local directory: Save current directory as
- // global directory (unless that was done already) and change to the
- // local directory.
- if (globaldir == NULL)
- {
- char_u cwd[MAXPATHL];
-
- if (mch_dirname(cwd, MAXPATHL) == OK)
- globaldir = vim_strsave(cwd);
- }
- if (curwin->w_localdir != NULL)
- dirname = curwin->w_localdir;
- else
- dirname = curtab->tp_localdir;
-
- if (mch_chdir((char *)dirname) == 0)
- shorten_fnames(TRUE);
- }
- else if (globaldir != NULL)
- {
- // Window doesn't have a local directory and we are not in the global
- // directory: Change to the global directory.
- vim_ignored = mch_chdir((char *)globaldir);
- VIM_CLEAR(globaldir);
- shorten_fnames(TRUE);
- }
+ fix_current_dir();
#ifdef FEAT_JOB_CHANNEL
entering_window(curwin);
@@ -4875,6 +4846,44 @@ win_enter_ext(win_T *wp, int flags)
return did_decrement;
}
+/*
+ * Used after making another window the current one: change directory if
+ * needed.
+ */
+ void
+fix_current_dir(void)
+{
+ if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL)
+ {
+ char_u *dirname;
+
+ // Window or tab has a local directory: Save current directory as
+ // global directory (unless that was done already) and change to the
+ // local directory.
+ if (globaldir == NULL)
+ {
+ char_u cwd[MAXPATHL];
+
+ if (mch_dirname(cwd, MAXPATHL) == OK)
+ globaldir = vim_strsave(cwd);
+ }
+ if (curwin->w_localdir != NULL)
+ dirname = curwin->w_localdir;
+ else
+ dirname = curtab->tp_localdir;
+
+ if (mch_chdir((char *)dirname) == 0)
+ shorten_fnames(TRUE);
+ }
+ else if (globaldir != NULL)
+ {
+ // Window doesn't have a local directory and we are not in the global
+ // directory: Change to the global directory.
+ vim_ignored = mch_chdir((char *)globaldir);
+ VIM_CLEAR(globaldir);
+ shorten_fnames(TRUE);
+ }
+}
/*
* Jump to the first open window that contains buffer "buf", if one exists.