vim-patch:8.0.1024

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 vim/vim#1958)

4bebc9a056
This commit is contained in:
James McCoy
2017-09-26 15:52:21 -04:00
parent 43da7ea27b
commit 25d4cd7e28
3 changed files with 209 additions and 17 deletions

View File

@@ -8813,7 +8813,7 @@ makeopens (
buf->b_wininfo == NULL ?
(int64_t)1L :
(int64_t)buf->b_wininfo->wi_fpos.lnum) < 0
|| ses_fname(fd, buf, &ssop_flags) == FAIL)
|| ses_fname(fd, buf, &ssop_flags, true) == FAIL)
return FAIL;
}
}
@@ -8885,7 +8885,7 @@ makeopens (
&& !bt_nofile(wp->w_buffer)
) {
if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0
|| ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL)
|| ses_fname(fd, wp->w_buffer, &ssop_flags, true) == FAIL)
return FAIL;
need_tabnew = FALSE;
if (!wp->w_arg_idx_invalid)
@@ -9223,21 +9223,30 @@ put_view (
if (wp->w_buffer->b_ffname != NULL
&& (!bt_nofile(wp->w_buffer) || wp->w_buffer->terminal)
) {
/*
* Editing a file in this buffer: use ":edit file".
* This may have side effects! (e.g., compressed or network file).
*/
if (fputs("edit ", fd) < 0
|| ses_fname(fd, wp->w_buffer, flagp) == FAIL)
// Editing a file in this buffer: use ":edit file".
// This may have side effects! (e.g., compressed or network file).
//
// Note, if a buffer for that file already exists, use :badd to
// edit that buffer, to not lose folding information (:edit resets
// folds in other buffers)
if (fputs("if bufexists('", fd) < 0
|| ses_fname(fd, wp->w_buffer, flagp, false) == FAIL
|| fputs("') | buffer ", fd) < 0
|| ses_fname(fd, wp->w_buffer, flagp, false) == FAIL
|| fputs(" | else | edit ", fd) < 0
|| ses_fname(fd, wp->w_buffer, flagp, false) == FAIL
|| fputs(" | endif", fd) < 0
|| put_eol(fd) == FAIL) {
return FAIL;
}
} else {
/* No file in this buffer, just make it empty. */
if (put_line(fd, "enew") == FAIL)
return FAIL;
if (wp->w_buffer->b_ffname != NULL) {
/* The buffer does have a name, but it's not a file name. */
// The buffer does have a name, but it's not a file name.
if (fputs("file ", fd) < 0
|| ses_fname(fd, wp->w_buffer, flagp) == FAIL)
|| ses_fname(fd, wp->w_buffer, flagp, true) == FAIL)
return FAIL;
}
do_cursor = FALSE;
@@ -9391,12 +9400,10 @@ ses_arglist (
return OK;
}
/*
* Write a buffer name to the session file.
* Also ends the line.
* Returns FAIL if writing fails.
*/
static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp)
/// Write a buffer name to the session file.
/// Also ends the line, if "add_eol" is true.
/// Returns FAIL if writing fails.
static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, bool add_eol)
{
char_u *name;
@@ -9413,8 +9420,10 @@ static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp)
name = buf->b_sfname;
else
name = buf->b_ffname;
if (ses_put_fname(fd, name, flagp) == FAIL || put_eol(fd) == FAIL)
if (ses_put_fname(fd, name, flagp) == FAIL
|| (add_eol && put_eol(fd) == FAIL)) {
return FAIL;
}
return OK;
}