1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read a list of people who contributed.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
13 # include <fcntl.h> /* for chdir() */
16 static int path_is_url
__ARGS((char_u
*p
));
17 #if defined(FEAT_WINDOWS) || defined(PROTO)
18 static int win_split_ins
__ARGS((int size
, int flags
, win_T
*newwin
, int dir
));
19 static void win_init
__ARGS((win_T
*newp
, win_T
*oldp
));
20 static void frame_comp_pos
__ARGS((frame_T
*topfrp
, int *row
, int *col
));
21 static void frame_setheight
__ARGS((frame_T
*curfrp
, int height
));
23 static void frame_setwidth
__ARGS((frame_T
*curfrp
, int width
));
25 static void win_exchange
__ARGS((long));
26 static void win_rotate
__ARGS((int, int));
27 static void win_totop
__ARGS((int size
, int flags
));
28 static void win_equal_rec
__ARGS((win_T
*next_curwin
, int current
, frame_T
*topfr
, int dir
, int col
, int row
, int width
, int height
));
29 static int last_window
__ARGS((void));
30 static win_T
*win_free_mem
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
31 static win_T
*winframe_remove
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
32 static frame_T
*win_altframe
__ARGS((win_T
*win
, tabpage_T
*tp
));
33 static tabpage_T
*alt_tabpage
__ARGS((void));
34 static win_T
*frame2win
__ARGS((frame_T
*frp
));
35 static int frame_has_win
__ARGS((frame_T
*frp
, win_T
*wp
));
36 static void frame_new_height
__ARGS((frame_T
*topfrp
, int height
, int topfirst
, int wfh
));
37 static int frame_fixed_height
__ARGS((frame_T
*frp
));
39 static int frame_fixed_width
__ARGS((frame_T
*frp
));
40 static void frame_add_statusline
__ARGS((frame_T
*frp
));
41 static void frame_new_width
__ARGS((frame_T
*topfrp
, int width
, int leftfirst
, int wfw
));
42 static void frame_add_vsep
__ARGS((frame_T
*frp
));
43 static int frame_minwidth
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
44 static void frame_fix_width
__ARGS((win_T
*wp
));
47 static int win_alloc_firstwin
__ARGS((win_T
*oldwin
));
48 #if defined(FEAT_WINDOWS) || defined(PROTO)
49 static tabpage_T
*alloc_tabpage
__ARGS((void));
50 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
51 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
52 static void frame_fix_height
__ARGS((win_T
*wp
));
53 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
54 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
55 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
56 static void win_append
__ARGS((win_T
*, win_T
*));
57 static void win_remove
__ARGS((win_T
*, tabpage_T
*tp
));
58 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
59 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
60 static void frame_remove
__ARGS((frame_T
*frp
));
62 static void win_new_width
__ARGS((win_T
*wp
, int width
));
63 static void win_goto_ver
__ARGS((int up
, long count
));
64 static void win_goto_hor
__ARGS((int left
, long count
));
66 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
67 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
69 static void make_snapshot
__ARGS((void));
70 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
71 static void clear_snapshot
__ARGS((tabpage_T
*tp
));
72 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
73 static void restore_snapshot
__ARGS((int close_curwin
));
74 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
75 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
77 #endif /* FEAT_WINDOWS */
78 static win_T
*win_alloc
__ARGS((win_T
*after
));
79 static void win_new_height
__ARGS((win_T
*, int));
81 #define URL_SLASH 1 /* path_is_url() has found "://" */
82 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
84 #define NOWIN (win_T *)-1 /* non-exisiting window */
87 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
89 # define ROWS_AVAIL (Rows - p_ch)
92 #if defined(FEAT_WINDOWS) || defined(PROTO)
94 static char *m_onlyone
= N_("Already only one window");
97 * all CTRL-W window commands are handled here, called from normal_cmd().
100 do_window(nchar
, Prenum
, xchar
)
103 int xchar
; /* extra char from ":wincmd gx" or NUL */
107 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
112 int type
= FIND_DEFINE
;
123 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
125 # define CHECK_CMDWIN
130 /* split current window in two parts, horizontally */
136 reset_VIsual_and_resel(); /* stop Visual mode */
139 /* When splitting the quickfix window open a new buffer in it,
140 * don't replicate the quickfix buffer. */
141 if (bt_quickfix(curbuf
))
145 need_mouse_correct
= TRUE
;
147 win_split((int)Prenum
, 0);
150 #ifdef FEAT_VERTSPLIT
151 /* split current window in two parts, vertically */
156 reset_VIsual_and_resel(); /* stop Visual mode */
159 need_mouse_correct
= TRUE
;
161 win_split((int)Prenum
, WSP_VERT
);
165 /* split current window and edit alternate file */
170 reset_VIsual_and_resel(); /* stop Visual mode */
172 STRCPY(cbuf
, "split #");
174 sprintf((char *)cbuf
+ 7, "%ld", Prenum
);
175 do_cmdline_cmd(cbuf
);
178 /* open new window */
183 reset_VIsual_and_resel(); /* stop Visual mode */
189 sprintf((char *)cbuf
, "%ld", Prenum
); /* window height */
193 do_cmdline_cmd(cbuf
);
196 /* quit current window */
200 reset_VIsual_and_resel(); /* stop Visual mode */
202 do_cmdline_cmd((char_u
*)"quit");
205 /* close current window */
209 reset_VIsual_and_resel(); /* stop Visual mode */
211 do_cmdline_cmd((char_u
*)"close");
214 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
215 /* close preview window */
220 reset_VIsual_and_resel(); /* stop Visual mode */
222 do_cmdline_cmd((char_u
*)"pclose");
225 /* cursor to preview window */
227 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
231 EMSG(_("E441: There is no preview window"));
237 /* close all but current window */
242 reset_VIsual_and_resel(); /* stop Visual mode */
244 do_cmdline_cmd((char_u
*)"only");
247 /* cursor to next window with wrap around */
250 /* cursor to previous window with wrap around */
253 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
257 if (Prenum
) /* go to specified window */
259 for (wp
= firstwin
; --Prenum
> 0; )
261 if (wp
->w_next
== NULL
)
269 if (nchar
== 'W') /* go to previous window */
273 wp
= lastwin
; /* wrap around */
275 else /* go to next window */
279 wp
= firstwin
; /* wrap around */
286 /* cursor to window below */
291 #ifdef FEAT_VERTSPLIT
292 win_goto_ver(FALSE
, Prenum1
);
294 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
301 /* cursor to window above */
306 #ifdef FEAT_VERTSPLIT
307 win_goto_ver(TRUE
, Prenum1
);
309 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
316 #ifdef FEAT_VERTSPLIT
317 /* cursor to left window */
323 win_goto_hor(TRUE
, Prenum1
);
326 /* cursor to right window */
331 win_goto_hor(FALSE
, Prenum1
);
335 /* move window to new tab page */
337 if (firstwin
== lastwin
)
341 tabpage_T
*oldtab
= curtab
;
344 /* First create a new tab with the window, then go back to
345 * the old tab and close the window there. */
347 if (win_new_tabpage((int)Prenum
) == OK
348 && valid_tabpage(oldtab
))
351 goto_tabpage_tp(oldtab
);
353 win_close(curwin
, FALSE
);
354 if (valid_tabpage(newtab
))
355 goto_tabpage_tp(newtab
);
360 /* cursor to top-left window */
366 /* cursor to bottom-right window */
372 /* cursor to last accessed (previous) window */
381 /* exchange current and next window */
385 win_exchange(Prenum
);
388 /* rotate windows downwards */
393 reset_VIsual_and_resel(); /* stop Visual mode */
395 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
398 /* rotate windows upwards */
402 reset_VIsual_and_resel(); /* stop Visual mode */
404 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
407 /* move window to the very top/bottom/left/right */
410 #ifdef FEAT_VERTSPLIT
415 win_totop((int)Prenum
,
416 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
417 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
420 /* make all windows the same height */
423 need_mouse_correct
= TRUE
;
425 win_equal(NULL
, FALSE
, 'b');
428 /* increase current window height */
431 need_mouse_correct
= TRUE
;
433 win_setheight(curwin
->w_height
+ (int)Prenum1
);
436 /* decrease current window height */
439 need_mouse_correct
= TRUE
;
441 win_setheight(curwin
->w_height
- (int)Prenum1
);
444 /* set current window height */
448 need_mouse_correct
= TRUE
;
450 win_setheight(Prenum
? (int)Prenum
: 9999);
453 #ifdef FEAT_VERTSPLIT
454 /* increase current window width */
457 need_mouse_correct
= TRUE
;
459 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
462 /* decrease current window width */
465 need_mouse_correct
= TRUE
;
467 win_setwidth(curwin
->w_width
- (int)Prenum1
);
470 /* set current window width */
473 need_mouse_correct
= TRUE
;
475 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
479 /* jump to tag and split window if tag exists (in preview window) */
480 #if defined(FEAT_QUICKFIX)
484 g_do_tagpreview
= Prenum
;
486 g_do_tagpreview
= p_pvh
;
493 reset_VIsual_and_resel(); /* stop Visual mode */
496 postponed_split
= Prenum
;
498 postponed_split
= -1;
500 /* Execute the command right here, required when
501 * "wincmd ]" was used in a function. */
502 do_nv_ident(Ctrl_RSB
, NUL
);
505 #ifdef FEAT_SEARCHPATH
506 /* edit file name under cursor in a new window */
513 ptr
= grab_file_name(Prenum1
, &lnum
);
517 need_mouse_correct
= TRUE
;
520 if (win_split(0, 0) == OK
)
522 # ifdef FEAT_SCROLLBIND
523 curwin
->w_p_scb
= FALSE
;
525 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
, ECMD_HIDE
);
526 if (nchar
== 'F' && lnum
>= 0)
528 curwin
->w_cursor
.lnum
= lnum
;
530 beginline(BL_SOL
| BL_FIX
);
539 /* Go to the first occurence of the identifier under cursor along path in a
542 case 'i': /* Go to any match */
546 case 'd': /* Go to definition, using 'define' */
549 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
551 find_pattern_in_path(ptr
, 0, len
, TRUE
,
552 Prenum
== 0 ? TRUE
: FALSE
, type
,
553 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
554 curwin
->w_set_curswant
= TRUE
;
560 #if defined(FEAT_QUICKFIX)
562 * In a quickfix window a <CR> jumps to the error under the
563 * cursor in a new window.
565 if (bt_quickfix(curbuf
))
567 sprintf((char *)cbuf
, "split +%ld%s",
568 (long)curwin
->w_cursor
.lnum
,
569 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
570 do_cmdline_cmd(cbuf
);
576 /* CTRL-W g extended commands */
580 #ifdef USE_ON_FLY_SCROLL
581 dont_scroll
= TRUE
; /* disallow scrolling here */
584 ++allow_keys
; /* no mapping for xchar, but allow key codes */
586 xchar
= safe_vgetc();
588 LANGMAP_ADJUST(xchar
, TRUE
);
592 #ifdef FEAT_CMDL_INFO
593 (void)add_to_showcmd(xchar
);
597 #if defined(FEAT_QUICKFIX)
601 g_do_tagpreview
= Prenum
;
603 g_do_tagpreview
= p_pvh
;
609 reset_VIsual_and_resel(); /* stop Visual mode */
612 postponed_split
= Prenum
;
614 postponed_split
= -1;
616 /* Execute the command right here, required when
617 * "wincmd g}" was used in a function. */
618 do_nv_ident('g', xchar
);
621 #ifdef FEAT_SEARCHPATH
622 case 'f': /* CTRL-W gf: "gf" in a new tab page */
623 case 'F': /* CTRL-W gF: "gF" in a new tab page */
634 default: beep_flush();
640 * split the current window, implements CTRL-W s and :split
642 * "size" is the height or width for the new window, 0 to use half of current
646 * WSP_ROOM: require enough room for new window
647 * WSP_VERT: vertical split.
648 * WSP_TOP: open window at the top-left of the shell (help window).
649 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
650 * WSP_HELP: creating the help window, keep layout snapshot
652 * return FAIL for failure, OK otherwise
655 win_split(size
, flags
)
659 /* When the ":tab" modifier was used open a new tab page instead. */
660 if (may_open_tabpage() == OK
)
663 /* Add flags from ":vertical", ":topleft" and ":botright". */
664 flags
|= cmdmod
.split
;
665 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
667 EMSG(_("E442: Can't split topleft and botright at the same time"));
671 /* When creating the help window make a snapshot of the window layout.
672 * Otherwise clear the snapshot, it's now invalid. */
673 if (flags
& WSP_HELP
)
676 clear_snapshot(curtab
);
678 return win_split_ins(size
, flags
, NULL
, 0);
682 * When "newwin" is NULL: split the current window in two.
683 * When "newwin" is not NULL: insert this window at the far
684 * top/left/right/bottom.
685 * return FAIL for failure, OK otherwise
688 win_split_ins(size
, flags
, newwin
, dir
)
699 int do_equal
= FALSE
;
702 int oldwin_height
= 0;
704 frame_T
*frp
, *curfrp
;
709 else if (flags
& WSP_BOT
)
714 /* add a status line when p_ls == 1 and splitting the first window */
715 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
717 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
722 need_status
= STATUS_HEIGHT
;
726 /* May be needed for the scrollbars that are going to change. */
731 #ifdef FEAT_VERTSPLIT
732 if (flags
& WSP_VERT
)
735 do_equal
= (p_ea
&& new_size
== 0 && *p_ead
!= 'v');
738 * Check if we are able to split the current window and compute its
742 if (flags
& WSP_ROOM
)
743 needed
+= p_wiw
- p_wmw
;
744 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
746 available
= topframe
->fr_width
;
747 needed
+= frame_minwidth(topframe
, NULL
);
750 available
= oldwin
->w_width
;
751 if (available
< needed
&& newwin
== NULL
)
757 new_size
= oldwin
->w_width
/ 2;
758 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
759 new_size
= oldwin
->w_width
- p_wmw
- 1;
760 if (new_size
< p_wmw
)
763 /* if it doesn't fit in the current window, need win_equal() */
764 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
767 /* We don't like to take lines for the new window from a
768 * 'winfixwidth' window. Take them from a window to the left or right
769 * instead, if possible. */
771 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
777 do_equal
= (p_ea
&& new_size
== 0
778 #ifdef FEAT_VERTSPLIT
784 * Check if we are able to split the current window and compute its
787 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
788 if (flags
& WSP_ROOM
)
789 needed
+= p_wh
- p_wmh
;
790 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
792 available
= topframe
->fr_height
;
793 needed
+= frame_minheight(topframe
, NULL
);
797 available
= oldwin
->w_height
;
800 if (available
< needed
&& newwin
== NULL
)
805 oldwin_height
= oldwin
->w_height
;
808 oldwin
->w_status_height
= STATUS_HEIGHT
;
809 oldwin_height
-= STATUS_HEIGHT
;
812 new_size
= oldwin_height
/ 2;
814 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
815 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
816 if (new_size
< p_wmh
)
819 /* if it doesn't fit in the current window, need win_equal() */
820 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
823 /* We don't like to take lines for the new window from a
824 * 'winfixheight' window. Take them from a window above or below
825 * instead, if possible. */
828 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
830 oldwin_height
= oldwin
->w_height
;
832 oldwin_height
-= STATUS_HEIGHT
;
837 * allocate new window structure and link it in the window list
839 if ((flags
& WSP_TOP
) == 0
840 && ((flags
& WSP_BOT
)
841 || (flags
& WSP_BELOW
)
842 || (!(flags
& WSP_ABOVE
)
844 #ifdef FEAT_VERTSPLIT
845 (flags
& WSP_VERT
) ? p_spr
:
849 /* new window below/right of current one */
851 wp
= win_alloc(oldwin
);
853 win_append(oldwin
, wp
);
858 wp
= win_alloc(oldwin
->w_prev
);
860 win_append(oldwin
->w_prev
, wp
);
868 /* make the contents of the new window the same as the current one */
869 win_init(wp
, curwin
);
873 * Reorganise the tree of frames to insert the new window.
875 if (flags
& (WSP_TOP
| WSP_BOT
))
877 #ifdef FEAT_VERTSPLIT
878 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
879 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
881 if (topframe
->fr_layout
== FR_COL
)
884 curfrp
= topframe
->fr_child
;
886 while (curfrp
->fr_next
!= NULL
)
887 curfrp
= curfrp
->fr_next
;
891 before
= (flags
& WSP_TOP
);
895 curfrp
= oldwin
->w_frame
;
896 if (flags
& WSP_BELOW
)
898 else if (flags
& WSP_ABOVE
)
901 #ifdef FEAT_VERTSPLIT
902 if (flags
& WSP_VERT
)
908 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
910 /* Need to create a new frame in the tree to make a branch. */
911 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
913 curfrp
->fr_layout
= layout
;
914 frp
->fr_parent
= curfrp
;
917 curfrp
->fr_child
= frp
;
918 curfrp
->fr_win
= NULL
;
920 if (frp
->fr_win
!= NULL
)
921 oldwin
->w_frame
= frp
;
923 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
924 frp
->fr_parent
= curfrp
;
929 /* Create a frame for the new window. */
930 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
931 frp
->fr_layout
= FR_LEAF
;
936 frp
= newwin
->w_frame
;
937 frp
->fr_parent
= curfrp
->fr_parent
;
939 /* Insert the new frame at the right place in the frame list. */
941 frame_insert(curfrp
, frp
);
943 frame_append(curfrp
, frp
);
945 #ifdef FEAT_VERTSPLIT
946 if (flags
& WSP_VERT
)
948 wp
->w_p_scr
= curwin
->w_p_scr
;
952 oldwin
->w_status_height
= need_status
;
954 if (flags
& (WSP_TOP
| WSP_BOT
))
956 /* set height and row of new window to full height */
957 wp
->w_winrow
= tabline_height();
958 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
959 wp
->w_status_height
= (p_ls
> 0);
963 /* height and row of new window is same as current window */
964 wp
->w_winrow
= oldwin
->w_winrow
;
965 wp
->w_height
= oldwin
->w_height
;
966 wp
->w_status_height
= oldwin
->w_status_height
;
968 frp
->fr_height
= curfrp
->fr_height
;
970 /* "new_size" of the current window goes to the new window, use
971 * one column for the vertical separator */
972 wp
->w_width
= new_size
;
974 wp
->w_vsep_width
= 1;
977 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
978 oldwin
->w_vsep_width
= 1;
980 if (flags
& (WSP_TOP
| WSP_BOT
))
983 frame_add_vsep(curfrp
);
984 /* Set width of neighbor frame */
985 frame_new_width(curfrp
, curfrp
->fr_width
986 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
990 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
991 if (before
) /* new window left of current one */
993 wp
->w_wincol
= oldwin
->w_wincol
;
994 oldwin
->w_wincol
+= new_size
+ 1;
996 else /* new window right of current one */
997 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
998 frame_fix_width(oldwin
);
1004 /* width and column of new window is same as current window */
1005 #ifdef FEAT_VERTSPLIT
1006 if (flags
& (WSP_TOP
| WSP_BOT
))
1009 wp
->w_width
= Columns
;
1010 wp
->w_vsep_width
= 0;
1014 wp
->w_wincol
= oldwin
->w_wincol
;
1015 wp
->w_width
= oldwin
->w_width
;
1016 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1018 frp
->fr_width
= curfrp
->fr_width
;
1021 /* "new_size" of the current window goes to the new window, use
1022 * one row for the status line */
1023 win_new_height(wp
, new_size
);
1024 if (flags
& (WSP_TOP
| WSP_BOT
))
1025 frame_new_height(curfrp
, curfrp
->fr_height
1026 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1028 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1029 if (before
) /* new window above current one */
1031 wp
->w_winrow
= oldwin
->w_winrow
;
1032 wp
->w_status_height
= STATUS_HEIGHT
;
1033 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1035 else /* new window below current one */
1037 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1038 wp
->w_status_height
= oldwin
->w_status_height
;
1039 oldwin
->w_status_height
= STATUS_HEIGHT
;
1041 #ifdef FEAT_VERTSPLIT
1042 if (flags
& WSP_BOT
)
1043 frame_add_statusline(curfrp
);
1045 frame_fix_height(wp
);
1046 frame_fix_height(oldwin
);
1049 if (flags
& (WSP_TOP
| WSP_BOT
))
1050 (void)win_comp_pos();
1053 * Both windows need redrawing
1055 redraw_win_later(wp
, NOT_VALID
);
1056 wp
->w_redr_status
= TRUE
;
1057 redraw_win_later(oldwin
, NOT_VALID
);
1058 oldwin
->w_redr_status
= TRUE
;
1064 msg_clr_eos_force(); /* Old command/ruler may still be there */
1067 msg_col
= 0; /* put position back at start of line */
1071 * make the new window the current window and redraw
1073 if (do_equal
|| dir
!= 0)
1075 #ifdef FEAT_VERTSPLIT
1076 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1077 : dir
== 'h' ? 'b' :
1081 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1082 * size was given. */
1083 #ifdef FEAT_VERTSPLIT
1084 if (flags
& WSP_VERT
)
1091 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1093 gui_init_which_components(NULL
);
1103 win_enter(wp
, FALSE
);
1104 #ifdef FEAT_VERTSPLIT
1105 if (flags
& WSP_VERT
)
1115 * Initialize window "newp" from window "oldp".
1116 * Used when splitting a window and when creating a new tab page.
1117 * The windows will both edit the same buffer.
1120 win_init(newp
, oldp
)
1126 newp
->w_buffer
= oldp
->w_buffer
;
1127 oldp
->w_buffer
->b_nwindows
++;
1128 newp
->w_cursor
= oldp
->w_cursor
;
1130 newp
->w_curswant
= oldp
->w_curswant
;
1131 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1132 newp
->w_topline
= oldp
->w_topline
;
1134 newp
->w_topfill
= oldp
->w_topfill
;
1136 newp
->w_leftcol
= oldp
->w_leftcol
;
1137 newp
->w_pcmark
= oldp
->w_pcmark
;
1138 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1139 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1140 newp
->w_wrow
= oldp
->w_wrow
;
1141 newp
->w_fraction
= oldp
->w_fraction
;
1142 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1143 #ifdef FEAT_JUMPLIST
1144 copy_jumplist(oldp
, newp
);
1146 #ifdef FEAT_QUICKFIX
1147 copy_loclist(oldp
, newp
);
1149 if (oldp
->w_localdir
!= NULL
)
1150 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1152 /* Use the same argument list. */
1153 newp
->w_alist
= oldp
->w_alist
;
1154 ++newp
->w_alist
->al_refcount
;
1155 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1158 * copy tagstack and options from existing window
1160 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1162 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1163 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1164 newp
->w_tagstack
[i
].tagname
=
1165 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1167 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1168 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1169 win_copy_options(oldp
, newp
);
1170 # ifdef FEAT_FOLDING
1171 copyFoldingState(oldp
, newp
);
1175 #endif /* FEAT_WINDOWS */
1177 #if defined(FEAT_WINDOWS) || defined(PROTO)
1179 * Check if "win" is a pointer to an existing window.
1189 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1196 * Return the number of windows.
1204 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1210 * Make "count" windows on the screen.
1211 * Return actual number of windows on the screen.
1212 * Must be called when there is just one window, filling the whole screen
1213 * (excluding the command line).
1217 make_windows(count
, vertical
)
1219 int vertical
; /* split windows vertically if TRUE */
1224 #ifdef FEAT_VERTSPLIT
1227 /* Each windows needs at least 'winminwidth' lines and a separator
1229 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1230 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1235 /* Each window needs at least 'winminheight' lines and a status line. */
1236 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1237 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1242 if (count
> maxcount
)
1246 * add status line now, otherwise first window will be too big
1253 * Don't execute autocommands while creating the windows. Must do that
1254 * when putting the buffers in the windows.
1259 /* todo is number of windows left to create */
1260 for (todo
= count
- 1; todo
> 0; --todo
)
1261 #ifdef FEAT_VERTSPLIT
1264 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1265 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1271 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1272 * STATUS_HEIGHT
) / (todo
+ 1)
1273 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1281 /* return actual number of windows */
1282 return (count
- todo
);
1286 * Exchange current and next window
1289 win_exchange(Prenum
)
1298 if (lastwin
== firstwin
) /* just one window */
1305 need_mouse_correct
= TRUE
;
1309 * find window to exchange with
1313 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1314 while (frp
!= NULL
&& --Prenum
> 0)
1317 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1318 frp
= curwin
->w_frame
->fr_next
;
1319 else /* Swap last window in row/col with previous */
1320 frp
= curwin
->w_frame
->fr_prev
;
1322 /* We can only exchange a window with another window, not with a frame
1323 * containing windows. */
1324 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1329 * 1. remove curwin from the list. Remember after which window it was in wp2
1330 * 2. insert curwin before wp in the list
1332 * 3. remove wp from the list
1333 * 4. insert wp after wp2
1334 * 5. exchange the status line height and vsep width.
1336 wp2
= curwin
->w_prev
;
1337 frp2
= curwin
->w_frame
->fr_prev
;
1338 if (wp
->w_prev
!= curwin
)
1340 win_remove(curwin
, NULL
);
1341 frame_remove(curwin
->w_frame
);
1342 win_append(wp
->w_prev
, curwin
);
1343 frame_insert(frp
, curwin
->w_frame
);
1347 win_remove(wp
, NULL
);
1348 frame_remove(wp
->w_frame
);
1349 win_append(wp2
, wp
);
1351 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1353 frame_append(frp2
, wp
->w_frame
);
1355 temp
= curwin
->w_status_height
;
1356 curwin
->w_status_height
= wp
->w_status_height
;
1357 wp
->w_status_height
= temp
;
1358 #ifdef FEAT_VERTSPLIT
1359 temp
= curwin
->w_vsep_width
;
1360 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1361 wp
->w_vsep_width
= temp
;
1363 /* If the windows are not in the same frame, exchange the sizes to avoid
1364 * messing up the window layout. Otherwise fix the frame sizes. */
1365 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1367 temp
= curwin
->w_height
;
1368 curwin
->w_height
= wp
->w_height
;
1369 wp
->w_height
= temp
;
1370 temp
= curwin
->w_width
;
1371 curwin
->w_width
= wp
->w_width
;
1376 frame_fix_height(curwin
);
1377 frame_fix_height(wp
);
1378 frame_fix_width(curwin
);
1379 frame_fix_width(wp
);
1383 (void)win_comp_pos(); /* recompute window positions */
1385 win_enter(wp
, TRUE
);
1386 redraw_later(CLEAR
);
1390 * rotate windows: if upwards TRUE the second window becomes the first one
1391 * if upwards FALSE the first window becomes the second one
1394 win_rotate(upwards
, count
)
1403 if (firstwin
== lastwin
) /* nothing to do */
1410 need_mouse_correct
= TRUE
;
1413 #ifdef FEAT_VERTSPLIT
1414 /* Check if all frames in this row/col have one window. */
1415 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1417 if (frp
->fr_win
== NULL
)
1419 EMSG(_("E443: Cannot rotate when another window is split"));
1426 if (upwards
) /* first window becomes last window */
1428 /* remove first window/frame from the list */
1429 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1431 win_remove(wp1
, NULL
);
1434 /* find last frame and append removed window/frame after it */
1435 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1437 win_append(frp
->fr_win
, wp1
);
1438 frame_append(frp
, wp1
->w_frame
);
1440 wp2
= frp
->fr_win
; /* previously last window */
1442 else /* last window becomes first window */
1444 /* find last window/frame in the list and remove it */
1445 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1449 wp2
= wp1
->w_prev
; /* will become last window */
1450 win_remove(wp1
, NULL
);
1453 /* append the removed window/frame before the first in the list */
1454 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1455 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1458 /* exchange status height and vsep width of old and new last window */
1459 n
= wp2
->w_status_height
;
1460 wp2
->w_status_height
= wp1
->w_status_height
;
1461 wp1
->w_status_height
= n
;
1462 frame_fix_height(wp1
);
1463 frame_fix_height(wp2
);
1464 #ifdef FEAT_VERTSPLIT
1465 n
= wp2
->w_vsep_width
;
1466 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1467 wp1
->w_vsep_width
= n
;
1468 frame_fix_width(wp1
);
1469 frame_fix_width(wp2
);
1472 /* recompute w_winrow and w_wincol for all windows */
1473 (void)win_comp_pos();
1476 redraw_later(CLEAR
);
1480 * Move the current window to the very top/bottom/left/right of the screen.
1483 win_totop(size
, flags
)
1488 int height
= curwin
->w_height
;
1490 if (lastwin
== firstwin
)
1496 /* Remove the window and frame from the tree of frames. */
1497 (void)winframe_remove(curwin
, &dir
, NULL
);
1498 win_remove(curwin
, NULL
);
1499 last_status(FALSE
); /* may need to remove last status line */
1500 (void)win_comp_pos(); /* recompute window positions */
1502 /* Split a window on the desired side and put the window there. */
1503 (void)win_split_ins(size
, flags
, curwin
, dir
);
1504 if (!(flags
& WSP_VERT
))
1506 win_setheight(height
);
1508 win_equal(curwin
, TRUE
, 'v');
1511 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1512 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1513 * scrollbars. Have to update them anyway. */
1517 gui_init_which_components(NULL
);
1518 gui_update_scrollbars(TRUE
);
1520 need_mouse_correct
= TRUE
;
1526 * Move window "win1" to below/right of "win2" and make "win1" the current
1527 * window. Only works within the same frame!
1530 win_move_after(win1
, win2
)
1535 /* check if the arguments are reasonable */
1539 /* check if there is something to do */
1540 if (win2
->w_next
!= win1
)
1542 /* may need move the status line/vertical separator of the last window
1544 if (win1
== lastwin
)
1546 height
= win1
->w_prev
->w_status_height
;
1547 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1548 win1
->w_status_height
= height
;
1549 #ifdef FEAT_VERTSPLIT
1550 if (win1
->w_prev
->w_vsep_width
== 1)
1552 /* Remove the vertical separator from the last-but-one window,
1553 * add it to the last window. Adjust the frame widths. */
1554 win1
->w_prev
->w_vsep_width
= 0;
1555 win1
->w_prev
->w_frame
->fr_width
-= 1;
1556 win1
->w_vsep_width
= 1;
1557 win1
->w_frame
->fr_width
+= 1;
1561 else if (win2
== lastwin
)
1563 height
= win1
->w_status_height
;
1564 win1
->w_status_height
= win2
->w_status_height
;
1565 win2
->w_status_height
= height
;
1566 #ifdef FEAT_VERTSPLIT
1567 if (win1
->w_vsep_width
== 1)
1569 /* Remove the vertical separator from win1, add it to the last
1570 * window, win2. Adjust the frame widths. */
1571 win2
->w_vsep_width
= 1;
1572 win2
->w_frame
->fr_width
+= 1;
1573 win1
->w_vsep_width
= 0;
1574 win1
->w_frame
->fr_width
-= 1;
1578 win_remove(win1
, NULL
);
1579 frame_remove(win1
->w_frame
);
1580 win_append(win2
, win1
);
1581 frame_append(win2
->w_frame
, win1
->w_frame
);
1583 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1584 redraw_later(NOT_VALID
);
1586 win_enter(win1
, FALSE
);
1590 * Make all windows the same height.
1591 * 'next_curwin' will soon be the current window, make sure it has enough
1595 win_equal(next_curwin
, current
, dir
)
1596 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1597 int current
; /* do only frame with current window */
1598 int dir
; /* 'v' for vertically, 'h' for horizontally,
1599 'b' for both, 0 for using p_ead */
1602 #ifdef FEAT_VERTSPLIT
1607 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1608 topframe
, dir
, 0, tabline_height(),
1609 (int)Columns
, topframe
->fr_height
);
1613 * Set a frame to a new position and height, spreading the available room
1614 * equally over contained frames.
1615 * The window "next_curwin" (if not NULL) should at least get the size from
1616 * 'winheight' and 'winwidth' if possible.
1619 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1620 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1621 int current
; /* do only frame with current window */
1622 frame_T
*topfr
; /* frame to set size off */
1623 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1624 int col
; /* horizontal position for frame */
1625 int row
; /* vertical position for frame */
1626 int width
; /* new width of frame */
1627 int height
; /* new height of frame */
1631 int wincount
, totwincount
= 0;
1633 int next_curwin_size
= 0;
1636 int has_next_curwin
= 0;
1639 if (topfr
->fr_layout
== FR_LEAF
)
1641 /* Set the width/height of this frame.
1642 * Redraw when size or position changes */
1643 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1644 #ifdef FEAT_VERTSPLIT
1645 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1649 topfr
->fr_win
->w_winrow
= row
;
1650 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1651 #ifdef FEAT_VERTSPLIT
1652 topfr
->fr_win
->w_wincol
= col
;
1653 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1655 redraw_all_later(CLEAR
);
1658 #ifdef FEAT_VERTSPLIT
1659 else if (topfr
->fr_layout
== FR_ROW
)
1661 topfr
->fr_width
= width
;
1662 topfr
->fr_height
= height
;
1664 if (dir
!= 'v') /* equalize frame widths */
1666 /* Compute the maximum number of windows horizontally in this
1668 n
= frame_minwidth(topfr
, NOWIN
);
1669 /* add one for the rightmost window, it doesn't have a separator */
1670 if (col
+ width
== Columns
)
1674 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1675 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1678 * Compute width for "next_curwin" window and room available for
1680 * "m" is the minimal width when counting p_wiw for "next_curwin".
1682 m
= frame_minwidth(topfr
, next_curwin
);
1686 next_curwin_size
= p_wiw
+ room
;
1691 next_curwin_size
= -1;
1692 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1694 /* If 'winfixwidth' set keep the window width if
1696 * Watch out for this window being the next_curwin. */
1697 if (frame_fixed_width(fr
))
1699 n
= frame_minwidth(fr
, NOWIN
);
1700 new_size
= fr
->fr_width
;
1701 if (frame_has_win(fr
, next_curwin
))
1703 room
+= p_wiw
- p_wmw
;
1704 next_curwin_size
= 0;
1705 if (new_size
< p_wiw
)
1709 /* These windows don't use up room. */
1710 totwincount
-= (n
+ (fr
->fr_next
== NULL
1711 ? extra_sep
: 0)) / (p_wmw
+ 1);
1712 room
-= new_size
- n
;
1718 fr
->fr_newwidth
= new_size
;
1721 if (next_curwin_size
== -1)
1723 if (!has_next_curwin
)
1724 next_curwin_size
= 0;
1725 else if (totwincount
> 1
1726 && (room
+ (totwincount
- 2))
1727 / (totwincount
- 1) > p_wiw
)
1729 /* Can make all windows wider than 'winwidth', spread
1730 * the room equally. */
1731 next_curwin_size
= (room
+ p_wiw
1732 + (totwincount
- 1) * p_wmw
1733 + (totwincount
- 1)) / totwincount
;
1734 room
-= next_curwin_size
- p_wiw
;
1737 next_curwin_size
= p_wiw
;
1741 if (has_next_curwin
)
1742 --totwincount
; /* don't count curwin */
1745 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1749 if (fr
->fr_next
== NULL
)
1750 /* last frame gets all that remains (avoid roundoff error) */
1752 else if (dir
== 'v')
1753 new_size
= fr
->fr_width
;
1754 else if (frame_fixed_width(fr
))
1756 new_size
= fr
->fr_newwidth
;
1757 wincount
= 0; /* doesn't count as a sizeable window */
1761 /* Compute the maximum number of windows horiz. in "fr". */
1762 n
= frame_minwidth(fr
, NOWIN
);
1763 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1765 m
= frame_minwidth(fr
, next_curwin
);
1766 if (has_next_curwin
)
1767 hnc
= frame_has_win(fr
, next_curwin
);
1770 if (hnc
) /* don't count next_curwin */
1772 if (totwincount
== 0)
1775 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1777 if (hnc
) /* add next_curwin size */
1779 next_curwin_size
-= p_wiw
- (m
- n
);
1780 new_size
+= next_curwin_size
;
1781 room
-= new_size
- next_curwin_size
;
1788 /* Skip frame that is full width when splitting or closing a
1789 * window, unless equalizing all frames. */
1790 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1791 || (new_size
!= fr
->fr_width
)
1792 || frame_has_win(fr
, next_curwin
))
1793 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1797 totwincount
-= wincount
;
1801 else /* topfr->fr_layout == FR_COL */
1803 #ifdef FEAT_VERTSPLIT
1804 topfr
->fr_width
= width
;
1806 topfr
->fr_height
= height
;
1808 if (dir
!= 'h') /* equalize frame heights */
1810 /* Compute maximum number of windows vertically in this frame. */
1811 n
= frame_minheight(topfr
, NOWIN
);
1812 /* add one for the bottom window if it doesn't have a statusline */
1813 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1817 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1818 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1821 * Compute height for "next_curwin" window and room available for
1823 * "m" is the minimal height when counting p_wh for "next_curwin".
1825 m
= frame_minheight(topfr
, next_curwin
);
1829 /* The room is less then 'winheight', use all space for the
1830 * current window. */
1831 next_curwin_size
= p_wh
+ room
;
1836 next_curwin_size
= -1;
1837 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1839 /* If 'winfixheight' set keep the window height if
1841 * Watch out for this window being the next_curwin. */
1842 if (frame_fixed_height(fr
))
1844 n
= frame_minheight(fr
, NOWIN
);
1845 new_size
= fr
->fr_height
;
1846 if (frame_has_win(fr
, next_curwin
))
1848 room
+= p_wh
- p_wmh
;
1849 next_curwin_size
= 0;
1850 if (new_size
< p_wh
)
1854 /* These windows don't use up room. */
1855 totwincount
-= (n
+ (fr
->fr_next
== NULL
1856 ? extra_sep
: 0)) / (p_wmh
+ 1);
1857 room
-= new_size
- n
;
1863 fr
->fr_newheight
= new_size
;
1866 if (next_curwin_size
== -1)
1868 if (!has_next_curwin
)
1869 next_curwin_size
= 0;
1870 else if (totwincount
> 1
1871 && (room
+ (totwincount
- 2))
1872 / (totwincount
- 1) > p_wh
)
1874 /* can make all windows higher than 'winheight',
1875 * spread the room equally. */
1876 next_curwin_size
= (room
+ p_wh
1877 + (totwincount
- 1) * p_wmh
1878 + (totwincount
- 1)) / totwincount
;
1879 room
-= next_curwin_size
- p_wh
;
1882 next_curwin_size
= p_wh
;
1886 if (has_next_curwin
)
1887 --totwincount
; /* don't count curwin */
1890 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1894 if (fr
->fr_next
== NULL
)
1895 /* last frame gets all that remains (avoid roundoff error) */
1897 else if (dir
== 'h')
1898 new_size
= fr
->fr_height
;
1899 else if (frame_fixed_height(fr
))
1901 new_size
= fr
->fr_newheight
;
1902 wincount
= 0; /* doesn't count as a sizeable window */
1906 /* Compute the maximum number of windows vert. in "fr". */
1907 n
= frame_minheight(fr
, NOWIN
);
1908 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1910 m
= frame_minheight(fr
, next_curwin
);
1911 if (has_next_curwin
)
1912 hnc
= frame_has_win(fr
, next_curwin
);
1915 if (hnc
) /* don't count next_curwin */
1917 if (totwincount
== 0)
1920 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1922 if (hnc
) /* add next_curwin size */
1924 next_curwin_size
-= p_wh
- (m
- n
);
1925 new_size
+= next_curwin_size
;
1926 room
-= new_size
- next_curwin_size
;
1932 /* Skip frame that is full width when splitting or closing a
1933 * window, unless equalizing all frames. */
1934 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1935 || (new_size
!= fr
->fr_height
)
1936 || frame_has_win(fr
, next_curwin
))
1937 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1941 totwincount
-= wincount
;
1947 * close all windows for buffer 'buf'
1950 close_windows(buf
, keep_curwin
)
1952 int keep_curwin
; /* don't close "curwin" */
1955 tabpage_T
*tp
, *nexttp
;
1956 int h
= tabline_height();
1958 ++RedrawingDisabled
;
1960 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
1962 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
1964 win_close(wp
, FALSE
);
1966 /* Start all over, autocommands may change the window layout. */
1973 /* Also check windows in other tab pages. */
1974 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
1976 nexttp
= tp
->tp_next
;
1978 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1979 if (wp
->w_buffer
== buf
)
1981 win_close_othertab(wp
, FALSE
, tp
);
1983 /* Start all over, the tab page may be closed and
1984 * autocommands may change the window layout. */
1985 nexttp
= first_tabpage
;
1990 --RedrawingDisabled
;
1992 if (h
!= tabline_height())
1997 * Return TRUE if the current window is the only window that exists.
1998 * Returns FALSE if there is a window, possibly in another tab page.
2003 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2007 * Close window "win". Only works for the current tab page.
2008 * If "free_buf" is TRUE related buffer may be unloaded.
2010 * called by :quit, :close, :xit, :wq and findtag()
2013 win_close(win
, free_buf
)
2019 int other_buffer
= FALSE
;
2021 int close_curwin
= FALSE
;
2023 int help_window
= FALSE
;
2024 tabpage_T
*prev_curtab
= curtab
;
2028 EMSG(_("E444: Cannot close last window"));
2033 * When closing the last window in a tab page first go to another tab
2034 * page and then close the window and the tab page. This avoids that
2035 * curwin and curtab are not invalid while we are freeing memory, they may
2036 * be used in GUI events.
2038 if (firstwin
== lastwin
)
2040 goto_tabpage_tp(alt_tabpage());
2041 redraw_tabline
= TRUE
;
2043 /* Safety check: Autocommands may have closed the window when jumping
2044 * to the other tab page. */
2045 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2047 int h
= tabline_height();
2049 win_close_othertab(win
, free_buf
, prev_curtab
);
2050 if (h
!= tabline_height())
2056 /* When closing the help window, try restoring a snapshot after closing
2057 * the window. Otherwise clear the snapshot, it's now invalid. */
2058 if (win
->w_buffer
->b_help
)
2061 clear_snapshot(curtab
);
2067 * Guess which window is going to be the new current window.
2068 * This may change because of the autocommands (sigh).
2070 wp
= frame2win(win_altframe(win
, NULL
));
2073 * Be careful: If autocommands delete the window, return now.
2075 if (wp
->w_buffer
!= curbuf
)
2077 other_buffer
= TRUE
;
2078 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2079 if (!win_valid(win
) || last_window())
2082 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2083 if (!win_valid(win
) || last_window())
2086 /* autocmds may abort script processing */
2094 /* Avoid trouble with scrollbars that are going to be deleted in
2101 * Close the link to the buffer.
2103 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2105 /* Autocommands may have closed the window already, or closed the only
2106 * other window or moved to another tab page. */
2107 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2110 /* Free the memory used for the window. */
2111 wp
= win_free_mem(win
, &dir
, NULL
);
2113 /* Make sure curwin isn't invalid. It can cause severe trouble when
2114 * printing an error message. For win_equal() curbuf needs to be valid
2119 #ifdef FEAT_QUICKFIX
2120 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2123 * The cursor goes to the preview or the quickfix window, try
2124 * finding another window to go to.
2128 if (wp
->w_next
== NULL
)
2134 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2142 curbuf
= curwin
->w_buffer
;
2143 close_curwin
= TRUE
;
2146 #ifdef FEAT_VERTSPLIT
2147 && (*p_ead
== 'b' || *p_ead
== dir
)
2150 win_equal(curwin
, TRUE
,
2151 #ifdef FEAT_VERTSPLIT
2161 win_enter_ext(wp
, FALSE
, TRUE
);
2164 /* careful: after this wp and win may be invalid! */
2165 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2170 * If last window has a status line now and we don't want one,
2171 * remove the status line.
2175 /* After closing the help window, try restoring the window layout from
2176 * before it was opened. */
2178 restore_snapshot(close_curwin
);
2180 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2181 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2182 if (gui
.in_use
&& !win_hasvertsplit())
2183 gui_init_which_components(NULL
);
2186 redraw_all_later(NOT_VALID
);
2190 * Close window "win" in tab page "tp", which is not the current tab page.
2191 * This may be the last window ih that tab page and result in closing the tab,
2192 * thus "tp" may become invalid!
2193 * Caller must check if buffer is hidden and whether the tabline needs to be
2197 win_close_othertab(win
, free_buf
, tp
)
2204 tabpage_T
*ptp
= NULL
;
2206 /* Close the link to the buffer. */
2207 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2209 /* Careful: Autocommands may have closed the tab page or made it the
2210 * current tab page. */
2211 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2213 if (ptp
== NULL
|| tp
== curtab
)
2216 /* Autocommands may have closed the window already. */
2217 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2222 /* Free the memory used for the window. */
2223 wp
= win_free_mem(win
, &dir
, tp
);
2225 /* When closing the last window in a tab page remove the tab page. */
2228 if (tp
== first_tabpage
)
2229 first_tabpage
= tp
->tp_next
;
2232 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2237 EMSG2(_(e_intern2
), "win_close_othertab()");
2240 ptp
->tp_next
= tp
->tp_next
;
2247 * Free the memory used for a window.
2248 * Returns a pointer to the window that got the freed up space.
2251 win_free_mem(win
, dirp
, tp
)
2253 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2254 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2263 /* reduce the reference count to the argument list. */
2264 alist_unlink(win
->w_alist
);
2266 /* Remove the window and its frame from the tree of frames. */
2268 wp
= winframe_remove(win
, dirp
, tp
);
2272 /* When deleting the current window of another tab page select a new
2273 * current window. */
2274 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2280 #if defined(EXITFREE) || defined(PROTO)
2286 # ifdef FEAT_WINDOWS
2287 while (first_tabpage
->tp_next
!= NULL
)
2288 tabpage_close(TRUE
);
2291 while (firstwin
!= NULL
)
2292 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2297 * Remove a window and its frame from the tree of frames.
2298 * Returns a pointer to the window that got the freed up space.
2302 winframe_remove(win
, dirp
, tp
)
2304 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2305 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2307 frame_T
*frp
, *frp2
, *frp3
;
2308 frame_T
*frp_close
= win
->w_frame
;
2313 * If there is only one window there is nothing to remove.
2315 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2319 * Remove the window from its frame.
2321 frp2
= win_altframe(win
, tp
);
2322 wp
= frame2win(frp2
);
2324 /* Remove this frame from the list of frames. */
2325 frame_remove(frp_close
);
2327 #ifdef FEAT_VERTSPLIT
2328 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2331 /* When 'winfixheight' is set, remember its old size and restore
2332 * it later (it's a simplistic solution...). Don't do this if the
2333 * window will occupy the full height of the screen. */
2334 if (frp2
->fr_win
!= NULL
2335 && (frp2
->fr_next
!= NULL
|| frp2
->fr_prev
!= NULL
)
2336 && frp2
->fr_win
->w_p_wfh
)
2337 old_size
= frp2
->fr_win
->w_height
;
2338 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2339 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2341 win_setheight_win(old_size
, frp2
->fr_win
);
2342 #ifdef FEAT_VERTSPLIT
2347 /* When 'winfixwidth' is set, remember its old size and restore
2348 * it later (it's a simplistic solution...). Don't do this if the
2349 * window will occupy the full width of the screen. */
2350 if (frp2
->fr_win
!= NULL
2351 && (frp2
->fr_next
!= NULL
|| frp2
->fr_prev
!= NULL
)
2352 && frp2
->fr_win
->w_p_wfw
)
2353 old_size
= frp2
->fr_win
->w_width
;
2354 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2355 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2357 win_setwidth_win(old_size
, frp2
->fr_win
);
2362 /* If rows/columns go to a window below/right its positions need to be
2363 * updated. Can only be done after the sizes have been updated. */
2364 if (frp2
== frp_close
->fr_next
)
2366 int row
= win
->w_winrow
;
2367 int col
= W_WINCOL(win
);
2369 frame_comp_pos(frp2
, &row
, &col
);
2372 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2374 /* There is no other frame in this list, move its info to the parent
2376 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2377 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2378 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2379 frp
->fr_parent
= frp2
->fr_parent
;
2380 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2381 if (frp2
->fr_win
!= NULL
)
2382 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2383 frp
= frp2
->fr_parent
;
2386 frp2
= frp
->fr_parent
;
2387 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2389 /* The frame above the parent has the same layout, have to merge
2390 * the frames into this list. */
2391 if (frp2
->fr_child
== frp
)
2392 frp2
->fr_child
= frp
->fr_child
;
2393 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2394 if (frp
->fr_prev
!= NULL
)
2395 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2396 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2398 frp3
->fr_parent
= frp2
;
2399 if (frp3
->fr_next
== NULL
)
2401 frp3
->fr_next
= frp
->fr_next
;
2402 if (frp
->fr_next
!= NULL
)
2403 frp
->fr_next
->fr_prev
= frp3
;
2415 * Find out which frame is going to get the freed up space when "win" is
2417 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2418 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2419 * This makes opening a window and closing it immediately keep the same window
2423 win_altframe(win
, tp
)
2425 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2430 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2431 /* Last window in this tab page, will go to next tab page. */
2432 return alt_tabpage()->tp_curwin
->w_frame
;
2435 #ifdef FEAT_VERTSPLIT
2436 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2441 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2442 return frp
->fr_next
;
2443 return frp
->fr_prev
;
2447 * Return the tabpage that will be used if the current one is closed.
2454 /* Use the next tab page if possible. */
2455 if (curtab
->tp_next
!= NULL
)
2456 return curtab
->tp_next
;
2458 /* Find the last but one tab page. */
2459 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2465 * Find the left-upper window in frame "frp".
2471 while (frp
->fr_win
== NULL
)
2472 frp
= frp
->fr_child
;
2477 * Return TRUE if frame "frp" contains window "wp".
2480 frame_has_win(frp
, wp
)
2486 if (frp
->fr_layout
== FR_LEAF
)
2487 return frp
->fr_win
== wp
;
2489 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2490 if (frame_has_win(p
, wp
))
2496 * Set a new height for a frame. Recursively sets the height for contained
2497 * frames and windows. Caller must take care of positions.
2500 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2503 int topfirst
; /* resize topmost contained frame first */
2504 int wfh
; /* obey 'winfixheight' when there is a choice;
2505 may cause the height not to be set */
2511 if (topfrp
->fr_win
!= NULL
)
2513 /* Simple case: just one window. */
2514 win_new_height(topfrp
->fr_win
,
2515 height
- topfrp
->fr_win
->w_status_height
);
2517 #ifdef FEAT_VERTSPLIT
2518 else if (topfrp
->fr_layout
== FR_ROW
)
2522 /* All frames in this row get the same new height. */
2523 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2525 frame_new_height(frp
, height
, topfirst
, wfh
);
2526 if (frp
->fr_height
> height
)
2528 /* Could not fit the windows, make the whole row higher. */
2529 height
= frp
->fr_height
;
2534 while (frp
!= NULL
);
2537 else /* fr_layout == FR_COL */
2539 /* Complicated case: Resize a column of frames. Resize the bottom
2540 * frame first, frames above that when needed. */
2542 frp
= topfrp
->fr_child
;
2544 /* Advance past frames with one window with 'wfh' set. */
2545 while (frame_fixed_height(frp
))
2549 return; /* no frame without 'wfh', give up */
2553 /* Find the bottom frame of this column */
2554 while (frp
->fr_next
!= NULL
)
2557 /* Advance back for frames with one window with 'wfh' set. */
2558 while (frame_fixed_height(frp
))
2562 extra_lines
= height
- topfrp
->fr_height
;
2563 if (extra_lines
< 0)
2565 /* reduce height of contained frames, bottom or top frame first */
2568 h
= frame_minheight(frp
, NULL
);
2569 if (frp
->fr_height
+ extra_lines
< h
)
2571 extra_lines
+= frp
->fr_height
- h
;
2572 frame_new_height(frp
, h
, topfirst
, wfh
);
2576 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2584 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2590 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2592 /* Increase "height" if we could not reduce enough frames. */
2594 height
-= extra_lines
;
2597 else if (extra_lines
> 0)
2599 /* increase height of bottom or top frame */
2600 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2603 topfrp
->fr_height
= height
;
2607 * Return TRUE if height of frame "frp" should not be changed because of
2608 * the 'winfixheight' option.
2611 frame_fixed_height(frp
)
2614 /* frame with one window: fixed height if 'winfixheight' set. */
2615 if (frp
->fr_win
!= NULL
)
2616 return frp
->fr_win
->w_p_wfh
;
2618 if (frp
->fr_layout
== FR_ROW
)
2620 /* The frame is fixed height if one of the frames in the row is fixed
2622 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2623 if (frame_fixed_height(frp
))
2628 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2629 * frames in the row are fixed height. */
2630 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2631 if (!frame_fixed_height(frp
))
2636 #ifdef FEAT_VERTSPLIT
2638 * Return TRUE if width of frame "frp" should not be changed because of
2639 * the 'winfixwidth' option.
2642 frame_fixed_width(frp
)
2645 /* frame with one window: fixed width if 'winfixwidth' set. */
2646 if (frp
->fr_win
!= NULL
)
2647 return frp
->fr_win
->w_p_wfw
;
2649 if (frp
->fr_layout
== FR_COL
)
2651 /* The frame is fixed width if one of the frames in the row is fixed
2653 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2654 if (frame_fixed_width(frp
))
2659 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2660 * frames in the row are fixed width. */
2661 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2662 if (!frame_fixed_width(frp
))
2668 * Add a status line to windows at the bottom of "frp".
2669 * Note: Does not check if there is room!
2672 frame_add_statusline(frp
)
2677 if (frp
->fr_layout
== FR_LEAF
)
2680 if (wp
->w_status_height
== 0)
2682 if (wp
->w_height
> 0) /* don't make it negative */
2684 wp
->w_status_height
= STATUS_HEIGHT
;
2687 else if (frp
->fr_layout
== FR_ROW
)
2689 /* Handle all the frames in the row. */
2690 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2691 frame_add_statusline(frp
);
2693 else /* frp->fr_layout == FR_COL */
2695 /* Only need to handle the last frame in the column. */
2696 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2698 frame_add_statusline(frp
);
2703 * Set width of a frame. Handles recursively going through contained frames.
2704 * May remove separator line for windows at the right side (for win_close()).
2707 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2710 int leftfirst
; /* resize leftmost contained frame first */
2711 int wfw
; /* obey 'winfixwidth' when there is a choice;
2712 may cause the width not to be set */
2719 if (topfrp
->fr_layout
== FR_LEAF
)
2721 /* Simple case: just one window. */
2722 wp
= topfrp
->fr_win
;
2723 /* Find out if there are any windows right of this one. */
2724 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2725 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2727 if (frp
->fr_parent
== NULL
)
2728 wp
->w_vsep_width
= 0;
2729 win_new_width(wp
, width
- wp
->w_vsep_width
);
2731 else if (topfrp
->fr_layout
== FR_COL
)
2735 /* All frames in this column get the same new width. */
2736 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2738 frame_new_width(frp
, width
, leftfirst
, wfw
);
2739 if (frp
->fr_width
> width
)
2741 /* Could not fit the windows, make whole column wider. */
2742 width
= frp
->fr_width
;
2746 } while (frp
!= NULL
);
2748 else /* fr_layout == FR_ROW */
2750 /* Complicated case: Resize a row of frames. Resize the rightmost
2751 * frame first, frames left of it when needed. */
2753 frp
= topfrp
->fr_child
;
2755 /* Advance past frames with one window with 'wfw' set. */
2756 while (frame_fixed_width(frp
))
2760 return; /* no frame without 'wfw', give up */
2764 /* Find the rightmost frame of this row */
2765 while (frp
->fr_next
!= NULL
)
2768 /* Advance back for frames with one window with 'wfw' set. */
2769 while (frame_fixed_width(frp
))
2773 extra_cols
= width
- topfrp
->fr_width
;
2776 /* reduce frame width, rightmost frame first */
2779 w
= frame_minwidth(frp
, NULL
);
2780 if (frp
->fr_width
+ extra_cols
< w
)
2782 extra_cols
+= frp
->fr_width
- w
;
2783 frame_new_width(frp
, w
, leftfirst
, wfw
);
2787 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2795 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2801 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2803 /* Increase "width" if we could not reduce enough frames. */
2805 width
-= extra_cols
;
2808 else if (extra_cols
> 0)
2810 /* increase width of rightmost frame */
2811 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2814 topfrp
->fr_width
= width
;
2818 * Add the vertical separator to windows at the right side of "frp".
2819 * Note: Does not check if there is room!
2827 if (frp
->fr_layout
== FR_LEAF
)
2830 if (wp
->w_vsep_width
== 0)
2832 if (wp
->w_width
> 0) /* don't make it negative */
2834 wp
->w_vsep_width
= 1;
2837 else if (frp
->fr_layout
== FR_COL
)
2839 /* Handle all the frames in the column. */
2840 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2841 frame_add_vsep(frp
);
2843 else /* frp->fr_layout == FR_ROW */
2845 /* Only need to handle the last frame in the row. */
2846 frp
= frp
->fr_child
;
2847 while (frp
->fr_next
!= NULL
)
2849 frame_add_vsep(frp
);
2854 * Set frame width from the window it contains.
2860 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2865 * Set frame height from the window it contains.
2868 frame_fix_height(wp
)
2871 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2875 * Compute the minimal height for frame "topfrp".
2876 * Uses the 'winminheight' option.
2877 * When "next_curwin" isn't NULL, use p_wh for this window.
2878 * When "next_curwin" is NOWIN, don't use at least one line for the current
2882 frame_minheight(topfrp
, next_curwin
)
2888 #ifdef FEAT_VERTSPLIT
2892 if (topfrp
->fr_win
!= NULL
)
2894 if (topfrp
->fr_win
== next_curwin
)
2895 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2898 /* window: minimal height of the window plus status line */
2899 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2900 /* Current window is minimal one line high */
2901 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2905 #ifdef FEAT_VERTSPLIT
2906 else if (topfrp
->fr_layout
== FR_ROW
)
2908 /* get the minimal height from each frame in this row */
2910 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2912 n
= frame_minheight(frp
, next_curwin
);
2920 /* Add up the minimal heights for all frames in this column. */
2922 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2923 m
+= frame_minheight(frp
, next_curwin
);
2929 #ifdef FEAT_VERTSPLIT
2931 * Compute the minimal width for frame "topfrp".
2932 * When "next_curwin" isn't NULL, use p_wiw for this window.
2933 * When "next_curwin" is NOWIN, don't use at least one column for the current
2937 frame_minwidth(topfrp
, next_curwin
)
2939 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
2944 if (topfrp
->fr_win
!= NULL
)
2946 if (topfrp
->fr_win
== next_curwin
)
2947 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
2950 /* window: minimal width of the window plus separator column */
2951 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
2952 /* Current window is minimal one column wide */
2953 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2957 else if (topfrp
->fr_layout
== FR_COL
)
2959 /* get the minimal width from each frame in this column */
2961 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2963 n
= frame_minwidth(frp
, next_curwin
);
2970 /* Add up the minimal widths for all frames in this row. */
2972 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2973 m
+= frame_minwidth(frp
, next_curwin
);
2982 * Try to close all windows except current one.
2983 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
2984 * used and the buffer was modified.
2986 * Used by ":bdel" and ":only".
2989 close_others(message
, forceit
)
2991 int forceit
; /* always hide all other windows */
2997 if (lastwin
== firstwin
)
3008 /* Be very careful here: autocommands may change the window layout. */
3009 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3011 nextwp
= wp
->w_next
;
3012 if (wp
!= curwin
) /* don't close current window */
3015 /* Check if it's allowed to abandon this window */
3016 r
= can_abandon(wp
->w_buffer
, forceit
);
3018 if (!win_valid(wp
)) /* autocommands messed wp up */
3026 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3027 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3029 dialog_changed(wp
->w_buffer
, FALSE
);
3030 # ifdef FEAT_AUTOCMD
3031 if (!win_valid(wp
)) /* autocommands messed wp up */
3038 if (bufIsChanged(wp
->w_buffer
))
3042 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3046 if (message
&& lastwin
!= firstwin
)
3047 EMSG(_("E445: Other window contains changes"));
3050 #endif /* FEAT_WINDOWS */
3053 * Init the current window "curwin".
3054 * Called when a new file is being edited.
3059 redraw_win_later(curwin
, NOT_VALID
);
3060 curwin
->w_lines_valid
= 0;
3061 curwin
->w_cursor
.lnum
= 1;
3062 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3063 #ifdef FEAT_VIRTUALEDIT
3064 curwin
->w_cursor
.coladd
= 0;
3066 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3067 curwin
->w_pcmark
.col
= 0;
3068 curwin
->w_prev_pcmark
.lnum
= 0;
3069 curwin
->w_prev_pcmark
.col
= 0;
3070 curwin
->w_topline
= 1;
3072 curwin
->w_topfill
= 0;
3074 curwin
->w_botline
= 2;
3077 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3079 curwin
->w_farsi
= W_CONV
;
3084 * Allocate the first window and put an empty buffer in it.
3085 * Called from main().
3086 * Return FAIL when something goes wrong (out of memory).
3091 if (win_alloc_firstwin(NULL
) == FAIL
)
3095 first_tabpage
= alloc_tabpage();
3096 if (first_tabpage
== NULL
)
3098 first_tabpage
->tp_topframe
= topframe
;
3099 curtab
= first_tabpage
;
3105 * Allocate the first window or the first window in a new tab page.
3106 * When "oldwin" is NULL create an empty buffer for it.
3107 * When "oldwin" is not NULL copy info from it to the new window (only with
3109 * Return FAIL when something goes wrong (out of memory).
3112 win_alloc_firstwin(oldwin
)
3115 curwin
= win_alloc(NULL
);
3118 /* Very first window, need to create an empty buffer for it and
3119 * initialize from scratch. */
3120 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3121 if (curwin
== NULL
|| curbuf
== NULL
)
3123 curwin
->w_buffer
= curbuf
;
3124 curbuf
->b_nwindows
= 1; /* there is one window */
3126 curwin
->w_alist
= &global_alist
;
3128 curwin_init(); /* init current window */
3133 /* First window in new tab page, initialize it from "oldwin". */
3134 win_init(curwin
, oldwin
);
3136 # ifdef FEAT_SCROLLBIND
3137 /* We don't want scroll-binding in the first window. */
3138 curwin
->w_p_scb
= FALSE
;
3143 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3144 if (topframe
== NULL
)
3146 topframe
->fr_layout
= FR_LEAF
;
3147 #ifdef FEAT_VERTSPLIT
3148 topframe
->fr_width
= Columns
;
3150 topframe
->fr_height
= Rows
- p_ch
;
3151 topframe
->fr_win
= curwin
;
3152 curwin
->w_frame
= topframe
;
3158 * Initialize the window and frame size to the maximum.
3163 firstwin
->w_height
= ROWS_AVAIL
;
3164 topframe
->fr_height
= ROWS_AVAIL
;
3165 #ifdef FEAT_VERTSPLIT
3166 firstwin
->w_width
= Columns
;
3167 topframe
->fr_width
= Columns
;
3171 #if defined(FEAT_WINDOWS) || defined(PROTO)
3174 * Allocate a new tabpage_T and init the values.
3175 * Returns NULL when out of memory.
3182 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3188 for (i
= 0; i
< 3; i
++)
3189 tp
->tp_prev_which_scrollbars
[i
] = -1;
3192 tp
->tp_diff_invalid
= TRUE
;
3195 /* init t: variables */
3196 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3198 tp
->tp_ch_used
= p_ch
;
3212 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3218 * Create a new Tab page with one window.
3219 * It will edit the current buffer, like after ":split".
3220 * When "after" is 0 put it just after the current Tab page.
3221 * Otherwise put it just before tab page "after".
3222 * Return FAIL or OK.
3225 win_new_tabpage(after
)
3228 tabpage_T
*tp
= curtab
;
3232 newtp
= alloc_tabpage();
3236 /* Remember the current windows in this Tab page. */
3237 if (leave_tabpage(curbuf
) == FAIL
)
3244 /* Create a new empty window. */
3245 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3247 /* Make the new Tab page the new topframe. */
3250 /* New tab page becomes the first one. */
3251 newtp
->tp_next
= first_tabpage
;
3252 first_tabpage
= newtp
;
3258 /* Put new tab page before tab page "after". */
3260 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3261 && n
< after
; tp
= tp
->tp_next
)
3264 newtp
->tp_next
= tp
->tp_next
;
3265 tp
->tp_next
= newtp
;
3268 firstwin
->w_winrow
= tabline_height();
3269 win_comp_scroll(curwin
);
3271 newtp
->tp_topframe
= topframe
;
3274 #if defined(FEAT_GUI)
3275 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3276 * scrollbars. Have to update them anyway. */
3277 if (gui
.in_use
&& starting
== 0)
3279 gui_init_which_components(NULL
);
3280 gui_update_scrollbars(TRUE
);
3282 need_mouse_correct
= TRUE
;
3285 redraw_all_later(CLEAR
);
3287 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3288 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3293 /* Failed, get back the previous Tab page */
3294 enter_tabpage(curtab
, curbuf
);
3299 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3300 * like with ":split".
3301 * Returns OK if a new tab page was created, FAIL otherwise.
3306 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3310 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3311 postponed_split_tab
= 0;
3312 return win_new_tabpage(n
);
3318 * Create up to "maxcount" tabpages with empty windows.
3319 * Returns the number of resulting tab pages.
3322 make_tabpages(maxcount
)
3325 int count
= maxcount
;
3328 /* Limit to 'tabpagemax' tabs. */
3334 * Don't execute autocommands while creating the tab pages. Must do that
3335 * when putting the buffers in the windows.
3340 for (todo
= count
- 1; todo
> 0; --todo
)
3341 if (win_new_tabpage(0) == FAIL
)
3348 /* return actual number of tab pages */
3349 return (count
- todo
);
3353 * Return TRUE when "tpc" points to a valid tab page.
3361 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3368 * Find tab page "n" (first one is 1). Returns NULL when not found.
3377 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3383 * Get index of tab page "tp". First one has index 1.
3384 * When not found returns number of tab pages plus one.
3393 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3399 * Prepare for leaving the current tab page.
3400 * When autocomands change "curtab" we don't leave the tab page and return
3402 * Careful: When OK is returned need to get a new tab page very very soon!
3406 leave_tabpage(new_curbuf
)
3407 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3410 tabpage_T
*tp
= curtab
;
3413 reset_VIsual_and_resel(); /* stop Visual mode */
3416 if (new_curbuf
!= curbuf
)
3418 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3422 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3425 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3429 #if defined(FEAT_GUI)
3430 /* Remove the scrollbars. They may be added back later. */
3432 gui_remove_scrollbars();
3434 tp
->tp_curwin
= curwin
;
3435 tp
->tp_prevwin
= prevwin
;
3436 tp
->tp_firstwin
= firstwin
;
3437 tp
->tp_lastwin
= lastwin
;
3438 tp
->tp_old_Rows
= Rows
;
3439 tp
->tp_old_Columns
= Columns
;
3446 * Start using tab page "tp".
3447 * Only to be used after leave_tabpage() or freeing the current tab page.
3451 enter_tabpage(tp
, old_curbuf
)
3455 int old_off
= tp
->tp_firstwin
->w_winrow
;
3456 win_T
*next_prevwin
= tp
->tp_prevwin
;
3459 firstwin
= tp
->tp_firstwin
;
3460 lastwin
= tp
->tp_lastwin
;
3461 topframe
= tp
->tp_topframe
;
3463 /* We would like doing the TabEnter event first, but we don't have a
3464 * valid current window yet, which may break some commands.
3465 * This triggers autocommands, thus may make "tp" invalid. */
3466 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3467 prevwin
= next_prevwin
;
3470 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3472 if (old_curbuf
!= curbuf
)
3473 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3476 last_status(FALSE
); /* status line may appear or disappear */
3477 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3478 must_redraw
= CLEAR
; /* need to redraw everything */
3480 diff_need_scrollbind
= TRUE
;
3483 /* The tabpage line may have appeared or disappeared, may need to resize
3484 * the frames for that. When the Vim window was resized need to update
3485 * frame sizes too. Use the stored value of p_ch, so that it can be
3486 * different for each tab page. */
3487 p_ch
= curtab
->tp_ch_used
;
3488 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3489 #ifdef FEAT_GUI_TABLINE
3490 && !gui_use_tabline()
3494 #ifdef FEAT_VERTSPLIT
3495 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3496 shell_new_columns(); /* update window widths */
3499 #if defined(FEAT_GUI)
3500 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3501 * scrollbars. Have to update them anyway. */
3502 if (gui
.in_use
&& starting
== 0)
3504 gui_init_which_components(NULL
);
3505 gui_update_scrollbars(TRUE
);
3507 need_mouse_correct
= TRUE
;
3510 redraw_all_later(CLEAR
);
3514 * Go to tab page "n". For ":tab N" and "Ngt".
3515 * When "n" is 9999 go to the last tab page.
3527 /* Not allowed when editing the command line. */
3529 if (cmdwin_type
!= 0)
3537 /* If there is only one it can't work. */
3538 if (first_tabpage
->tp_next
== NULL
)
3547 /* No count, go to next tab page, wrap around end. */
3548 if (curtab
->tp_next
== NULL
)
3551 tp
= curtab
->tp_next
;
3555 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3558 for (i
= n
; i
< 0; ++i
)
3560 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3568 /* Go to last tab page. */
3569 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3574 /* Go to tab page "n". */
3575 tp
= find_tabpage(n
);
3583 goto_tabpage_tp(tp
);
3585 #ifdef FEAT_GUI_TABLINE
3586 if (gui_use_tabline())
3587 gui_mch_set_curtab(tabpage_index(curtab
));
3592 * Go to tabpage "tp".
3593 * Note: doesn't update the GUI tab.
3599 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3601 if (valid_tabpage(tp
))
3602 enter_tabpage(tp
, curbuf
);
3604 enter_tabpage(curtab
, curbuf
);
3609 * Enter window "wp" in tab page "tp".
3610 * Also updates the GUI tab.
3613 goto_tabpage_win(tp
, wp
)
3617 goto_tabpage_tp(tp
);
3618 if (curtab
== tp
&& win_valid(wp
))
3620 win_enter(wp
, TRUE
);
3621 # ifdef FEAT_GUI_TABLINE
3622 if (gui_use_tabline())
3623 gui_mch_set_curtab(tabpage_index(curtab
));
3629 * Move the current tab page to before tab page "nr".
3638 if (first_tabpage
->tp_next
== NULL
)
3641 /* Remove the current tab page from the list of tab pages. */
3642 if (curtab
== first_tabpage
)
3643 first_tabpage
= curtab
->tp_next
;
3646 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3647 if (tp
->tp_next
== curtab
)
3649 if (tp
== NULL
) /* "cannot happen" */
3651 tp
->tp_next
= curtab
->tp_next
;
3654 /* Re-insert it at the specified position. */
3657 curtab
->tp_next
= first_tabpage
;
3658 first_tabpage
= curtab
;
3662 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3664 curtab
->tp_next
= tp
->tp_next
;
3665 tp
->tp_next
= curtab
;
3668 /* Need to redraw the tabline. Tab page contents doesn't change. */
3669 redraw_tabline
= TRUE
;
3674 * Go to another window.
3675 * When jumping to another buffer, stop Visual mode. Do this before
3676 * changing windows so we can yank the selection into the '*' register.
3677 * When jumping to another window on the same buffer, adjust its cursor
3678 * position to keep the same Visual area.
3691 if (curbuf_locked())
3696 if (wp
->w_buffer
!= curbuf
)
3697 reset_VIsual_and_resel();
3698 else if (VIsual_active
)
3699 wp
->w_cursor
= curwin
->w_cursor
;
3703 need_mouse_correct
= TRUE
;
3705 win_enter(wp
, TRUE
);
3708 #if defined(FEAT_PERL) || defined(PROTO)
3710 * Find window number "winnr" (counting top to bottom).
3718 # ifdef FEAT_WINDOWS
3719 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3729 #ifdef FEAT_VERTSPLIT
3731 * Move to window above or below "count" times.
3734 win_goto_ver(up
, count
)
3735 int up
; /* TRUE to go to win above */
3742 foundfr
= curwin
->w_frame
;
3746 * First go upwards in the tree of frames until we find a upwards or
3747 * downwards neighbor.
3758 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3764 * Now go downwards to find the bottom or top frame in it.
3768 if (nfr
->fr_layout
== FR_LEAF
)
3774 if (nfr
->fr_layout
== FR_ROW
)
3776 /* Find the frame at the cursor row. */
3777 while (fr
->fr_next
!= NULL
3778 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3779 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3782 if (nfr
->fr_layout
== FR_COL
&& up
)
3783 while (fr
->fr_next
!= NULL
)
3789 if (foundfr
!= NULL
)
3790 win_goto(foundfr
->fr_win
);
3794 * Move to left or right window.
3797 win_goto_hor(left
, count
)
3798 int left
; /* TRUE to go to left win */
3805 foundfr
= curwin
->w_frame
;
3809 * First go upwards in the tree of frames until we find a left or
3821 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3827 * Now go downwards to find the leftmost or rightmost frame in it.
3831 if (nfr
->fr_layout
== FR_LEAF
)
3837 if (nfr
->fr_layout
== FR_COL
)
3839 /* Find the frame at the cursor row. */
3840 while (fr
->fr_next
!= NULL
3841 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3842 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3845 if (nfr
->fr_layout
== FR_ROW
&& left
)
3846 while (fr
->fr_next
!= NULL
)
3852 if (foundfr
!= NULL
)
3853 win_goto(foundfr
->fr_win
);
3858 * Make window "wp" the current window.
3861 win_enter(wp
, undo_sync
)
3865 win_enter_ext(wp
, undo_sync
, FALSE
);
3869 * Make window wp the current window.
3870 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3871 * been closed and isn't valid.
3874 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3880 int other_buffer
= FALSE
;
3883 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3887 if (!curwin_invalid
)
3890 * Be careful: If autocommands delete the window, return now.
3892 if (wp
->w_buffer
!= curbuf
)
3894 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3895 other_buffer
= TRUE
;
3899 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3903 /* autocmds may abort script processing */
3910 /* sync undo before leaving the current buffer */
3911 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
3913 /* may have to copy the buffer options when 'cpo' contains 'S' */
3914 if (wp
->w_buffer
!= curbuf
)
3915 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
3916 if (!curwin_invalid
)
3918 prevwin
= curwin
; /* remember for CTRL-W p */
3919 curwin
->w_redr_status
= TRUE
;
3922 curbuf
= wp
->w_buffer
;
3924 #ifdef FEAT_VIRTUALEDIT
3925 if (!virtual_active())
3926 curwin
->w_cursor
.coladd
= 0;
3928 changed_line_abv_curs(); /* assume cursor position needs updating */
3930 if (curwin
->w_localdir
!= NULL
)
3932 /* Window has a local directory: Save current directory as global
3933 * directory (unless that was done already) and change to the local
3935 if (globaldir
== NULL
)
3937 char_u cwd
[MAXPATHL
];
3939 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
3940 globaldir
= vim_strsave(cwd
);
3942 mch_chdir((char *)curwin
->w_localdir
);
3943 shorten_fnames(TRUE
);
3945 else if (globaldir
!= NULL
)
3947 /* Window doesn't have a local directory and we are not in the global
3948 * directory: Change to the global directory. */
3949 mch_chdir((char *)globaldir
);
3950 vim_free(globaldir
);
3952 shorten_fnames(TRUE
);
3956 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3958 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3964 curwin
->w_redr_status
= TRUE
;
3965 redraw_tabline
= TRUE
;
3967 redraw_later(VALID
); /* causes status line redraw */
3969 /* set window height to desired minimal value */
3970 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
3971 win_setheight((int)p_wh
);
3972 else if (curwin
->w_height
== 0)
3975 #ifdef FEAT_VERTSPLIT
3976 /* set window width to desired minimal value */
3977 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
3978 win_setwidth((int)p_wiw
);
3982 setmouse(); /* in case jumped to/from help buffer */
3985 /* Change directories when the 'acd' option is set. */
3989 #endif /* FEAT_WINDOWS */
3991 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
3993 * Jump to the first open window that contains buffer "buf", if one exists.
3994 * Returns a pointer to the window found, otherwise NULL.
3997 buf_jump_open_win(buf
)
4000 # ifdef FEAT_WINDOWS
4003 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4004 if (wp
->w_buffer
== buf
)
4007 win_enter(wp
, FALSE
);
4010 if (curwin
->w_buffer
== buf
)
4017 * Jump to the first open window in any tab page that contains buffer "buf",
4019 * Returns a pointer to the window found, otherwise NULL.
4022 buf_jump_open_tab(buf
)
4025 # ifdef FEAT_WINDOWS
4029 /* First try the current tab page. */
4030 wp
= buf_jump_open_win(buf
);
4034 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4037 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4038 if (wp
->w_buffer
== buf
)
4042 goto_tabpage_win(tp
, wp
);
4044 wp
= NULL
; /* something went wrong */
4051 if (curwin
->w_buffer
== buf
)
4059 * allocate a window structure and link it in the window list
4069 * allocate window structure and linesizes arrays
4071 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4072 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4081 /* Don't execute autocommands while the window is not properly
4082 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4087 * link the window in the window list
4090 win_append(after
, newwin
);
4092 #ifdef FEAT_VERTSPLIT
4093 newwin
->w_wincol
= 0;
4094 newwin
->w_width
= Columns
;
4097 /* position the display and the cursor at the top of the file. */
4098 newwin
->w_topline
= 1;
4100 newwin
->w_topfill
= 0;
4102 newwin
->w_botline
= 2;
4103 newwin
->w_cursor
.lnum
= 1;
4104 #ifdef FEAT_SCROLLBIND
4105 newwin
->w_scbind_pos
= 1;
4108 /* We won't calculate w_fraction until resizing the window */
4109 newwin
->w_fraction
= 0;
4110 newwin
->w_prev_fraction_row
= -1;
4115 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4117 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4118 SBAR_RIGHT
, newwin
);
4122 /* init w: variables */
4123 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4126 foldInitWin(newwin
);
4135 #if defined(FEAT_WINDOWS) || defined(PROTO)
4138 * remove window 'wp' from the window list and free the structure
4143 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4148 /* Don't execute autocommands while the window is halfway being deleted.
4149 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4153 #ifdef FEAT_MZSCHEME
4154 mzscheme_window_free(wp
);
4162 python_window_free(wp
);
4166 tcl_window_free(wp
);
4170 ruby_window_free(wp
);
4173 clear_winopt(&wp
->w_onebuf_opt
);
4174 clear_winopt(&wp
->w_allbuf_opt
);
4177 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4184 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4185 vim_free(wp
->w_tagstack
[i
].tagname
);
4187 vim_free(wp
->w_localdir
);
4188 #ifdef FEAT_SEARCH_EXTRA
4189 vim_free(wp
->w_match
[0].regprog
);
4190 vim_free(wp
->w_match
[1].regprog
);
4191 vim_free(wp
->w_match
[2].regprog
);
4193 #ifdef FEAT_JUMPLIST
4197 #ifdef FEAT_QUICKFIX
4204 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4205 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4207 #endif /* FEAT_GUI */
4218 * Append window "wp" in the window list after window "after".
4221 win_append(after
, wp
)
4226 if (after
== NULL
) /* after NULL is in front of the first */
4229 before
= after
->w_next
;
4231 wp
->w_next
= before
;
4240 before
->w_prev
= wp
;
4244 * Remove a window from the window list.
4249 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4251 if (wp
->w_prev
!= NULL
)
4252 wp
->w_prev
->w_next
= wp
->w_next
;
4253 else if (tp
== NULL
)
4254 firstwin
= wp
->w_next
;
4256 tp
->tp_firstwin
= wp
->w_next
;
4257 if (wp
->w_next
!= NULL
)
4258 wp
->w_next
->w_prev
= wp
->w_prev
;
4259 else if (tp
== NULL
)
4260 lastwin
= wp
->w_prev
;
4262 tp
->tp_lastwin
= wp
->w_prev
;
4266 * Append frame "frp" in a frame list after frame "after".
4269 frame_append(after
, frp
)
4270 frame_T
*after
, *frp
;
4272 frp
->fr_next
= after
->fr_next
;
4273 after
->fr_next
= frp
;
4274 if (frp
->fr_next
!= NULL
)
4275 frp
->fr_next
->fr_prev
= frp
;
4276 frp
->fr_prev
= after
;
4280 * Insert frame "frp" in a frame list before frame "before".
4283 frame_insert(before
, frp
)
4284 frame_T
*before
, *frp
;
4286 frp
->fr_next
= before
;
4287 frp
->fr_prev
= before
->fr_prev
;
4288 before
->fr_prev
= frp
;
4289 if (frp
->fr_prev
!= NULL
)
4290 frp
->fr_prev
->fr_next
= frp
;
4292 frp
->fr_parent
->fr_child
= frp
;
4296 * Remove a frame from a frame list.
4302 if (frp
->fr_prev
!= NULL
)
4303 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4305 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4306 if (frp
->fr_next
!= NULL
)
4307 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4310 #endif /* FEAT_WINDOWS */
4313 * Allocate w_lines[] for window "wp".
4314 * Return FAIL for failure, OK for success.
4320 wp
->w_lines_valid
= 0;
4321 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4322 if (wp
->w_lines
== NULL
)
4328 * free lsize arrays for a window
4334 vim_free(wp
->w_lines
);
4339 * Called from win_new_shellsize() after Rows changed.
4340 * This only does the current tab page, others must be done when made active.
4345 int h
= (int)ROWS_AVAIL
;
4347 if (firstwin
== NULL
) /* not initialized yet */
4350 if (h
< frame_minheight(topframe
, NULL
))
4351 h
= frame_minheight(topframe
, NULL
);
4353 /* First try setting the heights of windows with 'winfixheight'. If
4354 * that doesn't result in the right height, forget about that option. */
4355 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4356 if (topframe
->fr_height
!= h
)
4357 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4359 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4363 win_new_height(firstwin
, h
);
4367 curtab
->tp_ch_used
= p_ch
;
4371 /* Disabled: don't want making the screen smaller make a window larger. */
4373 win_equal(curwin
, FALSE
, 'v');
4377 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4379 * Called from win_new_shellsize() after Columns changed.
4384 if (firstwin
== NULL
) /* not initialized yet */
4387 /* First try setting the widths of windows with 'winfixwidth'. If that
4388 * doesn't result in the right width, forget about that option. */
4389 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4390 if (topframe
->fr_width
!= Columns
)
4391 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4393 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4395 /* Disabled: don't want making the screen smaller make a window larger. */
4397 win_equal(curwin
, FALSE
, 'h');
4402 #if defined(FEAT_CMDWIN) || defined(PROTO)
4404 * Save the size of all windows in "gap".
4413 ga_init2(gap
, (int)sizeof(int), 1);
4414 if (ga_grow(gap
, win_count() * 2) == OK
)
4415 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4417 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4418 wp
->w_width
+ wp
->w_vsep_width
;
4419 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4424 * Restore window sizes, but only if the number of windows is still the same.
4425 * Does not free the growarray.
4428 win_size_restore(gap
)
4434 if (win_count() * 2 == gap
->ga_len
)
4437 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4439 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4440 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4442 /* recompute the window positions */
4443 (void)win_comp_pos();
4446 #endif /* FEAT_CMDWIN */
4448 #if defined(FEAT_WINDOWS) || defined(PROTO)
4450 * Update the position for all windows, using the width and height of the
4452 * Returns the row just after the last window.
4457 int row
= tabline_height();
4460 frame_comp_pos(topframe
, &row
, &col
);
4465 * Update the position of the windows in frame "topfrp", using the width and
4466 * height of the frames.
4467 * "*row" and "*col" are the top-left position of the frame. They are updated
4468 * to the bottom-right position plus one.
4471 frame_comp_pos(topfrp
, row
, col
)
4478 #ifdef FEAT_VERTSPLIT
4483 wp
= topfrp
->fr_win
;
4486 if (wp
->w_winrow
!= *row
4487 #ifdef FEAT_VERTSPLIT
4488 || wp
->w_wincol
!= *col
4492 /* position changed, redraw */
4493 wp
->w_winrow
= *row
;
4494 #ifdef FEAT_VERTSPLIT
4495 wp
->w_wincol
= *col
;
4497 redraw_win_later(wp
, NOT_VALID
);
4498 wp
->w_redr_status
= TRUE
;
4500 *row
+= wp
->w_height
+ wp
->w_status_height
;
4501 #ifdef FEAT_VERTSPLIT
4502 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4507 #ifdef FEAT_VERTSPLIT
4511 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4513 #ifdef FEAT_VERTSPLIT
4514 if (topfrp
->fr_layout
== FR_ROW
)
4515 *row
= startrow
; /* all frames are at the same row */
4517 *col
= startcol
; /* all frames are at the same col */
4519 frame_comp_pos(frp
, row
, col
);
4524 #endif /* FEAT_WINDOWS */
4527 * Set current window height and take care of repositioning other windows to
4531 win_setheight(height
)
4534 win_setheight_win(height
, curwin
);
4538 * Set the window height of window "win" and take care of repositioning other
4539 * windows to fit around it.
4542 win_setheight_win(height
, win
)
4550 /* Always keep current window at least one line high, even when
4551 * 'winminheight' is zero. */
4561 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4563 /* recompute the window positions */
4564 row
= win_comp_pos();
4566 if (height
> topframe
->fr_height
)
4567 height
= topframe
->fr_height
;
4568 win
->w_height
= height
;
4573 * If there is extra space created between the last window and the command
4576 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4577 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4582 redraw_all_later(NOT_VALID
);
4585 #if defined(FEAT_WINDOWS) || defined(PROTO)
4588 * Set the height of a frame to "height" and take care that all frames and
4589 * windows inside it are resized. Also resize frames on the left and right if
4590 * the are in the same FR_ROW frame.
4593 * If the frame is part of a FR_COL frame, try fitting the frame in that
4594 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4595 * go to containing frames to resize them and make room.
4596 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4597 * Check for the minimal height of the FR_ROW frame.
4598 * At the top level we can also use change the command line height.
4601 frame_setheight(curfrp
, height
)
4605 int room
; /* total number of lines available */
4606 int take
; /* number of lines taken from other windows */
4607 int room_cmdline
; /* lines available from cmdline */
4613 /* If the height already is the desired value, nothing to do. */
4614 if (curfrp
->fr_height
== height
)
4617 if (curfrp
->fr_parent
== NULL
)
4619 /* topframe: can only change the command line */
4620 if (height
> ROWS_AVAIL
)
4621 height
= ROWS_AVAIL
;
4623 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4625 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4627 /* Row of frames: Also need to resize frames left and right of this
4628 * one. First check for the minimal height of these. */
4629 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4632 frame_setheight(curfrp
->fr_parent
, height
);
4637 * Column of frames: try to change only frames in this column.
4639 #ifdef FEAT_VERTSPLIT
4642 * 1: compute room available, if it's not enough try resizing the
4644 * 2: compute the room available and adjust the height to it.
4645 * Try not to reduce the height of a window with 'winfixheight' set.
4647 for (run
= 1; run
<= 2; ++run
)
4654 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4658 && frp
->fr_win
!= NULL
4659 && frp
->fr_win
->w_p_wfh
)
4660 room_reserved
+= frp
->fr_height
;
4661 room
+= frp
->fr_height
;
4663 room
-= frame_minheight(frp
, NULL
);
4665 #ifdef FEAT_VERTSPLIT
4666 if (curfrp
->fr_width
!= Columns
)
4671 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4672 + lastwin
->w_height
+ lastwin
->w_status_height
);
4673 if (room_cmdline
< 0)
4677 if (height
<= room
+ room_cmdline
)
4679 #ifdef FEAT_VERTSPLIT
4680 if (run
== 2 || curfrp
->fr_width
== Columns
)
4683 if (height
> room
+ room_cmdline
)
4684 height
= room
+ room_cmdline
;
4687 #ifdef FEAT_VERTSPLIT
4688 frame_setheight(curfrp
->fr_parent
, height
4689 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4695 * Compute the number of lines we will take from others frames (can be
4698 take
= height
- curfrp
->fr_height
;
4700 /* If there is not enough room, also reduce the height of a window
4701 * with 'winfixheight' set. */
4702 if (height
> room
+ room_cmdline
- room_reserved
)
4703 room_reserved
= room
+ room_cmdline
- height
;
4704 /* If there is only a 'winfixheight' window and making the
4705 * window smaller, need to make the other window taller. */
4706 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4709 if (take
> 0 && room_cmdline
> 0)
4711 /* use lines from cmdline first */
4712 if (take
< room_cmdline
)
4713 room_cmdline
= take
;
4714 take
-= room_cmdline
;
4715 topframe
->fr_height
+= room_cmdline
;
4719 * set the current frame to the new height
4721 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4724 * First take lines from the frames after the current frame. If
4725 * that is not enough, takes lines from frames above the current
4728 for (run
= 0; run
< 2; ++run
)
4731 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4733 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4734 while (frp
!= NULL
&& take
!= 0)
4736 h
= frame_minheight(frp
, NULL
);
4737 if (room_reserved
> 0
4738 && frp
->fr_win
!= NULL
4739 && frp
->fr_win
->w_p_wfh
)
4741 if (room_reserved
>= frp
->fr_height
)
4742 room_reserved
-= frp
->fr_height
;
4745 if (frp
->fr_height
- room_reserved
> take
)
4746 room_reserved
= frp
->fr_height
- take
;
4747 take
-= frp
->fr_height
- room_reserved
;
4748 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4754 if (frp
->fr_height
- take
< h
)
4756 take
-= frp
->fr_height
- h
;
4757 frame_new_height(frp
, h
, FALSE
, FALSE
);
4761 frame_new_height(frp
, frp
->fr_height
- take
,
4775 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4777 * Set current window width and take care of repositioning other windows to
4784 win_setwidth_win(width
, curwin
);
4788 win_setwidth_win(width
, wp
)
4792 /* Always keep current window at least one column wide, even when
4793 * 'winminwidth' is zero. */
4802 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4804 /* recompute the window positions */
4805 (void)win_comp_pos();
4807 redraw_all_later(NOT_VALID
);
4811 * Set the width of a frame to "width" and take care that all frames and
4812 * windows inside it are resized. Also resize frames above and below if the
4813 * are in the same FR_ROW frame.
4815 * Strategy is similar to frame_setheight().
4818 frame_setwidth(curfrp
, width
)
4822 int room
; /* total number of lines available */
4823 int take
; /* number of lines taken from other windows */
4829 /* If the width already is the desired value, nothing to do. */
4830 if (curfrp
->fr_width
== width
)
4833 if (curfrp
->fr_parent
== NULL
)
4834 /* topframe: can't change width */
4837 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4839 /* Column of frames: Also need to resize frames above and below of
4840 * this one. First check for the minimal width of these. */
4841 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4844 frame_setwidth(curfrp
->fr_parent
, width
);
4849 * Row of frames: try to change only frames in this row.
4852 * 1: compute room available, if it's not enough try resizing the
4854 * 2: compute the room available and adjust the width to it.
4856 for (run
= 1; run
<= 2; ++run
)
4860 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4864 && frp
->fr_win
!= NULL
4865 && frp
->fr_win
->w_p_wfw
)
4866 room_reserved
+= frp
->fr_width
;
4867 room
+= frp
->fr_width
;
4869 room
-= frame_minwidth(frp
, NULL
);
4874 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4880 frame_setwidth(curfrp
->fr_parent
, width
4881 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4885 * Compute the number of lines we will take from others frames (can be
4888 take
= width
- curfrp
->fr_width
;
4890 /* If there is not enough room, also reduce the width of a window
4891 * with 'winfixwidth' set. */
4892 if (width
> room
- room_reserved
)
4893 room_reserved
= room
- width
;
4894 /* If there is only a 'winfixwidth' window and making the
4895 * window smaller, need to make the other window narrower. */
4896 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4900 * set the current frame to the new width
4902 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
4905 * First take lines from the frames right of the current frame. If
4906 * that is not enough, takes lines from frames left of the current
4909 for (run
= 0; run
< 2; ++run
)
4912 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4914 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4915 while (frp
!= NULL
&& take
!= 0)
4917 w
= frame_minwidth(frp
, NULL
);
4918 if (room_reserved
> 0
4919 && frp
->fr_win
!= NULL
4920 && frp
->fr_win
->w_p_wfw
)
4922 if (room_reserved
>= frp
->fr_width
)
4923 room_reserved
-= frp
->fr_width
;
4926 if (frp
->fr_width
- room_reserved
> take
)
4927 room_reserved
= frp
->fr_width
- take
;
4928 take
-= frp
->fr_width
- room_reserved
;
4929 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
4935 if (frp
->fr_width
- take
< w
)
4937 take
-= frp
->fr_width
- w
;
4938 frame_new_width(frp
, w
, FALSE
, FALSE
);
4942 frame_new_width(frp
, frp
->fr_width
- take
,
4955 #endif /* FEAT_VERTSPLIT */
4958 * Check 'winminheight' for a valid value.
4967 /* loop until there is a 'winminheight' that is possible */
4970 /* TODO: handle vertical splits */
4972 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4973 room
+= wp
->w_height
- p_wmh
;
4988 * Status line of dragwin is dragged "offset" lines down (negative is up).
4991 win_drag_status_line(dragwin
, offset
)
4999 int up
; /* if TRUE, drag status line up, otherwise down */
5002 fr
= dragwin
->w_frame
;
5004 if (fr
!= topframe
) /* more than one window */
5007 /* When the parent frame is not a column of frames, its parent should
5009 if (fr
->fr_layout
!= FR_COL
)
5012 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5017 /* If this is the last frame in a column, may want to resize the parent
5018 * frame instead (go two up to skip a row of frames). */
5019 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5028 if (offset
< 0) /* drag up */
5032 /* sum up the room of the current frame and above it */
5035 /* only one window */
5036 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5041 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5043 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5048 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5050 else /* drag down */
5054 * Only dragging the last status line can reduce p_ch.
5056 room
= Rows
- cmdline_row
;
5057 if (curfr
->fr_next
== NULL
)
5063 /* sum up the room of frames below of the current one */
5064 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5065 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5066 fr
= curfr
; /* put fr at window that grows */
5069 if (room
< offset
) /* Not enough room */
5070 offset
= room
; /* Move as far as we can */
5075 * Grow frame fr by "offset" lines.
5076 * Doesn't happen when dragging the last status line up.
5079 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5082 fr
= curfr
; /* current frame gets smaller */
5084 fr
= curfr
->fr_next
; /* next frame gets smaller */
5087 * Now make the other frames smaller.
5089 while (fr
!= NULL
&& offset
> 0)
5091 n
= frame_minheight(fr
, NULL
);
5092 if (fr
->fr_height
- offset
<= n
)
5094 offset
-= fr
->fr_height
- n
;
5095 frame_new_height(fr
, n
, !up
, FALSE
);
5099 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5107 row
= win_comp_pos();
5108 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5110 p_ch
= Rows
- cmdline_row
;
5113 curtab
->tp_ch_used
= p_ch
;
5114 redraw_all_later(SOME_VALID
);
5118 #ifdef FEAT_VERTSPLIT
5120 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5123 win_drag_vsep_line(dragwin
, offset
)
5130 int left
; /* if TRUE, drag separator line left, otherwise right */
5133 fr
= dragwin
->w_frame
;
5134 if (fr
== topframe
) /* only one window (cannot happen?) */
5138 /* When the parent frame is not a row of frames, its parent should be. */
5139 if (fr
->fr_layout
!= FR_ROW
)
5141 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5147 /* If this is the last frame in a row, may want to resize a parent
5149 while (curfr
->fr_next
== NULL
)
5162 if (offset
< 0) /* drag left */
5166 /* sum up the room of the current frame and left of it */
5168 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5170 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5174 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5176 else /* drag right */
5179 /* sum up the room of frames right of the current one */
5181 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5182 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5183 fr
= curfr
; /* put fr at window that grows */
5186 if (room
< offset
) /* Not enough room */
5187 offset
= room
; /* Move as far as we can */
5188 if (offset
<= 0) /* No room at all, quit. */
5191 /* grow frame fr by offset lines */
5192 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5194 /* shrink other frames: current and at the left or at the right */
5196 fr
= curfr
; /* current frame gets smaller */
5198 fr
= curfr
->fr_next
; /* next frame gets smaller */
5200 while (fr
!= NULL
&& offset
> 0)
5202 n
= frame_minwidth(fr
, NULL
);
5203 if (fr
->fr_width
- offset
<= n
)
5205 offset
-= fr
->fr_width
- n
;
5206 frame_new_width(fr
, n
, !left
, FALSE
);
5210 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5218 (void)win_comp_pos();
5219 redraw_all_later(NOT_VALID
);
5221 #endif /* FEAT_VERTSPLIT */
5222 #endif /* FEAT_MOUSE */
5224 #endif /* FEAT_WINDOWS */
5227 * Set the height of a window.
5228 * This takes care of the things inside the window, not what happens to the
5229 * window position, the frame or to other windows.
5232 win_new_height(wp
, height
)
5237 int sline
, line_size
;
5238 #define FRACTION_MULT 16384L
5240 /* Don't want a negative height. Happens when splitting a tiny window.
5241 * Will equalize heights soon to fix it. */
5244 if (wp
->w_height
== height
)
5245 return; /* nothing to do */
5247 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5248 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5249 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5251 wp
->w_height
= height
;
5254 /* Don't change w_topline when height is zero. Don't set w_topline when
5255 * 'scrollbind' is set and this isn't the current window. */
5257 #ifdef FEAT_SCROLLBIND
5258 && (!wp
->w_p_scb
|| wp
== curwin
)
5263 * Find a value for w_topline that shows the cursor at the same
5264 * relative position in the window as before (more or less).
5266 lnum
= wp
->w_cursor
.lnum
;
5267 if (lnum
< 1) /* can happen when starting up */
5269 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5270 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5271 sline
= wp
->w_wrow
- line_size
;
5275 /* Make sure the whole cursor line is visible, if possible. */
5276 int rows
= plines_win(wp
, lnum
, FALSE
);
5278 if (sline
> wp
->w_height
- rows
)
5280 sline
= wp
->w_height
- rows
;
5281 wp
->w_wrow
-= rows
- line_size
;
5288 * Cursor line would go off top of screen if w_wrow was this high.
5289 * Make cursor line the first line in the window. If not enough
5290 * room use w_skipcol;
5292 wp
->w_wrow
= line_size
;
5293 if (wp
->w_wrow
>= wp
->w_height
5294 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5296 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5298 while (wp
->w_wrow
>= wp
->w_height
)
5300 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5308 while (sline
> 0 && lnum
> 1)
5311 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5314 /* first line in buffer is folded */
5322 if (lnum
== wp
->w_topline
)
5323 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5327 line_size
= plines_win(wp
, lnum
, TRUE
);
5334 * Line we want at top would go off top of screen. Use next
5338 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5341 wp
->w_wrow
-= line_size
+ sline
;
5345 /* First line of file reached, use that as topline. */
5347 wp
->w_wrow
-= sline
;
5350 set_topline(wp
, lnum
);
5357 curs_columns(FALSE
); /* validate w_wrow */
5359 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5361 win_comp_scroll(wp
);
5362 redraw_win_later(wp
, SOME_VALID
);
5364 wp
->w_redr_status
= TRUE
;
5366 invalidate_botline_win(wp
);
5369 #ifdef FEAT_VERTSPLIT
5371 * Set the width of a window.
5374 win_new_width(wp
, width
)
5378 wp
->w_width
= width
;
5379 wp
->w_lines_valid
= 0;
5380 changed_line_abv_curs_win(wp
);
5381 invalidate_botline_win(wp
);
5385 curs_columns(TRUE
); /* validate w_wrow */
5387 redraw_win_later(wp
, NOT_VALID
);
5388 wp
->w_redr_status
= TRUE
;
5396 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5397 if (wp
->w_p_scr
== 0)
5402 * command_height: called whenever p_ch has been changed
5410 int old_p_ch
= curtab
->tp_ch_used
;
5412 /* Use the value of p_ch that we remembered. This is needed for when the
5413 * GUI starts up, we can't be sure in what order things happen. And when
5414 * p_ch was changed in another tab page. */
5415 curtab
->tp_ch_used
= p_ch
;
5417 /* Find bottom frame with width of screen. */
5418 frp
= lastwin
->w_frame
;
5419 # ifdef FEAT_VERTSPLIT
5420 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5421 frp
= frp
->fr_parent
;
5424 /* Avoid changing the height of a window with 'winfixheight' set. */
5425 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5426 && frp
->fr_win
->w_p_wfh
)
5429 if (starting
!= NO_SCREEN
)
5431 cmdline_row
= Rows
- p_ch
;
5433 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5435 while (p_ch
> old_p_ch
)
5441 cmdline_row
= Rows
- p_ch
;
5444 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5445 if (h
> p_ch
- old_p_ch
)
5446 h
= p_ch
- old_p_ch
;
5448 frame_add_height(frp
, -h
);
5452 /* Recompute window positions. */
5453 (void)win_comp_pos();
5455 /* clear the lines added to cmdline */
5457 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5458 (int)Columns
, ' ', ' ', 0);
5459 msg_row
= cmdline_row
;
5460 redraw_cmdline
= TRUE
;
5464 if (msg_row
< cmdline_row
)
5465 msg_row
= cmdline_row
;
5466 redraw_cmdline
= TRUE
;
5468 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5470 /* Recompute window positions. */
5471 if (frp
!= lastwin
->w_frame
)
5472 (void)win_comp_pos();
5474 cmdline_row
= Rows
- p_ch
;
5475 win_setheight(cmdline_row
);
5479 #if defined(FEAT_WINDOWS) || defined(PROTO)
5481 * Resize frame "frp" to be "n" lines higher (negative for less high).
5482 * Also resize the frames it is contained in.
5485 frame_add_height(frp
, n
)
5489 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5492 frp
= frp
->fr_parent
;
5495 frp
->fr_height
+= n
;
5500 * Add or remove a status line for the bottom window(s), according to the
5501 * value of 'laststatus'.
5504 last_status(morewin
)
5505 int morewin
; /* pretend there are two or more windows */
5507 /* Don't make a difference between horizontal or vertical split. */
5508 last_status_rec(topframe
, (p_ls
== 2
5509 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5513 last_status_rec(fr
, statusline
)
5520 if (fr
->fr_layout
== FR_LEAF
)
5523 if (wp
->w_status_height
!= 0 && !statusline
)
5525 /* remove status line */
5526 win_new_height(wp
, wp
->w_height
+ 1);
5527 wp
->w_status_height
= 0;
5530 else if (wp
->w_status_height
== 0 && statusline
)
5532 /* Find a frame to take a line from. */
5534 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5541 /* In a column of frames: go to frame above. If already at
5542 * the top or in a row of frames: go to parent. */
5543 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5548 wp
->w_status_height
= 1;
5551 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5552 frame_fix_height(wp
);
5553 (void)win_comp_pos();
5556 win_new_height(wp
, wp
->w_height
- 1);
5558 redraw_all_later(SOME_VALID
);
5561 #ifdef FEAT_VERTSPLIT
5562 else if (fr
->fr_layout
== FR_ROW
)
5564 /* vertically split windows, set status line for each one */
5565 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5566 last_status_rec(fp
, statusline
);
5571 /* horizontally split window, set status line for last one */
5572 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5574 last_status_rec(fp
, statusline
);
5579 * Return the number of lines used by the tab page line.
5584 #ifdef FEAT_GUI_TABLINE
5585 /* When the GUI has the tabline then this always returns zero. */
5586 if (gui_use_tabline())
5592 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5597 #endif /* FEAT_WINDOWS */
5599 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5601 * Get the file name at the cursor.
5602 * If Visual mode is active, use the selected text if it's in one line.
5603 * Returns the name in allocated memory, NULL for failure.
5606 grab_file_name(count
, file_lnum
)
5608 linenr_T
*file_lnum
;
5616 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5618 return find_file_name_in_path(ptr
, len
,
5619 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5622 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5628 * Return the file name under or after the cursor.
5630 * The 'path' option is searched if the file name is not absolute.
5631 * The string returned has been alloc'ed and should be freed by the caller.
5632 * NULL is returned if the file name or file is not found.
5635 * FNAME_MESS give error messages
5636 * FNAME_EXP expand to path
5637 * FNAME_HYP check for hypertext link
5638 * FNAME_INCL apply "includeexpr"
5641 file_name_at_cursor(options
, count
, file_lnum
)
5644 linenr_T
*file_lnum
;
5646 return file_name_in_line(ml_get_curline(),
5647 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5652 * Return the name of the file under or after ptr[col].
5653 * Otherwise like file_name_at_cursor().
5656 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5661 char_u
*rel_fname
; /* file we are searching relative to */
5662 linenr_T
*file_lnum
; /* line number after the file name */
5668 * search forward for what could be the start of a file name
5671 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5673 if (*ptr
== NUL
) /* nothing found */
5675 if (options
& FNAME_MESS
)
5676 EMSG(_("E446: No file name under cursor"));
5681 * Search backward for first char of the file name.
5682 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5687 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5691 if (vim_isfilec(ptr
[-1])
5692 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5699 * Search forward for the last char of the file name.
5700 * Also allow "://" when ':' is not in 'isfname'.
5703 while (vim_isfilec(ptr
[len
])
5704 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5707 len
+= (*mb_ptr2len
)(ptr
+ len
);
5713 * If there is trailing punctuation, remove it.
5714 * But don't remove "..", could be a directory name.
5716 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5717 && ptr
[len
- 2] != '.')
5720 if (file_lnum
!= NULL
)
5724 /* Get the number after the file name and a separator character */
5730 ++p
; /* skip the separator */
5733 *file_lnum
= (int)getdigits(&p
);
5737 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5740 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5741 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5744 eval_includeexpr(ptr
, len
)
5750 set_vim_var_string(VV_FNAME
, ptr
, len
);
5751 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5752 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5753 set_vim_var_string(VV_FNAME
, NULL
, 0);
5759 * Return the name of the file ptr[len] in 'path'.
5760 * Otherwise like file_name_at_cursor().
5763 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5768 char_u
*rel_fname
; /* file we are searching relative to */
5772 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5773 char_u
*tofree
= NULL
;
5775 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5777 tofree
= eval_includeexpr(ptr
, len
);
5781 len
= (int)STRLEN(ptr
);
5786 if (options
& FNAME_EXP
)
5788 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5791 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5793 * If the file could not be found in a normal way, try applying
5794 * 'includeexpr' (unless done already).
5796 if (file_name
== NULL
5797 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5799 tofree
= eval_includeexpr(ptr
, len
);
5803 len
= (int)STRLEN(ptr
);
5804 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5809 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5813 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5817 /* Repeat finding the file "count" times. This matters when it
5818 * appears several times in the path. */
5819 while (file_name
!= NULL
&& --count
> 0)
5821 vim_free(file_name
);
5822 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5826 file_name
= vim_strnsave(ptr
, len
);
5828 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5834 #endif /* FEAT_SEARCHPATH */
5837 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5838 * Also check for ":\\", which MS Internet Explorer accepts, return
5845 if (STRNCMP(p
, "://", (size_t)3) == 0)
5847 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5848 return URL_BACKSLASH
;
5853 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5854 * Return URL_BACKSLASH for "name:\\".
5855 * Return zero otherwise.
5858 path_with_url(fname
)
5863 for (p
= fname
; isalpha(*p
); ++p
)
5865 return path_is_url(p
);
5869 * Return TRUE if "name" is a full (absolute) path name or URL.
5875 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5879 * Get absolute file name into buffer "buf[len]".
5881 * return FAIL for failure, OK otherwise
5884 vim_FullName(fname
, buf
, len
, force
)
5885 char_u
*fname
, *buf
;
5887 int force
; /* force expansion even when already absolute */
5896 url
= path_with_url(fname
);
5898 retval
= mch_FullName(fname
, buf
, len
, force
);
5899 if (url
|| retval
== FAIL
)
5901 /* something failed; use the file name (truncate when too long) */
5902 vim_strncpy(buf
, fname
, len
- 1);
5904 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
5911 * Return the minimal number of rows that is needed on the screen to display
5912 * the current number of windows.
5923 if (firstwin
== NULL
) /* not initialized yet */
5928 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
5930 n
= frame_minheight(tp
->tp_topframe
, NULL
);
5934 total
+= tabline_height();
5936 total
= 1; /* at least one window should have a line! */
5938 total
+= 1; /* count the room for the command line */
5943 * Return TRUE if there is only one window (in the current tab page), not
5944 * counting a help or preview window, unless it is the current window.
5953 /* If there is another tab page there always is another window. */
5954 if (first_tabpage
->tp_next
!= NULL
)
5957 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5958 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
5959 # ifdef FEAT_QUICKFIX
5964 return (count
<= 1);
5970 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
5972 * Correct the cursor line number in other windows. Used after changing the
5973 * current buffer, and before applying autocommands.
5974 * When "do_curwin" is TRUE, also check current window.
5977 check_lnums(do_curwin
)
5985 FOR_ALL_TAB_WINDOWS(tp
, wp
)
5986 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
5992 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
5993 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
5994 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
5995 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6000 #if defined(FEAT_WINDOWS) || defined(PROTO)
6003 * A snapshot of the window sizes, to restore them after closing the help
6005 * Only these fields are used:
6011 * fr_win (only valid for the old curwin, NULL otherwise)
6015 * Create a snapshot of the current frame sizes.
6020 clear_snapshot(curtab
);
6021 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6025 make_snapshot_rec(fr
, frp
)
6029 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6032 (*frp
)->fr_layout
= fr
->fr_layout
;
6033 # ifdef FEAT_VERTSPLIT
6034 (*frp
)->fr_width
= fr
->fr_width
;
6036 (*frp
)->fr_height
= fr
->fr_height
;
6037 if (fr
->fr_next
!= NULL
)
6038 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6039 if (fr
->fr_child
!= NULL
)
6040 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6041 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6042 (*frp
)->fr_win
= curwin
;
6046 * Remove any existing snapshot.
6052 clear_snapshot_rec(tp
->tp_snapshot
);
6053 tp
->tp_snapshot
= NULL
;
6057 clear_snapshot_rec(fr
)
6062 clear_snapshot_rec(fr
->fr_next
);
6063 clear_snapshot_rec(fr
->fr_child
);
6069 * Restore a previously created snapshot, if there is any.
6070 * This is only done if the screen size didn't change and the window layout is
6074 restore_snapshot(close_curwin
)
6075 int close_curwin
; /* closing current window */
6079 if (curtab
->tp_snapshot
!= NULL
6080 # ifdef FEAT_VERTSPLIT
6081 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6083 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6084 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6086 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6088 if (wp
!= NULL
&& close_curwin
)
6090 redraw_all_later(CLEAR
);
6092 clear_snapshot(curtab
);
6096 * Check if frames "sn" and "fr" have the same layout, same following frames
6097 * and same children.
6100 check_snapshot_rec(sn
, fr
)
6104 if (sn
->fr_layout
!= fr
->fr_layout
6105 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6106 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6107 || (sn
->fr_next
!= NULL
6108 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6109 || (sn
->fr_child
!= NULL
6110 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6116 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6117 * following frames and children.
6118 * Returns a pointer to the old current window, or NULL.
6121 restore_snapshot_rec(sn
, fr
)
6128 fr
->fr_height
= sn
->fr_height
;
6129 # ifdef FEAT_VERTSPLIT
6130 fr
->fr_width
= sn
->fr_width
;
6132 if (fr
->fr_layout
== FR_LEAF
)
6134 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6135 # ifdef FEAT_VERTSPLIT
6136 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6140 if (sn
->fr_next
!= NULL
)
6142 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6146 if (sn
->fr_child
!= NULL
)
6148 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6157 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6159 * Return TRUE if there is any vertically split window.
6166 if (topframe
->fr_layout
== FR_ROW
)
6169 if (topframe
->fr_layout
== FR_COL
)
6170 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6171 if (fr
->fr_layout
== FR_ROW
)