Skip to content

Commit d39e275

Browse files
committed
patch 8.1.0829: when 'hidden' is set session creates extra buffers
Problem: When 'hidden' is set session creates extra buffers. Solution: Move :badd commands to the end. (Jason Franklin)
1 parent 6aba96d commit d39e275

3 files changed

Lines changed: 48 additions & 20 deletions

File tree

src/ex_docmd.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11280,26 +11280,6 @@ makeopens(
1128011280
if (put_line(fd, "set shortmess=aoO") == FAIL)
1128111281
return FAIL;
1128211282

11283-
/* Now put the other buffers into the buffer list */
11284-
FOR_ALL_BUFFERS(buf)
11285-
{
11286-
if (!(only_save_windows && buf->b_nwindows == 0)
11287-
&& !(buf->b_help && !(ssop_flags & SSOP_HELP))
11288-
#ifdef FEAT_TERMINAL
11289-
/* skip terminal buffers: finished ones are not useful, others
11290-
* will be resurrected and result in a new buffer */
11291-
&& !bt_terminal(buf)
11292-
#endif
11293-
&& buf->b_fname != NULL
11294-
&& buf->b_p_bl)
11295-
{
11296-
if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
11297-
: buf->b_wininfo->wi_fpos.lnum) < 0
11298-
|| ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL)
11299-
return FAIL;
11300-
}
11301-
}
11302-
1130311283
/* the global argument list */
1130411284
if (ses_arglist(fd, "argglobal", &global_alist.al_ga,
1130511285
!(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL)
@@ -11515,6 +11495,29 @@ makeopens(
1151511495
if (restore_stal && put_line(fd, "set stal=1") == FAIL)
1151611496
return FAIL;
1151711497

11498+
// Now put the remaining buffers into the buffer list.
11499+
// This is near the end, so that when 'hidden' is set we don't create extra
11500+
// buffers. If the buffer was already created with another command the
11501+
// ":badd" will have no effect.
11502+
FOR_ALL_BUFFERS(buf)
11503+
{
11504+
if (!(only_save_windows && buf->b_nwindows == 0)
11505+
&& !(buf->b_help && !(ssop_flags & SSOP_HELP))
11506+
#ifdef FEAT_TERMINAL
11507+
// Skip terminal buffers: finished ones are not useful, others
11508+
// will be resurrected and result in a new buffer.
11509+
&& !bt_terminal(buf)
11510+
#endif
11511+
&& buf->b_fname != NULL
11512+
&& buf->b_p_bl)
11513+
{
11514+
if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
11515+
: buf->b_wininfo->wi_fpos.lnum) < 0
11516+
|| ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL)
11517+
return FAIL;
11518+
}
11519+
}
11520+
1151811521
/*
1151911522
* Wipe out an empty unnamed buffer we started in.
1152011523
*/

src/testdir/test_mksession.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,29 @@ func Test_mksession_blank_tabs()
225225
call delete('Xtest_mks.out')
226226
endfunc
227227

228+
func Test_mksession_buffer_count()
229+
set hidden
230+
231+
" Edit exactly three files in the current session.
232+
%bwipe!
233+
e Xfoo | tabe Xbar | tabe Xbaz
234+
tabdo write
235+
mksession! Xtest_mks.out
236+
237+
" Verify that loading the session does not create additional buffers.
238+
%bwipe!
239+
source Xtest_mks.out
240+
call assert_equal(3, len(getbufinfo()))
241+
242+
" Clean up.
243+
call delete('Xfoo')
244+
call delete('Xbar')
245+
call delete('Xbaz')
246+
call delete('Xtest_mks.out')
247+
%bwipe!
248+
set hidden&
249+
endfunc
250+
228251
if has('extra_search')
229252

230253
func Test_mksession_hlsearch()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ static char *(features[]) =
783783

784784
static int included_patches[] =
785785
{ /* Add new patch number below this line */
786+
/**/
787+
829,
786788
/**/
787789
828,
788790
/**/

0 commit comments

Comments
 (0)