To: vim_dev@googlegroups.com Subject: Patch 8.2.1967 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1967 Problem: The session file does not restore the alternate file. Solution: Add ":balt". Works like ":badd" and also sets the buffer as the alternate file. Use it in the session file. (closes #7269, closes #6714) Files: runtime/doc/windows.txt, src/ex_cmds.h, src/ex_cmdidxs.h, src/ex_docmd.c, src/vim.h, src/ex_cmds.c, src/session.c, src/testdir/test_buffer.vim *** ../vim-8.2.1966/runtime/doc/windows.txt 2019-12-12 12:49:07.000000000 +0100 --- runtime/doc/windows.txt 2020-11-07 17:54:43.071448171 +0100 *************** *** 1105,1115 **** < *:bad* *:badd* :bad[d] [+lnum] {fname} ! Add file name {fname} to the buffer list, without loading it. If "lnum" is specified, the cursor will be positioned at that line when the buffer is first entered. Note that other commands after the + will be ignored. :[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516* :bd[elete][!] [N] Unload buffer [N] (default: current buffer) and delete it from --- 1112,1129 ---- < *:bad* *:badd* :bad[d] [+lnum] {fname} ! Add file name {fname} to the buffer list, without loading it, ! if it wasn't listed yet. If the buffer was previously ! deleted, not wiped, it will be made listed again. If "lnum" is specified, the cursor will be positioned at that line when the buffer is first entered. Note that other commands after the + will be ignored. + *:balt* + :balt [+lnum] {fname} + Like `:badd` and also set the alternate file for the current + window to {fname}. + :[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516* :bd[elete][!] [N] Unload buffer [N] (default: current buffer) and delete it from *** ../vim-8.2.1966/src/ex_cmds.h 2020-10-24 17:19:12.135743402 +0200 --- src/ex_cmds.h 2020-11-07 17:42:57.682700683 +0100 *************** *** 178,183 **** --- 178,186 ---- EXCMD(CMD_badd, "badd", ex_edit, EX_NEEDARG|EX_FILE1|EX_CMDARG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), + EXCMD(CMD_balt, "balt", ex_edit, + EX_NEEDARG|EX_FILE1|EX_CMDARG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, + ADDR_NONE), EXCMD(CMD_bdelete, "bdelete", ex_bunload, EX_BANG|EX_RANGE|EX_BUFNAME|EX_COUNT|EX_EXTRA|EX_TRLBAR, ADDR_BUFFERS), *** ../vim-8.2.1966/src/ex_cmdidxs.h 2020-10-10 21:33:42.403033529 +0200 --- src/ex_cmdidxs.h 2020-11-07 17:45:21.194106040 +0100 *************** *** 7,36 **** { /* a */ 0, /* b */ 19, ! /* c */ 42, ! /* d */ 108, ! /* e */ 133, ! /* f */ 156, ! /* g */ 173, ! /* h */ 179, ! /* i */ 188, ! /* j */ 207, ! /* k */ 209, ! /* l */ 214, ! /* m */ 276, ! /* n */ 294, ! /* o */ 314, ! /* p */ 326, ! /* q */ 365, ! /* r */ 368, ! /* s */ 388, ! /* t */ 457, ! /* u */ 502, ! /* v */ 513, ! /* w */ 533, ! /* x */ 547, ! /* y */ 557, ! /* z */ 558 }; /* --- 7,36 ---- { /* a */ 0, /* b */ 19, ! /* c */ 43, ! /* d */ 109, ! /* e */ 134, ! /* f */ 157, ! /* g */ 174, ! /* h */ 180, ! /* i */ 189, ! /* j */ 208, ! /* k */ 210, ! /* l */ 215, ! /* m */ 277, ! /* n */ 295, ! /* o */ 315, ! /* p */ 327, ! /* q */ 366, ! /* r */ 369, ! /* s */ 389, ! /* t */ 458, ! /* u */ 503, ! /* v */ 514, ! /* w */ 534, ! /* x */ 548, ! /* y */ 558, ! /* z */ 559 }; /* *************** *** 42,48 **** static const unsigned char cmdidxs2[26][26] = { /* a b c d e f g h i j k l m n o p q r s t u v w x y z */ /* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0 }, ! /* b */ { 2, 0, 0, 4, 5, 7, 0, 0, 0, 0, 0, 8, 9, 10, 11, 12, 0, 13, 0, 0, 0, 0, 22, 0, 0, 0 }, /* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 37, 40, 46, 56, 58, 59, 60, 0, 62, 0, 65, 0, 0, 0 }, /* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 19, 0, 0, 20, 0, 0, 22, 23, 0, 0, 0, 0, 0, 0, 0 }, /* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 17, 0, 18, 0, 0 }, --- 42,48 ---- static const unsigned char cmdidxs2[26][26] = { /* a b c d e f g h i j k l m n o p q r s t u v w x y z */ /* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0 }, ! /* b */ { 2, 0, 0, 5, 6, 8, 0, 0, 0, 0, 0, 9, 10, 11, 12, 13, 0, 14, 0, 0, 0, 0, 23, 0, 0, 0 }, /* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 37, 40, 46, 56, 58, 59, 60, 0, 62, 0, 65, 0, 0, 0 }, /* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 19, 0, 0, 20, 0, 0, 22, 23, 0, 0, 0, 0, 0, 0, 0 }, /* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 17, 0, 18, 0, 0 }, *************** *** 69,72 **** /* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; ! static const int command_count = 573; --- 69,72 ---- /* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; ! static const int command_count = 574; *** ../vim-8.2.1966/src/ex_docmd.c 2020-11-02 21:08:43.118288911 +0100 --- src/ex_docmd.c 2020-11-07 17:46:29.233824624 +0100 *************** *** 6506,6512 **** } /* ! * ":edit", ":badd", ":visual". */ static void ex_edit(exarg_T *eap) --- 6506,6512 ---- } /* ! * ":edit", ":badd", ":balt", ":visual". */ static void ex_edit(exarg_T *eap) *************** *** 6621,6627 **** + (eap->forceit ? ECMD_FORCEIT : 0) // after a split we can use an existing buffer + (old_curwin != NULL ? ECMD_OLDBUF : 0) ! + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 ) , old_curwin == NULL ? curwin : NULL) == FAIL) { // Editing the file failed. If the window was split, close it. --- 6621,6628 ---- + (eap->forceit ? ECMD_FORCEIT : 0) // after a split we can use an existing buffer + (old_curwin != NULL ? ECMD_OLDBUF : 0) ! + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0) ! + (eap->cmdidx == CMD_balt ? ECMD_ALTBUF : 0) , old_curwin == NULL ? curwin : NULL) == FAIL) { // Editing the file failed. If the window was split, close it. *************** *** 8472,8478 **** * Evaluate cmdline variables. * * change '%' to curbuf->b_ffname ! * '#' to curwin->w_altfile * '' to word under the cursor * '' to WORD under the cursor * '' to C-expression under the cursor --- 8473,8479 ---- * Evaluate cmdline variables. * * change '%' to curbuf->b_ffname ! * '#' to curwin->w_alt_fnum * '' to word under the cursor * '' to WORD under the cursor * '' to C-expression under the cursor *** ../vim-8.2.1966/src/vim.h 2020-10-26 21:05:23.905469139 +0100 --- src/vim.h 2020-11-07 17:47:38.197539723 +0100 *************** *** 1029,1034 **** --- 1029,1035 ---- #define ECMD_OLDBUF 0x04 // use existing buffer if it exists #define ECMD_FORCEIT 0x08 // ! used in Ex command #define ECMD_ADDBUF 0x10 // don't edit, just add to buffer list + #define ECMD_ALTBUF 0x20 // like ECMD_ADDBUF and set the alternate file // for lnum argument in do_ecmd() #define ECMD_LASTL (linenr_T)0 // use last position in loaded file *** ../vim-8.2.1966/src/ex_cmds.c 2020-11-04 18:02:41.221407563 +0100 --- src/ex_cmds.c 2020-11-07 17:52:14.092170656 +0100 *************** *** 2459,2464 **** --- 2459,2465 ---- * ECMD_OLDBUF: use existing buffer if it exists * ECMD_FORCEIT: ! used for Ex command * ECMD_ADDBUF: don't edit, just add to buffer list + * ECMD_ALTBUF: like ECMD_ADDBUF and also set the alternate file * oldwin: Should be "curwin" when editing a new buffer in the current * window, NULL when splitting the window first. When not NULL info * of the previous buffer for "oldwin" is stored. *************** *** 2555,2561 **** fname_case(sfname, 0); // set correct case for sfname #endif ! if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) goto theend; if (ffname == NULL) --- 2556,2563 ---- fname_case(sfname, 0); // set correct case for sfname #endif ! if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF)) ! && (ffname == NULL || *ffname == NUL)) goto theend; if (ffname == NULL) *************** *** 2584,2590 **** */ if ( ((!other_file && !(flags & ECMD_OLDBUF)) || (curbuf->b_nwindows == 1 ! && !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) && check_changed(curbuf, (p_awa ? CCGD_AW : 0) | (other_file ? 0 : CCGD_MULTWIN) | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) --- 2586,2592 ---- */ if ( ((!other_file && !(flags & ECMD_OLDBUF)) || (curbuf->b_nwindows == 1 ! && !(flags & (ECMD_HIDE | ECMD_ADDBUF | ECMD_ALTBUF)))) && check_changed(curbuf, (p_awa ? CCGD_AW : 0) | (other_file ? 0 : CCGD_MULTWIN) | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) *************** *** 2633,2639 **** */ if (other_file) { ! if (!(flags & ECMD_ADDBUF)) { if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) curwin->w_alt_fnum = curbuf->b_fnum; --- 2635,2641 ---- */ if (other_file) { ! if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF))) { if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) curwin->w_alt_fnum = curbuf->b_fnum; *************** *** 2645,2655 **** buf = buflist_findnr(fnum); else { ! if (flags & ECMD_ADDBUF) { // Default the line number to zero to avoid that a wininfo item // is added for the current window. linenr_T tlnum = 0; if (command != NULL) { --- 2647,2658 ---- buf = buflist_findnr(fnum); else { ! if (flags & (ECMD_ADDBUF | ECMD_ALTBUF)) { // Default the line number to zero to avoid that a wininfo item // is added for the current window. linenr_T tlnum = 0; + buf_T *newbuf; if (command != NULL) { *************** *** 2657,2666 **** if (tlnum <= 0) tlnum = 1L; } ! // Add BLN_NOCURWIN to avoid a new wininfo items is assocated // with the current window. ! (void)buflist_new(ffname, sfname, tlnum, BLN_LISTED | BLN_NOCURWIN); goto theend; } buf = buflist_new(ffname, sfname, 0L, --- 2660,2671 ---- if (tlnum <= 0) tlnum = 1L; } ! // Add BLN_NOCURWIN to avoid a new wininfo items are assocated // with the current window. ! newbuf = buflist_new(ffname, sfname, tlnum, BLN_LISTED | BLN_NOCURWIN); + if (newbuf != NULL && (flags & ECMD_ALTBUF)) + curwin->w_alt_fnum = newbuf->b_fnum; goto theend; } buf = buflist_new(ffname, sfname, 0L, *************** *** 2818,2824 **** } else // !other_file { ! if ((flags & ECMD_ADDBUF) || check_fname() == FAIL) goto theend; oldbuf = (flags & ECMD_OLDBUF); --- 2823,2829 ---- } else // !other_file { ! if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF)) || check_fname() == FAIL) goto theend; oldbuf = (flags & ECMD_OLDBUF); *** ../vim-8.2.1966/src/session.c 2020-11-01 17:40:47.829631403 +0100 --- src/session.c 2020-11-07 18:24:57.972726135 +0100 *************** *** 397,402 **** --- 397,415 ---- } } + if (wp->w_alt_fnum) + { + buf_T *alt = buflist_findnr(wp->w_alt_fnum); + + // Set the alternate file. + if (alt != NULL + && alt->b_fname != NULL + && *alt->b_fname != NUL + && (fputs("balt ", fd) < 0 + || ses_fname(fd, alt, flagp, TRUE) == FAIL)) + return FAIL; + } + // Local mappings and abbreviations. if ((*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS)) && makemap(fd, wp->w_buffer) == FAIL) *** ../vim-8.2.1966/src/testdir/test_buffer.vim 2020-10-25 17:09:46.217011625 +0100 --- src/testdir/test_buffer.vim 2020-11-07 18:11:40.434904330 +0100 *************** *** 374,377 **** --- 374,384 ---- bwipe! SomeNewBuffer endfunc + func Test_balt() + new SomeNewBuffer + balt +3 OtherBuffer + e # + call assert_equal('OtherBuffer', bufname()) + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.1966/src/version.c 2020-11-07 16:58:55.894354883 +0100 --- src/version.c 2020-11-07 18:12:04.898798965 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1967, /**/ -- hundred-and-one symptoms of being an internet addict: 214. Your MCI "Circle of Friends" are all Hayes-compatible. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///