To: vim_dev@googlegroups.com Subject: Patch 8.0.1024 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ 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 #1958) Files: src/ex_docmd.c, src/testdir/test_mksession.vim *** ../vim-8.0.1023/src/ex_docmd.c 2017-08-17 16:55:08.637414759 +0200 --- src/ex_docmd.c 2017-08-30 20:56:28.636685384 +0200 *************** *** 11099,11105 **** static int ses_do_win(win_T *wp); static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp); static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp); ! static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp); /* * Write openfile commands for the current buffers to an .exrc file. --- 11099,11105 ---- static int ses_do_win(win_T *wp); static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp); static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp); ! static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol); /* * Write openfile commands for the current buffers to an .exrc file. *************** *** 11195,11201 **** { if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L : buf->b_wininfo->wi_fpos.lnum) < 0 ! || ses_fname(fd, buf, &ssop_flags) == FAIL) return FAIL; } } --- 11195,11201 ---- { if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L : buf->b_wininfo->wi_fpos.lnum) < 0 ! || ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL) return FAIL; } } *************** *** 11289,11295 **** ) { if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0 ! || ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL) return FAIL; need_tabnew = FALSE; if (!wp->w_arg_idx_invalid) --- 11289,11296 ---- ) { if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0 ! || ses_fname(fd, wp->w_buffer, &ssop_flags, TRUE) ! == FAIL) return FAIL; need_tabnew = FALSE; if (!wp->w_arg_idx_invalid) *************** *** 11636,11644 **** /* * 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) return FAIL; } else --- 11637,11656 ---- /* * 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 *************** *** 11651,11657 **** { /* 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) return FAIL; } #endif --- 11663,11669 ---- { /* 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, TRUE) == FAIL) return FAIL; } #endif *************** *** 11823,11833 **** /* * 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) { char_u *name; --- 11835,11845 ---- /* * 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, int add_eol) { char_u *name; *************** *** 11846,11852 **** name = buf->b_sfname; else name = buf->b_ffname; ! if (ses_put_fname(fd, name, flagp) == FAIL || put_eol(fd) == FAIL) return FAIL; return OK; } --- 11858,11865 ---- name = buf->b_sfname; else name = buf->b_ffname; ! if (ses_put_fname(fd, name, flagp) == FAIL ! || (add_eol && put_eol(fd) == FAIL)) return FAIL; return OK; } *** ../vim-8.0.1023/src/testdir/test_mksession.vim 2017-02-01 22:52:38.747796468 +0100 --- src/testdir/test_mksession.vim 2017-08-30 21:03:56.233601533 +0200 *************** *** 121,125 **** --- 121,156 ---- argdel * endfunc + func Test_mksession_one_buffer_two_windows() + edit Xtest1 + new Xtest2 + split + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let count1 = 0 + let count2 = 0 + let count2buf = 0 + for line in lines + if line =~ 'edit \f*Xtest1$' + let count1 += 1 + endif + if line =~ 'edit \f\{-}Xtest2' + let count2 += 1 + endif + if line =~ 'buffer \f\{-}Xtest2' + let count2buf += 1 + endif + endfor + call assert_equal(1, count1, 'Xtest1 count') + call assert_equal(2, count2, 'Xtest2 count') + call assert_equal(2, count2buf, 'Xtest2 buffer count') + + close + bwipe! + !cp Xtest_mks.out /tmp + call delete('Xtest_mks.out') + endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.0.1023/src/version.c 2017-08-30 20:33:51.758040889 +0200 --- src/version.c 2017-08-30 20:50:09.875288990 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 1024, /**/ -- On the other hand, you have different fingers. -- Steven Wright /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///