To: vim_dev@googlegroups.com Subject: Patch 8.2.3593 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.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) Files: src/evalwindow.c, src/window.c, src/proto/window.pro, src/testdir/test_execute_func.vim *** ../vim-8.2.3592/src/evalwindow.c 2021-07-31 11:43:19.464837526 +0100 --- src/evalwindow.c 2021-11-14 11:34:25.229965169 +0000 *************** *** 1311,1315 **** --- 1311,1319 ---- // 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 *** ../vim-8.2.3592/src/window.c 2021-11-13 12:38:45.538835898 +0000 --- src/window.c 2021-11-14 11:27:26.067475055 +0000 *************** *** 4796,4831 **** } #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); ! } #ifdef FEAT_JOB_CHANNEL entering_window(curwin); --- 4796,4802 ---- } #endif ! fix_current_dir(); #ifdef FEAT_JOB_CHANNEL entering_window(curwin); *************** *** 4875,4880 **** --- 4846,4889 ---- 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. *** ../vim-8.2.3592/src/proto/window.pro 2020-11-07 15:58:55.894354883 +0000 --- src/proto/window.pro 2021-11-14 11:27:56.231365747 +0000 *************** *** 43,48 **** --- 43,49 ---- 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); *** ../vim-8.2.3592/src/testdir/test_execute_func.vim 2021-07-27 21:00:39.753712380 +0100 --- src/testdir/test_execute_func.vim 2021-11-14 11:33:21.738192889 +0000 *************** *** 105,110 **** --- 105,122 ---- 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() *** ../vim-8.2.3592/src/version.c 2021-11-13 18:44:34.322363534 +0000 --- src/version.c 2021-11-14 11:27:49.275390945 +0000 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 3593, /**/ -- GUARD #2: It could be carried by an African swallow! GUARD #1: Oh, yeah, an African swallow maybe, but not a European swallow, that's my point. GUARD #2: Oh, yeah, I agree with that... The Quest for the Holy Grail (Monty Python) /// 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 ///