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 */
155 # ifdef FEAT_QUICKFIX
156 /* When splitting the quickfix window open a new buffer in it,
157 * don't replicate the quickfix buffer. */
158 if (bt_quickfix(curbuf
))
162 need_mouse_correct
= TRUE
;
164 win_split((int)Prenum
, WSP_VERT
);
168 /* split current window and edit alternate file */
173 reset_VIsual_and_resel(); /* stop Visual mode */
175 STRCPY(cbuf
, "split #");
177 vim_snprintf((char *)cbuf
+ 7, sizeof(cbuf
) - 7,
179 do_cmdline_cmd(cbuf
);
182 /* open new window */
187 reset_VIsual_and_resel(); /* stop Visual mode */
194 vim_snprintf((char *)cbuf
, sizeof(cbuf
) - 5, "%ld", Prenum
);
197 #if defined(FEAT_VERTSPLIT) && defined(FEAT_QUICKFIX)
198 if (nchar
== 'v' || nchar
== Ctrl_V
)
202 do_cmdline_cmd(cbuf
);
205 /* quit current window */
209 reset_VIsual_and_resel(); /* stop Visual mode */
211 do_cmdline_cmd((char_u
*)"quit");
214 /* close current window */
218 reset_VIsual_and_resel(); /* stop Visual mode */
220 do_cmdline_cmd((char_u
*)"close");
223 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
224 /* close preview window */
229 reset_VIsual_and_resel(); /* stop Visual mode */
231 do_cmdline_cmd((char_u
*)"pclose");
234 /* cursor to preview window */
236 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
240 EMSG(_("E441: There is no preview window"));
246 /* close all but current window */
251 reset_VIsual_and_resel(); /* stop Visual mode */
253 do_cmdline_cmd((char_u
*)"only");
256 /* cursor to next window with wrap around */
259 /* cursor to previous window with wrap around */
262 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
266 if (Prenum
) /* go to specified window */
268 for (wp
= firstwin
; --Prenum
> 0; )
270 if (wp
->w_next
== NULL
)
278 if (nchar
== 'W') /* go to previous window */
282 wp
= lastwin
; /* wrap around */
284 else /* go to next window */
288 wp
= firstwin
; /* wrap around */
295 /* cursor to window below */
300 #ifdef FEAT_VERTSPLIT
301 win_goto_ver(FALSE
, Prenum1
);
303 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
310 /* cursor to window above */
315 #ifdef FEAT_VERTSPLIT
316 win_goto_ver(TRUE
, Prenum1
);
318 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
325 #ifdef FEAT_VERTSPLIT
326 /* cursor to left window */
332 win_goto_hor(TRUE
, Prenum1
);
335 /* cursor to right window */
340 win_goto_hor(FALSE
, Prenum1
);
344 /* move window to new tab page */
346 if (firstwin
== lastwin
)
350 tabpage_T
*oldtab
= curtab
;
353 /* First create a new tab with the window, then go back to
354 * the old tab and close the window there. */
356 if (win_new_tabpage((int)Prenum
) == OK
357 && valid_tabpage(oldtab
))
360 goto_tabpage_tp(oldtab
);
362 win_close(curwin
, FALSE
);
363 if (valid_tabpage(newtab
))
364 goto_tabpage_tp(newtab
);
369 /* cursor to top-left window */
375 /* cursor to bottom-right window */
381 /* cursor to last accessed (previous) window */
390 /* exchange current and next window */
394 win_exchange(Prenum
);
397 /* rotate windows downwards */
402 reset_VIsual_and_resel(); /* stop Visual mode */
404 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
407 /* rotate windows upwards */
411 reset_VIsual_and_resel(); /* stop Visual mode */
413 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
416 /* move window to the very top/bottom/left/right */
419 #ifdef FEAT_VERTSPLIT
424 win_totop((int)Prenum
,
425 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
426 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
429 /* make all windows the same height */
432 need_mouse_correct
= TRUE
;
434 win_equal(NULL
, FALSE
, 'b');
437 /* increase current window height */
440 need_mouse_correct
= TRUE
;
442 win_setheight(curwin
->w_height
+ (int)Prenum1
);
445 /* decrease current window height */
448 need_mouse_correct
= TRUE
;
450 win_setheight(curwin
->w_height
- (int)Prenum1
);
453 /* set current window height */
457 need_mouse_correct
= TRUE
;
459 win_setheight(Prenum
? (int)Prenum
: 9999);
462 #ifdef FEAT_VERTSPLIT
463 /* increase current window width */
466 need_mouse_correct
= TRUE
;
468 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
471 /* decrease current window width */
474 need_mouse_correct
= TRUE
;
476 win_setwidth(curwin
->w_width
- (int)Prenum1
);
479 /* set current window width */
482 need_mouse_correct
= TRUE
;
484 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
488 /* jump to tag and split window if tag exists (in preview window) */
489 #if defined(FEAT_QUICKFIX)
493 g_do_tagpreview
= Prenum
;
495 g_do_tagpreview
= p_pvh
;
502 reset_VIsual_and_resel(); /* stop Visual mode */
505 postponed_split
= Prenum
;
507 postponed_split
= -1;
509 /* Execute the command right here, required when
510 * "wincmd ]" was used in a function. */
511 do_nv_ident(Ctrl_RSB
, NUL
);
514 #ifdef FEAT_SEARCHPATH
515 /* edit file name under cursor in a new window */
522 ptr
= grab_file_name(Prenum1
, &lnum
);
526 need_mouse_correct
= TRUE
;
529 if (win_split(0, 0) == OK
)
531 # ifdef FEAT_SCROLLBIND
532 curwin
->w_p_scb
= FALSE
;
534 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
,
536 if (nchar
== 'F' && lnum
>= 0)
538 curwin
->w_cursor
.lnum
= lnum
;
540 beginline(BL_SOL
| BL_FIX
);
549 /* Go to the first occurrence of the identifier under cursor along path in a
552 case 'i': /* Go to any match */
556 case 'd': /* Go to definition, using 'define' */
559 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
561 find_pattern_in_path(ptr
, 0, len
, TRUE
,
562 Prenum
== 0 ? TRUE
: FALSE
, type
,
563 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
564 curwin
->w_set_curswant
= TRUE
;
570 #if defined(FEAT_QUICKFIX)
572 * In a quickfix window a <CR> jumps to the error under the
573 * cursor in a new window.
575 if (bt_quickfix(curbuf
))
577 sprintf((char *)cbuf
, "split +%ld%s",
578 (long)curwin
->w_cursor
.lnum
,
579 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
580 do_cmdline_cmd(cbuf
);
586 /* CTRL-W g extended commands */
590 #ifdef USE_ON_FLY_SCROLL
591 dont_scroll
= TRUE
; /* disallow scrolling here */
594 ++allow_keys
; /* no mapping for xchar, but allow key codes */
596 xchar
= plain_vgetc();
598 LANGMAP_ADJUST(xchar
, TRUE
);
602 #ifdef FEAT_CMDL_INFO
603 (void)add_to_showcmd(xchar
);
607 #if defined(FEAT_QUICKFIX)
611 g_do_tagpreview
= Prenum
;
613 g_do_tagpreview
= p_pvh
;
619 reset_VIsual_and_resel(); /* stop Visual mode */
622 postponed_split
= Prenum
;
624 postponed_split
= -1;
626 /* Execute the command right here, required when
627 * "wincmd g}" was used in a function. */
628 do_nv_ident('g', xchar
);
631 #ifdef FEAT_SEARCHPATH
632 case 'f': /* CTRL-W gf: "gf" in a new tab page */
633 case 'F': /* CTRL-W gF: "gF" in a new tab page */
644 default: beep_flush();
650 * split the current window, implements CTRL-W s and :split
652 * "size" is the height or width for the new window, 0 to use half of current
656 * WSP_ROOM: require enough room for new window
657 * WSP_VERT: vertical split.
658 * WSP_TOP: open window at the top-left of the shell (help window).
659 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
660 * WSP_HELP: creating the help window, keep layout snapshot
662 * return FAIL for failure, OK otherwise
665 win_split(size
, flags
)
669 /* When the ":tab" modifier was used open a new tab page instead. */
670 if (may_open_tabpage() == OK
)
673 /* Add flags from ":vertical", ":topleft" and ":botright". */
674 flags
|= cmdmod
.split
;
675 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
677 EMSG(_("E442: Can't split topleft and botright at the same time"));
681 /* When creating the help window make a snapshot of the window layout.
682 * Otherwise clear the snapshot, it's now invalid. */
683 if (flags
& WSP_HELP
)
686 clear_snapshot(curtab
);
688 return win_split_ins(size
, flags
, NULL
, 0);
692 * When "newwin" is NULL: split the current window in two.
693 * When "newwin" is not NULL: insert this window at the far
694 * top/left/right/bottom.
695 * return FAIL for failure, OK otherwise
698 win_split_ins(size
, flags
, newwin
, dir
)
709 int do_equal
= FALSE
;
712 int oldwin_height
= 0;
714 frame_T
*frp
, *curfrp
;
719 else if (flags
& WSP_BOT
)
724 /* add a status line when p_ls == 1 and splitting the first window */
725 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
727 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
732 need_status
= STATUS_HEIGHT
;
736 /* May be needed for the scrollbars that are going to change. */
741 #ifdef FEAT_VERTSPLIT
742 if (flags
& WSP_VERT
)
747 * Check if we are able to split the current window and compute its
751 if (flags
& WSP_ROOM
)
752 needed
+= p_wiw
- p_wmw
;
753 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
755 available
= topframe
->fr_width
;
756 needed
+= frame_minwidth(topframe
, NULL
);
759 available
= oldwin
->w_width
;
760 if (available
< needed
&& newwin
== NULL
)
766 new_size
= oldwin
->w_width
/ 2;
767 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
768 new_size
= oldwin
->w_width
- p_wmw
- 1;
769 if (new_size
< p_wmw
)
772 /* if it doesn't fit in the current window, need win_equal() */
773 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
776 /* We don't like to take lines for the new window from a
777 * 'winfixwidth' window. Take them from a window to the left or right
778 * instead, if possible. */
780 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
782 /* Only make all windows the same width if one of them (except oldwin)
783 * is wider than one of the split windows. */
784 if (!do_equal
&& p_ea
&& size
== 0 && *p_ead
!= 'v'
785 && oldwin
->w_frame
->fr_parent
!= NULL
)
787 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
790 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
791 && (frp
->fr_win
->w_width
> new_size
792 || frp
->fr_win
->w_width
> oldwin
->w_width
793 - new_size
- STATUS_HEIGHT
))
808 * Check if we are able to split the current window and compute its
811 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
812 if (flags
& WSP_ROOM
)
813 needed
+= p_wh
- p_wmh
;
814 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
816 available
= topframe
->fr_height
;
817 needed
+= frame_minheight(topframe
, NULL
);
821 available
= oldwin
->w_height
;
824 if (available
< needed
&& newwin
== NULL
)
829 oldwin_height
= oldwin
->w_height
;
832 oldwin
->w_status_height
= STATUS_HEIGHT
;
833 oldwin_height
-= STATUS_HEIGHT
;
836 new_size
= oldwin_height
/ 2;
838 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
839 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
840 if (new_size
< p_wmh
)
843 /* if it doesn't fit in the current window, need win_equal() */
844 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
847 /* We don't like to take lines for the new window from a
848 * 'winfixheight' window. Take them from a window above or below
849 * instead, if possible. */
852 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
854 oldwin_height
= oldwin
->w_height
;
856 oldwin_height
-= STATUS_HEIGHT
;
859 /* Only make all windows the same height if one of them (except oldwin)
860 * is higher than one of the split windows. */
861 if (!do_equal
&& p_ea
&& size
== 0
862 #ifdef FEAT_VERTSPLIT
865 && oldwin
->w_frame
->fr_parent
!= NULL
)
867 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
870 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
871 && (frp
->fr_win
->w_height
> new_size
872 || frp
->fr_win
->w_height
> oldwin_height
- new_size
884 * allocate new window structure and link it in the window list
886 if ((flags
& WSP_TOP
) == 0
887 && ((flags
& WSP_BOT
)
888 || (flags
& WSP_BELOW
)
889 || (!(flags
& WSP_ABOVE
)
891 #ifdef FEAT_VERTSPLIT
892 (flags
& WSP_VERT
) ? p_spr
:
896 /* new window below/right of current one */
898 wp
= win_alloc(oldwin
);
900 win_append(oldwin
, wp
);
905 wp
= win_alloc(oldwin
->w_prev
);
907 win_append(oldwin
->w_prev
, wp
);
915 /* make the contents of the new window the same as the current one */
916 win_init(wp
, curwin
);
920 * Reorganise the tree of frames to insert the new window.
922 if (flags
& (WSP_TOP
| WSP_BOT
))
924 #ifdef FEAT_VERTSPLIT
925 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
926 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
928 if (topframe
->fr_layout
== FR_COL
)
931 curfrp
= topframe
->fr_child
;
933 while (curfrp
->fr_next
!= NULL
)
934 curfrp
= curfrp
->fr_next
;
938 before
= (flags
& WSP_TOP
);
942 curfrp
= oldwin
->w_frame
;
943 if (flags
& WSP_BELOW
)
945 else if (flags
& WSP_ABOVE
)
948 #ifdef FEAT_VERTSPLIT
949 if (flags
& WSP_VERT
)
955 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
957 /* Need to create a new frame in the tree to make a branch. */
958 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
960 curfrp
->fr_layout
= layout
;
961 frp
->fr_parent
= curfrp
;
964 curfrp
->fr_child
= frp
;
965 curfrp
->fr_win
= NULL
;
967 if (frp
->fr_win
!= NULL
)
968 oldwin
->w_frame
= frp
;
970 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
971 frp
->fr_parent
= curfrp
;
976 /* Create a frame for the new window. */
977 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
978 frp
->fr_layout
= FR_LEAF
;
983 frp
= newwin
->w_frame
;
984 frp
->fr_parent
= curfrp
->fr_parent
;
986 /* Insert the new frame at the right place in the frame list. */
988 frame_insert(curfrp
, frp
);
990 frame_append(curfrp
, frp
);
992 #ifdef FEAT_VERTSPLIT
993 if (flags
& WSP_VERT
)
995 wp
->w_p_scr
= curwin
->w_p_scr
;
999 oldwin
->w_status_height
= need_status
;
1001 if (flags
& (WSP_TOP
| WSP_BOT
))
1003 /* set height and row of new window to full height */
1004 wp
->w_winrow
= tabline_height();
1005 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
1006 wp
->w_status_height
= (p_ls
> 0);
1010 /* height and row of new window is same as current window */
1011 wp
->w_winrow
= oldwin
->w_winrow
;
1012 wp
->w_height
= oldwin
->w_height
;
1013 wp
->w_status_height
= oldwin
->w_status_height
;
1015 frp
->fr_height
= curfrp
->fr_height
;
1017 /* "new_size" of the current window goes to the new window, use
1018 * one column for the vertical separator */
1019 wp
->w_width
= new_size
;
1021 wp
->w_vsep_width
= 1;
1024 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1025 oldwin
->w_vsep_width
= 1;
1027 if (flags
& (WSP_TOP
| WSP_BOT
))
1029 if (flags
& WSP_BOT
)
1030 frame_add_vsep(curfrp
);
1031 /* Set width of neighbor frame */
1032 frame_new_width(curfrp
, curfrp
->fr_width
1033 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
1037 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
1038 if (before
) /* new window left of current one */
1040 wp
->w_wincol
= oldwin
->w_wincol
;
1041 oldwin
->w_wincol
+= new_size
+ 1;
1043 else /* new window right of current one */
1044 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
1045 frame_fix_width(oldwin
);
1046 frame_fix_width(wp
);
1051 /* width and column of new window is same as current window */
1052 #ifdef FEAT_VERTSPLIT
1053 if (flags
& (WSP_TOP
| WSP_BOT
))
1056 wp
->w_width
= Columns
;
1057 wp
->w_vsep_width
= 0;
1061 wp
->w_wincol
= oldwin
->w_wincol
;
1062 wp
->w_width
= oldwin
->w_width
;
1063 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1065 frp
->fr_width
= curfrp
->fr_width
;
1068 /* "new_size" of the current window goes to the new window, use
1069 * one row for the status line */
1070 win_new_height(wp
, new_size
);
1071 if (flags
& (WSP_TOP
| WSP_BOT
))
1072 frame_new_height(curfrp
, curfrp
->fr_height
1073 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1075 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1076 if (before
) /* new window above current one */
1078 wp
->w_winrow
= oldwin
->w_winrow
;
1079 wp
->w_status_height
= STATUS_HEIGHT
;
1080 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1082 else /* new window below current one */
1084 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1085 wp
->w_status_height
= oldwin
->w_status_height
;
1086 oldwin
->w_status_height
= STATUS_HEIGHT
;
1088 #ifdef FEAT_VERTSPLIT
1089 if (flags
& WSP_BOT
)
1090 frame_add_statusline(curfrp
);
1092 frame_fix_height(wp
);
1093 frame_fix_height(oldwin
);
1096 if (flags
& (WSP_TOP
| WSP_BOT
))
1097 (void)win_comp_pos();
1100 * Both windows need redrawing
1102 redraw_win_later(wp
, NOT_VALID
);
1103 wp
->w_redr_status
= TRUE
;
1104 redraw_win_later(oldwin
, NOT_VALID
);
1105 oldwin
->w_redr_status
= TRUE
;
1111 msg_clr_eos_force(); /* Old command/ruler may still be there */
1114 msg_col
= 0; /* put position back at start of line */
1118 * make the new window the current window and redraw
1120 if (do_equal
|| dir
!= 0)
1122 #ifdef FEAT_VERTSPLIT
1123 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1124 : dir
== 'h' ? 'b' :
1128 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1129 * size was given. */
1130 #ifdef FEAT_VERTSPLIT
1131 if (flags
& WSP_VERT
)
1138 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1140 gui_init_which_components(NULL
);
1150 win_enter(wp
, FALSE
);
1151 #ifdef FEAT_VERTSPLIT
1152 if (flags
& WSP_VERT
)
1162 * Initialize window "newp" from window "oldp".
1163 * Used when splitting a window and when creating a new tab page.
1164 * The windows will both edit the same buffer.
1167 win_init(newp
, oldp
)
1173 newp
->w_buffer
= oldp
->w_buffer
;
1174 oldp
->w_buffer
->b_nwindows
++;
1175 newp
->w_cursor
= oldp
->w_cursor
;
1177 newp
->w_curswant
= oldp
->w_curswant
;
1178 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1179 newp
->w_topline
= oldp
->w_topline
;
1181 newp
->w_topfill
= oldp
->w_topfill
;
1183 newp
->w_leftcol
= oldp
->w_leftcol
;
1184 newp
->w_pcmark
= oldp
->w_pcmark
;
1185 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1186 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1187 newp
->w_wrow
= oldp
->w_wrow
;
1188 newp
->w_fraction
= oldp
->w_fraction
;
1189 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1190 #ifdef FEAT_JUMPLIST
1191 copy_jumplist(oldp
, newp
);
1193 #ifdef FEAT_QUICKFIX
1194 copy_loclist(oldp
, newp
);
1196 if (oldp
->w_localdir
!= NULL
)
1197 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1199 /* Use the same argument list. */
1200 newp
->w_alist
= oldp
->w_alist
;
1201 ++newp
->w_alist
->al_refcount
;
1202 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1205 * copy tagstack and options from existing window
1207 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1209 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1210 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1211 newp
->w_tagstack
[i
].tagname
=
1212 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1214 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1215 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1216 win_copy_options(oldp
, newp
);
1217 # ifdef FEAT_FOLDING
1218 copyFoldingState(oldp
, newp
);
1222 #endif /* FEAT_WINDOWS */
1224 #if defined(FEAT_WINDOWS) || defined(PROTO)
1226 * Check if "win" is a pointer to an existing window.
1236 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1243 * Return the number of windows.
1251 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1257 * Make "count" windows on the screen.
1258 * Return actual number of windows on the screen.
1259 * Must be called when there is just one window, filling the whole screen
1260 * (excluding the command line).
1264 make_windows(count
, vertical
)
1266 int vertical
; /* split windows vertically if TRUE */
1271 #ifdef FEAT_VERTSPLIT
1274 /* Each windows needs at least 'winminwidth' lines and a separator
1276 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1277 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1282 /* Each window needs at least 'winminheight' lines and a status line. */
1283 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1284 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1289 if (count
> maxcount
)
1293 * add status line now, otherwise first window will be too big
1300 * Don't execute autocommands while creating the windows. Must do that
1301 * when putting the buffers in the windows.
1306 /* todo is number of windows left to create */
1307 for (todo
= count
- 1; todo
> 0; --todo
)
1308 #ifdef FEAT_VERTSPLIT
1311 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1312 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1318 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1319 * STATUS_HEIGHT
) / (todo
+ 1)
1320 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1328 /* return actual number of windows */
1329 return (count
- todo
);
1333 * Exchange current and next window
1336 win_exchange(Prenum
)
1345 if (lastwin
== firstwin
) /* just one window */
1352 need_mouse_correct
= TRUE
;
1356 * find window to exchange with
1360 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1361 while (frp
!= NULL
&& --Prenum
> 0)
1364 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1365 frp
= curwin
->w_frame
->fr_next
;
1366 else /* Swap last window in row/col with previous */
1367 frp
= curwin
->w_frame
->fr_prev
;
1369 /* We can only exchange a window with another window, not with a frame
1370 * containing windows. */
1371 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1376 * 1. remove curwin from the list. Remember after which window it was in wp2
1377 * 2. insert curwin before wp in the list
1379 * 3. remove wp from the list
1380 * 4. insert wp after wp2
1381 * 5. exchange the status line height and vsep width.
1383 wp2
= curwin
->w_prev
;
1384 frp2
= curwin
->w_frame
->fr_prev
;
1385 if (wp
->w_prev
!= curwin
)
1387 win_remove(curwin
, NULL
);
1388 frame_remove(curwin
->w_frame
);
1389 win_append(wp
->w_prev
, curwin
);
1390 frame_insert(frp
, curwin
->w_frame
);
1394 win_remove(wp
, NULL
);
1395 frame_remove(wp
->w_frame
);
1396 win_append(wp2
, wp
);
1398 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1400 frame_append(frp2
, wp
->w_frame
);
1402 temp
= curwin
->w_status_height
;
1403 curwin
->w_status_height
= wp
->w_status_height
;
1404 wp
->w_status_height
= temp
;
1405 #ifdef FEAT_VERTSPLIT
1406 temp
= curwin
->w_vsep_width
;
1407 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1408 wp
->w_vsep_width
= temp
;
1410 /* If the windows are not in the same frame, exchange the sizes to avoid
1411 * messing up the window layout. Otherwise fix the frame sizes. */
1412 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1414 temp
= curwin
->w_height
;
1415 curwin
->w_height
= wp
->w_height
;
1416 wp
->w_height
= temp
;
1417 temp
= curwin
->w_width
;
1418 curwin
->w_width
= wp
->w_width
;
1423 frame_fix_height(curwin
);
1424 frame_fix_height(wp
);
1425 frame_fix_width(curwin
);
1426 frame_fix_width(wp
);
1430 (void)win_comp_pos(); /* recompute window positions */
1432 win_enter(wp
, TRUE
);
1433 redraw_later(CLEAR
);
1437 * rotate windows: if upwards TRUE the second window becomes the first one
1438 * if upwards FALSE the first window becomes the second one
1441 win_rotate(upwards
, count
)
1450 if (firstwin
== lastwin
) /* nothing to do */
1457 need_mouse_correct
= TRUE
;
1460 #ifdef FEAT_VERTSPLIT
1461 /* Check if all frames in this row/col have one window. */
1462 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1464 if (frp
->fr_win
== NULL
)
1466 EMSG(_("E443: Cannot rotate when another window is split"));
1473 if (upwards
) /* first window becomes last window */
1475 /* remove first window/frame from the list */
1476 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1478 win_remove(wp1
, NULL
);
1481 /* find last frame and append removed window/frame after it */
1482 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1484 win_append(frp
->fr_win
, wp1
);
1485 frame_append(frp
, wp1
->w_frame
);
1487 wp2
= frp
->fr_win
; /* previously last window */
1489 else /* last window becomes first window */
1491 /* find last window/frame in the list and remove it */
1492 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1496 wp2
= wp1
->w_prev
; /* will become last window */
1497 win_remove(wp1
, NULL
);
1500 /* append the removed window/frame before the first in the list */
1501 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1502 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1505 /* exchange status height and vsep width of old and new last window */
1506 n
= wp2
->w_status_height
;
1507 wp2
->w_status_height
= wp1
->w_status_height
;
1508 wp1
->w_status_height
= n
;
1509 frame_fix_height(wp1
);
1510 frame_fix_height(wp2
);
1511 #ifdef FEAT_VERTSPLIT
1512 n
= wp2
->w_vsep_width
;
1513 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1514 wp1
->w_vsep_width
= n
;
1515 frame_fix_width(wp1
);
1516 frame_fix_width(wp2
);
1519 /* recompute w_winrow and w_wincol for all windows */
1520 (void)win_comp_pos();
1523 redraw_later(CLEAR
);
1527 * Move the current window to the very top/bottom/left/right of the screen.
1530 win_totop(size
, flags
)
1535 int height
= curwin
->w_height
;
1537 if (lastwin
== firstwin
)
1543 /* Remove the window and frame from the tree of frames. */
1544 (void)winframe_remove(curwin
, &dir
, NULL
);
1545 win_remove(curwin
, NULL
);
1546 last_status(FALSE
); /* may need to remove last status line */
1547 (void)win_comp_pos(); /* recompute window positions */
1549 /* Split a window on the desired side and put the window there. */
1550 (void)win_split_ins(size
, flags
, curwin
, dir
);
1551 if (!(flags
& WSP_VERT
))
1553 win_setheight(height
);
1555 win_equal(curwin
, TRUE
, 'v');
1558 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1559 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1560 * scrollbars. Have to update them anyway. */
1564 gui_init_which_components(NULL
);
1565 gui_update_scrollbars(TRUE
);
1567 need_mouse_correct
= TRUE
;
1573 * Move window "win1" to below/right of "win2" and make "win1" the current
1574 * window. Only works within the same frame!
1577 win_move_after(win1
, win2
)
1582 /* check if the arguments are reasonable */
1586 /* check if there is something to do */
1587 if (win2
->w_next
!= win1
)
1589 /* may need move the status line/vertical separator of the last window
1591 if (win1
== lastwin
)
1593 height
= win1
->w_prev
->w_status_height
;
1594 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1595 win1
->w_status_height
= height
;
1596 #ifdef FEAT_VERTSPLIT
1597 if (win1
->w_prev
->w_vsep_width
== 1)
1599 /* Remove the vertical separator from the last-but-one window,
1600 * add it to the last window. Adjust the frame widths. */
1601 win1
->w_prev
->w_vsep_width
= 0;
1602 win1
->w_prev
->w_frame
->fr_width
-= 1;
1603 win1
->w_vsep_width
= 1;
1604 win1
->w_frame
->fr_width
+= 1;
1608 else if (win2
== lastwin
)
1610 height
= win1
->w_status_height
;
1611 win1
->w_status_height
= win2
->w_status_height
;
1612 win2
->w_status_height
= height
;
1613 #ifdef FEAT_VERTSPLIT
1614 if (win1
->w_vsep_width
== 1)
1616 /* Remove the vertical separator from win1, add it to the last
1617 * window, win2. Adjust the frame widths. */
1618 win2
->w_vsep_width
= 1;
1619 win2
->w_frame
->fr_width
+= 1;
1620 win1
->w_vsep_width
= 0;
1621 win1
->w_frame
->fr_width
-= 1;
1625 win_remove(win1
, NULL
);
1626 frame_remove(win1
->w_frame
);
1627 win_append(win2
, win1
);
1628 frame_append(win2
->w_frame
, win1
->w_frame
);
1630 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1631 redraw_later(NOT_VALID
);
1633 win_enter(win1
, FALSE
);
1637 * Make all windows the same height.
1638 * 'next_curwin' will soon be the current window, make sure it has enough
1642 win_equal(next_curwin
, current
, dir
)
1643 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1644 int current
; /* do only frame with current window */
1645 int dir
; /* 'v' for vertically, 'h' for horizontally,
1646 'b' for both, 0 for using p_ead */
1649 #ifdef FEAT_VERTSPLIT
1654 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1655 topframe
, dir
, 0, tabline_height(),
1656 (int)Columns
, topframe
->fr_height
);
1660 * Set a frame to a new position and height, spreading the available room
1661 * equally over contained frames.
1662 * The window "next_curwin" (if not NULL) should at least get the size from
1663 * 'winheight' and 'winwidth' if possible.
1666 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1667 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1668 int current
; /* do only frame with current window */
1669 frame_T
*topfr
; /* frame to set size off */
1670 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1671 int col
; /* horizontal position for frame */
1672 int row
; /* vertical position for frame */
1673 int width
; /* new width of frame */
1674 int height
; /* new height of frame */
1678 int wincount
, totwincount
= 0;
1680 int next_curwin_size
= 0;
1683 int has_next_curwin
= 0;
1686 if (topfr
->fr_layout
== FR_LEAF
)
1688 /* Set the width/height of this frame.
1689 * Redraw when size or position changes */
1690 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1691 #ifdef FEAT_VERTSPLIT
1692 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1696 topfr
->fr_win
->w_winrow
= row
;
1697 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1698 #ifdef FEAT_VERTSPLIT
1699 topfr
->fr_win
->w_wincol
= col
;
1700 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1702 redraw_all_later(CLEAR
);
1705 #ifdef FEAT_VERTSPLIT
1706 else if (topfr
->fr_layout
== FR_ROW
)
1708 topfr
->fr_width
= width
;
1709 topfr
->fr_height
= height
;
1711 if (dir
!= 'v') /* equalize frame widths */
1713 /* Compute the maximum number of windows horizontally in this
1715 n
= frame_minwidth(topfr
, NOWIN
);
1716 /* add one for the rightmost window, it doesn't have a separator */
1717 if (col
+ width
== Columns
)
1721 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1722 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1725 * Compute width for "next_curwin" window and room available for
1727 * "m" is the minimal width when counting p_wiw for "next_curwin".
1729 m
= frame_minwidth(topfr
, next_curwin
);
1733 next_curwin_size
= p_wiw
+ room
;
1738 next_curwin_size
= -1;
1739 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1741 /* If 'winfixwidth' set keep the window width if
1743 * Watch out for this window being the next_curwin. */
1744 if (frame_fixed_width(fr
))
1746 n
= frame_minwidth(fr
, NOWIN
);
1747 new_size
= fr
->fr_width
;
1748 if (frame_has_win(fr
, next_curwin
))
1750 room
+= p_wiw
- p_wmw
;
1751 next_curwin_size
= 0;
1752 if (new_size
< p_wiw
)
1756 /* These windows don't use up room. */
1757 totwincount
-= (n
+ (fr
->fr_next
== NULL
1758 ? extra_sep
: 0)) / (p_wmw
+ 1);
1759 room
-= new_size
- n
;
1765 fr
->fr_newwidth
= new_size
;
1768 if (next_curwin_size
== -1)
1770 if (!has_next_curwin
)
1771 next_curwin_size
= 0;
1772 else if (totwincount
> 1
1773 && (room
+ (totwincount
- 2))
1774 / (totwincount
- 1) > p_wiw
)
1776 /* Can make all windows wider than 'winwidth', spread
1777 * the room equally. */
1778 next_curwin_size
= (room
+ p_wiw
1779 + (totwincount
- 1) * p_wmw
1780 + (totwincount
- 1)) / totwincount
;
1781 room
-= next_curwin_size
- p_wiw
;
1784 next_curwin_size
= p_wiw
;
1788 if (has_next_curwin
)
1789 --totwincount
; /* don't count curwin */
1792 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1796 if (fr
->fr_next
== NULL
)
1797 /* last frame gets all that remains (avoid roundoff error) */
1799 else if (dir
== 'v')
1800 new_size
= fr
->fr_width
;
1801 else if (frame_fixed_width(fr
))
1803 new_size
= fr
->fr_newwidth
;
1804 wincount
= 0; /* doesn't count as a sizeable window */
1808 /* Compute the maximum number of windows horiz. in "fr". */
1809 n
= frame_minwidth(fr
, NOWIN
);
1810 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1812 m
= frame_minwidth(fr
, next_curwin
);
1813 if (has_next_curwin
)
1814 hnc
= frame_has_win(fr
, next_curwin
);
1817 if (hnc
) /* don't count next_curwin */
1819 if (totwincount
== 0)
1822 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1824 if (hnc
) /* add next_curwin size */
1826 next_curwin_size
-= p_wiw
- (m
- n
);
1827 new_size
+= next_curwin_size
;
1828 room
-= new_size
- next_curwin_size
;
1835 /* Skip frame that is full width when splitting or closing a
1836 * window, unless equalizing all frames. */
1837 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1838 || (new_size
!= fr
->fr_width
)
1839 || frame_has_win(fr
, next_curwin
))
1840 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1844 totwincount
-= wincount
;
1848 else /* topfr->fr_layout == FR_COL */
1850 #ifdef FEAT_VERTSPLIT
1851 topfr
->fr_width
= width
;
1853 topfr
->fr_height
= height
;
1855 if (dir
!= 'h') /* equalize frame heights */
1857 /* Compute maximum number of windows vertically in this frame. */
1858 n
= frame_minheight(topfr
, NOWIN
);
1859 /* add one for the bottom window if it doesn't have a statusline */
1860 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1864 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1865 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1868 * Compute height for "next_curwin" window and room available for
1870 * "m" is the minimal height when counting p_wh for "next_curwin".
1872 m
= frame_minheight(topfr
, next_curwin
);
1876 /* The room is less then 'winheight', use all space for the
1877 * current window. */
1878 next_curwin_size
= p_wh
+ room
;
1883 next_curwin_size
= -1;
1884 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1886 /* If 'winfixheight' set keep the window height if
1888 * Watch out for this window being the next_curwin. */
1889 if (frame_fixed_height(fr
))
1891 n
= frame_minheight(fr
, NOWIN
);
1892 new_size
= fr
->fr_height
;
1893 if (frame_has_win(fr
, next_curwin
))
1895 room
+= p_wh
- p_wmh
;
1896 next_curwin_size
= 0;
1897 if (new_size
< p_wh
)
1901 /* These windows don't use up room. */
1902 totwincount
-= (n
+ (fr
->fr_next
== NULL
1903 ? extra_sep
: 0)) / (p_wmh
+ 1);
1904 room
-= new_size
- n
;
1910 fr
->fr_newheight
= new_size
;
1913 if (next_curwin_size
== -1)
1915 if (!has_next_curwin
)
1916 next_curwin_size
= 0;
1917 else if (totwincount
> 1
1918 && (room
+ (totwincount
- 2))
1919 / (totwincount
- 1) > p_wh
)
1921 /* can make all windows higher than 'winheight',
1922 * spread the room equally. */
1923 next_curwin_size
= (room
+ p_wh
1924 + (totwincount
- 1) * p_wmh
1925 + (totwincount
- 1)) / totwincount
;
1926 room
-= next_curwin_size
- p_wh
;
1929 next_curwin_size
= p_wh
;
1933 if (has_next_curwin
)
1934 --totwincount
; /* don't count curwin */
1937 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1941 if (fr
->fr_next
== NULL
)
1942 /* last frame gets all that remains (avoid roundoff error) */
1944 else if (dir
== 'h')
1945 new_size
= fr
->fr_height
;
1946 else if (frame_fixed_height(fr
))
1948 new_size
= fr
->fr_newheight
;
1949 wincount
= 0; /* doesn't count as a sizeable window */
1953 /* Compute the maximum number of windows vert. in "fr". */
1954 n
= frame_minheight(fr
, NOWIN
);
1955 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1957 m
= frame_minheight(fr
, next_curwin
);
1958 if (has_next_curwin
)
1959 hnc
= frame_has_win(fr
, next_curwin
);
1962 if (hnc
) /* don't count next_curwin */
1964 if (totwincount
== 0)
1967 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1969 if (hnc
) /* add next_curwin size */
1971 next_curwin_size
-= p_wh
- (m
- n
);
1972 new_size
+= next_curwin_size
;
1973 room
-= new_size
- next_curwin_size
;
1979 /* Skip frame that is full width when splitting or closing a
1980 * window, unless equalizing all frames. */
1981 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1982 || (new_size
!= fr
->fr_height
)
1983 || frame_has_win(fr
, next_curwin
))
1984 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1988 totwincount
-= wincount
;
1994 * close all windows for buffer 'buf'
1997 close_windows(buf
, keep_curwin
)
1999 int keep_curwin
; /* don't close "curwin" */
2002 tabpage_T
*tp
, *nexttp
;
2003 int h
= tabline_height();
2005 ++RedrawingDisabled
;
2007 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2009 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2011 win_close(wp
, FALSE
);
2013 /* Start all over, autocommands may change the window layout. */
2020 /* Also check windows in other tab pages. */
2021 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2023 nexttp
= tp
->tp_next
;
2025 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2026 if (wp
->w_buffer
== buf
)
2028 win_close_othertab(wp
, FALSE
, tp
);
2030 /* Start all over, the tab page may be closed and
2031 * autocommands may change the window layout. */
2032 nexttp
= first_tabpage
;
2037 --RedrawingDisabled
;
2039 if (h
!= tabline_height())
2044 * Return TRUE if the current window is the only window that exists.
2045 * Returns FALSE if there is a window, possibly in another tab page.
2050 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2054 * Close window "win". Only works for the current tab page.
2055 * If "free_buf" is TRUE related buffer may be unloaded.
2057 * called by :quit, :close, :xit, :wq and findtag()
2060 win_close(win
, free_buf
)
2066 int other_buffer
= FALSE
;
2068 int close_curwin
= FALSE
;
2070 int help_window
= FALSE
;
2071 tabpage_T
*prev_curtab
= curtab
;
2075 EMSG(_("E444: Cannot close last window"));
2080 * When closing the last window in a tab page first go to another tab
2081 * page and then close the window and the tab page. This avoids that
2082 * curwin and curtab are not invalid while we are freeing memory, they may
2083 * be used in GUI events.
2085 if (firstwin
== lastwin
)
2087 goto_tabpage_tp(alt_tabpage());
2088 redraw_tabline
= TRUE
;
2090 /* Safety check: Autocommands may have closed the window when jumping
2091 * to the other tab page. */
2092 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2094 int h
= tabline_height();
2096 win_close_othertab(win
, free_buf
, prev_curtab
);
2097 if (h
!= tabline_height())
2103 /* When closing the help window, try restoring a snapshot after closing
2104 * the window. Otherwise clear the snapshot, it's now invalid. */
2105 if (win
->w_buffer
->b_help
)
2108 clear_snapshot(curtab
);
2114 * Guess which window is going to be the new current window.
2115 * This may change because of the autocommands (sigh).
2117 wp
= frame2win(win_altframe(win
, NULL
));
2120 * Be careful: If autocommands delete the window, return now.
2122 if (wp
->w_buffer
!= curbuf
)
2124 other_buffer
= TRUE
;
2125 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2126 if (!win_valid(win
) || last_window())
2129 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2130 if (!win_valid(win
) || last_window())
2133 /* autocmds may abort script processing */
2141 /* Avoid trouble with scrollbars that are going to be deleted in
2148 * Close the link to the buffer.
2150 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2152 /* Autocommands may have closed the window already, or closed the only
2153 * other window or moved to another tab page. */
2154 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2157 /* Free the memory used for the window. */
2158 wp
= win_free_mem(win
, &dir
, NULL
);
2160 /* Make sure curwin isn't invalid. It can cause severe trouble when
2161 * printing an error message. For win_equal() curbuf needs to be valid
2166 #ifdef FEAT_QUICKFIX
2167 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2170 * If the cursor goes to the preview or the quickfix window, try
2171 * finding another window to go to.
2175 if (wp
->w_next
== NULL
)
2181 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2189 curbuf
= curwin
->w_buffer
;
2190 close_curwin
= TRUE
;
2193 #ifdef FEAT_VERTSPLIT
2194 && (*p_ead
== 'b' || *p_ead
== dir
)
2197 win_equal(curwin
, TRUE
,
2198 #ifdef FEAT_VERTSPLIT
2208 win_enter_ext(wp
, FALSE
, TRUE
);
2211 /* careful: after this wp and win may be invalid! */
2212 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2217 * If last window has a status line now and we don't want one,
2218 * remove the status line.
2222 /* After closing the help window, try restoring the window layout from
2223 * before it was opened. */
2225 restore_snapshot(close_curwin
);
2227 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2228 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2229 if (gui
.in_use
&& !win_hasvertsplit())
2230 gui_init_which_components(NULL
);
2233 redraw_all_later(NOT_VALID
);
2237 * Close window "win" in tab page "tp", which is not the current tab page.
2238 * This may be the last window ih that tab page and result in closing the tab,
2239 * thus "tp" may become invalid!
2240 * Caller must check if buffer is hidden and whether the tabline needs to be
2244 win_close_othertab(win
, free_buf
, tp
)
2251 tabpage_T
*ptp
= NULL
;
2253 /* Close the link to the buffer. */
2254 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2256 /* Careful: Autocommands may have closed the tab page or made it the
2257 * current tab page. */
2258 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2260 if (ptp
== NULL
|| tp
== curtab
)
2263 /* Autocommands may have closed the window already. */
2264 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2269 /* Free the memory used for the window. */
2270 wp
= win_free_mem(win
, &dir
, tp
);
2272 /* When closing the last window in a tab page remove the tab page. */
2275 if (tp
== first_tabpage
)
2276 first_tabpage
= tp
->tp_next
;
2279 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2284 EMSG2(_(e_intern2
), "win_close_othertab()");
2287 ptp
->tp_next
= tp
->tp_next
;
2294 * Free the memory used for a window.
2295 * Returns a pointer to the window that got the freed up space.
2298 win_free_mem(win
, dirp
, tp
)
2300 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2301 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2310 /* reduce the reference count to the argument list. */
2311 alist_unlink(win
->w_alist
);
2313 /* Remove the window and its frame from the tree of frames. */
2315 wp
= winframe_remove(win
, dirp
, tp
);
2319 /* When deleting the current window of another tab page select a new
2320 * current window. */
2321 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2327 #if defined(EXITFREE) || defined(PROTO)
2333 # ifdef FEAT_WINDOWS
2334 while (first_tabpage
->tp_next
!= NULL
)
2335 tabpage_close(TRUE
);
2338 while (firstwin
!= NULL
)
2339 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2344 * Remove a window and its frame from the tree of frames.
2345 * Returns a pointer to the window that got the freed up space.
2349 winframe_remove(win
, dirp
, tp
)
2351 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2352 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2354 frame_T
*frp
, *frp2
, *frp3
;
2355 frame_T
*frp_close
= win
->w_frame
;
2359 * If there is only one window there is nothing to remove.
2361 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2365 * Remove the window from its frame.
2367 frp2
= win_altframe(win
, tp
);
2368 wp
= frame2win(frp2
);
2370 /* Remove this frame from the list of frames. */
2371 frame_remove(frp_close
);
2373 #ifdef FEAT_VERTSPLIT
2374 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2377 /* When 'winfixheight' is set, try to find another frame in the column
2378 * (as close to the closed frame as possible) to distribute the height
2380 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2382 frp
= frp_close
->fr_prev
;
2383 frp3
= frp_close
->fr_next
;
2384 while (frp
!= NULL
|| frp3
!= NULL
)
2388 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2398 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2404 frp3
= frp3
->fr_next
;
2408 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2409 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2410 #ifdef FEAT_VERTSPLIT
2415 /* When 'winfixwidth' is set, try to find another frame in the column
2416 * (as close to the closed frame as possible) to distribute the width
2418 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2420 frp
= frp_close
->fr_prev
;
2421 frp3
= frp_close
->fr_next
;
2422 while (frp
!= NULL
|| frp3
!= NULL
)
2426 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2436 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2442 frp3
= frp3
->fr_next
;
2446 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2447 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2452 /* If rows/columns go to a window below/right its positions need to be
2453 * updated. Can only be done after the sizes have been updated. */
2454 if (frp2
== frp_close
->fr_next
)
2456 int row
= win
->w_winrow
;
2457 int col
= W_WINCOL(win
);
2459 frame_comp_pos(frp2
, &row
, &col
);
2462 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2464 /* There is no other frame in this list, move its info to the parent
2466 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2467 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2468 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2469 frp
->fr_parent
= frp2
->fr_parent
;
2470 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2471 if (frp2
->fr_win
!= NULL
)
2472 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2473 frp
= frp2
->fr_parent
;
2476 frp2
= frp
->fr_parent
;
2477 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2479 /* The frame above the parent has the same layout, have to merge
2480 * the frames into this list. */
2481 if (frp2
->fr_child
== frp
)
2482 frp2
->fr_child
= frp
->fr_child
;
2483 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2484 if (frp
->fr_prev
!= NULL
)
2485 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2486 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2488 frp3
->fr_parent
= frp2
;
2489 if (frp3
->fr_next
== NULL
)
2491 frp3
->fr_next
= frp
->fr_next
;
2492 if (frp
->fr_next
!= NULL
)
2493 frp
->fr_next
->fr_prev
= frp3
;
2505 * Find out which frame is going to get the freed up space when "win" is
2507 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2508 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2509 * This makes opening a window and closing it immediately keep the same window
2513 win_altframe(win
, tp
)
2515 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2520 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2521 /* Last window in this tab page, will go to next tab page. */
2522 return alt_tabpage()->tp_curwin
->w_frame
;
2525 #ifdef FEAT_VERTSPLIT
2526 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2531 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2532 return frp
->fr_next
;
2533 return frp
->fr_prev
;
2537 * Return the tabpage that will be used if the current one is closed.
2544 /* Use the next tab page if possible. */
2545 if (curtab
->tp_next
!= NULL
)
2546 return curtab
->tp_next
;
2548 /* Find the last but one tab page. */
2549 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2555 * Find the left-upper window in frame "frp".
2561 while (frp
->fr_win
== NULL
)
2562 frp
= frp
->fr_child
;
2567 * Return TRUE if frame "frp" contains window "wp".
2570 frame_has_win(frp
, wp
)
2576 if (frp
->fr_layout
== FR_LEAF
)
2577 return frp
->fr_win
== wp
;
2579 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2580 if (frame_has_win(p
, wp
))
2586 * Set a new height for a frame. Recursively sets the height for contained
2587 * frames and windows. Caller must take care of positions.
2590 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2593 int topfirst
; /* resize topmost contained frame first */
2594 int wfh
; /* obey 'winfixheight' when there is a choice;
2595 may cause the height not to be set */
2601 if (topfrp
->fr_win
!= NULL
)
2603 /* Simple case: just one window. */
2604 win_new_height(topfrp
->fr_win
,
2605 height
- topfrp
->fr_win
->w_status_height
);
2607 #ifdef FEAT_VERTSPLIT
2608 else if (topfrp
->fr_layout
== FR_ROW
)
2612 /* All frames in this row get the same new height. */
2613 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2615 frame_new_height(frp
, height
, topfirst
, wfh
);
2616 if (frp
->fr_height
> height
)
2618 /* Could not fit the windows, make the whole row higher. */
2619 height
= frp
->fr_height
;
2624 while (frp
!= NULL
);
2627 else /* fr_layout == FR_COL */
2629 /* Complicated case: Resize a column of frames. Resize the bottom
2630 * frame first, frames above that when needed. */
2632 frp
= topfrp
->fr_child
;
2634 /* Advance past frames with one window with 'wfh' set. */
2635 while (frame_fixed_height(frp
))
2639 return; /* no frame without 'wfh', give up */
2643 /* Find the bottom frame of this column */
2644 while (frp
->fr_next
!= NULL
)
2647 /* Advance back for frames with one window with 'wfh' set. */
2648 while (frame_fixed_height(frp
))
2652 extra_lines
= height
- topfrp
->fr_height
;
2653 if (extra_lines
< 0)
2655 /* reduce height of contained frames, bottom or top frame first */
2658 h
= frame_minheight(frp
, NULL
);
2659 if (frp
->fr_height
+ extra_lines
< h
)
2661 extra_lines
+= frp
->fr_height
- h
;
2662 frame_new_height(frp
, h
, topfirst
, wfh
);
2666 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2674 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2680 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2682 /* Increase "height" if we could not reduce enough frames. */
2684 height
-= extra_lines
;
2687 else if (extra_lines
> 0)
2689 /* increase height of bottom or top frame */
2690 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2693 topfrp
->fr_height
= height
;
2697 * Return TRUE if height of frame "frp" should not be changed because of
2698 * the 'winfixheight' option.
2701 frame_fixed_height(frp
)
2704 /* frame with one window: fixed height if 'winfixheight' set. */
2705 if (frp
->fr_win
!= NULL
)
2706 return frp
->fr_win
->w_p_wfh
;
2708 if (frp
->fr_layout
== FR_ROW
)
2710 /* The frame is fixed height if one of the frames in the row is fixed
2712 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2713 if (frame_fixed_height(frp
))
2718 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2719 * frames in the row are fixed height. */
2720 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2721 if (!frame_fixed_height(frp
))
2726 #ifdef FEAT_VERTSPLIT
2728 * Return TRUE if width of frame "frp" should not be changed because of
2729 * the 'winfixwidth' option.
2732 frame_fixed_width(frp
)
2735 /* frame with one window: fixed width if 'winfixwidth' set. */
2736 if (frp
->fr_win
!= NULL
)
2737 return frp
->fr_win
->w_p_wfw
;
2739 if (frp
->fr_layout
== FR_COL
)
2741 /* The frame is fixed width if one of the frames in the row is fixed
2743 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2744 if (frame_fixed_width(frp
))
2749 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2750 * frames in the row are fixed width. */
2751 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2752 if (!frame_fixed_width(frp
))
2758 * Add a status line to windows at the bottom of "frp".
2759 * Note: Does not check if there is room!
2762 frame_add_statusline(frp
)
2767 if (frp
->fr_layout
== FR_LEAF
)
2770 if (wp
->w_status_height
== 0)
2772 if (wp
->w_height
> 0) /* don't make it negative */
2774 wp
->w_status_height
= STATUS_HEIGHT
;
2777 else if (frp
->fr_layout
== FR_ROW
)
2779 /* Handle all the frames in the row. */
2780 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2781 frame_add_statusline(frp
);
2783 else /* frp->fr_layout == FR_COL */
2785 /* Only need to handle the last frame in the column. */
2786 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2788 frame_add_statusline(frp
);
2793 * Set width of a frame. Handles recursively going through contained frames.
2794 * May remove separator line for windows at the right side (for win_close()).
2797 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2800 int leftfirst
; /* resize leftmost contained frame first */
2801 int wfw
; /* obey 'winfixwidth' when there is a choice;
2802 may cause the width not to be set */
2809 if (topfrp
->fr_layout
== FR_LEAF
)
2811 /* Simple case: just one window. */
2812 wp
= topfrp
->fr_win
;
2813 /* Find out if there are any windows right of this one. */
2814 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2815 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2817 if (frp
->fr_parent
== NULL
)
2818 wp
->w_vsep_width
= 0;
2819 win_new_width(wp
, width
- wp
->w_vsep_width
);
2821 else if (topfrp
->fr_layout
== FR_COL
)
2825 /* All frames in this column get the same new width. */
2826 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2828 frame_new_width(frp
, width
, leftfirst
, wfw
);
2829 if (frp
->fr_width
> width
)
2831 /* Could not fit the windows, make whole column wider. */
2832 width
= frp
->fr_width
;
2836 } while (frp
!= NULL
);
2838 else /* fr_layout == FR_ROW */
2840 /* Complicated case: Resize a row of frames. Resize the rightmost
2841 * frame first, frames left of it when needed. */
2843 frp
= topfrp
->fr_child
;
2845 /* Advance past frames with one window with 'wfw' set. */
2846 while (frame_fixed_width(frp
))
2850 return; /* no frame without 'wfw', give up */
2854 /* Find the rightmost frame of this row */
2855 while (frp
->fr_next
!= NULL
)
2858 /* Advance back for frames with one window with 'wfw' set. */
2859 while (frame_fixed_width(frp
))
2863 extra_cols
= width
- topfrp
->fr_width
;
2866 /* reduce frame width, rightmost frame first */
2869 w
= frame_minwidth(frp
, NULL
);
2870 if (frp
->fr_width
+ extra_cols
< w
)
2872 extra_cols
+= frp
->fr_width
- w
;
2873 frame_new_width(frp
, w
, leftfirst
, wfw
);
2877 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2885 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2891 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2893 /* Increase "width" if we could not reduce enough frames. */
2895 width
-= extra_cols
;
2898 else if (extra_cols
> 0)
2900 /* increase width of rightmost frame */
2901 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2904 topfrp
->fr_width
= width
;
2908 * Add the vertical separator to windows at the right side of "frp".
2909 * Note: Does not check if there is room!
2917 if (frp
->fr_layout
== FR_LEAF
)
2920 if (wp
->w_vsep_width
== 0)
2922 if (wp
->w_width
> 0) /* don't make it negative */
2924 wp
->w_vsep_width
= 1;
2927 else if (frp
->fr_layout
== FR_COL
)
2929 /* Handle all the frames in the column. */
2930 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2931 frame_add_vsep(frp
);
2933 else /* frp->fr_layout == FR_ROW */
2935 /* Only need to handle the last frame in the row. */
2936 frp
= frp
->fr_child
;
2937 while (frp
->fr_next
!= NULL
)
2939 frame_add_vsep(frp
);
2944 * Set frame width from the window it contains.
2950 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2955 * Set frame height from the window it contains.
2958 frame_fix_height(wp
)
2961 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2965 * Compute the minimal height for frame "topfrp".
2966 * Uses the 'winminheight' option.
2967 * When "next_curwin" isn't NULL, use p_wh for this window.
2968 * When "next_curwin" is NOWIN, don't use at least one line for the current
2972 frame_minheight(topfrp
, next_curwin
)
2978 #ifdef FEAT_VERTSPLIT
2982 if (topfrp
->fr_win
!= NULL
)
2984 if (topfrp
->fr_win
== next_curwin
)
2985 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2988 /* window: minimal height of the window plus status line */
2989 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2990 /* Current window is minimal one line high */
2991 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2995 #ifdef FEAT_VERTSPLIT
2996 else if (topfrp
->fr_layout
== FR_ROW
)
2998 /* get the minimal height from each frame in this row */
3000 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3002 n
= frame_minheight(frp
, next_curwin
);
3010 /* Add up the minimal heights for all frames in this column. */
3012 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3013 m
+= frame_minheight(frp
, next_curwin
);
3019 #ifdef FEAT_VERTSPLIT
3021 * Compute the minimal width for frame "topfrp".
3022 * When "next_curwin" isn't NULL, use p_wiw for this window.
3023 * When "next_curwin" is NOWIN, don't use at least one column for the current
3027 frame_minwidth(topfrp
, next_curwin
)
3029 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3034 if (topfrp
->fr_win
!= NULL
)
3036 if (topfrp
->fr_win
== next_curwin
)
3037 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3040 /* window: minimal width of the window plus separator column */
3041 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3042 /* Current window is minimal one column wide */
3043 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3047 else if (topfrp
->fr_layout
== FR_COL
)
3049 /* get the minimal width from each frame in this column */
3051 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3053 n
= frame_minwidth(frp
, next_curwin
);
3060 /* Add up the minimal widths for all frames in this row. */
3062 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3063 m
+= frame_minwidth(frp
, next_curwin
);
3072 * Try to close all windows except current one.
3073 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3074 * used and the buffer was modified.
3076 * Used by ":bdel" and ":only".
3079 close_others(message
, forceit
)
3081 int forceit
; /* always hide all other windows */
3087 if (lastwin
== firstwin
)
3098 /* Be very careful here: autocommands may change the window layout. */
3099 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3101 nextwp
= wp
->w_next
;
3102 if (wp
!= curwin
) /* don't close current window */
3105 /* Check if it's allowed to abandon this window */
3106 r
= can_abandon(wp
->w_buffer
, forceit
);
3108 if (!win_valid(wp
)) /* autocommands messed wp up */
3116 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3117 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3119 dialog_changed(wp
->w_buffer
, FALSE
);
3120 # ifdef FEAT_AUTOCMD
3121 if (!win_valid(wp
)) /* autocommands messed wp up */
3128 if (bufIsChanged(wp
->w_buffer
))
3132 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3136 if (message
&& lastwin
!= firstwin
)
3137 EMSG(_("E445: Other window contains changes"));
3140 #endif /* FEAT_WINDOWS */
3143 * Init the current window "curwin".
3144 * Called when a new file is being edited.
3149 redraw_win_later(curwin
, NOT_VALID
);
3150 curwin
->w_lines_valid
= 0;
3151 curwin
->w_cursor
.lnum
= 1;
3152 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3153 #ifdef FEAT_VIRTUALEDIT
3154 curwin
->w_cursor
.coladd
= 0;
3156 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3157 curwin
->w_pcmark
.col
= 0;
3158 curwin
->w_prev_pcmark
.lnum
= 0;
3159 curwin
->w_prev_pcmark
.col
= 0;
3160 curwin
->w_topline
= 1;
3162 curwin
->w_topfill
= 0;
3164 curwin
->w_botline
= 2;
3167 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3169 curwin
->w_farsi
= W_CONV
;
3174 * Allocate the first window and put an empty buffer in it.
3175 * Called from main().
3176 * Return FAIL when something goes wrong (out of memory).
3181 if (win_alloc_firstwin(NULL
) == FAIL
)
3185 first_tabpage
= alloc_tabpage();
3186 if (first_tabpage
== NULL
)
3188 first_tabpage
->tp_topframe
= topframe
;
3189 curtab
= first_tabpage
;
3195 * Allocate the first window or the first window in a new tab page.
3196 * When "oldwin" is NULL create an empty buffer for it.
3197 * When "oldwin" is not NULL copy info from it to the new window (only with
3199 * Return FAIL when something goes wrong (out of memory).
3202 win_alloc_firstwin(oldwin
)
3205 curwin
= win_alloc(NULL
);
3208 /* Very first window, need to create an empty buffer for it and
3209 * initialize from scratch. */
3210 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3211 if (curwin
== NULL
|| curbuf
== NULL
)
3213 curwin
->w_buffer
= curbuf
;
3214 curbuf
->b_nwindows
= 1; /* there is one window */
3216 curwin
->w_alist
= &global_alist
;
3218 curwin_init(); /* init current window */
3223 /* First window in new tab page, initialize it from "oldwin". */
3224 win_init(curwin
, oldwin
);
3226 # ifdef FEAT_SCROLLBIND
3227 /* We don't want scroll-binding in the first window. */
3228 curwin
->w_p_scb
= FALSE
;
3233 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3234 if (topframe
== NULL
)
3236 topframe
->fr_layout
= FR_LEAF
;
3237 #ifdef FEAT_VERTSPLIT
3238 topframe
->fr_width
= Columns
;
3240 topframe
->fr_height
= Rows
- p_ch
;
3241 topframe
->fr_win
= curwin
;
3242 curwin
->w_frame
= topframe
;
3248 * Initialize the window and frame size to the maximum.
3253 firstwin
->w_height
= ROWS_AVAIL
;
3254 topframe
->fr_height
= ROWS_AVAIL
;
3255 #ifdef FEAT_VERTSPLIT
3256 firstwin
->w_width
= Columns
;
3257 topframe
->fr_width
= Columns
;
3261 #if defined(FEAT_WINDOWS) || defined(PROTO)
3264 * Allocate a new tabpage_T and init the values.
3265 * Returns NULL when out of memory.
3272 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3278 for (i
= 0; i
< 3; i
++)
3279 tp
->tp_prev_which_scrollbars
[i
] = -1;
3282 tp
->tp_diff_invalid
= TRUE
;
3285 /* init t: variables */
3286 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3288 tp
->tp_ch_used
= p_ch
;
3302 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3308 * Create a new Tab page with one window.
3309 * It will edit the current buffer, like after ":split".
3310 * When "after" is 0 put it just after the current Tab page.
3311 * Otherwise put it just before tab page "after".
3312 * Return FAIL or OK.
3315 win_new_tabpage(after
)
3318 tabpage_T
*tp
= curtab
;
3322 newtp
= alloc_tabpage();
3326 /* Remember the current windows in this Tab page. */
3327 if (leave_tabpage(curbuf
) == FAIL
)
3334 /* Create a new empty window. */
3335 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3337 /* Make the new Tab page the new topframe. */
3340 /* New tab page becomes the first one. */
3341 newtp
->tp_next
= first_tabpage
;
3342 first_tabpage
= newtp
;
3348 /* Put new tab page before tab page "after". */
3350 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3351 && n
< after
; tp
= tp
->tp_next
)
3354 newtp
->tp_next
= tp
->tp_next
;
3355 tp
->tp_next
= newtp
;
3358 firstwin
->w_winrow
= tabline_height();
3359 win_comp_scroll(curwin
);
3361 newtp
->tp_topframe
= topframe
;
3364 #if defined(FEAT_GUI)
3365 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3366 * scrollbars. Have to update them anyway. */
3367 if (gui
.in_use
&& starting
== 0)
3369 gui_init_which_components(NULL
);
3370 gui_update_scrollbars(TRUE
);
3372 need_mouse_correct
= TRUE
;
3375 redraw_all_later(CLEAR
);
3377 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3378 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3383 /* Failed, get back the previous Tab page */
3384 enter_tabpage(curtab
, curbuf
);
3389 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3390 * like with ":split".
3391 * Returns OK if a new tab page was created, FAIL otherwise.
3396 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3400 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3401 postponed_split_tab
= 0;
3402 return win_new_tabpage(n
);
3408 * Create up to "maxcount" tabpages with empty windows.
3409 * Returns the number of resulting tab pages.
3412 make_tabpages(maxcount
)
3415 int count
= maxcount
;
3418 /* Limit to 'tabpagemax' tabs. */
3424 * Don't execute autocommands while creating the tab pages. Must do that
3425 * when putting the buffers in the windows.
3430 for (todo
= count
- 1; todo
> 0; --todo
)
3431 if (win_new_tabpage(0) == FAIL
)
3438 /* return actual number of tab pages */
3439 return (count
- todo
);
3443 * Return TRUE when "tpc" points to a valid tab page.
3451 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3458 * Find tab page "n" (first one is 1). Returns NULL when not found.
3467 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3473 * Get index of tab page "tp". First one has index 1.
3474 * When not found returns number of tab pages plus one.
3483 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3489 * Prepare for leaving the current tab page.
3490 * When autocomands change "curtab" we don't leave the tab page and return
3492 * Careful: When OK is returned need to get a new tab page very very soon!
3496 leave_tabpage(new_curbuf
)
3497 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3500 tabpage_T
*tp
= curtab
;
3503 reset_VIsual_and_resel(); /* stop Visual mode */
3506 if (new_curbuf
!= curbuf
)
3508 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3512 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3515 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3519 #if defined(FEAT_GUI)
3520 /* Remove the scrollbars. They may be added back later. */
3522 gui_remove_scrollbars();
3524 tp
->tp_curwin
= curwin
;
3525 tp
->tp_prevwin
= prevwin
;
3526 tp
->tp_firstwin
= firstwin
;
3527 tp
->tp_lastwin
= lastwin
;
3528 tp
->tp_old_Rows
= Rows
;
3529 tp
->tp_old_Columns
= Columns
;
3536 * Start using tab page "tp".
3537 * Only to be used after leave_tabpage() or freeing the current tab page.
3541 enter_tabpage(tp
, old_curbuf
)
3545 int old_off
= tp
->tp_firstwin
->w_winrow
;
3546 win_T
*next_prevwin
= tp
->tp_prevwin
;
3549 firstwin
= tp
->tp_firstwin
;
3550 lastwin
= tp
->tp_lastwin
;
3551 topframe
= tp
->tp_topframe
;
3553 /* We would like doing the TabEnter event first, but we don't have a
3554 * valid current window yet, which may break some commands.
3555 * This triggers autocommands, thus may make "tp" invalid. */
3556 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3557 prevwin
= next_prevwin
;
3560 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3562 if (old_curbuf
!= curbuf
)
3563 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3566 last_status(FALSE
); /* status line may appear or disappear */
3567 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3568 must_redraw
= CLEAR
; /* need to redraw everything */
3570 diff_need_scrollbind
= TRUE
;
3573 /* The tabpage line may have appeared or disappeared, may need to resize
3574 * the frames for that. When the Vim window was resized need to update
3575 * frame sizes too. Use the stored value of p_ch, so that it can be
3576 * different for each tab page. */
3577 p_ch
= curtab
->tp_ch_used
;
3578 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3579 #ifdef FEAT_GUI_TABLINE
3580 && !gui_use_tabline()
3584 #ifdef FEAT_VERTSPLIT
3585 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3586 shell_new_columns(); /* update window widths */
3589 #if defined(FEAT_GUI)
3590 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3591 * scrollbars. Have to update them anyway. */
3592 if (gui
.in_use
&& starting
== 0)
3594 gui_init_which_components(NULL
);
3595 gui_update_scrollbars(TRUE
);
3597 need_mouse_correct
= TRUE
;
3600 redraw_all_later(CLEAR
);
3604 * Go to tab page "n". For ":tab N" and "Ngt".
3605 * When "n" is 9999 go to the last tab page.
3617 /* Not allowed when editing the command line. */
3619 if (cmdwin_type
!= 0)
3627 /* If there is only one it can't work. */
3628 if (first_tabpage
->tp_next
== NULL
)
3637 /* No count, go to next tab page, wrap around end. */
3638 if (curtab
->tp_next
== NULL
)
3641 tp
= curtab
->tp_next
;
3645 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3648 for (i
= n
; i
< 0; ++i
)
3650 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3658 /* Go to last tab page. */
3659 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3664 /* Go to tab page "n". */
3665 tp
= find_tabpage(n
);
3673 goto_tabpage_tp(tp
);
3675 #ifdef FEAT_GUI_TABLINE
3676 if (gui_use_tabline())
3677 gui_mch_set_curtab(tabpage_index(curtab
));
3682 * Go to tabpage "tp".
3683 * Note: doesn't update the GUI tab.
3689 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3691 if (valid_tabpage(tp
))
3692 enter_tabpage(tp
, curbuf
);
3694 enter_tabpage(curtab
, curbuf
);
3699 * Enter window "wp" in tab page "tp".
3700 * Also updates the GUI tab.
3703 goto_tabpage_win(tp
, wp
)
3707 goto_tabpage_tp(tp
);
3708 if (curtab
== tp
&& win_valid(wp
))
3710 win_enter(wp
, TRUE
);
3711 # ifdef FEAT_GUI_TABLINE
3712 if (gui_use_tabline())
3713 gui_mch_set_curtab(tabpage_index(curtab
));
3719 * Move the current tab page to before tab page "nr".
3728 if (first_tabpage
->tp_next
== NULL
)
3731 /* Remove the current tab page from the list of tab pages. */
3732 if (curtab
== first_tabpage
)
3733 first_tabpage
= curtab
->tp_next
;
3736 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3737 if (tp
->tp_next
== curtab
)
3739 if (tp
== NULL
) /* "cannot happen" */
3741 tp
->tp_next
= curtab
->tp_next
;
3744 /* Re-insert it at the specified position. */
3747 curtab
->tp_next
= first_tabpage
;
3748 first_tabpage
= curtab
;
3752 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3754 curtab
->tp_next
= tp
->tp_next
;
3755 tp
->tp_next
= curtab
;
3758 /* Need to redraw the tabline. Tab page contents doesn't change. */
3759 redraw_tabline
= TRUE
;
3764 * Go to another window.
3765 * When jumping to another buffer, stop Visual mode. Do this before
3766 * changing windows so we can yank the selection into the '*' register.
3767 * When jumping to another window on the same buffer, adjust its cursor
3768 * position to keep the same Visual area.
3781 if (curbuf_locked())
3786 if (wp
->w_buffer
!= curbuf
)
3787 reset_VIsual_and_resel();
3788 else if (VIsual_active
)
3789 wp
->w_cursor
= curwin
->w_cursor
;
3793 need_mouse_correct
= TRUE
;
3795 win_enter(wp
, TRUE
);
3798 #if defined(FEAT_PERL) || defined(PROTO)
3800 * Find window number "winnr" (counting top to bottom).
3808 # ifdef FEAT_WINDOWS
3809 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3819 #ifdef FEAT_VERTSPLIT
3821 * Move to window above or below "count" times.
3824 win_goto_ver(up
, count
)
3825 int up
; /* TRUE to go to win above */
3832 foundfr
= curwin
->w_frame
;
3836 * First go upwards in the tree of frames until we find a upwards or
3837 * downwards neighbor.
3848 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3854 * Now go downwards to find the bottom or top frame in it.
3858 if (nfr
->fr_layout
== FR_LEAF
)
3864 if (nfr
->fr_layout
== FR_ROW
)
3866 /* Find the frame at the cursor row. */
3867 while (fr
->fr_next
!= NULL
3868 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3869 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3872 if (nfr
->fr_layout
== FR_COL
&& up
)
3873 while (fr
->fr_next
!= NULL
)
3879 if (foundfr
!= NULL
)
3880 win_goto(foundfr
->fr_win
);
3884 * Move to left or right window.
3887 win_goto_hor(left
, count
)
3888 int left
; /* TRUE to go to left win */
3895 foundfr
= curwin
->w_frame
;
3899 * First go upwards in the tree of frames until we find a left or
3911 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3917 * Now go downwards to find the leftmost or rightmost frame in it.
3921 if (nfr
->fr_layout
== FR_LEAF
)
3927 if (nfr
->fr_layout
== FR_COL
)
3929 /* Find the frame at the cursor row. */
3930 while (fr
->fr_next
!= NULL
3931 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3932 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3935 if (nfr
->fr_layout
== FR_ROW
&& left
)
3936 while (fr
->fr_next
!= NULL
)
3942 if (foundfr
!= NULL
)
3943 win_goto(foundfr
->fr_win
);
3948 * Make window "wp" the current window.
3951 win_enter(wp
, undo_sync
)
3955 win_enter_ext(wp
, undo_sync
, FALSE
);
3959 * Make window wp the current window.
3960 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3961 * been closed and isn't valid.
3964 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3970 int other_buffer
= FALSE
;
3973 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3977 if (!curwin_invalid
)
3980 * Be careful: If autocommands delete the window, return now.
3982 if (wp
->w_buffer
!= curbuf
)
3984 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3985 other_buffer
= TRUE
;
3989 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3993 /* autocmds may abort script processing */
4000 /* sync undo before leaving the current buffer */
4001 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4003 /* may have to copy the buffer options when 'cpo' contains 'S' */
4004 if (wp
->w_buffer
!= curbuf
)
4005 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4006 if (!curwin_invalid
)
4008 prevwin
= curwin
; /* remember for CTRL-W p */
4009 curwin
->w_redr_status
= TRUE
;
4012 curbuf
= wp
->w_buffer
;
4014 #ifdef FEAT_VIRTUALEDIT
4015 if (!virtual_active())
4016 curwin
->w_cursor
.coladd
= 0;
4018 changed_line_abv_curs(); /* assume cursor position needs updating */
4020 if (curwin
->w_localdir
!= NULL
)
4022 /* Window has a local directory: Save current directory as global
4023 * directory (unless that was done already) and change to the local
4025 if (globaldir
== NULL
)
4027 char_u cwd
[MAXPATHL
];
4029 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4030 globaldir
= vim_strsave(cwd
);
4032 if (mch_chdir((char *)curwin
->w_localdir
) == 0)
4033 shorten_fnames(TRUE
);
4035 else if (globaldir
!= NULL
)
4037 /* Window doesn't have a local directory and we are not in the global
4038 * directory: Change to the global directory. */
4039 ignored
= mch_chdir((char *)globaldir
);
4040 vim_free(globaldir
);
4042 shorten_fnames(TRUE
);
4046 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4048 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4054 curwin
->w_redr_status
= TRUE
;
4055 redraw_tabline
= TRUE
;
4057 redraw_later(VALID
); /* causes status line redraw */
4059 /* set window height to desired minimal value */
4060 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4061 win_setheight((int)p_wh
);
4062 else if (curwin
->w_height
== 0)
4065 #ifdef FEAT_VERTSPLIT
4066 /* set window width to desired minimal value */
4067 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4068 win_setwidth((int)p_wiw
);
4072 setmouse(); /* in case jumped to/from help buffer */
4075 /* Change directories when the 'acd' option is set. */
4079 #endif /* FEAT_WINDOWS */
4081 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4083 * Jump to the first open window that contains buffer "buf", if one exists.
4084 * Returns a pointer to the window found, otherwise NULL.
4087 buf_jump_open_win(buf
)
4090 # ifdef FEAT_WINDOWS
4093 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4094 if (wp
->w_buffer
== buf
)
4097 win_enter(wp
, FALSE
);
4100 if (curwin
->w_buffer
== buf
)
4107 * Jump to the first open window in any tab page that contains buffer "buf",
4109 * Returns a pointer to the window found, otherwise NULL.
4112 buf_jump_open_tab(buf
)
4115 # ifdef FEAT_WINDOWS
4119 /* First try the current tab page. */
4120 wp
= buf_jump_open_win(buf
);
4124 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4127 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4128 if (wp
->w_buffer
== buf
)
4132 goto_tabpage_win(tp
, wp
);
4134 wp
= NULL
; /* something went wrong */
4141 if (curwin
->w_buffer
== buf
)
4149 * allocate a window structure and link it in the window list
4159 * allocate window structure and linesizes arrays
4161 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4162 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4171 /* Don't execute autocommands while the window is not properly
4172 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4177 * link the window in the window list
4180 win_append(after
, newwin
);
4182 #ifdef FEAT_VERTSPLIT
4183 newwin
->w_wincol
= 0;
4184 newwin
->w_width
= Columns
;
4187 /* position the display and the cursor at the top of the file. */
4188 newwin
->w_topline
= 1;
4190 newwin
->w_topfill
= 0;
4192 newwin
->w_botline
= 2;
4193 newwin
->w_cursor
.lnum
= 1;
4194 #ifdef FEAT_SCROLLBIND
4195 newwin
->w_scbind_pos
= 1;
4198 /* We won't calculate w_fraction until resizing the window */
4199 newwin
->w_fraction
= 0;
4200 newwin
->w_prev_fraction_row
= -1;
4205 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4207 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4208 SBAR_RIGHT
, newwin
);
4212 /* init w: variables */
4213 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4216 foldInitWin(newwin
);
4221 #ifdef FEAT_SEARCH_EXTRA
4222 newwin
->w_match_head
= NULL
;
4223 newwin
->w_next_match_id
= 4;
4229 #if defined(FEAT_WINDOWS) || defined(PROTO)
4232 * remove window 'wp' from the window list and free the structure
4237 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4242 /* Don't execute autocommands while the window is halfway being deleted.
4243 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4247 #ifdef FEAT_MZSCHEME
4248 mzscheme_window_free(wp
);
4256 python_window_free(wp
);
4260 tcl_window_free(wp
);
4264 ruby_window_free(wp
);
4267 clear_winopt(&wp
->w_onebuf_opt
);
4268 clear_winopt(&wp
->w_allbuf_opt
);
4271 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4278 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4279 vim_free(wp
->w_tagstack
[i
].tagname
);
4281 vim_free(wp
->w_localdir
);
4283 #ifdef FEAT_SEARCH_EXTRA
4287 #ifdef FEAT_JUMPLIST
4291 #ifdef FEAT_QUICKFIX
4298 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4299 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4301 #endif /* FEAT_GUI */
4312 * Append window "wp" in the window list after window "after".
4315 win_append(after
, wp
)
4320 if (after
== NULL
) /* after NULL is in front of the first */
4323 before
= after
->w_next
;
4325 wp
->w_next
= before
;
4334 before
->w_prev
= wp
;
4338 * Remove a window from the window list.
4343 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4345 if (wp
->w_prev
!= NULL
)
4346 wp
->w_prev
->w_next
= wp
->w_next
;
4347 else if (tp
== NULL
)
4348 firstwin
= wp
->w_next
;
4350 tp
->tp_firstwin
= wp
->w_next
;
4351 if (wp
->w_next
!= NULL
)
4352 wp
->w_next
->w_prev
= wp
->w_prev
;
4353 else if (tp
== NULL
)
4354 lastwin
= wp
->w_prev
;
4356 tp
->tp_lastwin
= wp
->w_prev
;
4360 * Append frame "frp" in a frame list after frame "after".
4363 frame_append(after
, frp
)
4364 frame_T
*after
, *frp
;
4366 frp
->fr_next
= after
->fr_next
;
4367 after
->fr_next
= frp
;
4368 if (frp
->fr_next
!= NULL
)
4369 frp
->fr_next
->fr_prev
= frp
;
4370 frp
->fr_prev
= after
;
4374 * Insert frame "frp" in a frame list before frame "before".
4377 frame_insert(before
, frp
)
4378 frame_T
*before
, *frp
;
4380 frp
->fr_next
= before
;
4381 frp
->fr_prev
= before
->fr_prev
;
4382 before
->fr_prev
= frp
;
4383 if (frp
->fr_prev
!= NULL
)
4384 frp
->fr_prev
->fr_next
= frp
;
4386 frp
->fr_parent
->fr_child
= frp
;
4390 * Remove a frame from a frame list.
4396 if (frp
->fr_prev
!= NULL
)
4397 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4399 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4400 if (frp
->fr_next
!= NULL
)
4401 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4404 #endif /* FEAT_WINDOWS */
4407 * Allocate w_lines[] for window "wp".
4408 * Return FAIL for failure, OK for success.
4414 wp
->w_lines_valid
= 0;
4415 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4416 if (wp
->w_lines
== NULL
)
4422 * free lsize arrays for a window
4428 vim_free(wp
->w_lines
);
4433 * Called from win_new_shellsize() after Rows changed.
4434 * This only does the current tab page, others must be done when made active.
4439 int h
= (int)ROWS_AVAIL
;
4441 if (firstwin
== NULL
) /* not initialized yet */
4444 if (h
< frame_minheight(topframe
, NULL
))
4445 h
= frame_minheight(topframe
, NULL
);
4447 /* First try setting the heights of windows with 'winfixheight'. If
4448 * that doesn't result in the right height, forget about that option. */
4449 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4450 if (topframe
->fr_height
!= h
)
4451 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4453 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4457 win_new_height(firstwin
, h
);
4461 curtab
->tp_ch_used
= p_ch
;
4465 /* Disabled: don't want making the screen smaller make a window larger. */
4467 win_equal(curwin
, FALSE
, 'v');
4471 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4473 * Called from win_new_shellsize() after Columns changed.
4478 if (firstwin
== NULL
) /* not initialized yet */
4481 /* First try setting the widths of windows with 'winfixwidth'. If that
4482 * doesn't result in the right width, forget about that option. */
4483 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4484 if (topframe
->fr_width
!= Columns
)
4485 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4487 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4489 /* Disabled: don't want making the screen smaller make a window larger. */
4491 win_equal(curwin
, FALSE
, 'h');
4496 #if defined(FEAT_CMDWIN) || defined(PROTO)
4498 * Save the size of all windows in "gap".
4507 ga_init2(gap
, (int)sizeof(int), 1);
4508 if (ga_grow(gap
, win_count() * 2) == OK
)
4509 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4511 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4512 wp
->w_width
+ wp
->w_vsep_width
;
4513 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4518 * Restore window sizes, but only if the number of windows is still the same.
4519 * Does not free the growarray.
4522 win_size_restore(gap
)
4528 if (win_count() * 2 == gap
->ga_len
)
4531 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4533 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4534 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4536 /* recompute the window positions */
4537 (void)win_comp_pos();
4540 #endif /* FEAT_CMDWIN */
4542 #if defined(FEAT_WINDOWS) || defined(PROTO)
4544 * Update the position for all windows, using the width and height of the
4546 * Returns the row just after the last window.
4551 int row
= tabline_height();
4554 frame_comp_pos(topframe
, &row
, &col
);
4559 * Update the position of the windows in frame "topfrp", using the width and
4560 * height of the frames.
4561 * "*row" and "*col" are the top-left position of the frame. They are updated
4562 * to the bottom-right position plus one.
4565 frame_comp_pos(topfrp
, row
, col
)
4572 #ifdef FEAT_VERTSPLIT
4577 wp
= topfrp
->fr_win
;
4580 if (wp
->w_winrow
!= *row
4581 #ifdef FEAT_VERTSPLIT
4582 || wp
->w_wincol
!= *col
4586 /* position changed, redraw */
4587 wp
->w_winrow
= *row
;
4588 #ifdef FEAT_VERTSPLIT
4589 wp
->w_wincol
= *col
;
4591 redraw_win_later(wp
, NOT_VALID
);
4592 wp
->w_redr_status
= TRUE
;
4594 *row
+= wp
->w_height
+ wp
->w_status_height
;
4595 #ifdef FEAT_VERTSPLIT
4596 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4601 #ifdef FEAT_VERTSPLIT
4605 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4607 #ifdef FEAT_VERTSPLIT
4608 if (topfrp
->fr_layout
== FR_ROW
)
4609 *row
= startrow
; /* all frames are at the same row */
4611 *col
= startcol
; /* all frames are at the same col */
4613 frame_comp_pos(frp
, row
, col
);
4618 #endif /* FEAT_WINDOWS */
4621 * Set current window height and take care of repositioning other windows to
4625 win_setheight(height
)
4628 win_setheight_win(height
, curwin
);
4632 * Set the window height of window "win" and take care of repositioning other
4633 * windows to fit around it.
4636 win_setheight_win(height
, win
)
4644 /* Always keep current window at least one line high, even when
4645 * 'winminheight' is zero. */
4655 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4657 /* recompute the window positions */
4658 row
= win_comp_pos();
4660 if (height
> topframe
->fr_height
)
4661 height
= topframe
->fr_height
;
4662 win
->w_height
= height
;
4667 * If there is extra space created between the last window and the command
4670 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4671 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4676 redraw_all_later(NOT_VALID
);
4679 #if defined(FEAT_WINDOWS) || defined(PROTO)
4682 * Set the height of a frame to "height" and take care that all frames and
4683 * windows inside it are resized. Also resize frames on the left and right if
4684 * the are in the same FR_ROW frame.
4687 * If the frame is part of a FR_COL frame, try fitting the frame in that
4688 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4689 * go to containing frames to resize them and make room.
4690 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4691 * Check for the minimal height of the FR_ROW frame.
4692 * At the top level we can also use change the command line height.
4695 frame_setheight(curfrp
, height
)
4699 int room
; /* total number of lines available */
4700 int take
; /* number of lines taken from other windows */
4701 int room_cmdline
; /* lines available from cmdline */
4707 /* If the height already is the desired value, nothing to do. */
4708 if (curfrp
->fr_height
== height
)
4711 if (curfrp
->fr_parent
== NULL
)
4713 /* topframe: can only change the command line */
4714 if (height
> ROWS_AVAIL
)
4715 height
= ROWS_AVAIL
;
4717 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4719 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4721 /* Row of frames: Also need to resize frames left and right of this
4722 * one. First check for the minimal height of these. */
4723 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4726 frame_setheight(curfrp
->fr_parent
, height
);
4731 * Column of frames: try to change only frames in this column.
4733 #ifdef FEAT_VERTSPLIT
4736 * 1: compute room available, if it's not enough try resizing the
4738 * 2: compute the room available and adjust the height to it.
4739 * Try not to reduce the height of a window with 'winfixheight' set.
4741 for (run
= 1; run
<= 2; ++run
)
4748 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4752 && frp
->fr_win
!= NULL
4753 && frp
->fr_win
->w_p_wfh
)
4754 room_reserved
+= frp
->fr_height
;
4755 room
+= frp
->fr_height
;
4757 room
-= frame_minheight(frp
, NULL
);
4759 #ifdef FEAT_VERTSPLIT
4760 if (curfrp
->fr_width
!= Columns
)
4765 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4766 + lastwin
->w_height
+ lastwin
->w_status_height
);
4767 if (room_cmdline
< 0)
4771 if (height
<= room
+ room_cmdline
)
4773 #ifdef FEAT_VERTSPLIT
4774 if (run
== 2 || curfrp
->fr_width
== Columns
)
4777 if (height
> room
+ room_cmdline
)
4778 height
= room
+ room_cmdline
;
4781 #ifdef FEAT_VERTSPLIT
4782 frame_setheight(curfrp
->fr_parent
, height
4783 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4789 * Compute the number of lines we will take from others frames (can be
4792 take
= height
- curfrp
->fr_height
;
4794 /* If there is not enough room, also reduce the height of a window
4795 * with 'winfixheight' set. */
4796 if (height
> room
+ room_cmdline
- room_reserved
)
4797 room_reserved
= room
+ room_cmdline
- height
;
4798 /* If there is only a 'winfixheight' window and making the
4799 * window smaller, need to make the other window taller. */
4800 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4803 if (take
> 0 && room_cmdline
> 0)
4805 /* use lines from cmdline first */
4806 if (take
< room_cmdline
)
4807 room_cmdline
= take
;
4808 take
-= room_cmdline
;
4809 topframe
->fr_height
+= room_cmdline
;
4813 * set the current frame to the new height
4815 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4818 * First take lines from the frames after the current frame. If
4819 * that is not enough, takes lines from frames above the current
4822 for (run
= 0; run
< 2; ++run
)
4825 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4827 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4828 while (frp
!= NULL
&& take
!= 0)
4830 h
= frame_minheight(frp
, NULL
);
4831 if (room_reserved
> 0
4832 && frp
->fr_win
!= NULL
4833 && frp
->fr_win
->w_p_wfh
)
4835 if (room_reserved
>= frp
->fr_height
)
4836 room_reserved
-= frp
->fr_height
;
4839 if (frp
->fr_height
- room_reserved
> take
)
4840 room_reserved
= frp
->fr_height
- take
;
4841 take
-= frp
->fr_height
- room_reserved
;
4842 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4848 if (frp
->fr_height
- take
< h
)
4850 take
-= frp
->fr_height
- h
;
4851 frame_new_height(frp
, h
, FALSE
, FALSE
);
4855 frame_new_height(frp
, frp
->fr_height
- take
,
4869 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4871 * Set current window width and take care of repositioning other windows to
4878 win_setwidth_win(width
, curwin
);
4882 win_setwidth_win(width
, wp
)
4886 /* Always keep current window at least one column wide, even when
4887 * 'winminwidth' is zero. */
4896 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4898 /* recompute the window positions */
4899 (void)win_comp_pos();
4901 redraw_all_later(NOT_VALID
);
4905 * Set the width of a frame to "width" and take care that all frames and
4906 * windows inside it are resized. Also resize frames above and below if the
4907 * are in the same FR_ROW frame.
4909 * Strategy is similar to frame_setheight().
4912 frame_setwidth(curfrp
, width
)
4916 int room
; /* total number of lines available */
4917 int take
; /* number of lines taken from other windows */
4923 /* If the width already is the desired value, nothing to do. */
4924 if (curfrp
->fr_width
== width
)
4927 if (curfrp
->fr_parent
== NULL
)
4928 /* topframe: can't change width */
4931 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4933 /* Column of frames: Also need to resize frames above and below of
4934 * this one. First check for the minimal width of these. */
4935 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4938 frame_setwidth(curfrp
->fr_parent
, width
);
4943 * Row of frames: try to change only frames in this row.
4946 * 1: compute room available, if it's not enough try resizing the
4948 * 2: compute the room available and adjust the width to it.
4950 for (run
= 1; run
<= 2; ++run
)
4954 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4958 && frp
->fr_win
!= NULL
4959 && frp
->fr_win
->w_p_wfw
)
4960 room_reserved
+= frp
->fr_width
;
4961 room
+= frp
->fr_width
;
4963 room
-= frame_minwidth(frp
, NULL
);
4968 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4974 frame_setwidth(curfrp
->fr_parent
, width
4975 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4979 * Compute the number of lines we will take from others frames (can be
4982 take
= width
- curfrp
->fr_width
;
4984 /* If there is not enough room, also reduce the width of a window
4985 * with 'winfixwidth' set. */
4986 if (width
> room
- room_reserved
)
4987 room_reserved
= room
- width
;
4988 /* If there is only a 'winfixwidth' window and making the
4989 * window smaller, need to make the other window narrower. */
4990 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4994 * set the current frame to the new width
4996 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
4999 * First take lines from the frames right of the current frame. If
5000 * that is not enough, takes lines from frames left of the current
5003 for (run
= 0; run
< 2; ++run
)
5006 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5008 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5009 while (frp
!= NULL
&& take
!= 0)
5011 w
= frame_minwidth(frp
, NULL
);
5012 if (room_reserved
> 0
5013 && frp
->fr_win
!= NULL
5014 && frp
->fr_win
->w_p_wfw
)
5016 if (room_reserved
>= frp
->fr_width
)
5017 room_reserved
-= frp
->fr_width
;
5020 if (frp
->fr_width
- room_reserved
> take
)
5021 room_reserved
= frp
->fr_width
- take
;
5022 take
-= frp
->fr_width
- room_reserved
;
5023 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5029 if (frp
->fr_width
- take
< w
)
5031 take
-= frp
->fr_width
- w
;
5032 frame_new_width(frp
, w
, FALSE
, FALSE
);
5036 frame_new_width(frp
, frp
->fr_width
- take
,
5049 #endif /* FEAT_VERTSPLIT */
5052 * Check 'winminheight' for a valid value.
5061 /* loop until there is a 'winminheight' that is possible */
5064 /* TODO: handle vertical splits */
5066 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5067 room
+= wp
->w_height
- p_wmh
;
5082 * Status line of dragwin is dragged "offset" lines down (negative is up).
5085 win_drag_status_line(dragwin
, offset
)
5093 int up
; /* if TRUE, drag status line up, otherwise down */
5096 fr
= dragwin
->w_frame
;
5098 if (fr
!= topframe
) /* more than one window */
5101 /* When the parent frame is not a column of frames, its parent should
5103 if (fr
->fr_layout
!= FR_COL
)
5106 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5111 /* If this is the last frame in a column, may want to resize the parent
5112 * frame instead (go two up to skip a row of frames). */
5113 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5122 if (offset
< 0) /* drag up */
5126 /* sum up the room of the current frame and above it */
5129 /* only one window */
5130 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5135 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5137 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5142 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5144 else /* drag down */
5148 * Only dragging the last status line can reduce p_ch.
5150 room
= Rows
- cmdline_row
;
5151 if (curfr
->fr_next
== NULL
)
5157 /* sum up the room of frames below of the current one */
5158 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5159 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5160 fr
= curfr
; /* put fr at window that grows */
5163 if (room
< offset
) /* Not enough room */
5164 offset
= room
; /* Move as far as we can */
5169 * Grow frame fr by "offset" lines.
5170 * Doesn't happen when dragging the last status line up.
5173 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5176 fr
= curfr
; /* current frame gets smaller */
5178 fr
= curfr
->fr_next
; /* next frame gets smaller */
5181 * Now make the other frames smaller.
5183 while (fr
!= NULL
&& offset
> 0)
5185 n
= frame_minheight(fr
, NULL
);
5186 if (fr
->fr_height
- offset
<= n
)
5188 offset
-= fr
->fr_height
- n
;
5189 frame_new_height(fr
, n
, !up
, FALSE
);
5193 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5201 row
= win_comp_pos();
5202 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5204 p_ch
= Rows
- cmdline_row
;
5207 curtab
->tp_ch_used
= p_ch
;
5208 redraw_all_later(SOME_VALID
);
5212 #ifdef FEAT_VERTSPLIT
5214 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5217 win_drag_vsep_line(dragwin
, offset
)
5224 int left
; /* if TRUE, drag separator line left, otherwise right */
5227 fr
= dragwin
->w_frame
;
5228 if (fr
== topframe
) /* only one window (cannot happen?) */
5232 /* When the parent frame is not a row of frames, its parent should be. */
5233 if (fr
->fr_layout
!= FR_ROW
)
5235 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5241 /* If this is the last frame in a row, may want to resize a parent
5243 while (curfr
->fr_next
== NULL
)
5256 if (offset
< 0) /* drag left */
5260 /* sum up the room of the current frame and left of it */
5262 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5264 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5268 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5270 else /* drag right */
5273 /* sum up the room of frames right of the current one */
5275 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5276 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5277 fr
= curfr
; /* put fr at window that grows */
5280 if (room
< offset
) /* Not enough room */
5281 offset
= room
; /* Move as far as we can */
5282 if (offset
<= 0) /* No room at all, quit. */
5285 /* grow frame fr by offset lines */
5286 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5288 /* shrink other frames: current and at the left or at the right */
5290 fr
= curfr
; /* current frame gets smaller */
5292 fr
= curfr
->fr_next
; /* next frame gets smaller */
5294 while (fr
!= NULL
&& offset
> 0)
5296 n
= frame_minwidth(fr
, NULL
);
5297 if (fr
->fr_width
- offset
<= n
)
5299 offset
-= fr
->fr_width
- n
;
5300 frame_new_width(fr
, n
, !left
, FALSE
);
5304 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5312 (void)win_comp_pos();
5313 redraw_all_later(NOT_VALID
);
5315 #endif /* FEAT_VERTSPLIT */
5316 #endif /* FEAT_MOUSE */
5318 #endif /* FEAT_WINDOWS */
5321 * Set the height of a window.
5322 * This takes care of the things inside the window, not what happens to the
5323 * window position, the frame or to other windows.
5326 win_new_height(wp
, height
)
5331 int sline
, line_size
;
5332 #define FRACTION_MULT 16384L
5334 /* Don't want a negative height. Happens when splitting a tiny window.
5335 * Will equalize heights soon to fix it. */
5338 if (wp
->w_height
== height
)
5339 return; /* nothing to do */
5341 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5342 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5343 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5345 wp
->w_height
= height
;
5348 /* Don't change w_topline when height is zero. Don't set w_topline when
5349 * 'scrollbind' is set and this isn't the current window. */
5351 #ifdef FEAT_SCROLLBIND
5352 && (!wp
->w_p_scb
|| wp
== curwin
)
5357 * Find a value for w_topline that shows the cursor at the same
5358 * relative position in the window as before (more or less).
5360 lnum
= wp
->w_cursor
.lnum
;
5361 if (lnum
< 1) /* can happen when starting up */
5363 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5364 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5365 sline
= wp
->w_wrow
- line_size
;
5369 /* Make sure the whole cursor line is visible, if possible. */
5370 int rows
= plines_win(wp
, lnum
, FALSE
);
5372 if (sline
> wp
->w_height
- rows
)
5374 sline
= wp
->w_height
- rows
;
5375 wp
->w_wrow
-= rows
- line_size
;
5382 * Cursor line would go off top of screen if w_wrow was this high.
5383 * Make cursor line the first line in the window. If not enough
5384 * room use w_skipcol;
5386 wp
->w_wrow
= line_size
;
5387 if (wp
->w_wrow
>= wp
->w_height
5388 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5390 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5392 while (wp
->w_wrow
>= wp
->w_height
)
5394 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5402 while (sline
> 0 && lnum
> 1)
5405 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5408 /* first line in buffer is folded */
5416 if (lnum
== wp
->w_topline
)
5417 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5421 line_size
= plines_win(wp
, lnum
, TRUE
);
5428 * Line we want at top would go off top of screen. Use next
5432 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5435 wp
->w_wrow
-= line_size
+ sline
;
5439 /* First line of file reached, use that as topline. */
5441 wp
->w_wrow
-= sline
;
5444 set_topline(wp
, lnum
);
5451 curs_columns(FALSE
); /* validate w_wrow */
5453 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5455 win_comp_scroll(wp
);
5456 redraw_win_later(wp
, SOME_VALID
);
5458 wp
->w_redr_status
= TRUE
;
5460 invalidate_botline_win(wp
);
5463 #ifdef FEAT_VERTSPLIT
5465 * Set the width of a window.
5468 win_new_width(wp
, width
)
5472 wp
->w_width
= width
;
5473 wp
->w_lines_valid
= 0;
5474 changed_line_abv_curs_win(wp
);
5475 invalidate_botline_win(wp
);
5479 curs_columns(TRUE
); /* validate w_wrow */
5481 redraw_win_later(wp
, NOT_VALID
);
5482 wp
->w_redr_status
= TRUE
;
5490 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5491 if (wp
->w_p_scr
== 0)
5496 * command_height: called whenever p_ch has been changed
5504 int old_p_ch
= curtab
->tp_ch_used
;
5506 /* Use the value of p_ch that we remembered. This is needed for when the
5507 * GUI starts up, we can't be sure in what order things happen. And when
5508 * p_ch was changed in another tab page. */
5509 curtab
->tp_ch_used
= p_ch
;
5511 /* Find bottom frame with width of screen. */
5512 frp
= lastwin
->w_frame
;
5513 # ifdef FEAT_VERTSPLIT
5514 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5515 frp
= frp
->fr_parent
;
5518 /* Avoid changing the height of a window with 'winfixheight' set. */
5519 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5520 && frp
->fr_win
->w_p_wfh
)
5523 if (starting
!= NO_SCREEN
)
5525 cmdline_row
= Rows
- p_ch
;
5527 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5529 while (p_ch
> old_p_ch
)
5535 curtab
->tp_ch_used
= p_ch
;
5536 cmdline_row
= Rows
- p_ch
;
5539 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5540 if (h
> p_ch
- old_p_ch
)
5541 h
= p_ch
- old_p_ch
;
5543 frame_add_height(frp
, -h
);
5547 /* Recompute window positions. */
5548 (void)win_comp_pos();
5550 /* clear the lines added to cmdline */
5552 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5553 (int)Columns
, ' ', ' ', 0);
5554 msg_row
= cmdline_row
;
5555 redraw_cmdline
= TRUE
;
5559 if (msg_row
< cmdline_row
)
5560 msg_row
= cmdline_row
;
5561 redraw_cmdline
= TRUE
;
5563 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5565 /* Recompute window positions. */
5566 if (frp
!= lastwin
->w_frame
)
5567 (void)win_comp_pos();
5569 cmdline_row
= Rows
- p_ch
;
5570 win_setheight(cmdline_row
);
5574 #if defined(FEAT_WINDOWS) || defined(PROTO)
5576 * Resize frame "frp" to be "n" lines higher (negative for less high).
5577 * Also resize the frames it is contained in.
5580 frame_add_height(frp
, n
)
5584 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5587 frp
= frp
->fr_parent
;
5590 frp
->fr_height
+= n
;
5595 * Add or remove a status line for the bottom window(s), according to the
5596 * value of 'laststatus'.
5599 last_status(morewin
)
5600 int morewin
; /* pretend there are two or more windows */
5602 /* Don't make a difference between horizontal or vertical split. */
5603 last_status_rec(topframe
, (p_ls
== 2
5604 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5608 last_status_rec(fr
, statusline
)
5615 if (fr
->fr_layout
== FR_LEAF
)
5618 if (wp
->w_status_height
!= 0 && !statusline
)
5620 /* remove status line */
5621 win_new_height(wp
, wp
->w_height
+ 1);
5622 wp
->w_status_height
= 0;
5625 else if (wp
->w_status_height
== 0 && statusline
)
5627 /* Find a frame to take a line from. */
5629 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5636 /* In a column of frames: go to frame above. If already at
5637 * the top or in a row of frames: go to parent. */
5638 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5643 wp
->w_status_height
= 1;
5646 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5647 frame_fix_height(wp
);
5648 (void)win_comp_pos();
5651 win_new_height(wp
, wp
->w_height
- 1);
5653 redraw_all_later(SOME_VALID
);
5656 #ifdef FEAT_VERTSPLIT
5657 else if (fr
->fr_layout
== FR_ROW
)
5659 /* vertically split windows, set status line for each one */
5660 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5661 last_status_rec(fp
, statusline
);
5666 /* horizontally split window, set status line for last one */
5667 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5669 last_status_rec(fp
, statusline
);
5674 * Return the number of lines used by the tab page line.
5679 #ifdef FEAT_GUI_TABLINE
5680 /* When the GUI has the tabline then this always returns zero. */
5681 if (gui_use_tabline())
5687 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5692 #endif /* FEAT_WINDOWS */
5694 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5696 * Get the file name at the cursor.
5697 * If Visual mode is active, use the selected text if it's in one line.
5698 * Returns the name in allocated memory, NULL for failure.
5701 grab_file_name(count
, file_lnum
)
5703 linenr_T
*file_lnum
;
5711 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5713 return find_file_name_in_path(ptr
, len
,
5714 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5717 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5723 * Return the file name under or after the cursor.
5725 * The 'path' option is searched if the file name is not absolute.
5726 * The string returned has been alloc'ed and should be freed by the caller.
5727 * NULL is returned if the file name or file is not found.
5730 * FNAME_MESS give error messages
5731 * FNAME_EXP expand to path
5732 * FNAME_HYP check for hypertext link
5733 * FNAME_INCL apply "includeexpr"
5736 file_name_at_cursor(options
, count
, file_lnum
)
5739 linenr_T
*file_lnum
;
5741 return file_name_in_line(ml_get_curline(),
5742 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5747 * Return the name of the file under or after ptr[col].
5748 * Otherwise like file_name_at_cursor().
5751 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5756 char_u
*rel_fname
; /* file we are searching relative to */
5757 linenr_T
*file_lnum
; /* line number after the file name */
5763 * search forward for what could be the start of a file name
5766 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5768 if (*ptr
== NUL
) /* nothing found */
5770 if (options
& FNAME_MESS
)
5771 EMSG(_("E446: No file name under cursor"));
5776 * Search backward for first char of the file name.
5777 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5782 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5786 if (vim_isfilec(ptr
[-1])
5787 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5794 * Search forward for the last char of the file name.
5795 * Also allow "://" when ':' is not in 'isfname'.
5798 while (vim_isfilec(ptr
[len
])
5799 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5802 len
+= (*mb_ptr2len
)(ptr
+ len
);
5808 * If there is trailing punctuation, remove it.
5809 * But don't remove "..", could be a directory name.
5811 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5812 && ptr
[len
- 2] != '.')
5815 if (file_lnum
!= NULL
)
5819 /* Get the number after the file name and a separator character */
5825 ++p
; /* skip the separator */
5828 *file_lnum
= (int)getdigits(&p
);
5832 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5835 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5836 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5839 eval_includeexpr(ptr
, len
)
5845 set_vim_var_string(VV_FNAME
, ptr
, len
);
5846 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5847 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5848 set_vim_var_string(VV_FNAME
, NULL
, 0);
5854 * Return the name of the file ptr[len] in 'path'.
5855 * Otherwise like file_name_at_cursor().
5858 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5863 char_u
*rel_fname
; /* file we are searching relative to */
5867 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5868 char_u
*tofree
= NULL
;
5870 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5872 tofree
= eval_includeexpr(ptr
, len
);
5876 len
= (int)STRLEN(ptr
);
5881 if (options
& FNAME_EXP
)
5883 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5886 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5888 * If the file could not be found in a normal way, try applying
5889 * 'includeexpr' (unless done already).
5891 if (file_name
== NULL
5892 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5894 tofree
= eval_includeexpr(ptr
, len
);
5898 len
= (int)STRLEN(ptr
);
5899 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5904 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5908 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5912 /* Repeat finding the file "count" times. This matters when it
5913 * appears several times in the path. */
5914 while (file_name
!= NULL
&& --count
> 0)
5916 vim_free(file_name
);
5917 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5921 file_name
= vim_strnsave(ptr
, len
);
5923 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5929 #endif /* FEAT_SEARCHPATH */
5932 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5933 * Also check for ":\\", which MS Internet Explorer accepts, return
5940 if (STRNCMP(p
, "://", (size_t)3) == 0)
5942 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5943 return URL_BACKSLASH
;
5948 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5949 * Return URL_BACKSLASH for "name:\\".
5950 * Return zero otherwise.
5953 path_with_url(fname
)
5958 for (p
= fname
; isalpha(*p
); ++p
)
5960 return path_is_url(p
);
5964 * Return TRUE if "name" is a full (absolute) path name or URL.
5970 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5974 * Get absolute file name into buffer "buf[len]".
5976 * return FAIL for failure, OK otherwise
5979 vim_FullName(fname
, buf
, len
, force
)
5980 char_u
*fname
, *buf
;
5982 int force
; /* force expansion even when already absolute */
5991 url
= path_with_url(fname
);
5993 retval
= mch_FullName(fname
, buf
, len
, force
);
5994 if (url
|| retval
== FAIL
)
5996 /* something failed; use the file name (truncate when too long) */
5997 vim_strncpy(buf
, fname
, len
- 1);
5999 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6006 * Return the minimal number of rows that is needed on the screen to display
6007 * the current number of windows.
6018 if (firstwin
== NULL
) /* not initialized yet */
6023 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6025 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6029 total
+= tabline_height();
6031 total
= 1; /* at least one window should have a line! */
6033 total
+= 1; /* count the room for the command line */
6038 * Return TRUE if there is only one window (in the current tab page), not
6039 * counting a help or preview window, unless it is the current window.
6048 /* If there is another tab page there always is another window. */
6049 if (first_tabpage
->tp_next
!= NULL
)
6052 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6053 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6054 # ifdef FEAT_QUICKFIX
6059 return (count
<= 1);
6065 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6067 * Correct the cursor line number in other windows. Used after changing the
6068 * current buffer, and before applying autocommands.
6069 * When "do_curwin" is TRUE, also check current window.
6072 check_lnums(do_curwin
)
6080 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6081 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6087 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6088 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6089 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6090 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6095 #if defined(FEAT_WINDOWS) || defined(PROTO)
6098 * A snapshot of the window sizes, to restore them after closing the help
6100 * Only these fields are used:
6106 * fr_win (only valid for the old curwin, NULL otherwise)
6110 * Create a snapshot of the current frame sizes.
6115 clear_snapshot(curtab
);
6116 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6120 make_snapshot_rec(fr
, frp
)
6124 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6127 (*frp
)->fr_layout
= fr
->fr_layout
;
6128 # ifdef FEAT_VERTSPLIT
6129 (*frp
)->fr_width
= fr
->fr_width
;
6131 (*frp
)->fr_height
= fr
->fr_height
;
6132 if (fr
->fr_next
!= NULL
)
6133 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6134 if (fr
->fr_child
!= NULL
)
6135 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6136 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6137 (*frp
)->fr_win
= curwin
;
6141 * Remove any existing snapshot.
6147 clear_snapshot_rec(tp
->tp_snapshot
);
6148 tp
->tp_snapshot
= NULL
;
6152 clear_snapshot_rec(fr
)
6157 clear_snapshot_rec(fr
->fr_next
);
6158 clear_snapshot_rec(fr
->fr_child
);
6164 * Restore a previously created snapshot, if there is any.
6165 * This is only done if the screen size didn't change and the window layout is
6169 restore_snapshot(close_curwin
)
6170 int close_curwin
; /* closing current window */
6174 if (curtab
->tp_snapshot
!= NULL
6175 # ifdef FEAT_VERTSPLIT
6176 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6178 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6179 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6181 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6183 if (wp
!= NULL
&& close_curwin
)
6185 redraw_all_later(CLEAR
);
6187 clear_snapshot(curtab
);
6191 * Check if frames "sn" and "fr" have the same layout, same following frames
6192 * and same children.
6195 check_snapshot_rec(sn
, fr
)
6199 if (sn
->fr_layout
!= fr
->fr_layout
6200 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6201 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6202 || (sn
->fr_next
!= NULL
6203 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6204 || (sn
->fr_child
!= NULL
6205 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6211 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6212 * following frames and children.
6213 * Returns a pointer to the old current window, or NULL.
6216 restore_snapshot_rec(sn
, fr
)
6223 fr
->fr_height
= sn
->fr_height
;
6224 # ifdef FEAT_VERTSPLIT
6225 fr
->fr_width
= sn
->fr_width
;
6227 if (fr
->fr_layout
== FR_LEAF
)
6229 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6230 # ifdef FEAT_VERTSPLIT
6231 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6235 if (sn
->fr_next
!= NULL
)
6237 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6241 if (sn
->fr_child
!= NULL
)
6243 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6252 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6254 * Return TRUE if there is any vertically split window.
6261 if (topframe
->fr_layout
== FR_ROW
)
6264 if (topframe
->fr_layout
== FR_COL
)
6265 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6266 if (fr
->fr_layout
== FR_ROW
)
6273 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6275 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6276 * highlighted with the group 'grp' with priority 'prio'.
6277 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6278 * If no particular ID is desired, -1 must be specified for 'id'.
6279 * Return ID of added match, -1 on failure.
6282 match_add(wp
, grp
, pat
, prio
, id
)
6295 if (*grp
== NUL
|| *pat
== NUL
)
6297 if (id
< -1 || id
== 0)
6299 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6304 cur
= wp
->w_match_head
;
6309 EMSGN("E801: ID already taken: %ld", id
);
6315 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6317 EMSG2(_(e_nogroup
), grp
);
6320 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6322 EMSG2(_(e_invarg2
), pat
);
6326 /* Find available match ID. */
6329 cur
= wp
->w_match_head
;
6330 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6333 id
= wp
->w_next_match_id
;
6334 wp
->w_next_match_id
++;
6337 /* Build new match. */
6338 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6341 m
->pattern
= vim_strsave(pat
);
6343 m
->match
.regprog
= regprog
;
6344 m
->match
.rmm_ic
= FALSE
;
6345 m
->match
.rmm_maxcol
= 0;
6347 /* Insert new match. The match list is in ascending order with regard to
6348 * the match priorities. */
6349 cur
= wp
->w_match_head
;
6351 while (cur
!= NULL
&& prio
>= cur
->priority
)
6357 wp
->w_match_head
= m
;
6362 redraw_later(SOME_VALID
);
6367 * Delete match with ID 'id' in the match list of window 'wp'.
6368 * Print error messages if 'perr' is TRUE.
6371 match_delete(wp
, id
, perr
)
6376 matchitem_T
*cur
= wp
->w_match_head
;
6377 matchitem_T
*prev
= cur
;
6382 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6386 while (cur
!= NULL
&& cur
->id
!= id
)
6394 EMSGN("E803: ID not found: %ld", id
);
6398 wp
->w_match_head
= cur
->next
;
6400 prev
->next
= cur
->next
;
6401 vim_free(cur
->match
.regprog
);
6402 vim_free(cur
->pattern
);
6404 redraw_later(SOME_VALID
);
6409 * Delete all matches in the match list of window 'wp'.
6417 while (wp
->w_match_head
!= NULL
)
6419 m
= wp
->w_match_head
->next
;
6420 vim_free(wp
->w_match_head
->match
.regprog
);
6421 vim_free(wp
->w_match_head
->pattern
);
6422 vim_free(wp
->w_match_head
);
6423 wp
->w_match_head
= m
;
6425 redraw_later(SOME_VALID
);
6429 * Get match from ID 'id' in window 'wp'.
6430 * Return NULL if match not found.
6437 matchitem_T
*cur
= wp
->w_match_head
;
6439 while (cur
!= NULL
&& cur
->id
!= id
)