comparison src/session.c @ 27122:4fd87205ca80 v8.2.4090

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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 14 Jan 2022 14:30:03 +0100
parents 86f8718c643d
children f1c00b8085f6
comparison
equal deleted inserted replaced
27121:0c4b6fb98f76 27122:4fd87205ca80
688 688
689 // Now save the current files, current buffer first. 689 // Now save the current files, current buffer first.
690 if (put_line(fd, "set shortmess=aoO") == FAIL) 690 if (put_line(fd, "set shortmess=aoO") == FAIL)
691 goto fail; 691 goto fail;
692 692
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
693 // the global argument list 715 // the global argument list
694 if (ses_arglist(fd, "argglobal", &global_alist.al_ga, 716 if (ses_arglist(fd, "argglobal", &global_alist.al_ga,
695 !(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL) 717 !(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL)
696 goto fail; 718 goto fail;
697 719
739 tabpage_T *tp; 761 tabpage_T *tp;
740 762
741 // Similar to ses_win_rec() below, populate the tab pages first so 763 // Similar to ses_win_rec() below, populate the tab pages first so
742 // later local options won't be copied to the new tabs. 764 // later local options won't be copied to the new tabs.
743 FOR_ALL_TABPAGES(tp) 765 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)
745 goto fail; 771 goto fail;
746 if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL) 772 if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL)
747 goto fail; 773 goto fail;
748 } 774 }
749 for (tabnr = 1; ; ++tabnr) 775 for (tabnr = 1; ; ++tabnr)
916 || put_eol(fd) == FAIL) 942 || put_eol(fd) == FAIL)
917 goto fail; 943 goto fail;
918 } 944 }
919 if (restore_stal && put_line(fd, "set stal=1") == FAIL) 945 if (restore_stal && put_line(fd, "set stal=1") == FAIL)
920 goto fail; 946 goto fail;
921
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 947
945 // Wipe out an empty unnamed buffer we started in. 948 // Wipe out an empty unnamed buffer we started in.
946 if (put_line(fd, "if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0") 949 if (put_line(fd, "if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0")
947 == FAIL) 950 == FAIL)
948 goto fail; 951 goto fail;