From 538749410b8eae6d3c5b2c06c230132a6d7127ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Nov 2023 13:25:32 +0800 Subject: vim-patch:partial:8.1.1218: cannot set a directory for a tab page Problem: Cannot set a directory for a tab page. Solution: Add the tab-local directory. (Yegappan Lakshmanan, closes vim/vim#4212) https://github.com/vim/vim/commit/00aa069db8132851a91cfc5ca7f58ef945c75c73 Session-related changes only. Co-authored-by: Bram Moolenaar --- src/nvim/ex_session.c | 53 +++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 88c690a6a9..63dfdbc078 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -324,9 +324,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr // when 'viewoptions' contains "cursor". do_cursor = (flagp == &ssop_flags || *flagp & SSOP_CURSOR); - // // Local argument list. - // if (wp->w_alist == &global_alist) { PUTLINE_FAIL("argglobal"); } else { @@ -419,21 +417,17 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr } } - // // Local mappings and abbreviations. - // if ((*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS)) && makemap(fd, wp->w_buffer) == FAIL) { return FAIL; } - // // Local options. Need to go to the window temporarily. // Store only local values when using ":mkview" and when ":mksession" is // used and 'sessionoptions' doesn't include "nvim/options". // Some folding options are always stored when "folds" is included, // otherwise the folds would not be restored correctly. - // save_curwin = curwin; curwin = wp; curbuf = curwin->w_buffer; @@ -451,9 +445,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr return FAIL; } - // // Save Folds when 'buftype' is empty and for help files. - // if ((*flagp & SSOP_FOLDS) && wp->w_buffer->b_ffname != NULL && (bt_normal(wp->w_buffer) @@ -463,9 +455,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr } } - // // Set the cursor after creating folds, since that moves the cursor. - // if (do_cursor) { // Restore the cursor line in the file and relatively in the // window. Don't use "G", it changes the jumplist. @@ -516,10 +506,8 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr } } - // // Local directory, if the current flag is not view options or the "curdir" // option is included. - // if (wp->w_localdir != NULL && (flagp != &vop_flags || (*flagp & SSOP_CURDIR))) { if (fputs("lcd ", fd) < 0 @@ -574,9 +562,7 @@ static int makeopens(FILE *fd, char *dirnow) return FAIL; } - // // Now a :cd command to the session directory or the current directory - // if (ssop_flags & SSOP_SESDIR) { PUTLINE_FAIL("exe \"cd \" . escape(expand(\":p:h\"), ' ')"); } else if (ssop_flags & SSOP_CURDIR) { @@ -658,11 +644,9 @@ static int makeopens(FILE *fd, char *dirnow) restore_stal = true; } - // // For each tab: // - Put windows for each tab, when "tabpages" is in 'sessionoptions'. // - Don't use goto_tabpage(), it may change CWD and trigger autocommands. - // tab_firstwin = firstwin; // First window in tab page "tabnr". tab_topframe = topframe; if ((ssop_flags & SSOP_TABPAGES)) { @@ -703,11 +687,9 @@ static int makeopens(FILE *fd, char *dirnow) } } - // // Before creating the window layout, try loading one file. If this // is aborted we don't end up with a number of useless windows. // This may have side effects! (e.g., compressed or network file). - // for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) { if (ses_do_win(wp) && wp->w_buffer->b_ffname != NULL @@ -785,9 +767,19 @@ static int makeopens(FILE *fd, char *dirnow) return FAIL; } - // + // Restore the tab-local working directory if specified + // Do this before the windows, so that the window-local directory can + // override the tab-local directory. + if (tp != NULL && tp->tp_localdir != NULL && (ssop_flags & SSOP_CURDIR)) { + if (fputs("tcd ", fd) < 0 + || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL + || put_eol(fd) == FAIL) { + return FAIL; + } + did_lcd = true; + } + // Restore the view of the window (options, file, cursor, etc.). - // for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) { if (!ses_do_win(wp)) { continue; @@ -807,31 +799,17 @@ static int makeopens(FILE *fd, char *dirnow) // "tabedit". cur_arg_idx = next_arg_idx; - // // Restore cursor to the current window if it's not the first one. - // if (cnr > 1 && (fprintf(fd, "%dwincmd w\n", cnr) < 0)) { return FAIL; } - // // Restore window sizes again after jumping around in windows, because // the current window has a minimum size while others may not. - // if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) { return FAIL; } - // Take care of tab-local working directories if applicable - if (tp->tp_localdir) { - if (fputs("if exists(':tcd') == 2 | tcd ", fd) < 0 - || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL - || fputs(" | endif\n", fd) < 0) { - return FAIL; - } - did_lcd = true; - } - // Don't continue in another tab page when doing only the current one // or when at the last tab page. if (!(ssop_flags & SSOP_TABPAGES)) { @@ -848,9 +826,7 @@ static int makeopens(FILE *fd, char *dirnow) return FAIL; } - // // Wipe out an empty unnamed buffer we started in. - // if (fprintf(fd, "%s", "if exists('s:wipebuf') " "&& len(win_findbuf(s:wipebuf)) == 0 " @@ -882,9 +858,7 @@ static int makeopens(FILE *fd, char *dirnow) PUTLINE_FAIL("let &winminwidth = s:save_winminwidth"); } - // // Lastly, execute the x.vim file if it exists. - // if (fprintf(fd, "%s", "let s:sx = expand(\":p:r\").\"x.vim\"\n" "if filereadable(s:sx)\n" @@ -999,9 +973,8 @@ void ex_mkrc(exarg_T *eap) char *dirnow; // current directory dirnow = xmalloc(MAXPATHL); - // + // Change to session file's dir. - // if (os_dirname(dirnow, MAXPATHL) == FAIL || os_chdir(dirnow) != 0) { *dirnow = NUL; -- cgit From c23c44f845c8d357093d87f6e2e5636d2a11a8fb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Nov 2023 13:53:21 +0800 Subject: vim-patch:8.2.4850: mksession mixes up "tabpages" and "curdir" arguments Problem: Mksession mixes up "tabpages" and "curdir" arguments. Solution: Correct logic for storing tabpage in session. (closes vim/vim#10312) https://github.com/vim/vim/commit/d7c9564d8d24343f2e27205633032dd6ebe5232c Co-authored-by: LemonBoy --- src/nvim/ex_session.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 63dfdbc078..3807436efb 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -537,7 +537,6 @@ static int makeopens(FILE *fd, char *dirnow) win_T *wp; char *sname; win_T *edited_win = NULL; - int tabnr; win_T *tab_firstwin; frame_T *tab_topframe; int cur_arg_idx = 0; @@ -644,14 +643,10 @@ static int makeopens(FILE *fd, char *dirnow) restore_stal = true; } - // For each tab: - // - Put windows for each tab, when "tabpages" is in 'sessionoptions'. - // - Don't use goto_tabpage(), it may change CWD and trigger autocommands. - tab_firstwin = firstwin; // First window in tab page "tabnr". - tab_topframe = topframe; if ((ssop_flags & SSOP_TABPAGES)) { - // Similar to ses_win_rec() below, populate the tab pages first so - // later local options won't be copied to the new tabs. + // "tabpages" is in 'sessionoptions': Similar to ses_win_rec() below, + // populate the tab pages first so later local options won't be copied + // to the new tabs. FOR_ALL_TABS(tp) { // Use `bufhidden=wipe` to remove empty "placeholder" buffers once // they are not needed. This prevents creating extra buffers (see @@ -665,15 +660,17 @@ static int makeopens(FILE *fd, char *dirnow) return FAIL; } } - for (tabnr = 1;; tabnr++) { - tabpage_T *tp = find_tabpage(tabnr); - if (tp == NULL) { - break; // done all tab pages - } + // Assume "tabpages" is in 'sessionoptions'. If not then we only do + // "curtab" and bail out of the loop. + FOR_ALL_TABS(tp) { bool need_tabnext = false; int cnr = 1; + // May repeat putting Windows for each tab, when "tabpages" is in + // 'sessionoptions'. + // Don't use goto_tabpage(), it may change directory and trigger + // autocommands. if ((ssop_flags & SSOP_TABPAGES)) { if (tp == curtab) { tab_firstwin = firstwin; @@ -682,9 +679,13 @@ static int makeopens(FILE *fd, char *dirnow) tab_firstwin = tp->tp_firstwin; tab_topframe = tp->tp_topframe; } - if (tabnr > 1) { + if (tp != first_tabpage) { need_tabnext = true; } + } else { + tp = curtab; + tab_firstwin = firstwin; + tab_topframe = topframe; } // Before creating the window layout, try loading one file. If this @@ -770,7 +771,7 @@ static int makeopens(FILE *fd, char *dirnow) // Restore the tab-local working directory if specified // Do this before the windows, so that the window-local directory can // override the tab-local directory. - if (tp != NULL && tp->tp_localdir != NULL && (ssop_flags & SSOP_CURDIR)) { + if ((ssop_flags & SSOP_CURDIR) && tp->tp_localdir != NULL) { if (fputs("tcd ", fd) < 0 || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL || put_eol(fd) == FAIL) { -- cgit