]> granicus.if.org Git - vim/commitdiff
patch 8.2.1967: the session file does not restore the alternate file v8.2.1967
authorBram Moolenaar <Bram@vim.org>
Sat, 7 Nov 2020 17:41:10 +0000 (18:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 7 Nov 2020 17:41:10 +0000 (18:41 +0100)
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)

runtime/doc/windows.txt
src/ex_cmdidxs.h
src/ex_cmds.c
src/ex_cmds.h
src/ex_docmd.c
src/session.c
src/testdir/test_buffer.vim
src/version.c
src/vim.h

index 5f842c8e078c0abe7b609f95c7b05a9c592291fa..2a1c10bc5f44e190be8caf683e32486a41996e6d 100644 (file)
@@ -1,4 +1,4 @@
-*windows.txt*   For Vim version 8.2.  Last change: 2020 Sep 02
+*windows.txt*   For Vim version 8.2.  Last change: 2020 Nov 07
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1119,6 +1119,11 @@ list of buffers. |unlisted-buffer|
                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
index 2e59d2c502ed00b00e0153cf64a899fb2e31e184..290e9fa6b8f240aee75f9d802c83bcb94bfeca82 100644 (file)
@@ -7,30 +7,30 @@ static const unsigned short cmdidxs1[26] =
 {
   /* 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
+  /* 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,7 +42,7 @@ static const unsigned short cmdidxs1[26] =
 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 },
+  /* 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,4 +69,4 @@ static const unsigned char cmdidxs2[26][26] =
   /* 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;
+static const int command_count = 574;
index 185033f1d5520e603b704c4cebd6aaa26271663b..aa9fe9b0a0e836eba38d53f9a968096e21cf133f 100644 (file)
@@ -2459,6 +2459,7 @@ theend:
  *      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,7 +2556,8 @@ do_ecmd(
            fname_case(sfname, 0);   // set correct case for sfname
 #endif
 
-       if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL))
+       if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF))
+                                        && (ffname == NULL || *ffname == NUL))
            goto theend;
 
        if (ffname == NULL)
@@ -2584,7 +2586,7 @@ do_ecmd(
      */
     if (  ((!other_file && !(flags & ECMD_OLDBUF))
            || (curbuf->b_nwindows == 1
-               && !(flags & (ECMD_HIDE | ECMD_ADDBUF))))
+               && !(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,7 +2635,7 @@ do_ecmd(
      */
     if (other_file)
     {
-       if (!(flags & ECMD_ADDBUF))
+       if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF)))
        {
            if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
                curwin->w_alt_fnum = curbuf->b_fnum;
@@ -2645,11 +2647,12 @@ do_ecmd(
            buf = buflist_findnr(fnum);
        else
        {
-           if (flags & ECMD_ADDBUF)
+           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,10 +2660,12 @@ do_ecmd(
                    if (tlnum <= 0)
                        tlnum = 1L;
                }
-               // Add BLN_NOCURWIN to avoid a new wininfo items is assocated
+               // Add BLN_NOCURWIN to avoid a new wininfo items are assocated
                // with the current window.
-               (void)buflist_new(ffname, sfname, tlnum,
+               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,7 +2823,7 @@ do_ecmd(
     }
     else // !other_file
     {
-       if ((flags & ECMD_ADDBUF) || check_fname() == FAIL)
+       if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF)) || check_fname() == FAIL)
            goto theend;
 
        oldbuf = (flags & ECMD_OLDBUF);
index d53b6df6d222a6cf43413c7c4f9c14b8eab60647..4fe62cafe87c88b0559407d93961c83a710f54e8 100644 (file)
@@ -178,6 +178,9 @@ EXCMD(CMD_ball,             "ball",         ex_buffer_all,
 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),
index 290dcee26a9e71026be66f041ab49ce23a21da54..627dae71e9578d7f17aadbf3ff9e258f78603a7b 100644 (file)
@@ -6506,7 +6506,7 @@ ex_open(exarg_T *eap)
 }
 
 /*
- * ":edit", ":badd", ":visual".
+ * ":edit", ":badd", ":balt", ":visual".
  */
     static void
 ex_edit(exarg_T *eap)
@@ -6621,7 +6621,8 @@ do_exedit(
                    + (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_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,7 +8473,7 @@ find_cmdline_var(char_u *src, int *usedlen)
  * Evaluate cmdline variables.
  *
  * change '%'      to curbuf->b_ffname
- *       '#'       to curwin->w_altfile
+ *       '#'       to curwin->w_alt_fnum
  *       '<cword>' to word under the cursor
  *       '<cWORD>' to WORD under the cursor
  *       '<cexpr>' to C-expression under the cursor
index 44976e8cf45dc224a3d9289c9db6c8c8702fe508..9731bd3a460d7a17a428c8e94bb6086e176a0446 100644 (file)
@@ -397,6 +397,19 @@ put_view(
        }
     }
 
+    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)
index a743f1808cb2d1a93ac93600b3d489b90532f81d..4e8a79f0c68f478b59224d7acf87231f50fda047 100644 (file)
@@ -374,4 +374,11 @@ func Test_badd_options()
   bwipe! SomeNewBuffer
 endfunc
 
+func Test_balt()
+  new SomeNewBuffer
+  balt +3 OtherBuffer
+  e #
+  call assert_equal('OtherBuffer', bufname())
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 1fbae19e06206d6767edad196c3da9a8d0272fd8..fe89862d47bbce3b77adfa091b25af67470c11ad 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1967,
 /**/
     1966,
 /**/
index 289ef3cc8a515bdd92dc4be6e160984620654adb..d2e22fef0940f3a33a21a8ed167ac709130c68a0 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1029,6 +1029,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #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