comparison src/ex_docmd.c @ 827:fd1b3406fd1c v7.0d02

updated for version 7.0d02
author vimboss
date Wed, 12 Apr 2006 21:52:12 +0000
parents 45fad0f590d0
children 8bebcabccc2c
comparison
equal deleted inserted replaced
826:1cdd2661f34c 827:fd1b3406fd1c
9641 int cnr = 1; 9641 int cnr = 1;
9642 int restore_size = TRUE; 9642 int restore_size = TRUE;
9643 win_T *wp; 9643 win_T *wp;
9644 char_u *sname; 9644 char_u *sname;
9645 win_T *edited_win = NULL; 9645 win_T *edited_win = NULL;
9646 tabpage_T *old_curtab = curtab;
9647 int tabnr;
9646 9648
9647 if (ssop_flags & SSOP_BUFFERS) 9649 if (ssop_flags & SSOP_BUFFERS)
9648 only_save_windows = FALSE; /* Save ALL buffers */ 9650 only_save_windows = FALSE; /* Save ALL buffers */
9649 9651
9650 /* 9652 /*
9746 } 9748 }
9747 } 9749 }
9748 #endif 9750 #endif
9749 9751
9750 /* 9752 /*
9751 * Before creating the window layout, try loading one file. If this is 9753 * May repeat putting Windows for each tab, when "tabpages" is in
9752 * aborted we don't end up with a number of useless windows. 9754 * 'sessionoptions'.
9753 * This may have side effects! (e.g., compressed or network file).
9754 */ 9755 */
9755 for (wp = firstwin; wp != NULL; wp = wp->w_next) 9756 for (tabnr = 1; ; ++tabnr)
9756 { 9757 {
9757 if (ses_do_win(wp) 9758 if ((ssop_flags & SSOP_TABPAGES))
9758 && wp->w_buffer->b_ffname != NULL 9759 {
9759 && !wp->w_buffer->b_help 9760 goto_tabpage(tabnr);
9761 if (tabnr > 1 && put_line(fd, "tabnew") == FAIL)
9762 return FAIL;
9763 }
9764
9765 /*
9766 * Before creating the window layout, try loading one file. If this
9767 * is aborted we don't end up with a number of useless windows.
9768 * This may have side effects! (e.g., compressed or network file).
9769 */
9770 for (wp = firstwin; wp != NULL; wp = wp->w_next)
9771 {
9772 if (ses_do_win(wp)
9773 && wp->w_buffer->b_ffname != NULL
9774 && !wp->w_buffer->b_help
9760 #ifdef FEAT_QUICKFIX 9775 #ifdef FEAT_QUICKFIX
9761 && !bt_nofile(wp->w_buffer) 9776 && !bt_nofile(wp->w_buffer)
9762 #endif 9777 #endif
9763 ) 9778 )
9764 { 9779 {
9765 if (fputs("edit ", fd) < 0 9780 if (fputs("edit ", fd) < 0
9766 || ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL) 9781 || ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL)
9782 return FAIL;
9783 if (!wp->w_arg_idx_invalid)
9784 edited_win = wp;
9785 break;
9786 }
9787 }
9788
9789 /*
9790 * Save current window layout.
9791 */
9792 if (put_line(fd, "set splitbelow splitright") == FAIL)
9793 return FAIL;
9794 if (ses_win_rec(fd, topframe) == FAIL)
9795 return FAIL;
9796 if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL)
9797 return FAIL;
9798 if (!p_spr && put_line(fd, "set nosplitright") == FAIL)
9799 return FAIL;
9800
9801 /*
9802 * Check if window sizes can be restored (no windows omitted).
9803 * Remember the window number of the current window after restoring.
9804 */
9805 nr = 0;
9806 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
9807 {
9808 if (ses_do_win(wp))
9809 ++nr;
9810 else
9811 restore_size = FALSE;
9812 if (curwin == wp)
9813 cnr = nr;
9814 }
9815
9816 /* Go to the first window. */
9817 if (put_line(fd, "wincmd t") == FAIL)
9818 return FAIL;
9819
9820 /*
9821 * If more than one window, see if sizes can be restored.
9822 * First set 'winheight' and 'winwidth' to 1 to avoid the windows being
9823 * resized when moving between windows.
9824 * Do this before restoring the view, so that the topline and the
9825 * cursor can be set. This is done again below.
9826 */
9827 if (put_line(fd, "set winheight=1 winwidth=1") == FAIL)
9828 return FAIL;
9829 if (nr > 1 && ses_winsizes(fd, restore_size) == FAIL)
9830 return FAIL;
9831
9832 /*
9833 * Restore the view of the window (options, file, cursor, etc.).
9834 */
9835 for (wp = firstwin; wp != NULL; wp = wp->w_next)
9836 {
9837 if (!ses_do_win(wp))
9838 continue;
9839 if (put_view(fd, wp, wp != edited_win, &ssop_flags) == FAIL)
9767 return FAIL; 9840 return FAIL;
9768 if (!wp->w_arg_idx_invalid) 9841 if (nr > 1 && put_line(fd, "wincmd w") == FAIL)
9769 edited_win = wp; 9842 return FAIL;
9843 }
9844
9845 /*
9846 * Restore cursor to the current window if it's not the first one.
9847 */
9848 if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0
9849 || put_eol(fd) == FAIL))
9850 return FAIL;
9851
9852 /*
9853 * Wipe out an empty unnamed buffer we started in.
9854 */
9855 if (put_line(fd, "if exists('s:wipebuf')") == FAIL)
9856 return FAIL;
9857 if (put_line(fd, " exe 'bwipe ' . s:wipebuf") == FAIL)
9858 return FAIL;
9859 if (put_line(fd, "endif") == FAIL)
9860 return FAIL;
9861 if (put_line(fd, "unlet! s:wipebuf") == FAIL)
9862 return FAIL;
9863
9864 /*
9865 * Restore window sizes again after jumping around in windows, because
9866 * the current window has a minimum size while others may not.
9867 */
9868 if (nr > 1 && ses_winsizes(fd, restore_size) == FAIL)
9869 return FAIL;
9870
9871 /* Re-apply 'winheight', 'winwidth' and 'shortmess'. */
9872 if (fprintf(fd, "set winheight=%ld winwidth=%ld shortmess=%s",
9873 p_wh, p_wiw, p_shm) < 0 || put_eol(fd) == FAIL)
9874 return FAIL;
9875
9876 /* Don't continue in another tab page when doing only the current one
9877 * or when at the last tab page. */
9878 if (!(ssop_flags & SSOP_TABPAGES) || curtab->tp_next == NULL)
9770 break; 9879 break;
9771 } 9880 }
9772 } 9881
9773 9882 if (ssop_flags & SSOP_TABPAGES)
9774 /* 9883 {
9775 * Save current window layout. 9884 if (valid_tabpage(old_curtab))
9776 */ 9885 goto_tabpage_tp(old_curtab);
9777 if (put_line(fd, "set splitbelow splitright") == FAIL) 9886 if (fprintf(fd, "tabnext %d", tabpage_index(curtab)) < 0
9778 return FAIL; 9887 || put_eol(fd) == FAIL)
9779 if (ses_win_rec(fd, topframe) == FAIL)
9780 return FAIL;
9781 if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL)
9782 return FAIL;
9783 if (!p_spr && put_line(fd, "set nosplitright") == FAIL)
9784 return FAIL;
9785
9786 /*
9787 * Check if window sizes can be restored (no windows omitted).
9788 * Remember the window number of the current window after restoring.
9789 */
9790 nr = 0;
9791 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
9792 {
9793 if (ses_do_win(wp))
9794 ++nr;
9795 else
9796 restore_size = FALSE;
9797 if (curwin == wp)
9798 cnr = nr;
9799 }
9800
9801 /* Go to the first window. */
9802 if (put_line(fd, "wincmd t") == FAIL)
9803 return FAIL;
9804
9805 /*
9806 * If more than one window, see if sizes can be restored.
9807 * First set 'winheight' and 'winwidth' to 1 to avoid the windows being
9808 * resized when moving between windows.
9809 * Do this before restoring the view, so that the topline and the cursor
9810 * can be set. This is done again below.
9811 */
9812 if (put_line(fd, "set winheight=1 winwidth=1") == FAIL)
9813 return FAIL;
9814 if (nr > 1 && ses_winsizes(fd, restore_size) == FAIL)
9815 return FAIL;
9816
9817 /*
9818 * Restore the view of the window (options, file, cursor, etc.).
9819 */
9820 for (wp = firstwin; wp != NULL; wp = wp->w_next)
9821 {
9822 if (!ses_do_win(wp))
9823 continue;
9824 if (put_view(fd, wp, wp != edited_win, &ssop_flags) == FAIL)
9825 return FAIL; 9888 return FAIL;
9826 if (nr > 1 && put_line(fd, "wincmd w") == FAIL) 9889 }
9827 return FAIL; 9890
9828 }
9829
9830 /*
9831 * Restore cursor to the current window if it's not the first one.
9832 */
9833 if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0 || put_eol(fd) == FAIL))
9834 return FAIL;
9835
9836 /*
9837 * Wipe out an empty unnamed buffer we started in.
9838 */
9839 if (put_line(fd, "if exists('s:wipebuf')") == FAIL)
9840 return FAIL;
9841 if (put_line(fd, " exe 'bwipe ' . s:wipebuf") == FAIL)
9842 return FAIL;
9843 if (put_line(fd, "endif") == FAIL)
9844 return FAIL;
9845 if (put_line(fd, "unlet! s:wipebuf") == FAIL)
9846 return FAIL;
9847
9848 /*
9849 * Restore window sizes again after jumping around in windows, because the
9850 * current window has a minimum size while others may not.
9851 */
9852 if (nr > 1 && ses_winsizes(fd, restore_size) == FAIL)
9853 return FAIL;
9854
9855 /* Re-apply 'winheight', 'winwidth' and 'shortmess'. */
9856 if (fprintf(fd, "set winheight=%ld winwidth=%ld shortmess=%s",
9857 p_wh, p_wiw, p_shm) < 0 || put_eol(fd) == FAIL)
9858 return FAIL;
9859 9891
9860 /* 9892 /*
9861 * Lastly, execute the x.vim file if it exists. 9893 * Lastly, execute the x.vim file if it exists.
9862 */ 9894 */
9863 if (put_line(fd, "let s:sx = expand(\"<sfile>:p:r\").\"x.vim\"") == FAIL 9895 if (put_line(fd, "let s:sx = expand(\"<sfile>:p:r\").\"x.vim\"") == FAIL