@@ -11126,7 +11126,7 @@ static int ses_do_frame(frame_T *fr);
1112611126static int ses_do_win (win_T * wp );
1112711127static int ses_arglist (FILE * fd , char * cmd , garray_T * gap , int fullname , unsigned * flagp );
1112811128static int ses_put_fname (FILE * fd , char_u * name , unsigned * flagp );
11129- static int ses_fname (FILE * fd , buf_T * buf , unsigned * flagp );
11129+ static int ses_fname (FILE * fd , buf_T * buf , unsigned * flagp , int add_eol );
1113011130
1113111131/*
1113211132 * Write openfile commands for the current buffers to an .exrc file.
@@ -11222,7 +11222,7 @@ makeopens(
1122211222 {
1122311223 if (fprintf (fd , "badd +%ld " , buf -> b_wininfo == NULL ? 1L
1122411224 : buf -> b_wininfo -> wi_fpos .lnum ) < 0
11225- || ses_fname (fd , buf , & ssop_flags ) == FAIL )
11225+ || ses_fname (fd , buf , & ssop_flags , TRUE ) == FAIL )
1122611226 return FAIL ;
1122711227 }
1122811228 }
@@ -11324,7 +11324,8 @@ makeopens(
1132411324 )
1132511325 {
1132611326 if (fputs (need_tabnew ? "tabedit " : "edit " , fd ) < 0
11327- || ses_fname (fd , wp -> w_buffer , & ssop_flags ) == FAIL )
11327+ || ses_fname (fd , wp -> w_buffer , & ssop_flags , TRUE)
11328+ == FAIL )
1132811329 return FAIL ;
1132911330 need_tabnew = FALSE;
1133011331 if (!wp -> w_arg_idx_invalid )
@@ -11671,9 +11672,20 @@ put_view(
1167111672 /*
1167211673 * Editing a file in this buffer: use ":edit file".
1167311674 * This may have side effects! (e.g., compressed or network file).
11675+ *
11676+ * Note, if a buffer for that file already exists, use :badd to
11677+ * edit that buffer, to not lose folding information (:edit resets
11678+ * folds in other buffers)
1167411679 */
11675- if (fputs ("edit " , fd ) < 0
11676- || ses_fname (fd , wp -> w_buffer , flagp ) == FAIL )
11680+ if (fputs ("if bufexists('" , fd ) < 0
11681+ || ses_fname (fd , wp -> w_buffer , flagp , FALSE) == FAIL
11682+ || fputs ("') | buffer " , fd ) < 0
11683+ || ses_fname (fd , wp -> w_buffer , flagp , FALSE) == FAIL
11684+ || fputs (" | else | edit " , fd ) < 0
11685+ || ses_fname (fd , wp -> w_buffer , flagp , FALSE) == FAIL
11686+ || fputs (" | endif" , fd ) < 0
11687+ ||
11688+ put_eol (fd ) == FAIL )
1167711689 return FAIL ;
1167811690 }
1167911691 else
@@ -11686,7 +11698,7 @@ put_view(
1168611698 {
1168711699 /* The buffer does have a name, but it's not a file name. */
1168811700 if (fputs ("file " , fd ) < 0
11689- || ses_fname (fd , wp -> w_buffer , flagp ) == FAIL )
11701+ || ses_fname (fd , wp -> w_buffer , flagp , TRUE ) == FAIL )
1169011702 return FAIL ;
1169111703 }
1169211704#endif
@@ -11858,11 +11870,11 @@ ses_arglist(
1185811870
1185911871/*
1186011872 * Write a buffer name to the session file.
11861- * Also ends the line.
11873+ * Also ends the line, if "add_eol" is TRUE .
1186211874 * Returns FAIL if writing fails.
1186311875 */
1186411876 static int
11865- ses_fname (FILE * fd , buf_T * buf , unsigned * flagp )
11877+ ses_fname (FILE * fd , buf_T * buf , unsigned * flagp , int add_eol )
1186611878{
1186711879 char_u * name ;
1186811880
@@ -11881,7 +11893,8 @@ ses_fname(FILE *fd, buf_T *buf, unsigned *flagp)
1188111893 name = buf -> b_sfname ;
1188211894 else
1188311895 name = buf -> b_ffname ;
11884- if (ses_put_fname (fd , name , flagp ) == FAIL || put_eol (fd ) == FAIL )
11896+ if (ses_put_fname (fd , name , flagp ) == FAIL
11897+ || (add_eol && put_eol (fd ) == FAIL ))
1188511898 return FAIL ;
1188611899 return OK ;
1188711900}
0 commit comments