patch 8.2.1967: the session file does not restore the alternate file
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)
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 185033f..aa9fe9b 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2459,6 +2459,7 @@
* 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 @@
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 @@
*/
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 @@
*/
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 @@
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 @@
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 @@
}
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);