mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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)
This commit is contained in:
@@ -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
|
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
|
line when the buffer is first entered. Note that other
|
||||||
commands after the + will be ignored.
|
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*
|
:[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516*
|
||||||
:bd[elete][!] [N]
|
:bd[elete][!] [N]
|
||||||
Unload buffer [N] (default: current buffer) and delete it from
|
Unload buffer [N] (default: current buffer) and delete it from
|
||||||
|
@@ -7,30 +7,30 @@ static const unsigned short cmdidxs1[26] =
|
|||||||
{
|
{
|
||||||
/* a */ 0,
|
/* a */ 0,
|
||||||
/* b */ 19,
|
/* b */ 19,
|
||||||
/* c */ 42,
|
/* c */ 43,
|
||||||
/* d */ 108,
|
/* d */ 109,
|
||||||
/* e */ 133,
|
/* e */ 134,
|
||||||
/* f */ 156,
|
/* f */ 157,
|
||||||
/* g */ 173,
|
/* g */ 174,
|
||||||
/* h */ 179,
|
/* h */ 180,
|
||||||
/* i */ 188,
|
/* i */ 189,
|
||||||
/* j */ 207,
|
/* j */ 208,
|
||||||
/* k */ 209,
|
/* k */ 210,
|
||||||
/* l */ 214,
|
/* l */ 215,
|
||||||
/* m */ 276,
|
/* m */ 277,
|
||||||
/* n */ 294,
|
/* n */ 295,
|
||||||
/* o */ 314,
|
/* o */ 315,
|
||||||
/* p */ 326,
|
/* p */ 327,
|
||||||
/* q */ 365,
|
/* q */ 366,
|
||||||
/* r */ 368,
|
/* r */ 369,
|
||||||
/* s */ 388,
|
/* s */ 389,
|
||||||
/* t */ 457,
|
/* t */ 458,
|
||||||
/* u */ 502,
|
/* u */ 503,
|
||||||
/* v */ 513,
|
/* v */ 514,
|
||||||
/* w */ 533,
|
/* w */ 534,
|
||||||
/* x */ 547,
|
/* x */ 548,
|
||||||
/* y */ 557,
|
/* y */ 558,
|
||||||
/* z */ 558
|
/* z */ 559
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -42,7 +42,7 @@ static const unsigned short cmdidxs1[26] =
|
|||||||
static const unsigned char cmdidxs2[26][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 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 },
|
/* 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 },
|
/* 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 },
|
/* 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 },
|
/* 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 }
|
/* 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;
|
||||||
|
@@ -2459,6 +2459,7 @@ theend:
|
|||||||
* ECMD_OLDBUF: use existing buffer if it exists
|
* ECMD_OLDBUF: use existing buffer if it exists
|
||||||
* ECMD_FORCEIT: ! used for Ex command
|
* ECMD_FORCEIT: ! used for Ex command
|
||||||
* ECMD_ADDBUF: don't edit, just add to buffer list
|
* 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
|
* oldwin: Should be "curwin" when editing a new buffer in the current
|
||||||
* window, NULL when splitting the window first. When not NULL info
|
* window, NULL when splitting the window first. When not NULL info
|
||||||
* of the previous buffer for "oldwin" is stored.
|
* of the previous buffer for "oldwin" is stored.
|
||||||
@@ -2555,7 +2556,8 @@ do_ecmd(
|
|||||||
fname_case(sfname, 0); // set correct case for sfname
|
fname_case(sfname, 0); // set correct case for sfname
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL))
|
if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF))
|
||||||
|
&& (ffname == NULL || *ffname == NUL))
|
||||||
goto theend;
|
goto theend;
|
||||||
|
|
||||||
if (ffname == NULL)
|
if (ffname == NULL)
|
||||||
@@ -2584,7 +2586,7 @@ do_ecmd(
|
|||||||
*/
|
*/
|
||||||
if ( ((!other_file && !(flags & ECMD_OLDBUF))
|
if ( ((!other_file && !(flags & ECMD_OLDBUF))
|
||||||
|| (curbuf->b_nwindows == 1
|
|| (curbuf->b_nwindows == 1
|
||||||
&& !(flags & (ECMD_HIDE | ECMD_ADDBUF))))
|
&& !(flags & (ECMD_HIDE | ECMD_ADDBUF | ECMD_ALTBUF))))
|
||||||
&& check_changed(curbuf, (p_awa ? CCGD_AW : 0)
|
&& check_changed(curbuf, (p_awa ? CCGD_AW : 0)
|
||||||
| (other_file ? 0 : CCGD_MULTWIN)
|
| (other_file ? 0 : CCGD_MULTWIN)
|
||||||
| ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0)
|
| ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0)
|
||||||
@@ -2633,7 +2635,7 @@ do_ecmd(
|
|||||||
*/
|
*/
|
||||||
if (other_file)
|
if (other_file)
|
||||||
{
|
{
|
||||||
if (!(flags & ECMD_ADDBUF))
|
if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF)))
|
||||||
{
|
{
|
||||||
if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
|
if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
|
||||||
curwin->w_alt_fnum = curbuf->b_fnum;
|
curwin->w_alt_fnum = curbuf->b_fnum;
|
||||||
@@ -2645,11 +2647,12 @@ do_ecmd(
|
|||||||
buf = buflist_findnr(fnum);
|
buf = buflist_findnr(fnum);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (flags & ECMD_ADDBUF)
|
if (flags & (ECMD_ADDBUF | ECMD_ALTBUF))
|
||||||
{
|
{
|
||||||
// Default the line number to zero to avoid that a wininfo item
|
// Default the line number to zero to avoid that a wininfo item
|
||||||
// is added for the current window.
|
// is added for the current window.
|
||||||
linenr_T tlnum = 0;
|
linenr_T tlnum = 0;
|
||||||
|
buf_T *newbuf;
|
||||||
|
|
||||||
if (command != NULL)
|
if (command != NULL)
|
||||||
{
|
{
|
||||||
@@ -2657,10 +2660,12 @@ do_ecmd(
|
|||||||
if (tlnum <= 0)
|
if (tlnum <= 0)
|
||||||
tlnum = 1L;
|
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.
|
// with the current window.
|
||||||
(void)buflist_new(ffname, sfname, tlnum,
|
newbuf = buflist_new(ffname, sfname, tlnum,
|
||||||
BLN_LISTED | BLN_NOCURWIN);
|
BLN_LISTED | BLN_NOCURWIN);
|
||||||
|
if (newbuf != NULL && (flags & ECMD_ALTBUF))
|
||||||
|
curwin->w_alt_fnum = newbuf->b_fnum;
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
buf = buflist_new(ffname, sfname, 0L,
|
buf = buflist_new(ffname, sfname, 0L,
|
||||||
@@ -2818,7 +2823,7 @@ do_ecmd(
|
|||||||
}
|
}
|
||||||
else // !other_file
|
else // !other_file
|
||||||
{
|
{
|
||||||
if ((flags & ECMD_ADDBUF) || check_fname() == FAIL)
|
if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF)) || check_fname() == FAIL)
|
||||||
goto theend;
|
goto theend;
|
||||||
|
|
||||||
oldbuf = (flags & ECMD_OLDBUF);
|
oldbuf = (flags & ECMD_OLDBUF);
|
||||||
|
@@ -178,6 +178,9 @@ EXCMD(CMD_ball, "ball", ex_buffer_all,
|
|||||||
EXCMD(CMD_badd, "badd", ex_edit,
|
EXCMD(CMD_badd, "badd", ex_edit,
|
||||||
EX_NEEDARG|EX_FILE1|EX_CMDARG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
|
EX_NEEDARG|EX_FILE1|EX_CMDARG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
|
||||||
ADDR_NONE),
|
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,
|
EXCMD(CMD_bdelete, "bdelete", ex_bunload,
|
||||||
EX_BANG|EX_RANGE|EX_BUFNAME|EX_COUNT|EX_EXTRA|EX_TRLBAR,
|
EX_BANG|EX_RANGE|EX_BUFNAME|EX_COUNT|EX_EXTRA|EX_TRLBAR,
|
||||||
ADDR_BUFFERS),
|
ADDR_BUFFERS),
|
||||||
|
@@ -6506,7 +6506,7 @@ ex_open(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":edit", ":badd", ":visual".
|
* ":edit", ":badd", ":balt", ":visual".
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ex_edit(exarg_T *eap)
|
ex_edit(exarg_T *eap)
|
||||||
@@ -6621,7 +6621,8 @@ do_exedit(
|
|||||||
+ (eap->forceit ? ECMD_FORCEIT : 0)
|
+ (eap->forceit ? ECMD_FORCEIT : 0)
|
||||||
// after a split we can use an existing buffer
|
// after a split we can use an existing buffer
|
||||||
+ (old_curwin != NULL ? ECMD_OLDBUF : 0)
|
+ (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)
|
, old_curwin == NULL ? curwin : NULL) == FAIL)
|
||||||
{
|
{
|
||||||
// Editing the file failed. If the window was split, close it.
|
// 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.
|
* Evaluate cmdline variables.
|
||||||
*
|
*
|
||||||
* change '%' to curbuf->b_ffname
|
* 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
|
||||||
* '<cWORD>' to WORD under the cursor
|
* '<cWORD>' to WORD under the cursor
|
||||||
* '<cexpr>' to C-expression under the cursor
|
* '<cexpr>' to C-expression under the cursor
|
||||||
|
@@ -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.
|
// Local mappings and abbreviations.
|
||||||
if ((*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS))
|
if ((*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS))
|
||||||
&& makemap(fd, wp->w_buffer) == FAIL)
|
&& makemap(fd, wp->w_buffer) == FAIL)
|
||||||
|
@@ -374,4 +374,11 @@ func Test_badd_options()
|
|||||||
bwipe! SomeNewBuffer
|
bwipe! SomeNewBuffer
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_balt()
|
||||||
|
new SomeNewBuffer
|
||||||
|
balt +3 OtherBuffer
|
||||||
|
e #
|
||||||
|
call assert_equal('OtherBuffer', bufname())
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1967,
|
||||||
/**/
|
/**/
|
||||||
1966,
|
1966,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -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_OLDBUF 0x04 // use existing buffer if it exists
|
||||||
#define ECMD_FORCEIT 0x08 // ! used in Ex command
|
#define ECMD_FORCEIT 0x08 // ! used in Ex command
|
||||||
#define ECMD_ADDBUF 0x10 // don't edit, just add to buffer list
|
#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()
|
// for lnum argument in do_ecmd()
|
||||||
#define ECMD_LASTL (linenr_T)0 // use last position in loaded file
|
#define ECMD_LASTL (linenr_T)0 // use last position in loaded file
|
||||||
|
Reference in New Issue
Block a user