Skip to content

Commit 4bebc9a

Browse files
committed
patch 8.0.1024: folds lost when session file has a buffer in two windows
Problem: Manual folds are lost when a session file has the same buffer in two windows. (Jeansen) Solution: Use ":edit" only once. (Christian Brabandt, closes #1958)
1 parent a539f4f commit 4bebc9a

3 files changed

Lines changed: 55 additions & 9 deletions

File tree

src/ex_docmd.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11099,7 +11099,7 @@ static int ses_do_frame(frame_T *fr);
1109911099
static int ses_do_win(win_T *wp);
1110011100
static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp);
1110111101
static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp);
11102-
static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp);
11102+
static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol);
1110311103

1110411104
/*
1110511105
* Write openfile commands for the current buffers to an .exrc file.
@@ -11195,7 +11195,7 @@ makeopens(
1119511195
{
1119611196
if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
1119711197
: buf->b_wininfo->wi_fpos.lnum) < 0
11198-
|| ses_fname(fd, buf, &ssop_flags) == FAIL)
11198+
|| ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL)
1119911199
return FAIL;
1120011200
}
1120111201
}
@@ -11289,7 +11289,8 @@ makeopens(
1128911289
)
1129011290
{
1129111291
if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0
11292-
|| ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL)
11292+
|| ses_fname(fd, wp->w_buffer, &ssop_flags, TRUE)
11293+
== FAIL)
1129311294
return FAIL;
1129411295
need_tabnew = FALSE;
1129511296
if (!wp->w_arg_idx_invalid)
@@ -11636,9 +11637,20 @@ put_view(
1163611637
/*
1163711638
* Editing a file in this buffer: use ":edit file".
1163811639
* This may have side effects! (e.g., compressed or network file).
11640+
*
11641+
* Note, if a buffer for that file already exists, use :badd to
11642+
* edit that buffer, to not lose folding information (:edit resets
11643+
* folds in other buffers)
1163911644
*/
11640-
if (fputs("edit ", fd) < 0
11641-
|| ses_fname(fd, wp->w_buffer, flagp) == FAIL)
11645+
if (fputs("if bufexists('", fd) < 0
11646+
|| ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
11647+
|| fputs("') | buffer ", fd) < 0
11648+
|| ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
11649+
|| fputs(" | else | edit ", fd) < 0
11650+
|| ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
11651+
|| fputs(" | endif", fd) < 0
11652+
||
11653+
put_eol(fd) == FAIL)
1164211654
return FAIL;
1164311655
}
1164411656
else
@@ -11651,7 +11663,7 @@ put_view(
1165111663
{
1165211664
/* The buffer does have a name, but it's not a file name. */
1165311665
if (fputs("file ", fd) < 0
11654-
|| ses_fname(fd, wp->w_buffer, flagp) == FAIL)
11666+
|| ses_fname(fd, wp->w_buffer, flagp, TRUE) == FAIL)
1165511667
return FAIL;
1165611668
}
1165711669
#endif
@@ -11823,11 +11835,11 @@ ses_arglist(
1182311835

1182411836
/*
1182511837
* Write a buffer name to the session file.
11826-
* Also ends the line.
11838+
* Also ends the line, if "add_eol" is TRUE.
1182711839
* Returns FAIL if writing fails.
1182811840
*/
1182911841
static int
11830-
ses_fname(FILE *fd, buf_T *buf, unsigned *flagp)
11842+
ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol)
1183111843
{
1183211844
char_u *name;
1183311845

@@ -11846,7 +11858,8 @@ ses_fname(FILE *fd, buf_T *buf, unsigned *flagp)
1184611858
name = buf->b_sfname;
1184711859
else
1184811860
name = buf->b_ffname;
11849-
if (ses_put_fname(fd, name, flagp) == FAIL || put_eol(fd) == FAIL)
11861+
if (ses_put_fname(fd, name, flagp) == FAIL
11862+
|| (add_eol && put_eol(fd) == FAIL))
1185011863
return FAIL;
1185111864
return OK;
1185211865
}

src/testdir/test_mksession.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,36 @@ func Test_mksession_arglist()
121121
argdel *
122122
endfunc
123123

124+
func Test_mksession_one_buffer_two_windows()
125+
edit Xtest1
126+
new Xtest2
127+
split
128+
mksession! Xtest_mks.out
129+
let lines = readfile('Xtest_mks.out')
130+
let count1 = 0
131+
let count2 = 0
132+
let count2buf = 0
133+
for line in lines
134+
if line =~ 'edit \f*Xtest1$'
135+
let count1 += 1
136+
endif
137+
if line =~ 'edit \f\{-}Xtest2'
138+
let count2 += 1
139+
endif
140+
if line =~ 'buffer \f\{-}Xtest2'
141+
let count2buf += 1
142+
endif
143+
endfor
144+
call assert_equal(1, count1, 'Xtest1 count')
145+
call assert_equal(2, count2, 'Xtest2 count')
146+
call assert_equal(2, count2buf, 'Xtest2 buffer count')
147+
148+
close
149+
bwipe!
150+
!cp Xtest_mks.out /tmp
151+
call delete('Xtest_mks.out')
152+
endfunc
153+
154+
124155

125156
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1024,
772774
/**/
773775
1023,
774776
/**/

0 commit comments

Comments
 (0)