• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision4fd87205ca807ddbdf65b97619099d2640617f5f (tree)
Zeit2022-01-14 22:30:03
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.4090: after restoring a session buffer order can be quite different

Commit: https://github.com/vim/vim/commit/26ebf1f036517ebeacf571c333a83cca7e13bbe2
Author: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Date: Fri Jan 14 13:19:43 2022 +0000

patch 8.2.4090: after restoring a session buffer order can be quite different
Problem: After restoring a session buffer order can be quite different.
Solution: Create buffers first. (Evgeni Chasnovski, closes https://github.com/vim/vim/issues/9520)

Ändern Zusammenfassung

Diff

diff -r 0c4b6fb98f76 -r 4fd87205ca80 src/session.c
--- a/src/session.c Fri Jan 14 13:15:05 2022 +0100
+++ b/src/session.c Fri Jan 14 14:30:03 2022 +0100
@@ -690,6 +690,28 @@
690690 if (put_line(fd, "set shortmess=aoO") == FAIL)
691691 goto fail;
692692
693+ // Put all buffers into the buffer list.
694+ // Do it very early to preserve buffer order after loading session (which
695+ // can be disrupted by prior `edit` or `tabedit` calls).
696+ FOR_ALL_BUFFERS(buf)
697+ {
698+ if (!(only_save_windows && buf->b_nwindows == 0)
699+ && !(buf->b_help && !(ssop_flags & SSOP_HELP))
700+#ifdef FEAT_TERMINAL
701+ // Skip terminal buffers: finished ones are not useful, others
702+ // will be resurrected and result in a new buffer.
703+ && !bt_terminal(buf)
704+#endif
705+ && buf->b_fname != NULL
706+ && buf->b_p_bl)
707+ {
708+ if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
709+ : buf->b_wininfo->wi_fpos.lnum) < 0
710+ || ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL)
711+ goto fail;
712+ }
713+ }
714+
693715 // the global argument list
694716 if (ses_arglist(fd, "argglobal", &global_alist.al_ga,
695717 !(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL)
@@ -741,7 +763,11 @@
741763 // Similar to ses_win_rec() below, populate the tab pages first so
742764 // later local options won't be copied to the new tabs.
743765 FOR_ALL_TABPAGES(tp)
744- if (tp->tp_next != NULL && put_line(fd, "tabnew") == FAIL)
766+ // Use `bufhidden=wipe` to remove empty "placeholder" buffers once
767+ // they are not needed. This prevents creating extra buffers (see
768+ // cause of patch 8.1.0829)
769+ if (tp->tp_next != NULL
770+ && put_line(fd, "tabnew +setlocal\\ bufhidden=wipe") == FAIL)
745771 goto fail;
746772 if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL)
747773 goto fail;
@@ -919,29 +945,6 @@
919945 if (restore_stal && put_line(fd, "set stal=1") == FAIL)
920946 goto fail;
921947
922- // Now put the remaining buffers into the buffer list.
923- // This is near the end, so that when 'hidden' is set we don't create extra
924- // buffers. If the buffer was already created with another command the
925- // ":badd" will have no effect.
926- FOR_ALL_BUFFERS(buf)
927- {
928- if (!(only_save_windows && buf->b_nwindows == 0)
929- && !(buf->b_help && !(ssop_flags & SSOP_HELP))
930-#ifdef FEAT_TERMINAL
931- // Skip terminal buffers: finished ones are not useful, others
932- // will be resurrected and result in a new buffer.
933- && !bt_terminal(buf)
934-#endif
935- && buf->b_fname != NULL
936- && buf->b_p_bl)
937- {
938- if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
939- : buf->b_wininfo->wi_fpos.lnum) < 0
940- || ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL)
941- goto fail;
942- }
943- }
944-
945948 // Wipe out an empty unnamed buffer we started in.
946949 if (put_line(fd, "if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0")
947950 == FAIL)
diff -r 0c4b6fb98f76 -r 4fd87205ca80 src/testdir/test_mksession.vim
--- a/src/testdir/test_mksession.vim Fri Jan 14 13:15:05 2022 +0100
+++ b/src/testdir/test_mksession.vim Fri Jan 14 14:30:03 2022 +0100
@@ -362,6 +362,31 @@
362362 set hidden&
363363 endfunc
364364
365+func Test_mksession_buffer_order()
366+ %bwipe!
367+ e Xfoo | e Xbar | e Xbaz | e Xqux
368+ bufdo write
369+ mksession! Xtest_mks.out
370+
371+ " Verify that loading the session preserves order of buffers
372+ %bwipe!
373+ source Xtest_mks.out
374+
375+ let s:buf_info = getbufinfo()
376+ call assert_true(s:buf_info[0]['name'] =~# 'Xfoo$')
377+ call assert_true(s:buf_info[1]['name'] =~# 'Xbar$')
378+ call assert_true(s:buf_info[2]['name'] =~# 'Xbaz$')
379+ call assert_true(s:buf_info[3]['name'] =~# 'Xqux$')
380+
381+ " Clean up.
382+ call delete('Xfoo')
383+ call delete('Xbar')
384+ call delete('Xbaz')
385+ call delete('Xqux')
386+ call delete('Xtest_mks.out')
387+ %bwipe!
388+endfunc
389+
365390 if has('extra_search')
366391
367392 func Test_mksession_hlsearch()
diff -r 0c4b6fb98f76 -r 4fd87205ca80 src/version.c
--- a/src/version.c Fri Jan 14 13:15:05 2022 +0100
+++ b/src/version.c Fri Jan 14 14:30:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4090,
755+/**/
754756 4089,
755757 /**/
756758 4088,
Show on old repository browser