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.
12 static int path_is_url
__ARGS((char_u
*p
));
13 #if defined(FEAT_WINDOWS) || defined(PROTO)
14 static int win_split_ins
__ARGS((int size
, int flags
, win_T
*newwin
, int dir
));
15 static void win_init
__ARGS((win_T
*newp
, win_T
*oldp
));
16 static void frame_comp_pos
__ARGS((frame_T
*topfrp
, int *row
, int *col
));
17 static void frame_setheight
__ARGS((frame_T
*curfrp
, int height
));
19 static void frame_setwidth
__ARGS((frame_T
*curfrp
, int width
));
21 static void win_exchange
__ARGS((long));
22 static void win_rotate
__ARGS((int, int));
23 static void win_totop
__ARGS((int size
, int flags
));
24 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
));
25 static int last_window
__ARGS((void));
26 static win_T
*win_free_mem
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
27 static win_T
*winframe_remove
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
28 static frame_T
*win_altframe
__ARGS((win_T
*win
, tabpage_T
*tp
));
29 static tabpage_T
*alt_tabpage
__ARGS((void));
30 static win_T
*frame2win
__ARGS((frame_T
*frp
));
31 static int frame_has_win
__ARGS((frame_T
*frp
, win_T
*wp
));
32 static void frame_new_height
__ARGS((frame_T
*topfrp
, int height
, int topfirst
, int wfh
));
33 static int frame_fixed_height
__ARGS((frame_T
*frp
));
35 static int frame_fixed_width
__ARGS((frame_T
*frp
));
36 static void frame_add_statusline
__ARGS((frame_T
*frp
));
37 static void frame_new_width
__ARGS((frame_T
*topfrp
, int width
, int leftfirst
, int wfw
));
38 static void frame_add_vsep
__ARGS((frame_T
*frp
));
39 static int frame_minwidth
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
40 static void frame_fix_width
__ARGS((win_T
*wp
));
43 static int win_alloc_firstwin
__ARGS((win_T
*oldwin
));
44 #if defined(FEAT_WINDOWS) || defined(PROTO)
45 static tabpage_T
*alloc_tabpage
__ARGS((void));
46 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
47 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
48 static void frame_fix_height
__ARGS((win_T
*wp
));
49 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
50 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
51 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
52 static void win_append
__ARGS((win_T
*, win_T
*));
53 static void win_remove
__ARGS((win_T
*, tabpage_T
*tp
));
54 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
55 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
56 static void frame_remove
__ARGS((frame_T
*frp
));
58 static void win_new_width
__ARGS((win_T
*wp
, int width
));
59 static void win_goto_ver
__ARGS((int up
, long count
));
60 static void win_goto_hor
__ARGS((int left
, long count
));
62 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
63 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
65 static void make_snapshot
__ARGS((void));
66 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
67 static void clear_snapshot
__ARGS((tabpage_T
*tp
));
68 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
69 static void restore_snapshot
__ARGS((int close_curwin
));
70 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
71 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
73 #endif /* FEAT_WINDOWS */
75 static win_T
*win_alloc
__ARGS((win_T
*after
));
76 static void win_new_height
__ARGS((win_T
*, int));
78 #define URL_SLASH 1 /* path_is_url() has found "://" */
79 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
81 #define NOWIN (win_T *)-1 /* non-existing window */
84 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
86 # define ROWS_AVAIL (Rows - p_ch)
89 #if defined(FEAT_WINDOWS) || defined(PROTO)
91 static char *m_onlyone
= N_("Already only one window");
94 * all CTRL-W window commands are handled here, called from normal_cmd().
97 do_window(nchar
, Prenum
, xchar
)
100 int xchar
; /* extra char from ":wincmd gx" or NUL */
104 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
109 int type
= FIND_DEFINE
;
120 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
122 # define CHECK_CMDWIN
127 /* split current window in two parts, horizontally */
133 reset_VIsual_and_resel(); /* stop Visual mode */
136 /* When splitting the quickfix window open a new buffer in it,
137 * don't replicate the quickfix buffer. */
138 if (bt_quickfix(curbuf
))
142 need_mouse_correct
= TRUE
;
144 win_split((int)Prenum
, 0);
147 #ifdef FEAT_VERTSPLIT
148 /* split current window in two parts, vertically */
153 reset_VIsual_and_resel(); /* stop Visual mode */
156 need_mouse_correct
= TRUE
;
158 win_split((int)Prenum
, WSP_VERT
);
162 /* split current window and edit alternate file */
167 reset_VIsual_and_resel(); /* stop Visual mode */
169 STRCPY(cbuf
, "split #");
171 sprintf((char *)cbuf
+ 7, "%ld", Prenum
);
172 do_cmdline_cmd(cbuf
);
175 /* open new window */
180 reset_VIsual_and_resel(); /* stop Visual mode */
186 sprintf((char *)cbuf
, "%ld", Prenum
); /* window height */
190 do_cmdline_cmd(cbuf
);
193 /* quit current window */
197 reset_VIsual_and_resel(); /* stop Visual mode */
199 do_cmdline_cmd((char_u
*)"quit");
202 /* close current window */
206 reset_VIsual_and_resel(); /* stop Visual mode */
208 do_cmdline_cmd((char_u
*)"close");
211 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
212 /* close preview window */
217 reset_VIsual_and_resel(); /* stop Visual mode */
219 do_cmdline_cmd((char_u
*)"pclose");
222 /* cursor to preview window */
224 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
228 EMSG(_("E441: There is no preview window"));
234 /* close all but current window */
239 reset_VIsual_and_resel(); /* stop Visual mode */
241 do_cmdline_cmd((char_u
*)"only");
244 /* cursor to next window with wrap around */
247 /* cursor to previous window with wrap around */
250 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
254 if (Prenum
) /* go to specified window */
256 for (wp
= firstwin
; --Prenum
> 0; )
258 if (wp
->w_next
== NULL
)
266 if (nchar
== 'W') /* go to previous window */
270 wp
= lastwin
; /* wrap around */
272 else /* go to next window */
276 wp
= firstwin
; /* wrap around */
283 /* cursor to window below */
288 #ifdef FEAT_VERTSPLIT
289 win_goto_ver(FALSE
, Prenum1
);
291 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
298 /* cursor to window above */
303 #ifdef FEAT_VERTSPLIT
304 win_goto_ver(TRUE
, Prenum1
);
306 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
313 #ifdef FEAT_VERTSPLIT
314 /* cursor to left window */
320 win_goto_hor(TRUE
, Prenum1
);
323 /* cursor to right window */
328 win_goto_hor(FALSE
, Prenum1
);
332 /* move window to new tab page */
334 if (firstwin
== lastwin
)
338 tabpage_T
*oldtab
= curtab
;
341 /* First create a new tab with the window, then go back to
342 * the old tab and close the window there. */
344 if (win_new_tabpage((int)Prenum
) == OK
345 && valid_tabpage(oldtab
))
348 goto_tabpage_tp(oldtab
);
350 win_close(curwin
, FALSE
);
351 if (valid_tabpage(newtab
))
352 goto_tabpage_tp(newtab
);
357 /* cursor to top-left window */
363 /* cursor to bottom-right window */
369 /* cursor to last accessed (previous) window */
378 /* exchange current and next window */
382 win_exchange(Prenum
);
385 /* rotate windows downwards */
390 reset_VIsual_and_resel(); /* stop Visual mode */
392 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
395 /* rotate windows upwards */
399 reset_VIsual_and_resel(); /* stop Visual mode */
401 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
404 /* move window to the very top/bottom/left/right */
407 #ifdef FEAT_VERTSPLIT
412 win_totop((int)Prenum
,
413 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
414 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
417 /* make all windows the same height */
420 need_mouse_correct
= TRUE
;
422 win_equal(NULL
, FALSE
, 'b');
425 /* increase current window height */
428 need_mouse_correct
= TRUE
;
430 win_setheight(curwin
->w_height
+ (int)Prenum1
);
433 /* decrease current window height */
436 need_mouse_correct
= TRUE
;
438 win_setheight(curwin
->w_height
- (int)Prenum1
);
441 /* set current window height */
445 need_mouse_correct
= TRUE
;
447 win_setheight(Prenum
? (int)Prenum
: 9999);
450 #ifdef FEAT_VERTSPLIT
451 /* increase current window width */
454 need_mouse_correct
= TRUE
;
456 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
459 /* decrease current window width */
462 need_mouse_correct
= TRUE
;
464 win_setwidth(curwin
->w_width
- (int)Prenum1
);
467 /* set current window width */
470 need_mouse_correct
= TRUE
;
472 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
476 /* jump to tag and split window if tag exists (in preview window) */
477 #if defined(FEAT_QUICKFIX)
481 g_do_tagpreview
= Prenum
;
483 g_do_tagpreview
= p_pvh
;
490 reset_VIsual_and_resel(); /* stop Visual mode */
493 postponed_split
= Prenum
;
495 postponed_split
= -1;
497 /* Execute the command right here, required when
498 * "wincmd ]" was used in a function. */
499 do_nv_ident(Ctrl_RSB
, NUL
);
502 #ifdef FEAT_SEARCHPATH
503 /* edit file name under cursor in a new window */
510 ptr
= grab_file_name(Prenum1
, &lnum
);
514 need_mouse_correct
= TRUE
;
517 if (win_split(0, 0) == OK
)
519 # ifdef FEAT_SCROLLBIND
520 curwin
->w_p_scb
= FALSE
;
522 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
, ECMD_HIDE
);
523 if (nchar
== 'F' && lnum
>= 0)
525 curwin
->w_cursor
.lnum
= lnum
;
527 beginline(BL_SOL
| BL_FIX
);
536 /* Go to the first occurrence of the identifier under cursor along path in a
539 case 'i': /* Go to any match */
543 case 'd': /* Go to definition, using 'define' */
546 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
548 find_pattern_in_path(ptr
, 0, len
, TRUE
,
549 Prenum
== 0 ? TRUE
: FALSE
, type
,
550 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
551 curwin
->w_set_curswant
= TRUE
;
557 #if defined(FEAT_QUICKFIX)
559 * In a quickfix window a <CR> jumps to the error under the
560 * cursor in a new window.
562 if (bt_quickfix(curbuf
))
564 sprintf((char *)cbuf
, "split +%ld%s",
565 (long)curwin
->w_cursor
.lnum
,
566 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
567 do_cmdline_cmd(cbuf
);
573 /* CTRL-W g extended commands */
577 #ifdef USE_ON_FLY_SCROLL
578 dont_scroll
= TRUE
; /* disallow scrolling here */
581 ++allow_keys
; /* no mapping for xchar, but allow key codes */
583 xchar
= plain_vgetc();
585 LANGMAP_ADJUST(xchar
, TRUE
);
589 #ifdef FEAT_CMDL_INFO
590 (void)add_to_showcmd(xchar
);
594 #if defined(FEAT_QUICKFIX)
598 g_do_tagpreview
= Prenum
;
600 g_do_tagpreview
= p_pvh
;
606 reset_VIsual_and_resel(); /* stop Visual mode */
609 postponed_split
= Prenum
;
611 postponed_split
= -1;
613 /* Execute the command right here, required when
614 * "wincmd g}" was used in a function. */
615 do_nv_ident('g', xchar
);
618 #ifdef FEAT_SEARCHPATH
619 case 'f': /* CTRL-W gf: "gf" in a new tab page */
620 case 'F': /* CTRL-W gF: "gF" in a new tab page */
631 default: beep_flush();
637 * split the current window, implements CTRL-W s and :split
639 * "size" is the height or width for the new window, 0 to use half of current
643 * WSP_ROOM: require enough room for new window
644 * WSP_VERT: vertical split.
645 * WSP_TOP: open window at the top-left of the shell (help window).
646 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
647 * WSP_HELP: creating the help window, keep layout snapshot
649 * return FAIL for failure, OK otherwise
652 win_split(size
, flags
)
656 /* When the ":tab" modifier was used open a new tab page instead. */
657 if (may_open_tabpage() == OK
)
660 /* Add flags from ":vertical", ":topleft" and ":botright". */
661 flags
|= cmdmod
.split
;
662 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
664 EMSG(_("E442: Can't split topleft and botright at the same time"));
668 /* When creating the help window make a snapshot of the window layout.
669 * Otherwise clear the snapshot, it's now invalid. */
670 if (flags
& WSP_HELP
)
673 clear_snapshot(curtab
);
675 return win_split_ins(size
, flags
, NULL
, 0);
679 * When "newwin" is NULL: split the current window in two.
680 * When "newwin" is not NULL: insert this window at the far
681 * top/left/right/bottom.
682 * return FAIL for failure, OK otherwise
685 win_split_ins(size
, flags
, newwin
, dir
)
696 int do_equal
= FALSE
;
699 int oldwin_height
= 0;
701 frame_T
*frp
, *curfrp
;
706 else if (flags
& WSP_BOT
)
711 /* add a status line when p_ls == 1 and splitting the first window */
712 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
714 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
719 need_status
= STATUS_HEIGHT
;
723 /* May be needed for the scrollbars that are going to change. */
728 #ifdef FEAT_VERTSPLIT
729 if (flags
& WSP_VERT
)
734 * Check if we are able to split the current window and compute its
738 if (flags
& WSP_ROOM
)
739 needed
+= p_wiw
- p_wmw
;
740 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
742 available
= topframe
->fr_width
;
743 needed
+= frame_minwidth(topframe
, NULL
);
746 available
= oldwin
->w_width
;
747 if (available
< needed
&& newwin
== NULL
)
753 new_size
= oldwin
->w_width
/ 2;
754 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
755 new_size
= oldwin
->w_width
- p_wmw
- 1;
756 if (new_size
< p_wmw
)
759 /* if it doesn't fit in the current window, need win_equal() */
760 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
763 /* We don't like to take lines for the new window from a
764 * 'winfixwidth' window. Take them from a window to the left or right
765 * instead, if possible. */
767 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
769 /* Only make all windows the same width if one of them (except oldwin)
770 * is wider than one of the split windows. */
771 if (!do_equal
&& p_ea
&& size
== 0 && *p_ead
!= 'v'
772 && oldwin
->w_frame
->fr_parent
!= NULL
)
774 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
777 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
778 && (frp
->fr_win
->w_width
> new_size
779 || frp
->fr_win
->w_width
> oldwin
->w_width
780 - new_size
- STATUS_HEIGHT
))
795 * Check if we are able to split the current window and compute its
798 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
799 if (flags
& WSP_ROOM
)
800 needed
+= p_wh
- p_wmh
;
801 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
803 available
= topframe
->fr_height
;
804 needed
+= frame_minheight(topframe
, NULL
);
808 available
= oldwin
->w_height
;
811 if (available
< needed
&& newwin
== NULL
)
816 oldwin_height
= oldwin
->w_height
;
819 oldwin
->w_status_height
= STATUS_HEIGHT
;
820 oldwin_height
-= STATUS_HEIGHT
;
823 new_size
= oldwin_height
/ 2;
825 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
826 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
827 if (new_size
< p_wmh
)
830 /* if it doesn't fit in the current window, need win_equal() */
831 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
834 /* We don't like to take lines for the new window from a
835 * 'winfixheight' window. Take them from a window above or below
836 * instead, if possible. */
839 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
841 oldwin_height
= oldwin
->w_height
;
843 oldwin_height
-= STATUS_HEIGHT
;
846 /* Only make all windows the same height if one of them (except oldwin)
847 * is higher than one of the split windows. */
848 if (!do_equal
&& p_ea
&& size
== 0
849 #ifdef FEAT_VERTSPLIT
852 && oldwin
->w_frame
->fr_parent
!= NULL
)
854 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
857 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
858 && (frp
->fr_win
->w_height
> new_size
859 || frp
->fr_win
->w_height
> oldwin_height
- new_size
871 * allocate new window structure and link it in the window list
873 if ((flags
& WSP_TOP
) == 0
874 && ((flags
& WSP_BOT
)
875 || (flags
& WSP_BELOW
)
876 || (!(flags
& WSP_ABOVE
)
878 #ifdef FEAT_VERTSPLIT
879 (flags
& WSP_VERT
) ? p_spr
:
883 /* new window below/right of current one */
885 wp
= win_alloc(oldwin
);
887 win_append(oldwin
, wp
);
892 wp
= win_alloc(oldwin
->w_prev
);
894 win_append(oldwin
->w_prev
, wp
);
902 /* make the contents of the new window the same as the current one */
903 win_init(wp
, curwin
);
907 * Reorganise the tree of frames to insert the new window.
909 if (flags
& (WSP_TOP
| WSP_BOT
))
911 #ifdef FEAT_VERTSPLIT
912 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
913 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
915 if (topframe
->fr_layout
== FR_COL
)
918 curfrp
= topframe
->fr_child
;
920 while (curfrp
->fr_next
!= NULL
)
921 curfrp
= curfrp
->fr_next
;
925 before
= (flags
& WSP_TOP
);
929 curfrp
= oldwin
->w_frame
;
930 if (flags
& WSP_BELOW
)
932 else if (flags
& WSP_ABOVE
)
935 #ifdef FEAT_VERTSPLIT
936 if (flags
& WSP_VERT
)
942 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
944 /* Need to create a new frame in the tree to make a branch. */
945 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
947 curfrp
->fr_layout
= layout
;
948 frp
->fr_parent
= curfrp
;
951 curfrp
->fr_child
= frp
;
952 curfrp
->fr_win
= NULL
;
954 if (frp
->fr_win
!= NULL
)
955 oldwin
->w_frame
= frp
;
957 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
958 frp
->fr_parent
= curfrp
;
963 /* Create a frame for the new window. */
964 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
965 frp
->fr_layout
= FR_LEAF
;
970 frp
= newwin
->w_frame
;
971 frp
->fr_parent
= curfrp
->fr_parent
;
973 /* Insert the new frame at the right place in the frame list. */
975 frame_insert(curfrp
, frp
);
977 frame_append(curfrp
, frp
);
979 #ifdef FEAT_VERTSPLIT
980 if (flags
& WSP_VERT
)
982 wp
->w_p_scr
= curwin
->w_p_scr
;
986 oldwin
->w_status_height
= need_status
;
988 if (flags
& (WSP_TOP
| WSP_BOT
))
990 /* set height and row of new window to full height */
991 wp
->w_winrow
= tabline_height();
992 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
993 wp
->w_status_height
= (p_ls
> 0);
997 /* height and row of new window is same as current window */
998 wp
->w_winrow
= oldwin
->w_winrow
;
999 wp
->w_height
= oldwin
->w_height
;
1000 wp
->w_status_height
= oldwin
->w_status_height
;
1002 frp
->fr_height
= curfrp
->fr_height
;
1004 /* "new_size" of the current window goes to the new window, use
1005 * one column for the vertical separator */
1006 wp
->w_width
= new_size
;
1008 wp
->w_vsep_width
= 1;
1011 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1012 oldwin
->w_vsep_width
= 1;
1014 if (flags
& (WSP_TOP
| WSP_BOT
))
1016 if (flags
& WSP_BOT
)
1017 frame_add_vsep(curfrp
);
1018 /* Set width of neighbor frame */
1019 frame_new_width(curfrp
, curfrp
->fr_width
1020 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
1024 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
1025 if (before
) /* new window left of current one */
1027 wp
->w_wincol
= oldwin
->w_wincol
;
1028 oldwin
->w_wincol
+= new_size
+ 1;
1030 else /* new window right of current one */
1031 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
1032 frame_fix_width(oldwin
);
1033 frame_fix_width(wp
);
1038 /* width and column of new window is same as current window */
1039 #ifdef FEAT_VERTSPLIT
1040 if (flags
& (WSP_TOP
| WSP_BOT
))
1043 wp
->w_width
= Columns
;
1044 wp
->w_vsep_width
= 0;
1048 wp
->w_wincol
= oldwin
->w_wincol
;
1049 wp
->w_width
= oldwin
->w_width
;
1050 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1052 frp
->fr_width
= curfrp
->fr_width
;
1055 /* "new_size" of the current window goes to the new window, use
1056 * one row for the status line */
1057 win_new_height(wp
, new_size
);
1058 if (flags
& (WSP_TOP
| WSP_BOT
))
1059 frame_new_height(curfrp
, curfrp
->fr_height
1060 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1062 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1063 if (before
) /* new window above current one */
1065 wp
->w_winrow
= oldwin
->w_winrow
;
1066 wp
->w_status_height
= STATUS_HEIGHT
;
1067 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1069 else /* new window below current one */
1071 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1072 wp
->w_status_height
= oldwin
->w_status_height
;
1073 oldwin
->w_status_height
= STATUS_HEIGHT
;
1075 #ifdef FEAT_VERTSPLIT
1076 if (flags
& WSP_BOT
)
1077 frame_add_statusline(curfrp
);
1079 frame_fix_height(wp
);
1080 frame_fix_height(oldwin
);
1083 if (flags
& (WSP_TOP
| WSP_BOT
))
1084 (void)win_comp_pos();
1087 * Both windows need redrawing
1089 redraw_win_later(wp
, NOT_VALID
);
1090 wp
->w_redr_status
= TRUE
;
1091 redraw_win_later(oldwin
, NOT_VALID
);
1092 oldwin
->w_redr_status
= TRUE
;
1098 msg_clr_eos_force(); /* Old command/ruler may still be there */
1101 msg_col
= 0; /* put position back at start of line */
1105 * make the new window the current window and redraw
1107 if (do_equal
|| dir
!= 0)
1109 #ifdef FEAT_VERTSPLIT
1110 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1111 : dir
== 'h' ? 'b' :
1115 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1116 * size was given. */
1117 #ifdef FEAT_VERTSPLIT
1118 if (flags
& WSP_VERT
)
1125 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1127 gui_init_which_components(NULL
);
1137 win_enter(wp
, FALSE
);
1138 #ifdef FEAT_VERTSPLIT
1139 if (flags
& WSP_VERT
)
1149 * Initialize window "newp" from window "oldp".
1150 * Used when splitting a window and when creating a new tab page.
1151 * The windows will both edit the same buffer.
1154 win_init(newp
, oldp
)
1160 newp
->w_buffer
= oldp
->w_buffer
;
1161 oldp
->w_buffer
->b_nwindows
++;
1162 newp
->w_cursor
= oldp
->w_cursor
;
1164 newp
->w_curswant
= oldp
->w_curswant
;
1165 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1166 newp
->w_topline
= oldp
->w_topline
;
1168 newp
->w_topfill
= oldp
->w_topfill
;
1170 newp
->w_leftcol
= oldp
->w_leftcol
;
1171 newp
->w_pcmark
= oldp
->w_pcmark
;
1172 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1173 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1174 newp
->w_wrow
= oldp
->w_wrow
;
1175 newp
->w_fraction
= oldp
->w_fraction
;
1176 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1177 #ifdef FEAT_JUMPLIST
1178 copy_jumplist(oldp
, newp
);
1180 #ifdef FEAT_QUICKFIX
1181 copy_loclist(oldp
, newp
);
1183 if (oldp
->w_localdir
!= NULL
)
1184 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1186 /* Use the same argument list. */
1187 newp
->w_alist
= oldp
->w_alist
;
1188 ++newp
->w_alist
->al_refcount
;
1189 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1192 * copy tagstack and options from existing window
1194 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1196 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1197 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1198 newp
->w_tagstack
[i
].tagname
=
1199 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1201 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1202 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1203 win_copy_options(oldp
, newp
);
1204 # ifdef FEAT_FOLDING
1205 copyFoldingState(oldp
, newp
);
1209 #endif /* FEAT_WINDOWS */
1211 #if defined(FEAT_WINDOWS) || defined(PROTO)
1213 * Check if "win" is a pointer to an existing window.
1223 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1230 * Return the number of windows.
1238 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1244 * Make "count" windows on the screen.
1245 * Return actual number of windows on the screen.
1246 * Must be called when there is just one window, filling the whole screen
1247 * (excluding the command line).
1251 make_windows(count
, vertical
)
1253 int vertical
; /* split windows vertically if TRUE */
1258 #ifdef FEAT_VERTSPLIT
1261 /* Each windows needs at least 'winminwidth' lines and a separator
1263 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1264 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1269 /* Each window needs at least 'winminheight' lines and a status line. */
1270 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1271 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1276 if (count
> maxcount
)
1280 * add status line now, otherwise first window will be too big
1287 * Don't execute autocommands while creating the windows. Must do that
1288 * when putting the buffers in the windows.
1293 /* todo is number of windows left to create */
1294 for (todo
= count
- 1; todo
> 0; --todo
)
1295 #ifdef FEAT_VERTSPLIT
1298 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1299 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1305 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1306 * STATUS_HEIGHT
) / (todo
+ 1)
1307 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1315 /* return actual number of windows */
1316 return (count
- todo
);
1320 * Exchange current and next window
1323 win_exchange(Prenum
)
1332 if (lastwin
== firstwin
) /* just one window */
1339 need_mouse_correct
= TRUE
;
1343 * find window to exchange with
1347 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1348 while (frp
!= NULL
&& --Prenum
> 0)
1351 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1352 frp
= curwin
->w_frame
->fr_next
;
1353 else /* Swap last window in row/col with previous */
1354 frp
= curwin
->w_frame
->fr_prev
;
1356 /* We can only exchange a window with another window, not with a frame
1357 * containing windows. */
1358 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1363 * 1. remove curwin from the list. Remember after which window it was in wp2
1364 * 2. insert curwin before wp in the list
1366 * 3. remove wp from the list
1367 * 4. insert wp after wp2
1368 * 5. exchange the status line height and vsep width.
1370 wp2
= curwin
->w_prev
;
1371 frp2
= curwin
->w_frame
->fr_prev
;
1372 if (wp
->w_prev
!= curwin
)
1374 win_remove(curwin
, NULL
);
1375 frame_remove(curwin
->w_frame
);
1376 win_append(wp
->w_prev
, curwin
);
1377 frame_insert(frp
, curwin
->w_frame
);
1381 win_remove(wp
, NULL
);
1382 frame_remove(wp
->w_frame
);
1383 win_append(wp2
, wp
);
1385 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1387 frame_append(frp2
, wp
->w_frame
);
1389 temp
= curwin
->w_status_height
;
1390 curwin
->w_status_height
= wp
->w_status_height
;
1391 wp
->w_status_height
= temp
;
1392 #ifdef FEAT_VERTSPLIT
1393 temp
= curwin
->w_vsep_width
;
1394 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1395 wp
->w_vsep_width
= temp
;
1397 /* If the windows are not in the same frame, exchange the sizes to avoid
1398 * messing up the window layout. Otherwise fix the frame sizes. */
1399 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1401 temp
= curwin
->w_height
;
1402 curwin
->w_height
= wp
->w_height
;
1403 wp
->w_height
= temp
;
1404 temp
= curwin
->w_width
;
1405 curwin
->w_width
= wp
->w_width
;
1410 frame_fix_height(curwin
);
1411 frame_fix_height(wp
);
1412 frame_fix_width(curwin
);
1413 frame_fix_width(wp
);
1417 (void)win_comp_pos(); /* recompute window positions */
1419 win_enter(wp
, TRUE
);
1420 redraw_later(CLEAR
);
1424 * rotate windows: if upwards TRUE the second window becomes the first one
1425 * if upwards FALSE the first window becomes the second one
1428 win_rotate(upwards
, count
)
1437 if (firstwin
== lastwin
) /* nothing to do */
1444 need_mouse_correct
= TRUE
;
1447 #ifdef FEAT_VERTSPLIT
1448 /* Check if all frames in this row/col have one window. */
1449 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1451 if (frp
->fr_win
== NULL
)
1453 EMSG(_("E443: Cannot rotate when another window is split"));
1460 if (upwards
) /* first window becomes last window */
1462 /* remove first window/frame from the list */
1463 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1465 win_remove(wp1
, NULL
);
1468 /* find last frame and append removed window/frame after it */
1469 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1471 win_append(frp
->fr_win
, wp1
);
1472 frame_append(frp
, wp1
->w_frame
);
1474 wp2
= frp
->fr_win
; /* previously last window */
1476 else /* last window becomes first window */
1478 /* find last window/frame in the list and remove it */
1479 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1483 wp2
= wp1
->w_prev
; /* will become last window */
1484 win_remove(wp1
, NULL
);
1487 /* append the removed window/frame before the first in the list */
1488 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1489 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1492 /* exchange status height and vsep width of old and new last window */
1493 n
= wp2
->w_status_height
;
1494 wp2
->w_status_height
= wp1
->w_status_height
;
1495 wp1
->w_status_height
= n
;
1496 frame_fix_height(wp1
);
1497 frame_fix_height(wp2
);
1498 #ifdef FEAT_VERTSPLIT
1499 n
= wp2
->w_vsep_width
;
1500 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1501 wp1
->w_vsep_width
= n
;
1502 frame_fix_width(wp1
);
1503 frame_fix_width(wp2
);
1506 /* recompute w_winrow and w_wincol for all windows */
1507 (void)win_comp_pos();
1510 redraw_later(CLEAR
);
1514 * Move the current window to the very top/bottom/left/right of the screen.
1517 win_totop(size
, flags
)
1522 int height
= curwin
->w_height
;
1524 if (lastwin
== firstwin
)
1530 /* Remove the window and frame from the tree of frames. */
1531 (void)winframe_remove(curwin
, &dir
, NULL
);
1532 win_remove(curwin
, NULL
);
1533 last_status(FALSE
); /* may need to remove last status line */
1534 (void)win_comp_pos(); /* recompute window positions */
1536 /* Split a window on the desired side and put the window there. */
1537 (void)win_split_ins(size
, flags
, curwin
, dir
);
1538 if (!(flags
& WSP_VERT
))
1540 win_setheight(height
);
1542 win_equal(curwin
, TRUE
, 'v');
1545 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1546 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1547 * scrollbars. Have to update them anyway. */
1551 gui_init_which_components(NULL
);
1552 gui_update_scrollbars(TRUE
);
1554 need_mouse_correct
= TRUE
;
1560 * Move window "win1" to below/right of "win2" and make "win1" the current
1561 * window. Only works within the same frame!
1564 win_move_after(win1
, win2
)
1569 /* check if the arguments are reasonable */
1573 /* check if there is something to do */
1574 if (win2
->w_next
!= win1
)
1576 /* may need move the status line/vertical separator of the last window
1578 if (win1
== lastwin
)
1580 height
= win1
->w_prev
->w_status_height
;
1581 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1582 win1
->w_status_height
= height
;
1583 #ifdef FEAT_VERTSPLIT
1584 if (win1
->w_prev
->w_vsep_width
== 1)
1586 /* Remove the vertical separator from the last-but-one window,
1587 * add it to the last window. Adjust the frame widths. */
1588 win1
->w_prev
->w_vsep_width
= 0;
1589 win1
->w_prev
->w_frame
->fr_width
-= 1;
1590 win1
->w_vsep_width
= 1;
1591 win1
->w_frame
->fr_width
+= 1;
1595 else if (win2
== lastwin
)
1597 height
= win1
->w_status_height
;
1598 win1
->w_status_height
= win2
->w_status_height
;
1599 win2
->w_status_height
= height
;
1600 #ifdef FEAT_VERTSPLIT
1601 if (win1
->w_vsep_width
== 1)
1603 /* Remove the vertical separator from win1, add it to the last
1604 * window, win2. Adjust the frame widths. */
1605 win2
->w_vsep_width
= 1;
1606 win2
->w_frame
->fr_width
+= 1;
1607 win1
->w_vsep_width
= 0;
1608 win1
->w_frame
->fr_width
-= 1;
1612 win_remove(win1
, NULL
);
1613 frame_remove(win1
->w_frame
);
1614 win_append(win2
, win1
);
1615 frame_append(win2
->w_frame
, win1
->w_frame
);
1617 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1618 redraw_later(NOT_VALID
);
1620 win_enter(win1
, FALSE
);
1624 * Make all windows the same height.
1625 * 'next_curwin' will soon be the current window, make sure it has enough
1629 win_equal(next_curwin
, current
, dir
)
1630 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1631 int current
; /* do only frame with current window */
1632 int dir
; /* 'v' for vertically, 'h' for horizontally,
1633 'b' for both, 0 for using p_ead */
1636 #ifdef FEAT_VERTSPLIT
1641 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1642 topframe
, dir
, 0, tabline_height(),
1643 (int)Columns
, topframe
->fr_height
);
1647 * Set a frame to a new position and height, spreading the available room
1648 * equally over contained frames.
1649 * The window "next_curwin" (if not NULL) should at least get the size from
1650 * 'winheight' and 'winwidth' if possible.
1653 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1654 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1655 int current
; /* do only frame with current window */
1656 frame_T
*topfr
; /* frame to set size off */
1657 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1658 int col
; /* horizontal position for frame */
1659 int row
; /* vertical position for frame */
1660 int width
; /* new width of frame */
1661 int height
; /* new height of frame */
1665 int wincount
, totwincount
= 0;
1667 int next_curwin_size
= 0;
1670 int has_next_curwin
= 0;
1673 if (topfr
->fr_layout
== FR_LEAF
)
1675 /* Set the width/height of this frame.
1676 * Redraw when size or position changes */
1677 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1678 #ifdef FEAT_VERTSPLIT
1679 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1683 topfr
->fr_win
->w_winrow
= row
;
1684 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1685 #ifdef FEAT_VERTSPLIT
1686 topfr
->fr_win
->w_wincol
= col
;
1687 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1689 redraw_all_later(CLEAR
);
1692 #ifdef FEAT_VERTSPLIT
1693 else if (topfr
->fr_layout
== FR_ROW
)
1695 topfr
->fr_width
= width
;
1696 topfr
->fr_height
= height
;
1698 if (dir
!= 'v') /* equalize frame widths */
1700 /* Compute the maximum number of windows horizontally in this
1702 n
= frame_minwidth(topfr
, NOWIN
);
1703 /* add one for the rightmost window, it doesn't have a separator */
1704 if (col
+ width
== Columns
)
1708 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1709 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1712 * Compute width for "next_curwin" window and room available for
1714 * "m" is the minimal width when counting p_wiw for "next_curwin".
1716 m
= frame_minwidth(topfr
, next_curwin
);
1720 next_curwin_size
= p_wiw
+ room
;
1725 next_curwin_size
= -1;
1726 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1728 /* If 'winfixwidth' set keep the window width if
1730 * Watch out for this window being the next_curwin. */
1731 if (frame_fixed_width(fr
))
1733 n
= frame_minwidth(fr
, NOWIN
);
1734 new_size
= fr
->fr_width
;
1735 if (frame_has_win(fr
, next_curwin
))
1737 room
+= p_wiw
- p_wmw
;
1738 next_curwin_size
= 0;
1739 if (new_size
< p_wiw
)
1743 /* These windows don't use up room. */
1744 totwincount
-= (n
+ (fr
->fr_next
== NULL
1745 ? extra_sep
: 0)) / (p_wmw
+ 1);
1746 room
-= new_size
- n
;
1752 fr
->fr_newwidth
= new_size
;
1755 if (next_curwin_size
== -1)
1757 if (!has_next_curwin
)
1758 next_curwin_size
= 0;
1759 else if (totwincount
> 1
1760 && (room
+ (totwincount
- 2))
1761 / (totwincount
- 1) > p_wiw
)
1763 /* Can make all windows wider than 'winwidth', spread
1764 * the room equally. */
1765 next_curwin_size
= (room
+ p_wiw
1766 + (totwincount
- 1) * p_wmw
1767 + (totwincount
- 1)) / totwincount
;
1768 room
-= next_curwin_size
- p_wiw
;
1771 next_curwin_size
= p_wiw
;
1775 if (has_next_curwin
)
1776 --totwincount
; /* don't count curwin */
1779 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1783 if (fr
->fr_next
== NULL
)
1784 /* last frame gets all that remains (avoid roundoff error) */
1786 else if (dir
== 'v')
1787 new_size
= fr
->fr_width
;
1788 else if (frame_fixed_width(fr
))
1790 new_size
= fr
->fr_newwidth
;
1791 wincount
= 0; /* doesn't count as a sizeable window */
1795 /* Compute the maximum number of windows horiz. in "fr". */
1796 n
= frame_minwidth(fr
, NOWIN
);
1797 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1799 m
= frame_minwidth(fr
, next_curwin
);
1800 if (has_next_curwin
)
1801 hnc
= frame_has_win(fr
, next_curwin
);
1804 if (hnc
) /* don't count next_curwin */
1806 if (totwincount
== 0)
1809 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1811 if (hnc
) /* add next_curwin size */
1813 next_curwin_size
-= p_wiw
- (m
- n
);
1814 new_size
+= next_curwin_size
;
1815 room
-= new_size
- next_curwin_size
;
1822 /* Skip frame that is full width when splitting or closing a
1823 * window, unless equalizing all frames. */
1824 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1825 || (new_size
!= fr
->fr_width
)
1826 || frame_has_win(fr
, next_curwin
))
1827 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1831 totwincount
-= wincount
;
1835 else /* topfr->fr_layout == FR_COL */
1837 #ifdef FEAT_VERTSPLIT
1838 topfr
->fr_width
= width
;
1840 topfr
->fr_height
= height
;
1842 if (dir
!= 'h') /* equalize frame heights */
1844 /* Compute maximum number of windows vertically in this frame. */
1845 n
= frame_minheight(topfr
, NOWIN
);
1846 /* add one for the bottom window if it doesn't have a statusline */
1847 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1851 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1852 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1855 * Compute height for "next_curwin" window and room available for
1857 * "m" is the minimal height when counting p_wh for "next_curwin".
1859 m
= frame_minheight(topfr
, next_curwin
);
1863 /* The room is less then 'winheight', use all space for the
1864 * current window. */
1865 next_curwin_size
= p_wh
+ room
;
1870 next_curwin_size
= -1;
1871 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1873 /* If 'winfixheight' set keep the window height if
1875 * Watch out for this window being the next_curwin. */
1876 if (frame_fixed_height(fr
))
1878 n
= frame_minheight(fr
, NOWIN
);
1879 new_size
= fr
->fr_height
;
1880 if (frame_has_win(fr
, next_curwin
))
1882 room
+= p_wh
- p_wmh
;
1883 next_curwin_size
= 0;
1884 if (new_size
< p_wh
)
1888 /* These windows don't use up room. */
1889 totwincount
-= (n
+ (fr
->fr_next
== NULL
1890 ? extra_sep
: 0)) / (p_wmh
+ 1);
1891 room
-= new_size
- n
;
1897 fr
->fr_newheight
= new_size
;
1900 if (next_curwin_size
== -1)
1902 if (!has_next_curwin
)
1903 next_curwin_size
= 0;
1904 else if (totwincount
> 1
1905 && (room
+ (totwincount
- 2))
1906 / (totwincount
- 1) > p_wh
)
1908 /* can make all windows higher than 'winheight',
1909 * spread the room equally. */
1910 next_curwin_size
= (room
+ p_wh
1911 + (totwincount
- 1) * p_wmh
1912 + (totwincount
- 1)) / totwincount
;
1913 room
-= next_curwin_size
- p_wh
;
1916 next_curwin_size
= p_wh
;
1920 if (has_next_curwin
)
1921 --totwincount
; /* don't count curwin */
1924 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1928 if (fr
->fr_next
== NULL
)
1929 /* last frame gets all that remains (avoid roundoff error) */
1931 else if (dir
== 'h')
1932 new_size
= fr
->fr_height
;
1933 else if (frame_fixed_height(fr
))
1935 new_size
= fr
->fr_newheight
;
1936 wincount
= 0; /* doesn't count as a sizeable window */
1940 /* Compute the maximum number of windows vert. in "fr". */
1941 n
= frame_minheight(fr
, NOWIN
);
1942 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1944 m
= frame_minheight(fr
, next_curwin
);
1945 if (has_next_curwin
)
1946 hnc
= frame_has_win(fr
, next_curwin
);
1949 if (hnc
) /* don't count next_curwin */
1951 if (totwincount
== 0)
1954 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1956 if (hnc
) /* add next_curwin size */
1958 next_curwin_size
-= p_wh
- (m
- n
);
1959 new_size
+= next_curwin_size
;
1960 room
-= new_size
- next_curwin_size
;
1966 /* Skip frame that is full width when splitting or closing a
1967 * window, unless equalizing all frames. */
1968 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1969 || (new_size
!= fr
->fr_height
)
1970 || frame_has_win(fr
, next_curwin
))
1971 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1975 totwincount
-= wincount
;
1981 * close all windows for buffer 'buf'
1984 close_windows(buf
, keep_curwin
)
1986 int keep_curwin
; /* don't close "curwin" */
1989 tabpage_T
*tp
, *nexttp
;
1990 int h
= tabline_height();
1992 ++RedrawingDisabled
;
1994 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
1996 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
1998 win_close(wp
, FALSE
);
2000 /* Start all over, autocommands may change the window layout. */
2007 /* Also check windows in other tab pages. */
2008 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2010 nexttp
= tp
->tp_next
;
2012 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2013 if (wp
->w_buffer
== buf
)
2015 win_close_othertab(wp
, FALSE
, tp
);
2017 /* Start all over, the tab page may be closed and
2018 * autocommands may change the window layout. */
2019 nexttp
= first_tabpage
;
2024 --RedrawingDisabled
;
2026 if (h
!= tabline_height())
2031 * Return TRUE if the current window is the only window that exists.
2032 * Returns FALSE if there is a window, possibly in another tab page.
2037 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2041 * Close window "win". Only works for the current tab page.
2042 * If "free_buf" is TRUE related buffer may be unloaded.
2044 * called by :quit, :close, :xit, :wq and findtag()
2047 win_close(win
, free_buf
)
2053 int other_buffer
= FALSE
;
2055 int close_curwin
= FALSE
;
2057 int help_window
= FALSE
;
2058 tabpage_T
*prev_curtab
= curtab
;
2062 EMSG(_("E444: Cannot close last window"));
2067 * When closing the last window in a tab page first go to another tab
2068 * page and then close the window and the tab page. This avoids that
2069 * curwin and curtab are not invalid while we are freeing memory, they may
2070 * be used in GUI events.
2072 if (firstwin
== lastwin
)
2074 goto_tabpage_tp(alt_tabpage());
2075 redraw_tabline
= TRUE
;
2077 /* Safety check: Autocommands may have closed the window when jumping
2078 * to the other tab page. */
2079 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2081 int h
= tabline_height();
2083 win_close_othertab(win
, free_buf
, prev_curtab
);
2084 if (h
!= tabline_height())
2090 /* When closing the help window, try restoring a snapshot after closing
2091 * the window. Otherwise clear the snapshot, it's now invalid. */
2092 if (win
->w_buffer
->b_help
)
2095 clear_snapshot(curtab
);
2101 * Guess which window is going to be the new current window.
2102 * This may change because of the autocommands (sigh).
2104 wp
= frame2win(win_altframe(win
, NULL
));
2107 * Be careful: If autocommands delete the window, return now.
2109 if (wp
->w_buffer
!= curbuf
)
2111 other_buffer
= TRUE
;
2112 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2113 if (!win_valid(win
) || last_window())
2116 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2117 if (!win_valid(win
) || last_window())
2120 /* autocmds may abort script processing */
2128 /* Avoid trouble with scrollbars that are going to be deleted in
2135 * Close the link to the buffer.
2137 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2139 /* Autocommands may have closed the window already, or closed the only
2140 * other window or moved to another tab page. */
2141 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2144 /* Free the memory used for the window. */
2145 wp
= win_free_mem(win
, &dir
, NULL
);
2147 /* Make sure curwin isn't invalid. It can cause severe trouble when
2148 * printing an error message. For win_equal() curbuf needs to be valid
2153 #ifdef FEAT_QUICKFIX
2154 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2157 * If the cursor goes to the preview or the quickfix window, try
2158 * finding another window to go to.
2162 if (wp
->w_next
== NULL
)
2168 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2176 curbuf
= curwin
->w_buffer
;
2177 close_curwin
= TRUE
;
2180 #ifdef FEAT_VERTSPLIT
2181 && (*p_ead
== 'b' || *p_ead
== dir
)
2184 win_equal(curwin
, TRUE
,
2185 #ifdef FEAT_VERTSPLIT
2195 win_enter_ext(wp
, FALSE
, TRUE
);
2198 /* careful: after this wp and win may be invalid! */
2199 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2204 * If last window has a status line now and we don't want one,
2205 * remove the status line.
2209 /* After closing the help window, try restoring the window layout from
2210 * before it was opened. */
2212 restore_snapshot(close_curwin
);
2214 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2215 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2216 if (gui
.in_use
&& !win_hasvertsplit())
2217 gui_init_which_components(NULL
);
2220 redraw_all_later(NOT_VALID
);
2224 * Close window "win" in tab page "tp", which is not the current tab page.
2225 * This may be the last window ih that tab page and result in closing the tab,
2226 * thus "tp" may become invalid!
2227 * Caller must check if buffer is hidden and whether the tabline needs to be
2231 win_close_othertab(win
, free_buf
, tp
)
2238 tabpage_T
*ptp
= NULL
;
2240 /* Close the link to the buffer. */
2241 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2243 /* Careful: Autocommands may have closed the tab page or made it the
2244 * current tab page. */
2245 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2247 if (ptp
== NULL
|| tp
== curtab
)
2250 /* Autocommands may have closed the window already. */
2251 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2256 /* Free the memory used for the window. */
2257 wp
= win_free_mem(win
, &dir
, tp
);
2259 /* When closing the last window in a tab page remove the tab page. */
2262 if (tp
== first_tabpage
)
2263 first_tabpage
= tp
->tp_next
;
2266 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2271 EMSG2(_(e_intern2
), "win_close_othertab()");
2274 ptp
->tp_next
= tp
->tp_next
;
2281 * Free the memory used for a window.
2282 * Returns a pointer to the window that got the freed up space.
2285 win_free_mem(win
, dirp
, tp
)
2287 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2288 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2297 /* reduce the reference count to the argument list. */
2298 alist_unlink(win
->w_alist
);
2300 /* Remove the window and its frame from the tree of frames. */
2302 wp
= winframe_remove(win
, dirp
, tp
);
2306 /* When deleting the current window of another tab page select a new
2307 * current window. */
2308 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2314 #if defined(EXITFREE) || defined(PROTO)
2320 # ifdef FEAT_WINDOWS
2321 while (first_tabpage
->tp_next
!= NULL
)
2322 tabpage_close(TRUE
);
2325 while (firstwin
!= NULL
)
2326 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2331 * Remove a window and its frame from the tree of frames.
2332 * Returns a pointer to the window that got the freed up space.
2336 winframe_remove(win
, dirp
, tp
)
2338 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2339 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2341 frame_T
*frp
, *frp2
, *frp3
;
2342 frame_T
*frp_close
= win
->w_frame
;
2346 * If there is only one window there is nothing to remove.
2348 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2352 * Remove the window from its frame.
2354 frp2
= win_altframe(win
, tp
);
2355 wp
= frame2win(frp2
);
2357 /* Remove this frame from the list of frames. */
2358 frame_remove(frp_close
);
2360 #ifdef FEAT_VERTSPLIT
2361 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2364 /* When 'winfixheight' is set, try to find another frame in the column
2365 * (as close to the closed frame as possible) to distribute the height
2367 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2369 frp
= frp_close
->fr_prev
;
2370 frp3
= frp_close
->fr_next
;
2371 while (frp
!= NULL
|| frp3
!= NULL
)
2375 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2385 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2391 frp3
= frp3
->fr_next
;
2395 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2396 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2397 #ifdef FEAT_VERTSPLIT
2402 /* When 'winfixwidth' is set, try to find another frame in the column
2403 * (as close to the closed frame as possible) to distribute the width
2405 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2407 frp
= frp_close
->fr_prev
;
2408 frp3
= frp_close
->fr_next
;
2409 while (frp
!= NULL
|| frp3
!= NULL
)
2413 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2423 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2429 frp3
= frp3
->fr_next
;
2433 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2434 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2439 /* If rows/columns go to a window below/right its positions need to be
2440 * updated. Can only be done after the sizes have been updated. */
2441 if (frp2
== frp_close
->fr_next
)
2443 int row
= win
->w_winrow
;
2444 int col
= W_WINCOL(win
);
2446 frame_comp_pos(frp2
, &row
, &col
);
2449 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2451 /* There is no other frame in this list, move its info to the parent
2453 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2454 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2455 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2456 frp
->fr_parent
= frp2
->fr_parent
;
2457 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2458 if (frp2
->fr_win
!= NULL
)
2459 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2460 frp
= frp2
->fr_parent
;
2463 frp2
= frp
->fr_parent
;
2464 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2466 /* The frame above the parent has the same layout, have to merge
2467 * the frames into this list. */
2468 if (frp2
->fr_child
== frp
)
2469 frp2
->fr_child
= frp
->fr_child
;
2470 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2471 if (frp
->fr_prev
!= NULL
)
2472 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2473 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2475 frp3
->fr_parent
= frp2
;
2476 if (frp3
->fr_next
== NULL
)
2478 frp3
->fr_next
= frp
->fr_next
;
2479 if (frp
->fr_next
!= NULL
)
2480 frp
->fr_next
->fr_prev
= frp3
;
2492 * Find out which frame is going to get the freed up space when "win" is
2494 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2495 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2496 * This makes opening a window and closing it immediately keep the same window
2500 win_altframe(win
, tp
)
2502 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2507 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2508 /* Last window in this tab page, will go to next tab page. */
2509 return alt_tabpage()->tp_curwin
->w_frame
;
2512 #ifdef FEAT_VERTSPLIT
2513 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2518 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2519 return frp
->fr_next
;
2520 return frp
->fr_prev
;
2524 * Return the tabpage that will be used if the current one is closed.
2531 /* Use the next tab page if possible. */
2532 if (curtab
->tp_next
!= NULL
)
2533 return curtab
->tp_next
;
2535 /* Find the last but one tab page. */
2536 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2542 * Find the left-upper window in frame "frp".
2548 while (frp
->fr_win
== NULL
)
2549 frp
= frp
->fr_child
;
2554 * Return TRUE if frame "frp" contains window "wp".
2557 frame_has_win(frp
, wp
)
2563 if (frp
->fr_layout
== FR_LEAF
)
2564 return frp
->fr_win
== wp
;
2566 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2567 if (frame_has_win(p
, wp
))
2573 * Set a new height for a frame. Recursively sets the height for contained
2574 * frames and windows. Caller must take care of positions.
2577 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2580 int topfirst
; /* resize topmost contained frame first */
2581 int wfh
; /* obey 'winfixheight' when there is a choice;
2582 may cause the height not to be set */
2588 if (topfrp
->fr_win
!= NULL
)
2590 /* Simple case: just one window. */
2591 win_new_height(topfrp
->fr_win
,
2592 height
- topfrp
->fr_win
->w_status_height
);
2594 #ifdef FEAT_VERTSPLIT
2595 else if (topfrp
->fr_layout
== FR_ROW
)
2599 /* All frames in this row get the same new height. */
2600 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2602 frame_new_height(frp
, height
, topfirst
, wfh
);
2603 if (frp
->fr_height
> height
)
2605 /* Could not fit the windows, make the whole row higher. */
2606 height
= frp
->fr_height
;
2611 while (frp
!= NULL
);
2614 else /* fr_layout == FR_COL */
2616 /* Complicated case: Resize a column of frames. Resize the bottom
2617 * frame first, frames above that when needed. */
2619 frp
= topfrp
->fr_child
;
2621 /* Advance past frames with one window with 'wfh' set. */
2622 while (frame_fixed_height(frp
))
2626 return; /* no frame without 'wfh', give up */
2630 /* Find the bottom frame of this column */
2631 while (frp
->fr_next
!= NULL
)
2634 /* Advance back for frames with one window with 'wfh' set. */
2635 while (frame_fixed_height(frp
))
2639 extra_lines
= height
- topfrp
->fr_height
;
2640 if (extra_lines
< 0)
2642 /* reduce height of contained frames, bottom or top frame first */
2645 h
= frame_minheight(frp
, NULL
);
2646 if (frp
->fr_height
+ extra_lines
< h
)
2648 extra_lines
+= frp
->fr_height
- h
;
2649 frame_new_height(frp
, h
, topfirst
, wfh
);
2653 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2661 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2667 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2669 /* Increase "height" if we could not reduce enough frames. */
2671 height
-= extra_lines
;
2674 else if (extra_lines
> 0)
2676 /* increase height of bottom or top frame */
2677 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2680 topfrp
->fr_height
= height
;
2684 * Return TRUE if height of frame "frp" should not be changed because of
2685 * the 'winfixheight' option.
2688 frame_fixed_height(frp
)
2691 /* frame with one window: fixed height if 'winfixheight' set. */
2692 if (frp
->fr_win
!= NULL
)
2693 return frp
->fr_win
->w_p_wfh
;
2695 if (frp
->fr_layout
== FR_ROW
)
2697 /* The frame is fixed height if one of the frames in the row is fixed
2699 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2700 if (frame_fixed_height(frp
))
2705 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2706 * frames in the row are fixed height. */
2707 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2708 if (!frame_fixed_height(frp
))
2713 #ifdef FEAT_VERTSPLIT
2715 * Return TRUE if width of frame "frp" should not be changed because of
2716 * the 'winfixwidth' option.
2719 frame_fixed_width(frp
)
2722 /* frame with one window: fixed width if 'winfixwidth' set. */
2723 if (frp
->fr_win
!= NULL
)
2724 return frp
->fr_win
->w_p_wfw
;
2726 if (frp
->fr_layout
== FR_COL
)
2728 /* The frame is fixed width if one of the frames in the row is fixed
2730 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2731 if (frame_fixed_width(frp
))
2736 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2737 * frames in the row are fixed width. */
2738 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2739 if (!frame_fixed_width(frp
))
2745 * Add a status line to windows at the bottom of "frp".
2746 * Note: Does not check if there is room!
2749 frame_add_statusline(frp
)
2754 if (frp
->fr_layout
== FR_LEAF
)
2757 if (wp
->w_status_height
== 0)
2759 if (wp
->w_height
> 0) /* don't make it negative */
2761 wp
->w_status_height
= STATUS_HEIGHT
;
2764 else if (frp
->fr_layout
== FR_ROW
)
2766 /* Handle all the frames in the row. */
2767 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2768 frame_add_statusline(frp
);
2770 else /* frp->fr_layout == FR_COL */
2772 /* Only need to handle the last frame in the column. */
2773 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2775 frame_add_statusline(frp
);
2780 * Set width of a frame. Handles recursively going through contained frames.
2781 * May remove separator line for windows at the right side (for win_close()).
2784 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2787 int leftfirst
; /* resize leftmost contained frame first */
2788 int wfw
; /* obey 'winfixwidth' when there is a choice;
2789 may cause the width not to be set */
2796 if (topfrp
->fr_layout
== FR_LEAF
)
2798 /* Simple case: just one window. */
2799 wp
= topfrp
->fr_win
;
2800 /* Find out if there are any windows right of this one. */
2801 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2802 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2804 if (frp
->fr_parent
== NULL
)
2805 wp
->w_vsep_width
= 0;
2806 win_new_width(wp
, width
- wp
->w_vsep_width
);
2808 else if (topfrp
->fr_layout
== FR_COL
)
2812 /* All frames in this column get the same new width. */
2813 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2815 frame_new_width(frp
, width
, leftfirst
, wfw
);
2816 if (frp
->fr_width
> width
)
2818 /* Could not fit the windows, make whole column wider. */
2819 width
= frp
->fr_width
;
2823 } while (frp
!= NULL
);
2825 else /* fr_layout == FR_ROW */
2827 /* Complicated case: Resize a row of frames. Resize the rightmost
2828 * frame first, frames left of it when needed. */
2830 frp
= topfrp
->fr_child
;
2832 /* Advance past frames with one window with 'wfw' set. */
2833 while (frame_fixed_width(frp
))
2837 return; /* no frame without 'wfw', give up */
2841 /* Find the rightmost frame of this row */
2842 while (frp
->fr_next
!= NULL
)
2845 /* Advance back for frames with one window with 'wfw' set. */
2846 while (frame_fixed_width(frp
))
2850 extra_cols
= width
- topfrp
->fr_width
;
2853 /* reduce frame width, rightmost frame first */
2856 w
= frame_minwidth(frp
, NULL
);
2857 if (frp
->fr_width
+ extra_cols
< w
)
2859 extra_cols
+= frp
->fr_width
- w
;
2860 frame_new_width(frp
, w
, leftfirst
, wfw
);
2864 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2872 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2878 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2880 /* Increase "width" if we could not reduce enough frames. */
2882 width
-= extra_cols
;
2885 else if (extra_cols
> 0)
2887 /* increase width of rightmost frame */
2888 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2891 topfrp
->fr_width
= width
;
2895 * Add the vertical separator to windows at the right side of "frp".
2896 * Note: Does not check if there is room!
2904 if (frp
->fr_layout
== FR_LEAF
)
2907 if (wp
->w_vsep_width
== 0)
2909 if (wp
->w_width
> 0) /* don't make it negative */
2911 wp
->w_vsep_width
= 1;
2914 else if (frp
->fr_layout
== FR_COL
)
2916 /* Handle all the frames in the column. */
2917 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2918 frame_add_vsep(frp
);
2920 else /* frp->fr_layout == FR_ROW */
2922 /* Only need to handle the last frame in the row. */
2923 frp
= frp
->fr_child
;
2924 while (frp
->fr_next
!= NULL
)
2926 frame_add_vsep(frp
);
2931 * Set frame width from the window it contains.
2937 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2942 * Set frame height from the window it contains.
2945 frame_fix_height(wp
)
2948 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2952 * Compute the minimal height for frame "topfrp".
2953 * Uses the 'winminheight' option.
2954 * When "next_curwin" isn't NULL, use p_wh for this window.
2955 * When "next_curwin" is NOWIN, don't use at least one line for the current
2959 frame_minheight(topfrp
, next_curwin
)
2965 #ifdef FEAT_VERTSPLIT
2969 if (topfrp
->fr_win
!= NULL
)
2971 if (topfrp
->fr_win
== next_curwin
)
2972 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2975 /* window: minimal height of the window plus status line */
2976 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2977 /* Current window is minimal one line high */
2978 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2982 #ifdef FEAT_VERTSPLIT
2983 else if (topfrp
->fr_layout
== FR_ROW
)
2985 /* get the minimal height from each frame in this row */
2987 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2989 n
= frame_minheight(frp
, next_curwin
);
2997 /* Add up the minimal heights for all frames in this column. */
2999 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3000 m
+= frame_minheight(frp
, next_curwin
);
3006 #ifdef FEAT_VERTSPLIT
3008 * Compute the minimal width for frame "topfrp".
3009 * When "next_curwin" isn't NULL, use p_wiw for this window.
3010 * When "next_curwin" is NOWIN, don't use at least one column for the current
3014 frame_minwidth(topfrp
, next_curwin
)
3016 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3021 if (topfrp
->fr_win
!= NULL
)
3023 if (topfrp
->fr_win
== next_curwin
)
3024 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3027 /* window: minimal width of the window plus separator column */
3028 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3029 /* Current window is minimal one column wide */
3030 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3034 else if (topfrp
->fr_layout
== FR_COL
)
3036 /* get the minimal width from each frame in this column */
3038 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3040 n
= frame_minwidth(frp
, next_curwin
);
3047 /* Add up the minimal widths for all frames in this row. */
3049 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3050 m
+= frame_minwidth(frp
, next_curwin
);
3059 * Try to close all windows except current one.
3060 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3061 * used and the buffer was modified.
3063 * Used by ":bdel" and ":only".
3066 close_others(message
, forceit
)
3068 int forceit
; /* always hide all other windows */
3074 if (lastwin
== firstwin
)
3085 /* Be very careful here: autocommands may change the window layout. */
3086 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3088 nextwp
= wp
->w_next
;
3089 if (wp
!= curwin
) /* don't close current window */
3092 /* Check if it's allowed to abandon this window */
3093 r
= can_abandon(wp
->w_buffer
, forceit
);
3095 if (!win_valid(wp
)) /* autocommands messed wp up */
3103 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3104 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3106 dialog_changed(wp
->w_buffer
, FALSE
);
3107 # ifdef FEAT_AUTOCMD
3108 if (!win_valid(wp
)) /* autocommands messed wp up */
3115 if (bufIsChanged(wp
->w_buffer
))
3119 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3123 if (message
&& lastwin
!= firstwin
)
3124 EMSG(_("E445: Other window contains changes"));
3127 #endif /* FEAT_WINDOWS */
3130 * Init the current window "curwin".
3131 * Called when a new file is being edited.
3136 redraw_win_later(curwin
, NOT_VALID
);
3137 curwin
->w_lines_valid
= 0;
3138 curwin
->w_cursor
.lnum
= 1;
3139 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3140 #ifdef FEAT_VIRTUALEDIT
3141 curwin
->w_cursor
.coladd
= 0;
3143 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3144 curwin
->w_pcmark
.col
= 0;
3145 curwin
->w_prev_pcmark
.lnum
= 0;
3146 curwin
->w_prev_pcmark
.col
= 0;
3147 curwin
->w_topline
= 1;
3149 curwin
->w_topfill
= 0;
3151 curwin
->w_botline
= 2;
3154 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3156 curwin
->w_farsi
= W_CONV
;
3161 * Allocate the first window and put an empty buffer in it.
3162 * Called from main().
3163 * Return FAIL when something goes wrong (out of memory).
3168 if (win_alloc_firstwin(NULL
) == FAIL
)
3172 first_tabpage
= alloc_tabpage();
3173 if (first_tabpage
== NULL
)
3175 first_tabpage
->tp_topframe
= topframe
;
3176 curtab
= first_tabpage
;
3182 * Allocate the first window or the first window in a new tab page.
3183 * When "oldwin" is NULL create an empty buffer for it.
3184 * When "oldwin" is not NULL copy info from it to the new window (only with
3186 * Return FAIL when something goes wrong (out of memory).
3189 win_alloc_firstwin(oldwin
)
3192 curwin
= win_alloc(NULL
);
3195 /* Very first window, need to create an empty buffer for it and
3196 * initialize from scratch. */
3197 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3198 if (curwin
== NULL
|| curbuf
== NULL
)
3200 curwin
->w_buffer
= curbuf
;
3201 curbuf
->b_nwindows
= 1; /* there is one window */
3203 curwin
->w_alist
= &global_alist
;
3205 curwin_init(); /* init current window */
3210 /* First window in new tab page, initialize it from "oldwin". */
3211 win_init(curwin
, oldwin
);
3213 # ifdef FEAT_SCROLLBIND
3214 /* We don't want scroll-binding in the first window. */
3215 curwin
->w_p_scb
= FALSE
;
3220 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3221 if (topframe
== NULL
)
3223 topframe
->fr_layout
= FR_LEAF
;
3224 #ifdef FEAT_VERTSPLIT
3225 topframe
->fr_width
= Columns
;
3227 topframe
->fr_height
= Rows
- p_ch
;
3228 topframe
->fr_win
= curwin
;
3229 curwin
->w_frame
= topframe
;
3235 * Initialize the window and frame size to the maximum.
3240 firstwin
->w_height
= ROWS_AVAIL
;
3241 topframe
->fr_height
= ROWS_AVAIL
;
3242 #ifdef FEAT_VERTSPLIT
3243 firstwin
->w_width
= Columns
;
3244 topframe
->fr_width
= Columns
;
3248 #if defined(FEAT_WINDOWS) || defined(PROTO)
3251 * Allocate a new tabpage_T and init the values.
3252 * Returns NULL when out of memory.
3259 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3265 for (i
= 0; i
< 3; i
++)
3266 tp
->tp_prev_which_scrollbars
[i
] = -1;
3269 tp
->tp_diff_invalid
= TRUE
;
3272 /* init t: variables */
3273 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3275 tp
->tp_ch_used
= p_ch
;
3289 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3295 * Create a new Tab page with one window.
3296 * It will edit the current buffer, like after ":split".
3297 * When "after" is 0 put it just after the current Tab page.
3298 * Otherwise put it just before tab page "after".
3299 * Return FAIL or OK.
3302 win_new_tabpage(after
)
3305 tabpage_T
*tp
= curtab
;
3309 newtp
= alloc_tabpage();
3313 /* Remember the current windows in this Tab page. */
3314 if (leave_tabpage(curbuf
) == FAIL
)
3321 /* Create a new empty window. */
3322 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3324 /* Make the new Tab page the new topframe. */
3327 /* New tab page becomes the first one. */
3328 newtp
->tp_next
= first_tabpage
;
3329 first_tabpage
= newtp
;
3335 /* Put new tab page before tab page "after". */
3337 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3338 && n
< after
; tp
= tp
->tp_next
)
3341 newtp
->tp_next
= tp
->tp_next
;
3342 tp
->tp_next
= newtp
;
3345 firstwin
->w_winrow
= tabline_height();
3346 win_comp_scroll(curwin
);
3348 newtp
->tp_topframe
= topframe
;
3351 #if defined(FEAT_GUI)
3352 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3353 * scrollbars. Have to update them anyway. */
3354 if (gui
.in_use
&& starting
== 0)
3356 gui_init_which_components(NULL
);
3357 gui_update_scrollbars(TRUE
);
3359 need_mouse_correct
= TRUE
;
3362 redraw_all_later(CLEAR
);
3364 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3365 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3370 /* Failed, get back the previous Tab page */
3371 enter_tabpage(curtab
, curbuf
);
3376 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3377 * like with ":split".
3378 * Returns OK if a new tab page was created, FAIL otherwise.
3383 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3387 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3388 postponed_split_tab
= 0;
3389 return win_new_tabpage(n
);
3395 * Create up to "maxcount" tabpages with empty windows.
3396 * Returns the number of resulting tab pages.
3399 make_tabpages(maxcount
)
3402 int count
= maxcount
;
3405 /* Limit to 'tabpagemax' tabs. */
3411 * Don't execute autocommands while creating the tab pages. Must do that
3412 * when putting the buffers in the windows.
3417 for (todo
= count
- 1; todo
> 0; --todo
)
3418 if (win_new_tabpage(0) == FAIL
)
3425 /* return actual number of tab pages */
3426 return (count
- todo
);
3430 * Return TRUE when "tpc" points to a valid tab page.
3438 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3445 * Find tab page "n" (first one is 1). Returns NULL when not found.
3454 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3460 * Get index of tab page "tp". First one has index 1.
3461 * When not found returns number of tab pages plus one.
3470 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3476 * Prepare for leaving the current tab page.
3477 * When autocomands change "curtab" we don't leave the tab page and return
3479 * Careful: When OK is returned need to get a new tab page very very soon!
3483 leave_tabpage(new_curbuf
)
3484 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3487 tabpage_T
*tp
= curtab
;
3490 reset_VIsual_and_resel(); /* stop Visual mode */
3493 if (new_curbuf
!= curbuf
)
3495 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3499 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3502 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3506 #if defined(FEAT_GUI)
3507 /* Remove the scrollbars. They may be added back later. */
3509 gui_remove_scrollbars();
3511 tp
->tp_curwin
= curwin
;
3512 tp
->tp_prevwin
= prevwin
;
3513 tp
->tp_firstwin
= firstwin
;
3514 tp
->tp_lastwin
= lastwin
;
3515 tp
->tp_old_Rows
= Rows
;
3516 tp
->tp_old_Columns
= Columns
;
3523 * Start using tab page "tp".
3524 * Only to be used after leave_tabpage() or freeing the current tab page.
3528 enter_tabpage(tp
, old_curbuf
)
3532 int old_off
= tp
->tp_firstwin
->w_winrow
;
3533 win_T
*next_prevwin
= tp
->tp_prevwin
;
3536 firstwin
= tp
->tp_firstwin
;
3537 lastwin
= tp
->tp_lastwin
;
3538 topframe
= tp
->tp_topframe
;
3540 /* We would like doing the TabEnter event first, but we don't have a
3541 * valid current window yet, which may break some commands.
3542 * This triggers autocommands, thus may make "tp" invalid. */
3543 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3544 prevwin
= next_prevwin
;
3547 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3549 if (old_curbuf
!= curbuf
)
3550 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3553 last_status(FALSE
); /* status line may appear or disappear */
3554 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3555 must_redraw
= CLEAR
; /* need to redraw everything */
3557 diff_need_scrollbind
= TRUE
;
3560 /* The tabpage line may have appeared or disappeared, may need to resize
3561 * the frames for that. When the Vim window was resized need to update
3562 * frame sizes too. Use the stored value of p_ch, so that it can be
3563 * different for each tab page. */
3564 p_ch
= curtab
->tp_ch_used
;
3565 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3566 #ifdef FEAT_GUI_TABLINE
3567 && !gui_use_tabline()
3571 #ifdef FEAT_VERTSPLIT
3572 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3573 shell_new_columns(); /* update window widths */
3576 #if defined(FEAT_GUI)
3577 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3578 * scrollbars. Have to update them anyway. */
3579 if (gui
.in_use
&& starting
== 0)
3581 gui_init_which_components(NULL
);
3582 gui_update_scrollbars(TRUE
);
3584 need_mouse_correct
= TRUE
;
3587 redraw_all_later(CLEAR
);
3591 * Go to tab page "n". For ":tab N" and "Ngt".
3592 * When "n" is 9999 go to the last tab page.
3604 /* Not allowed when editing the command line. */
3606 if (cmdwin_type
!= 0)
3614 /* If there is only one it can't work. */
3615 if (first_tabpage
->tp_next
== NULL
)
3624 /* No count, go to next tab page, wrap around end. */
3625 if (curtab
->tp_next
== NULL
)
3628 tp
= curtab
->tp_next
;
3632 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3635 for (i
= n
; i
< 0; ++i
)
3637 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3645 /* Go to last tab page. */
3646 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3651 /* Go to tab page "n". */
3652 tp
= find_tabpage(n
);
3660 goto_tabpage_tp(tp
);
3662 #ifdef FEAT_GUI_TABLINE
3663 if (gui_use_tabline())
3664 gui_mch_set_curtab(tabpage_index(curtab
));
3669 * Go to tabpage "tp".
3670 * Note: doesn't update the GUI tab.
3676 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3678 if (valid_tabpage(tp
))
3679 enter_tabpage(tp
, curbuf
);
3681 enter_tabpage(curtab
, curbuf
);
3686 * Enter window "wp" in tab page "tp".
3687 * Also updates the GUI tab.
3690 goto_tabpage_win(tp
, wp
)
3694 goto_tabpage_tp(tp
);
3695 if (curtab
== tp
&& win_valid(wp
))
3697 win_enter(wp
, TRUE
);
3698 # ifdef FEAT_GUI_TABLINE
3699 if (gui_use_tabline())
3700 gui_mch_set_curtab(tabpage_index(curtab
));
3706 * Move the current tab page to before tab page "nr".
3715 if (first_tabpage
->tp_next
== NULL
)
3718 /* Remove the current tab page from the list of tab pages. */
3719 if (curtab
== first_tabpage
)
3720 first_tabpage
= curtab
->tp_next
;
3723 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3724 if (tp
->tp_next
== curtab
)
3726 if (tp
== NULL
) /* "cannot happen" */
3728 tp
->tp_next
= curtab
->tp_next
;
3731 /* Re-insert it at the specified position. */
3734 curtab
->tp_next
= first_tabpage
;
3735 first_tabpage
= curtab
;
3739 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3741 curtab
->tp_next
= tp
->tp_next
;
3742 tp
->tp_next
= curtab
;
3745 /* Need to redraw the tabline. Tab page contents doesn't change. */
3746 redraw_tabline
= TRUE
;
3751 * Go to another window.
3752 * When jumping to another buffer, stop Visual mode. Do this before
3753 * changing windows so we can yank the selection into the '*' register.
3754 * When jumping to another window on the same buffer, adjust its cursor
3755 * position to keep the same Visual area.
3768 if (curbuf_locked())
3773 if (wp
->w_buffer
!= curbuf
)
3774 reset_VIsual_and_resel();
3775 else if (VIsual_active
)
3776 wp
->w_cursor
= curwin
->w_cursor
;
3780 need_mouse_correct
= TRUE
;
3782 win_enter(wp
, TRUE
);
3785 #if defined(FEAT_PERL) || defined(PROTO)
3787 * Find window number "winnr" (counting top to bottom).
3795 # ifdef FEAT_WINDOWS
3796 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3806 #ifdef FEAT_VERTSPLIT
3808 * Move to window above or below "count" times.
3811 win_goto_ver(up
, count
)
3812 int up
; /* TRUE to go to win above */
3819 foundfr
= curwin
->w_frame
;
3823 * First go upwards in the tree of frames until we find a upwards or
3824 * downwards neighbor.
3835 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3841 * Now go downwards to find the bottom or top frame in it.
3845 if (nfr
->fr_layout
== FR_LEAF
)
3851 if (nfr
->fr_layout
== FR_ROW
)
3853 /* Find the frame at the cursor row. */
3854 while (fr
->fr_next
!= NULL
3855 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3856 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3859 if (nfr
->fr_layout
== FR_COL
&& up
)
3860 while (fr
->fr_next
!= NULL
)
3866 if (foundfr
!= NULL
)
3867 win_goto(foundfr
->fr_win
);
3871 * Move to left or right window.
3874 win_goto_hor(left
, count
)
3875 int left
; /* TRUE to go to left win */
3882 foundfr
= curwin
->w_frame
;
3886 * First go upwards in the tree of frames until we find a left or
3898 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3904 * Now go downwards to find the leftmost or rightmost frame in it.
3908 if (nfr
->fr_layout
== FR_LEAF
)
3914 if (nfr
->fr_layout
== FR_COL
)
3916 /* Find the frame at the cursor row. */
3917 while (fr
->fr_next
!= NULL
3918 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3919 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3922 if (nfr
->fr_layout
== FR_ROW
&& left
)
3923 while (fr
->fr_next
!= NULL
)
3929 if (foundfr
!= NULL
)
3930 win_goto(foundfr
->fr_win
);
3935 * Make window "wp" the current window.
3938 win_enter(wp
, undo_sync
)
3942 win_enter_ext(wp
, undo_sync
, FALSE
);
3946 * Make window wp the current window.
3947 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3948 * been closed and isn't valid.
3951 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3957 int other_buffer
= FALSE
;
3960 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3964 if (!curwin_invalid
)
3967 * Be careful: If autocommands delete the window, return now.
3969 if (wp
->w_buffer
!= curbuf
)
3971 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3972 other_buffer
= TRUE
;
3976 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3980 /* autocmds may abort script processing */
3987 /* sync undo before leaving the current buffer */
3988 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
3990 /* may have to copy the buffer options when 'cpo' contains 'S' */
3991 if (wp
->w_buffer
!= curbuf
)
3992 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
3993 if (!curwin_invalid
)
3995 prevwin
= curwin
; /* remember for CTRL-W p */
3996 curwin
->w_redr_status
= TRUE
;
3999 curbuf
= wp
->w_buffer
;
4001 #ifdef FEAT_VIRTUALEDIT
4002 if (!virtual_active())
4003 curwin
->w_cursor
.coladd
= 0;
4005 changed_line_abv_curs(); /* assume cursor position needs updating */
4007 if (curwin
->w_localdir
!= NULL
)
4009 /* Window has a local directory: Save current directory as global
4010 * directory (unless that was done already) and change to the local
4012 if (globaldir
== NULL
)
4014 char_u cwd
[MAXPATHL
];
4016 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4017 globaldir
= vim_strsave(cwd
);
4019 mch_chdir((char *)curwin
->w_localdir
);
4020 shorten_fnames(TRUE
);
4022 else if (globaldir
!= NULL
)
4024 /* Window doesn't have a local directory and we are not in the global
4025 * directory: Change to the global directory. */
4026 mch_chdir((char *)globaldir
);
4027 vim_free(globaldir
);
4029 shorten_fnames(TRUE
);
4033 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4035 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4041 curwin
->w_redr_status
= TRUE
;
4042 redraw_tabline
= TRUE
;
4044 redraw_later(VALID
); /* causes status line redraw */
4046 /* set window height to desired minimal value */
4047 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4048 win_setheight((int)p_wh
);
4049 else if (curwin
->w_height
== 0)
4052 #ifdef FEAT_VERTSPLIT
4053 /* set window width to desired minimal value */
4054 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4055 win_setwidth((int)p_wiw
);
4059 setmouse(); /* in case jumped to/from help buffer */
4062 /* Change directories when the 'acd' option is set. */
4066 #endif /* FEAT_WINDOWS */
4068 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4070 * Jump to the first open window that contains buffer "buf", if one exists.
4071 * Returns a pointer to the window found, otherwise NULL.
4074 buf_jump_open_win(buf
)
4077 # ifdef FEAT_WINDOWS
4080 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4081 if (wp
->w_buffer
== buf
)
4084 win_enter(wp
, FALSE
);
4087 if (curwin
->w_buffer
== buf
)
4094 * Jump to the first open window in any tab page that contains buffer "buf",
4096 * Returns a pointer to the window found, otherwise NULL.
4099 buf_jump_open_tab(buf
)
4102 # ifdef FEAT_WINDOWS
4106 /* First try the current tab page. */
4107 wp
= buf_jump_open_win(buf
);
4111 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4114 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4115 if (wp
->w_buffer
== buf
)
4119 goto_tabpage_win(tp
, wp
);
4121 wp
= NULL
; /* something went wrong */
4128 if (curwin
->w_buffer
== buf
)
4136 * allocate a window structure and link it in the window list
4146 * allocate window structure and linesizes arrays
4148 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4149 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4158 /* Don't execute autocommands while the window is not properly
4159 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4164 * link the window in the window list
4167 win_append(after
, newwin
);
4169 #ifdef FEAT_VERTSPLIT
4170 newwin
->w_wincol
= 0;
4171 newwin
->w_width
= Columns
;
4174 /* position the display and the cursor at the top of the file. */
4175 newwin
->w_topline
= 1;
4177 newwin
->w_topfill
= 0;
4179 newwin
->w_botline
= 2;
4180 newwin
->w_cursor
.lnum
= 1;
4181 #ifdef FEAT_SCROLLBIND
4182 newwin
->w_scbind_pos
= 1;
4185 /* We won't calculate w_fraction until resizing the window */
4186 newwin
->w_fraction
= 0;
4187 newwin
->w_prev_fraction_row
= -1;
4192 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4194 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4195 SBAR_RIGHT
, newwin
);
4199 /* init w: variables */
4200 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4203 foldInitWin(newwin
);
4208 #ifdef FEAT_SEARCH_EXTRA
4209 newwin
->w_match_head
= NULL
;
4210 newwin
->w_next_match_id
= 4;
4216 #if defined(FEAT_WINDOWS) || defined(PROTO)
4219 * remove window 'wp' from the window list and free the structure
4224 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4229 /* Don't execute autocommands while the window is halfway being deleted.
4230 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4234 #ifdef FEAT_MZSCHEME
4235 mzscheme_window_free(wp
);
4243 python_window_free(wp
);
4247 tcl_window_free(wp
);
4251 ruby_window_free(wp
);
4254 clear_winopt(&wp
->w_onebuf_opt
);
4255 clear_winopt(&wp
->w_allbuf_opt
);
4258 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4265 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4266 vim_free(wp
->w_tagstack
[i
].tagname
);
4268 vim_free(wp
->w_localdir
);
4270 #ifdef FEAT_SEARCH_EXTRA
4274 #ifdef FEAT_JUMPLIST
4278 #ifdef FEAT_QUICKFIX
4285 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4286 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4288 #endif /* FEAT_GUI */
4299 * Append window "wp" in the window list after window "after".
4302 win_append(after
, wp
)
4307 if (after
== NULL
) /* after NULL is in front of the first */
4310 before
= after
->w_next
;
4312 wp
->w_next
= before
;
4321 before
->w_prev
= wp
;
4325 * Remove a window from the window list.
4330 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4332 if (wp
->w_prev
!= NULL
)
4333 wp
->w_prev
->w_next
= wp
->w_next
;
4334 else if (tp
== NULL
)
4335 firstwin
= wp
->w_next
;
4337 tp
->tp_firstwin
= wp
->w_next
;
4338 if (wp
->w_next
!= NULL
)
4339 wp
->w_next
->w_prev
= wp
->w_prev
;
4340 else if (tp
== NULL
)
4341 lastwin
= wp
->w_prev
;
4343 tp
->tp_lastwin
= wp
->w_prev
;
4347 * Append frame "frp" in a frame list after frame "after".
4350 frame_append(after
, frp
)
4351 frame_T
*after
, *frp
;
4353 frp
->fr_next
= after
->fr_next
;
4354 after
->fr_next
= frp
;
4355 if (frp
->fr_next
!= NULL
)
4356 frp
->fr_next
->fr_prev
= frp
;
4357 frp
->fr_prev
= after
;
4361 * Insert frame "frp" in a frame list before frame "before".
4364 frame_insert(before
, frp
)
4365 frame_T
*before
, *frp
;
4367 frp
->fr_next
= before
;
4368 frp
->fr_prev
= before
->fr_prev
;
4369 before
->fr_prev
= frp
;
4370 if (frp
->fr_prev
!= NULL
)
4371 frp
->fr_prev
->fr_next
= frp
;
4373 frp
->fr_parent
->fr_child
= frp
;
4377 * Remove a frame from a frame list.
4383 if (frp
->fr_prev
!= NULL
)
4384 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4386 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4387 if (frp
->fr_next
!= NULL
)
4388 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4391 #endif /* FEAT_WINDOWS */
4394 * Allocate w_lines[] for window "wp".
4395 * Return FAIL for failure, OK for success.
4401 wp
->w_lines_valid
= 0;
4402 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4403 if (wp
->w_lines
== NULL
)
4409 * free lsize arrays for a window
4415 vim_free(wp
->w_lines
);
4420 * Called from win_new_shellsize() after Rows changed.
4421 * This only does the current tab page, others must be done when made active.
4426 int h
= (int)ROWS_AVAIL
;
4428 if (firstwin
== NULL
) /* not initialized yet */
4431 if (h
< frame_minheight(topframe
, NULL
))
4432 h
= frame_minheight(topframe
, NULL
);
4434 /* First try setting the heights of windows with 'winfixheight'. If
4435 * that doesn't result in the right height, forget about that option. */
4436 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4437 if (topframe
->fr_height
!= h
)
4438 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4440 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4444 win_new_height(firstwin
, h
);
4448 curtab
->tp_ch_used
= p_ch
;
4452 /* Disabled: don't want making the screen smaller make a window larger. */
4454 win_equal(curwin
, FALSE
, 'v');
4458 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4460 * Called from win_new_shellsize() after Columns changed.
4465 if (firstwin
== NULL
) /* not initialized yet */
4468 /* First try setting the widths of windows with 'winfixwidth'. If that
4469 * doesn't result in the right width, forget about that option. */
4470 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4471 if (topframe
->fr_width
!= Columns
)
4472 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4474 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4476 /* Disabled: don't want making the screen smaller make a window larger. */
4478 win_equal(curwin
, FALSE
, 'h');
4483 #if defined(FEAT_CMDWIN) || defined(PROTO)
4485 * Save the size of all windows in "gap".
4494 ga_init2(gap
, (int)sizeof(int), 1);
4495 if (ga_grow(gap
, win_count() * 2) == OK
)
4496 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4498 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4499 wp
->w_width
+ wp
->w_vsep_width
;
4500 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4505 * Restore window sizes, but only if the number of windows is still the same.
4506 * Does not free the growarray.
4509 win_size_restore(gap
)
4515 if (win_count() * 2 == gap
->ga_len
)
4518 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4520 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4521 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4523 /* recompute the window positions */
4524 (void)win_comp_pos();
4527 #endif /* FEAT_CMDWIN */
4529 #if defined(FEAT_WINDOWS) || defined(PROTO)
4531 * Update the position for all windows, using the width and height of the
4533 * Returns the row just after the last window.
4538 int row
= tabline_height();
4541 frame_comp_pos(topframe
, &row
, &col
);
4546 * Update the position of the windows in frame "topfrp", using the width and
4547 * height of the frames.
4548 * "*row" and "*col" are the top-left position of the frame. They are updated
4549 * to the bottom-right position plus one.
4552 frame_comp_pos(topfrp
, row
, col
)
4559 #ifdef FEAT_VERTSPLIT
4564 wp
= topfrp
->fr_win
;
4567 if (wp
->w_winrow
!= *row
4568 #ifdef FEAT_VERTSPLIT
4569 || wp
->w_wincol
!= *col
4573 /* position changed, redraw */
4574 wp
->w_winrow
= *row
;
4575 #ifdef FEAT_VERTSPLIT
4576 wp
->w_wincol
= *col
;
4578 redraw_win_later(wp
, NOT_VALID
);
4579 wp
->w_redr_status
= TRUE
;
4581 *row
+= wp
->w_height
+ wp
->w_status_height
;
4582 #ifdef FEAT_VERTSPLIT
4583 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4588 #ifdef FEAT_VERTSPLIT
4592 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4594 #ifdef FEAT_VERTSPLIT
4595 if (topfrp
->fr_layout
== FR_ROW
)
4596 *row
= startrow
; /* all frames are at the same row */
4598 *col
= startcol
; /* all frames are at the same col */
4600 frame_comp_pos(frp
, row
, col
);
4605 #endif /* FEAT_WINDOWS */
4608 * Set current window height and take care of repositioning other windows to
4612 win_setheight(height
)
4615 win_setheight_win(height
, curwin
);
4619 * Set the window height of window "win" and take care of repositioning other
4620 * windows to fit around it.
4623 win_setheight_win(height
, win
)
4631 /* Always keep current window at least one line high, even when
4632 * 'winminheight' is zero. */
4642 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4644 /* recompute the window positions */
4645 row
= win_comp_pos();
4647 if (height
> topframe
->fr_height
)
4648 height
= topframe
->fr_height
;
4649 win
->w_height
= height
;
4654 * If there is extra space created between the last window and the command
4657 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4658 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4663 redraw_all_later(NOT_VALID
);
4666 #if defined(FEAT_WINDOWS) || defined(PROTO)
4669 * Set the height of a frame to "height" and take care that all frames and
4670 * windows inside it are resized. Also resize frames on the left and right if
4671 * the are in the same FR_ROW frame.
4674 * If the frame is part of a FR_COL frame, try fitting the frame in that
4675 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4676 * go to containing frames to resize them and make room.
4677 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4678 * Check for the minimal height of the FR_ROW frame.
4679 * At the top level we can also use change the command line height.
4682 frame_setheight(curfrp
, height
)
4686 int room
; /* total number of lines available */
4687 int take
; /* number of lines taken from other windows */
4688 int room_cmdline
; /* lines available from cmdline */
4694 /* If the height already is the desired value, nothing to do. */
4695 if (curfrp
->fr_height
== height
)
4698 if (curfrp
->fr_parent
== NULL
)
4700 /* topframe: can only change the command line */
4701 if (height
> ROWS_AVAIL
)
4702 height
= ROWS_AVAIL
;
4704 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4706 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4708 /* Row of frames: Also need to resize frames left and right of this
4709 * one. First check for the minimal height of these. */
4710 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4713 frame_setheight(curfrp
->fr_parent
, height
);
4718 * Column of frames: try to change only frames in this column.
4720 #ifdef FEAT_VERTSPLIT
4723 * 1: compute room available, if it's not enough try resizing the
4725 * 2: compute the room available and adjust the height to it.
4726 * Try not to reduce the height of a window with 'winfixheight' set.
4728 for (run
= 1; run
<= 2; ++run
)
4735 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4739 && frp
->fr_win
!= NULL
4740 && frp
->fr_win
->w_p_wfh
)
4741 room_reserved
+= frp
->fr_height
;
4742 room
+= frp
->fr_height
;
4744 room
-= frame_minheight(frp
, NULL
);
4746 #ifdef FEAT_VERTSPLIT
4747 if (curfrp
->fr_width
!= Columns
)
4752 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4753 + lastwin
->w_height
+ lastwin
->w_status_height
);
4754 if (room_cmdline
< 0)
4758 if (height
<= room
+ room_cmdline
)
4760 #ifdef FEAT_VERTSPLIT
4761 if (run
== 2 || curfrp
->fr_width
== Columns
)
4764 if (height
> room
+ room_cmdline
)
4765 height
= room
+ room_cmdline
;
4768 #ifdef FEAT_VERTSPLIT
4769 frame_setheight(curfrp
->fr_parent
, height
4770 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4776 * Compute the number of lines we will take from others frames (can be
4779 take
= height
- curfrp
->fr_height
;
4781 /* If there is not enough room, also reduce the height of a window
4782 * with 'winfixheight' set. */
4783 if (height
> room
+ room_cmdline
- room_reserved
)
4784 room_reserved
= room
+ room_cmdline
- height
;
4785 /* If there is only a 'winfixheight' window and making the
4786 * window smaller, need to make the other window taller. */
4787 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4790 if (take
> 0 && room_cmdline
> 0)
4792 /* use lines from cmdline first */
4793 if (take
< room_cmdline
)
4794 room_cmdline
= take
;
4795 take
-= room_cmdline
;
4796 topframe
->fr_height
+= room_cmdline
;
4800 * set the current frame to the new height
4802 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4805 * First take lines from the frames after the current frame. If
4806 * that is not enough, takes lines from frames above the current
4809 for (run
= 0; run
< 2; ++run
)
4812 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4814 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4815 while (frp
!= NULL
&& take
!= 0)
4817 h
= frame_minheight(frp
, NULL
);
4818 if (room_reserved
> 0
4819 && frp
->fr_win
!= NULL
4820 && frp
->fr_win
->w_p_wfh
)
4822 if (room_reserved
>= frp
->fr_height
)
4823 room_reserved
-= frp
->fr_height
;
4826 if (frp
->fr_height
- room_reserved
> take
)
4827 room_reserved
= frp
->fr_height
- take
;
4828 take
-= frp
->fr_height
- room_reserved
;
4829 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4835 if (frp
->fr_height
- take
< h
)
4837 take
-= frp
->fr_height
- h
;
4838 frame_new_height(frp
, h
, FALSE
, FALSE
);
4842 frame_new_height(frp
, frp
->fr_height
- take
,
4856 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4858 * Set current window width and take care of repositioning other windows to
4865 win_setwidth_win(width
, curwin
);
4869 win_setwidth_win(width
, wp
)
4873 /* Always keep current window at least one column wide, even when
4874 * 'winminwidth' is zero. */
4883 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4885 /* recompute the window positions */
4886 (void)win_comp_pos();
4888 redraw_all_later(NOT_VALID
);
4892 * Set the width of a frame to "width" and take care that all frames and
4893 * windows inside it are resized. Also resize frames above and below if the
4894 * are in the same FR_ROW frame.
4896 * Strategy is similar to frame_setheight().
4899 frame_setwidth(curfrp
, width
)
4903 int room
; /* total number of lines available */
4904 int take
; /* number of lines taken from other windows */
4910 /* If the width already is the desired value, nothing to do. */
4911 if (curfrp
->fr_width
== width
)
4914 if (curfrp
->fr_parent
== NULL
)
4915 /* topframe: can't change width */
4918 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4920 /* Column of frames: Also need to resize frames above and below of
4921 * this one. First check for the minimal width of these. */
4922 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4925 frame_setwidth(curfrp
->fr_parent
, width
);
4930 * Row of frames: try to change only frames in this row.
4933 * 1: compute room available, if it's not enough try resizing the
4935 * 2: compute the room available and adjust the width to it.
4937 for (run
= 1; run
<= 2; ++run
)
4941 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4945 && frp
->fr_win
!= NULL
4946 && frp
->fr_win
->w_p_wfw
)
4947 room_reserved
+= frp
->fr_width
;
4948 room
+= frp
->fr_width
;
4950 room
-= frame_minwidth(frp
, NULL
);
4955 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4961 frame_setwidth(curfrp
->fr_parent
, width
4962 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4966 * Compute the number of lines we will take from others frames (can be
4969 take
= width
- curfrp
->fr_width
;
4971 /* If there is not enough room, also reduce the width of a window
4972 * with 'winfixwidth' set. */
4973 if (width
> room
- room_reserved
)
4974 room_reserved
= room
- width
;
4975 /* If there is only a 'winfixwidth' window and making the
4976 * window smaller, need to make the other window narrower. */
4977 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4981 * set the current frame to the new width
4983 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
4986 * First take lines from the frames right of the current frame. If
4987 * that is not enough, takes lines from frames left of the current
4990 for (run
= 0; run
< 2; ++run
)
4993 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4995 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4996 while (frp
!= NULL
&& take
!= 0)
4998 w
= frame_minwidth(frp
, NULL
);
4999 if (room_reserved
> 0
5000 && frp
->fr_win
!= NULL
5001 && frp
->fr_win
->w_p_wfw
)
5003 if (room_reserved
>= frp
->fr_width
)
5004 room_reserved
-= frp
->fr_width
;
5007 if (frp
->fr_width
- room_reserved
> take
)
5008 room_reserved
= frp
->fr_width
- take
;
5009 take
-= frp
->fr_width
- room_reserved
;
5010 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5016 if (frp
->fr_width
- take
< w
)
5018 take
-= frp
->fr_width
- w
;
5019 frame_new_width(frp
, w
, FALSE
, FALSE
);
5023 frame_new_width(frp
, frp
->fr_width
- take
,
5036 #endif /* FEAT_VERTSPLIT */
5039 * Check 'winminheight' for a valid value.
5048 /* loop until there is a 'winminheight' that is possible */
5051 /* TODO: handle vertical splits */
5053 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5054 room
+= wp
->w_height
- p_wmh
;
5069 * Status line of dragwin is dragged "offset" lines down (negative is up).
5072 win_drag_status_line(dragwin
, offset
)
5080 int up
; /* if TRUE, drag status line up, otherwise down */
5083 fr
= dragwin
->w_frame
;
5085 if (fr
!= topframe
) /* more than one window */
5088 /* When the parent frame is not a column of frames, its parent should
5090 if (fr
->fr_layout
!= FR_COL
)
5093 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5098 /* If this is the last frame in a column, may want to resize the parent
5099 * frame instead (go two up to skip a row of frames). */
5100 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5109 if (offset
< 0) /* drag up */
5113 /* sum up the room of the current frame and above it */
5116 /* only one window */
5117 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5122 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5124 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5129 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5131 else /* drag down */
5135 * Only dragging the last status line can reduce p_ch.
5137 room
= Rows
- cmdline_row
;
5138 if (curfr
->fr_next
== NULL
)
5144 /* sum up the room of frames below of the current one */
5145 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5146 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5147 fr
= curfr
; /* put fr at window that grows */
5150 if (room
< offset
) /* Not enough room */
5151 offset
= room
; /* Move as far as we can */
5156 * Grow frame fr by "offset" lines.
5157 * Doesn't happen when dragging the last status line up.
5160 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5163 fr
= curfr
; /* current frame gets smaller */
5165 fr
= curfr
->fr_next
; /* next frame gets smaller */
5168 * Now make the other frames smaller.
5170 while (fr
!= NULL
&& offset
> 0)
5172 n
= frame_minheight(fr
, NULL
);
5173 if (fr
->fr_height
- offset
<= n
)
5175 offset
-= fr
->fr_height
- n
;
5176 frame_new_height(fr
, n
, !up
, FALSE
);
5180 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5188 row
= win_comp_pos();
5189 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5191 p_ch
= Rows
- cmdline_row
;
5194 curtab
->tp_ch_used
= p_ch
;
5195 redraw_all_later(SOME_VALID
);
5199 #ifdef FEAT_VERTSPLIT
5201 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5204 win_drag_vsep_line(dragwin
, offset
)
5211 int left
; /* if TRUE, drag separator line left, otherwise right */
5214 fr
= dragwin
->w_frame
;
5215 if (fr
== topframe
) /* only one window (cannot happen?) */
5219 /* When the parent frame is not a row of frames, its parent should be. */
5220 if (fr
->fr_layout
!= FR_ROW
)
5222 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5228 /* If this is the last frame in a row, may want to resize a parent
5230 while (curfr
->fr_next
== NULL
)
5243 if (offset
< 0) /* drag left */
5247 /* sum up the room of the current frame and left of it */
5249 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5251 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5255 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5257 else /* drag right */
5260 /* sum up the room of frames right of the current one */
5262 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5263 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5264 fr
= curfr
; /* put fr at window that grows */
5267 if (room
< offset
) /* Not enough room */
5268 offset
= room
; /* Move as far as we can */
5269 if (offset
<= 0) /* No room at all, quit. */
5272 /* grow frame fr by offset lines */
5273 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5275 /* shrink other frames: current and at the left or at the right */
5277 fr
= curfr
; /* current frame gets smaller */
5279 fr
= curfr
->fr_next
; /* next frame gets smaller */
5281 while (fr
!= NULL
&& offset
> 0)
5283 n
= frame_minwidth(fr
, NULL
);
5284 if (fr
->fr_width
- offset
<= n
)
5286 offset
-= fr
->fr_width
- n
;
5287 frame_new_width(fr
, n
, !left
, FALSE
);
5291 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5299 (void)win_comp_pos();
5300 redraw_all_later(NOT_VALID
);
5302 #endif /* FEAT_VERTSPLIT */
5303 #endif /* FEAT_MOUSE */
5305 #endif /* FEAT_WINDOWS */
5308 * Set the height of a window.
5309 * This takes care of the things inside the window, not what happens to the
5310 * window position, the frame or to other windows.
5313 win_new_height(wp
, height
)
5318 int sline
, line_size
;
5319 #define FRACTION_MULT 16384L
5321 /* Don't want a negative height. Happens when splitting a tiny window.
5322 * Will equalize heights soon to fix it. */
5325 if (wp
->w_height
== height
)
5326 return; /* nothing to do */
5328 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5329 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5330 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5332 wp
->w_height
= height
;
5335 /* Don't change w_topline when height is zero. Don't set w_topline when
5336 * 'scrollbind' is set and this isn't the current window. */
5338 #ifdef FEAT_SCROLLBIND
5339 && (!wp
->w_p_scb
|| wp
== curwin
)
5344 * Find a value for w_topline that shows the cursor at the same
5345 * relative position in the window as before (more or less).
5347 lnum
= wp
->w_cursor
.lnum
;
5348 if (lnum
< 1) /* can happen when starting up */
5350 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5351 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5352 sline
= wp
->w_wrow
- line_size
;
5356 /* Make sure the whole cursor line is visible, if possible. */
5357 int rows
= plines_win(wp
, lnum
, FALSE
);
5359 if (sline
> wp
->w_height
- rows
)
5361 sline
= wp
->w_height
- rows
;
5362 wp
->w_wrow
-= rows
- line_size
;
5369 * Cursor line would go off top of screen if w_wrow was this high.
5370 * Make cursor line the first line in the window. If not enough
5371 * room use w_skipcol;
5373 wp
->w_wrow
= line_size
;
5374 if (wp
->w_wrow
>= wp
->w_height
5375 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5377 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5379 while (wp
->w_wrow
>= wp
->w_height
)
5381 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5389 while (sline
> 0 && lnum
> 1)
5392 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5395 /* first line in buffer is folded */
5403 if (lnum
== wp
->w_topline
)
5404 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5408 line_size
= plines_win(wp
, lnum
, TRUE
);
5415 * Line we want at top would go off top of screen. Use next
5419 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5422 wp
->w_wrow
-= line_size
+ sline
;
5426 /* First line of file reached, use that as topline. */
5428 wp
->w_wrow
-= sline
;
5431 set_topline(wp
, lnum
);
5438 curs_columns(FALSE
); /* validate w_wrow */
5440 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5442 win_comp_scroll(wp
);
5443 redraw_win_later(wp
, SOME_VALID
);
5445 wp
->w_redr_status
= TRUE
;
5447 invalidate_botline_win(wp
);
5450 #ifdef FEAT_VERTSPLIT
5452 * Set the width of a window.
5455 win_new_width(wp
, width
)
5459 wp
->w_width
= width
;
5460 wp
->w_lines_valid
= 0;
5461 changed_line_abv_curs_win(wp
);
5462 invalidate_botline_win(wp
);
5466 curs_columns(TRUE
); /* validate w_wrow */
5468 redraw_win_later(wp
, NOT_VALID
);
5469 wp
->w_redr_status
= TRUE
;
5477 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5478 if (wp
->w_p_scr
== 0)
5483 * command_height: called whenever p_ch has been changed
5491 int old_p_ch
= curtab
->tp_ch_used
;
5493 /* Use the value of p_ch that we remembered. This is needed for when the
5494 * GUI starts up, we can't be sure in what order things happen. And when
5495 * p_ch was changed in another tab page. */
5496 curtab
->tp_ch_used
= p_ch
;
5498 /* Find bottom frame with width of screen. */
5499 frp
= lastwin
->w_frame
;
5500 # ifdef FEAT_VERTSPLIT
5501 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5502 frp
= frp
->fr_parent
;
5505 /* Avoid changing the height of a window with 'winfixheight' set. */
5506 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5507 && frp
->fr_win
->w_p_wfh
)
5510 if (starting
!= NO_SCREEN
)
5512 cmdline_row
= Rows
- p_ch
;
5514 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5516 while (p_ch
> old_p_ch
)
5522 curtab
->tp_ch_used
= p_ch
;
5523 cmdline_row
= Rows
- p_ch
;
5526 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5527 if (h
> p_ch
- old_p_ch
)
5528 h
= p_ch
- old_p_ch
;
5530 frame_add_height(frp
, -h
);
5534 /* Recompute window positions. */
5535 (void)win_comp_pos();
5537 /* clear the lines added to cmdline */
5539 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5540 (int)Columns
, ' ', ' ', 0);
5541 msg_row
= cmdline_row
;
5542 redraw_cmdline
= TRUE
;
5546 if (msg_row
< cmdline_row
)
5547 msg_row
= cmdline_row
;
5548 redraw_cmdline
= TRUE
;
5550 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5552 /* Recompute window positions. */
5553 if (frp
!= lastwin
->w_frame
)
5554 (void)win_comp_pos();
5556 cmdline_row
= Rows
- p_ch
;
5557 win_setheight(cmdline_row
);
5561 #if defined(FEAT_WINDOWS) || defined(PROTO)
5563 * Resize frame "frp" to be "n" lines higher (negative for less high).
5564 * Also resize the frames it is contained in.
5567 frame_add_height(frp
, n
)
5571 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5574 frp
= frp
->fr_parent
;
5577 frp
->fr_height
+= n
;
5582 * Add or remove a status line for the bottom window(s), according to the
5583 * value of 'laststatus'.
5586 last_status(morewin
)
5587 int morewin
; /* pretend there are two or more windows */
5589 /* Don't make a difference between horizontal or vertical split. */
5590 last_status_rec(topframe
, (p_ls
== 2
5591 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5595 last_status_rec(fr
, statusline
)
5602 if (fr
->fr_layout
== FR_LEAF
)
5605 if (wp
->w_status_height
!= 0 && !statusline
)
5607 /* remove status line */
5608 win_new_height(wp
, wp
->w_height
+ 1);
5609 wp
->w_status_height
= 0;
5612 else if (wp
->w_status_height
== 0 && statusline
)
5614 /* Find a frame to take a line from. */
5616 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5623 /* In a column of frames: go to frame above. If already at
5624 * the top or in a row of frames: go to parent. */
5625 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5630 wp
->w_status_height
= 1;
5633 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5634 frame_fix_height(wp
);
5635 (void)win_comp_pos();
5638 win_new_height(wp
, wp
->w_height
- 1);
5640 redraw_all_later(SOME_VALID
);
5643 #ifdef FEAT_VERTSPLIT
5644 else if (fr
->fr_layout
== FR_ROW
)
5646 /* vertically split windows, set status line for each one */
5647 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5648 last_status_rec(fp
, statusline
);
5653 /* horizontally split window, set status line for last one */
5654 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5656 last_status_rec(fp
, statusline
);
5661 * Return the number of lines used by the tab page line.
5666 #ifdef FEAT_GUI_TABLINE
5667 /* When the GUI has the tabline then this always returns zero. */
5668 if (gui_use_tabline())
5674 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5679 #endif /* FEAT_WINDOWS */
5681 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5683 * Get the file name at the cursor.
5684 * If Visual mode is active, use the selected text if it's in one line.
5685 * Returns the name in allocated memory, NULL for failure.
5688 grab_file_name(count
, file_lnum
)
5690 linenr_T
*file_lnum
;
5698 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5700 return find_file_name_in_path(ptr
, len
,
5701 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5704 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5710 * Return the file name under or after the cursor.
5712 * The 'path' option is searched if the file name is not absolute.
5713 * The string returned has been alloc'ed and should be freed by the caller.
5714 * NULL is returned if the file name or file is not found.
5717 * FNAME_MESS give error messages
5718 * FNAME_EXP expand to path
5719 * FNAME_HYP check for hypertext link
5720 * FNAME_INCL apply "includeexpr"
5723 file_name_at_cursor(options
, count
, file_lnum
)
5726 linenr_T
*file_lnum
;
5728 return file_name_in_line(ml_get_curline(),
5729 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5734 * Return the name of the file under or after ptr[col].
5735 * Otherwise like file_name_at_cursor().
5738 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5743 char_u
*rel_fname
; /* file we are searching relative to */
5744 linenr_T
*file_lnum
; /* line number after the file name */
5750 * search forward for what could be the start of a file name
5753 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5755 if (*ptr
== NUL
) /* nothing found */
5757 if (options
& FNAME_MESS
)
5758 EMSG(_("E446: No file name under cursor"));
5763 * Search backward for first char of the file name.
5764 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5769 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5773 if (vim_isfilec(ptr
[-1])
5774 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5781 * Search forward for the last char of the file name.
5782 * Also allow "://" when ':' is not in 'isfname'.
5785 while (vim_isfilec(ptr
[len
])
5786 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5789 len
+= (*mb_ptr2len
)(ptr
+ len
);
5795 * If there is trailing punctuation, remove it.
5796 * But don't remove "..", could be a directory name.
5798 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5799 && ptr
[len
- 2] != '.')
5802 if (file_lnum
!= NULL
)
5806 /* Get the number after the file name and a separator character */
5812 ++p
; /* skip the separator */
5815 *file_lnum
= (int)getdigits(&p
);
5819 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5822 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5823 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5826 eval_includeexpr(ptr
, len
)
5832 set_vim_var_string(VV_FNAME
, ptr
, len
);
5833 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5834 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5835 set_vim_var_string(VV_FNAME
, NULL
, 0);
5841 * Return the name of the file ptr[len] in 'path'.
5842 * Otherwise like file_name_at_cursor().
5845 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5850 char_u
*rel_fname
; /* file we are searching relative to */
5854 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5855 char_u
*tofree
= NULL
;
5857 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5859 tofree
= eval_includeexpr(ptr
, len
);
5863 len
= (int)STRLEN(ptr
);
5868 if (options
& FNAME_EXP
)
5870 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5873 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5875 * If the file could not be found in a normal way, try applying
5876 * 'includeexpr' (unless done already).
5878 if (file_name
== NULL
5879 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5881 tofree
= eval_includeexpr(ptr
, len
);
5885 len
= (int)STRLEN(ptr
);
5886 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5891 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5895 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5899 /* Repeat finding the file "count" times. This matters when it
5900 * appears several times in the path. */
5901 while (file_name
!= NULL
&& --count
> 0)
5903 vim_free(file_name
);
5904 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5908 file_name
= vim_strnsave(ptr
, len
);
5910 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5916 #endif /* FEAT_SEARCHPATH */
5919 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5920 * Also check for ":\\", which MS Internet Explorer accepts, return
5927 if (STRNCMP(p
, "://", (size_t)3) == 0)
5929 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5930 return URL_BACKSLASH
;
5935 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5936 * Return URL_BACKSLASH for "name:\\".
5937 * Return zero otherwise.
5940 path_with_url(fname
)
5945 for (p
= fname
; isalpha(*p
); ++p
)
5947 return path_is_url(p
);
5951 * Return TRUE if "name" is a full (absolute) path name or URL.
5957 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5961 * Get absolute file name into buffer "buf[len]".
5963 * return FAIL for failure, OK otherwise
5966 vim_FullName(fname
, buf
, len
, force
)
5967 char_u
*fname
, *buf
;
5969 int force
; /* force expansion even when already absolute */
5978 url
= path_with_url(fname
);
5980 retval
= mch_FullName(fname
, buf
, len
, force
);
5981 if (url
|| retval
== FAIL
)
5983 /* something failed; use the file name (truncate when too long) */
5984 vim_strncpy(buf
, fname
, len
- 1);
5986 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
5993 * Return the minimal number of rows that is needed on the screen to display
5994 * the current number of windows.
6005 if (firstwin
== NULL
) /* not initialized yet */
6010 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6012 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6016 total
+= tabline_height();
6018 total
= 1; /* at least one window should have a line! */
6020 total
+= 1; /* count the room for the command line */
6025 * Return TRUE if there is only one window (in the current tab page), not
6026 * counting a help or preview window, unless it is the current window.
6035 /* If there is another tab page there always is another window. */
6036 if (first_tabpage
->tp_next
!= NULL
)
6039 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6040 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6041 # ifdef FEAT_QUICKFIX
6046 return (count
<= 1);
6052 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6054 * Correct the cursor line number in other windows. Used after changing the
6055 * current buffer, and before applying autocommands.
6056 * When "do_curwin" is TRUE, also check current window.
6059 check_lnums(do_curwin
)
6067 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6068 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6074 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6075 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6076 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6077 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6082 #if defined(FEAT_WINDOWS) || defined(PROTO)
6085 * A snapshot of the window sizes, to restore them after closing the help
6087 * Only these fields are used:
6093 * fr_win (only valid for the old curwin, NULL otherwise)
6097 * Create a snapshot of the current frame sizes.
6102 clear_snapshot(curtab
);
6103 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6107 make_snapshot_rec(fr
, frp
)
6111 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6114 (*frp
)->fr_layout
= fr
->fr_layout
;
6115 # ifdef FEAT_VERTSPLIT
6116 (*frp
)->fr_width
= fr
->fr_width
;
6118 (*frp
)->fr_height
= fr
->fr_height
;
6119 if (fr
->fr_next
!= NULL
)
6120 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6121 if (fr
->fr_child
!= NULL
)
6122 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6123 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6124 (*frp
)->fr_win
= curwin
;
6128 * Remove any existing snapshot.
6134 clear_snapshot_rec(tp
->tp_snapshot
);
6135 tp
->tp_snapshot
= NULL
;
6139 clear_snapshot_rec(fr
)
6144 clear_snapshot_rec(fr
->fr_next
);
6145 clear_snapshot_rec(fr
->fr_child
);
6151 * Restore a previously created snapshot, if there is any.
6152 * This is only done if the screen size didn't change and the window layout is
6156 restore_snapshot(close_curwin
)
6157 int close_curwin
; /* closing current window */
6161 if (curtab
->tp_snapshot
!= NULL
6162 # ifdef FEAT_VERTSPLIT
6163 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6165 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6166 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6168 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6170 if (wp
!= NULL
&& close_curwin
)
6172 redraw_all_later(CLEAR
);
6174 clear_snapshot(curtab
);
6178 * Check if frames "sn" and "fr" have the same layout, same following frames
6179 * and same children.
6182 check_snapshot_rec(sn
, fr
)
6186 if (sn
->fr_layout
!= fr
->fr_layout
6187 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6188 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6189 || (sn
->fr_next
!= NULL
6190 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6191 || (sn
->fr_child
!= NULL
6192 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6198 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6199 * following frames and children.
6200 * Returns a pointer to the old current window, or NULL.
6203 restore_snapshot_rec(sn
, fr
)
6210 fr
->fr_height
= sn
->fr_height
;
6211 # ifdef FEAT_VERTSPLIT
6212 fr
->fr_width
= sn
->fr_width
;
6214 if (fr
->fr_layout
== FR_LEAF
)
6216 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6217 # ifdef FEAT_VERTSPLIT
6218 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6222 if (sn
->fr_next
!= NULL
)
6224 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6228 if (sn
->fr_child
!= NULL
)
6230 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6239 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6241 * Return TRUE if there is any vertically split window.
6248 if (topframe
->fr_layout
== FR_ROW
)
6251 if (topframe
->fr_layout
== FR_COL
)
6252 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6253 if (fr
->fr_layout
== FR_ROW
)
6260 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6262 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6263 * highligted with the group 'grp' with priority 'prio'.
6264 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6265 * If no particular ID is desired, -1 must be specified for 'id'.
6266 * Return ID of added match, -1 on failure.
6269 match_add(wp
, grp
, pat
, prio
, id
)
6282 if (*grp
== NUL
|| *pat
== NUL
)
6284 if (id
< -1 || id
== 0)
6286 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6291 cur
= wp
->w_match_head
;
6296 EMSGN("E801: ID already taken: %ld", id
);
6302 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6304 EMSG2(_(e_nogroup
), grp
);
6307 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6309 EMSG2(_(e_invarg2
), pat
);
6313 /* Find available match ID. */
6316 cur
= wp
->w_match_head
;
6317 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6320 id
= wp
->w_next_match_id
;
6321 wp
->w_next_match_id
++;
6324 /* Build new match. */
6325 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6328 m
->pattern
= vim_strsave(pat
);
6330 m
->match
.regprog
= regprog
;
6331 m
->match
.rmm_ic
= FALSE
;
6332 m
->match
.rmm_maxcol
= 0;
6334 /* Insert new match. The match list is in ascending order with regard to
6335 * the match priorities. */
6336 cur
= wp
->w_match_head
;
6338 while (cur
!= NULL
&& prio
>= cur
->priority
)
6344 wp
->w_match_head
= m
;
6349 redraw_later(SOME_VALID
);
6354 * Delete match with ID 'id' in the match list of window 'wp'.
6355 * Print error messages if 'perr' is TRUE.
6358 match_delete(wp
, id
, perr
)
6363 matchitem_T
*cur
= wp
->w_match_head
;
6364 matchitem_T
*prev
= cur
;
6369 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6373 while (cur
!= NULL
&& cur
->id
!= id
)
6381 EMSGN("E803: ID not found: %ld", id
);
6385 wp
->w_match_head
= cur
->next
;
6387 prev
->next
= cur
->next
;
6388 vim_free(cur
->match
.regprog
);
6389 vim_free(cur
->pattern
);
6391 redraw_later(SOME_VALID
);
6396 * Delete all matches in the match list of window 'wp'.
6404 while (wp
->w_match_head
!= NULL
)
6406 m
= wp
->w_match_head
->next
;
6407 vim_free(wp
->w_match_head
->match
.regprog
);
6408 vim_free(wp
->w_match_head
->pattern
);
6409 vim_free(wp
->w_match_head
);
6410 wp
->w_match_head
= m
;
6412 redraw_later(SOME_VALID
);
6416 * Get match from ID 'id' in window 'wp'.
6417 * Return NULL if match not found.
6424 matchitem_T
*cur
= wp
->w_match_head
;
6426 while (cur
!= NULL
&& cur
->id
!= id
)