diff options
author | James McCoy <jamessan@jamessan.com> | 2017-09-26 15:52:21 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-09-26 16:03:43 -0400 |
commit | 25d4cd7e2830265505b0f6f88e6d08b4954af6eb (patch) | |
tree | bf2ba2eba676036c95e9f32e57a7bc60c13a2fb9 /src/nvim/ex_docmd.c | |
parent | 43da7ea27b3391a9e74c658b90a5ed1cae926d40 (diff) | |
download | rneovim-25d4cd7e2830265505b0f6f88e6d08b4954af6eb.tar.gz rneovim-25d4cd7e2830265505b0f6f88e6d08b4954af6eb.tar.bz2 rneovim-25d4cd7e2830265505b0f6f88e6d08b4954af6eb.zip |
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)
https://github.com/vim/vim/commit/4bebc9a0565670b853d227f81a9a31eafdb47eed
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r-- | src/nvim/ex_docmd.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 5145c65bc7..87d9e10619 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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; } |