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 void win_init
__ARGS((win_T
*newp
, win_T
*oldp
, int flags
));
15 static void win_init_some
__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 int one_window
__ARGS((void));
27 static win_T
*win_free_mem
__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 static void new_frame
__ARGS((win_T
*wp
));
45 #if defined(FEAT_WINDOWS) || defined(PROTO)
46 static tabpage_T
*alloc_tabpage
__ARGS((void));
47 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
48 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
49 static void frame_fix_height
__ARGS((win_T
*wp
));
50 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
51 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
52 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
53 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
54 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
55 static void frame_remove
__ARGS((frame_T
*frp
));
57 static void win_new_width
__ARGS((win_T
*wp
, int width
));
58 static void win_goto_ver
__ARGS((int up
, long count
));
59 static void win_goto_hor
__ARGS((int left
, long count
));
61 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
62 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
64 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
65 static void clear_snapshot
__ARGS((tabpage_T
*tp
, int idx
));
66 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
67 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
68 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
70 #endif /* FEAT_WINDOWS */
72 static win_T
*win_alloc
__ARGS((win_T
*after
, int hidden
));
73 static void win_new_height
__ARGS((win_T
*, int));
75 #define URL_SLASH 1 /* path_is_url() has found "://" */
76 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
78 #define NOWIN (win_T *)-1 /* non-existing window */
81 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
83 # define ROWS_AVAIL (Rows - p_ch)
86 #if defined(FEAT_WINDOWS) || defined(PROTO)
88 static char *m_onlyone
= N_("Already only one window");
91 * all CTRL-W window commands are handled here, called from normal_cmd().
94 do_window(nchar
, Prenum
, xchar
)
97 int xchar
; /* extra char from ":wincmd gx" or NUL */
101 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
106 int type
= FIND_DEFINE
;
117 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
119 # define CHECK_CMDWIN
124 /* split current window in two parts, horizontally */
130 reset_VIsual_and_resel(); /* stop Visual mode */
133 /* When splitting the quickfix window open a new buffer in it,
134 * don't replicate the quickfix buffer. */
135 if (bt_quickfix(curbuf
))
139 need_mouse_correct
= TRUE
;
141 win_split((int)Prenum
, 0);
144 #ifdef FEAT_VERTSPLIT
145 /* split current window in two parts, vertically */
150 reset_VIsual_and_resel(); /* stop Visual mode */
152 # ifdef FEAT_QUICKFIX
153 /* When splitting the quickfix window open a new buffer in it,
154 * don't replicate the quickfix buffer. */
155 if (bt_quickfix(curbuf
))
159 need_mouse_correct
= TRUE
;
161 win_split((int)Prenum
, WSP_VERT
);
165 /* split current window and edit alternate file */
170 reset_VIsual_and_resel(); /* stop Visual mode */
172 STRCPY(cbuf
, "split #");
174 vim_snprintf((char *)cbuf
+ 7, sizeof(cbuf
) - 7,
176 do_cmdline_cmd(cbuf
);
179 /* open new window */
184 reset_VIsual_and_resel(); /* stop Visual mode */
191 vim_snprintf((char *)cbuf
, sizeof(cbuf
) - 5, "%ld", Prenum
);
194 #if defined(FEAT_VERTSPLIT) && defined(FEAT_QUICKFIX)
195 if (nchar
== 'v' || nchar
== Ctrl_V
)
199 do_cmdline_cmd(cbuf
);
202 /* quit current window */
206 reset_VIsual_and_resel(); /* stop Visual mode */
208 do_cmdline_cmd((char_u
*)"quit");
211 /* close current window */
215 reset_VIsual_and_resel(); /* stop Visual mode */
217 do_cmdline_cmd((char_u
*)"close");
220 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
221 /* close preview window */
226 reset_VIsual_and_resel(); /* stop Visual mode */
228 do_cmdline_cmd((char_u
*)"pclose");
231 /* cursor to preview window */
233 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
237 EMSG(_("E441: There is no preview window"));
243 /* close all but current window */
248 reset_VIsual_and_resel(); /* stop Visual mode */
250 do_cmdline_cmd((char_u
*)"only");
253 /* cursor to next window with wrap around */
256 /* cursor to previous window with wrap around */
259 if (firstwin
== lastwin
&& Prenum
!= 1) /* just one window */
263 if (Prenum
) /* go to specified window */
265 for (wp
= firstwin
; --Prenum
> 0; )
267 if (wp
->w_next
== NULL
)
275 if (nchar
== 'W') /* go to previous window */
279 wp
= lastwin
; /* wrap around */
281 else /* go to next window */
285 wp
= firstwin
; /* wrap around */
292 /* cursor to window below */
297 #ifdef FEAT_VERTSPLIT
298 win_goto_ver(FALSE
, Prenum1
);
300 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
307 /* cursor to window above */
312 #ifdef FEAT_VERTSPLIT
313 win_goto_ver(TRUE
, Prenum1
);
315 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
322 #ifdef FEAT_VERTSPLIT
323 /* cursor to left window */
329 win_goto_hor(TRUE
, Prenum1
);
332 /* cursor to right window */
337 win_goto_hor(FALSE
, Prenum1
);
341 /* move window to new tab page */
347 tabpage_T
*oldtab
= curtab
;
350 /* First create a new tab with the window, then go back to
351 * the old tab and close the window there. */
353 if (win_new_tabpage((int)Prenum
) == OK
354 && valid_tabpage(oldtab
))
357 goto_tabpage_tp(oldtab
);
359 win_close(curwin
, FALSE
);
360 if (valid_tabpage(newtab
))
361 goto_tabpage_tp(newtab
);
366 /* cursor to top-left window */
372 /* cursor to bottom-right window */
378 /* cursor to last accessed (previous) window */
387 /* exchange current and next window */
391 win_exchange(Prenum
);
394 /* rotate windows downwards */
399 reset_VIsual_and_resel(); /* stop Visual mode */
401 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
404 /* rotate windows upwards */
408 reset_VIsual_and_resel(); /* stop Visual mode */
410 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
413 /* move window to the very top/bottom/left/right */
416 #ifdef FEAT_VERTSPLIT
421 win_totop((int)Prenum
,
422 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
423 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
426 /* make all windows the same height */
429 need_mouse_correct
= TRUE
;
431 win_equal(NULL
, FALSE
, 'b');
434 /* increase current window height */
437 need_mouse_correct
= TRUE
;
439 win_setheight(curwin
->w_height
+ (int)Prenum1
);
442 /* decrease current window height */
445 need_mouse_correct
= TRUE
;
447 win_setheight(curwin
->w_height
- (int)Prenum1
);
450 /* set current window height */
454 need_mouse_correct
= TRUE
;
456 win_setheight(Prenum
? (int)Prenum
: 9999);
459 #ifdef FEAT_VERTSPLIT
460 /* increase current window width */
463 need_mouse_correct
= TRUE
;
465 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
468 /* decrease current window width */
471 need_mouse_correct
= TRUE
;
473 win_setwidth(curwin
->w_width
- (int)Prenum1
);
476 /* set current window width */
479 need_mouse_correct
= TRUE
;
481 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
485 /* jump to tag and split window if tag exists (in preview window) */
486 #if defined(FEAT_QUICKFIX)
490 g_do_tagpreview
= Prenum
;
492 g_do_tagpreview
= p_pvh
;
499 reset_VIsual_and_resel(); /* stop Visual mode */
502 postponed_split
= Prenum
;
504 postponed_split
= -1;
506 /* Execute the command right here, required when
507 * "wincmd ]" was used in a function. */
508 do_nv_ident(Ctrl_RSB
, NUL
);
511 #ifdef FEAT_SEARCHPATH
512 /* edit file name under cursor in a new window */
519 ptr
= grab_file_name(Prenum1
, &lnum
);
523 need_mouse_correct
= TRUE
;
526 if (win_split(0, 0) == OK
)
528 # ifdef FEAT_SCROLLBIND
529 curwin
->w_p_scb
= FALSE
;
531 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
,
533 if (nchar
== 'F' && lnum
>= 0)
535 curwin
->w_cursor
.lnum
= lnum
;
537 beginline(BL_SOL
| BL_FIX
);
546 /* Go to the first occurrence of the identifier under cursor along path in a
549 case 'i': /* Go to any match */
553 case 'd': /* Go to definition, using 'define' */
556 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
558 find_pattern_in_path(ptr
, 0, len
, TRUE
,
559 Prenum
== 0 ? TRUE
: FALSE
, type
,
560 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
561 curwin
->w_set_curswant
= TRUE
;
567 #if defined(FEAT_QUICKFIX)
569 * In a quickfix window a <CR> jumps to the error under the
570 * cursor in a new window.
572 if (bt_quickfix(curbuf
))
574 sprintf((char *)cbuf
, "split +%ld%s",
575 (long)curwin
->w_cursor
.lnum
,
576 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
577 do_cmdline_cmd(cbuf
);
583 /* CTRL-W g extended commands */
587 #ifdef USE_ON_FLY_SCROLL
588 dont_scroll
= TRUE
; /* disallow scrolling here */
591 ++allow_keys
; /* no mapping for xchar, but allow key codes */
593 xchar
= plain_vgetc();
594 LANGMAP_ADJUST(xchar
, TRUE
);
597 #ifdef FEAT_CMDL_INFO
598 (void)add_to_showcmd(xchar
);
602 #if defined(FEAT_QUICKFIX)
606 g_do_tagpreview
= Prenum
;
608 g_do_tagpreview
= p_pvh
;
614 reset_VIsual_and_resel(); /* stop Visual mode */
617 postponed_split
= Prenum
;
619 postponed_split
= -1;
621 /* Execute the command right here, required when
622 * "wincmd g}" was used in a function. */
623 do_nv_ident('g', xchar
);
626 #ifdef FEAT_SEARCHPATH
627 case 'f': /* CTRL-W gf: "gf" in a new tab page */
628 case 'F': /* CTRL-W gF: "gF" in a new tab page */
629 cmdmod
.tab
= tabpage_index(curtab
) + 1;
639 default: beep_flush();
645 * split the current window, implements CTRL-W s and :split
647 * "size" is the height or width for the new window, 0 to use half of current
651 * WSP_ROOM: require enough room for new window
652 * WSP_VERT: vertical split.
653 * WSP_TOP: open window at the top-left of the shell (help window).
654 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
655 * WSP_HELP: creating the help window, keep layout snapshot
657 * return FAIL for failure, OK otherwise
660 win_split(size
, flags
)
664 /* When the ":tab" modifier was used open a new tab page instead. */
665 if (may_open_tabpage() == OK
)
668 /* Add flags from ":vertical", ":topleft" and ":botright". */
669 flags
|= cmdmod
.split
;
670 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
672 EMSG(_("E442: Can't split topleft and botright at the same time"));
676 /* When creating the help window make a snapshot of the window layout.
677 * Otherwise clear the snapshot, it's now invalid. */
678 if (flags
& WSP_HELP
)
679 make_snapshot(SNAP_HELP_IDX
);
681 clear_snapshot(curtab
, SNAP_HELP_IDX
);
683 return win_split_ins(size
, flags
, NULL
, 0);
687 * When "newwin" is NULL: split the current window in two.
688 * When "newwin" is not NULL: insert this window at the far
689 * top/left/right/bottom.
690 * return FAIL for failure, OK otherwise
693 win_split_ins(size
, flags
, newwin
, dir
)
704 int do_equal
= FALSE
;
707 int oldwin_height
= 0;
709 frame_T
*frp
, *curfrp
;
714 else if (flags
& WSP_BOT
)
719 /* add a status line when p_ls == 1 and splitting the first window */
720 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
722 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
727 need_status
= STATUS_HEIGHT
;
731 /* May be needed for the scrollbars that are going to change. */
736 #ifdef FEAT_VERTSPLIT
737 if (flags
& WSP_VERT
)
742 * Check if we are able to split the current window and compute its
746 if (flags
& WSP_ROOM
)
747 needed
+= p_wiw
- p_wmw
;
748 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
750 available
= topframe
->fr_width
;
751 needed
+= frame_minwidth(topframe
, NULL
);
754 available
= oldwin
->w_width
;
755 if (available
< needed
&& newwin
== NULL
)
761 new_size
= oldwin
->w_width
/ 2;
762 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
763 new_size
= oldwin
->w_width
- p_wmw
- 1;
764 if (new_size
< p_wmw
)
767 /* if it doesn't fit in the current window, need win_equal() */
768 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
771 /* We don't like to take lines for the new window from a
772 * 'winfixwidth' window. Take them from a window to the left or right
773 * instead, if possible. */
775 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
777 /* Only make all windows the same width if one of them (except oldwin)
778 * is wider than one of the split windows. */
779 if (!do_equal
&& p_ea
&& size
== 0 && *p_ead
!= 'v'
780 && oldwin
->w_frame
->fr_parent
!= NULL
)
782 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
785 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
786 && (frp
->fr_win
->w_width
> new_size
787 || frp
->fr_win
->w_width
> oldwin
->w_width
788 - new_size
- STATUS_HEIGHT
))
803 * Check if we are able to split the current window and compute its
806 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
807 if (flags
& WSP_ROOM
)
808 needed
+= p_wh
- p_wmh
;
809 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
811 available
= topframe
->fr_height
;
812 needed
+= frame_minheight(topframe
, NULL
);
816 available
= oldwin
->w_height
;
819 if (available
< needed
&& newwin
== NULL
)
824 oldwin_height
= oldwin
->w_height
;
827 oldwin
->w_status_height
= STATUS_HEIGHT
;
828 oldwin_height
-= STATUS_HEIGHT
;
831 new_size
= oldwin_height
/ 2;
833 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
834 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
835 if (new_size
< p_wmh
)
838 /* if it doesn't fit in the current window, need win_equal() */
839 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
842 /* We don't like to take lines for the new window from a
843 * 'winfixheight' window. Take them from a window above or below
844 * instead, if possible. */
847 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
849 oldwin_height
= oldwin
->w_height
;
851 oldwin_height
-= STATUS_HEIGHT
;
854 /* Only make all windows the same height if one of them (except oldwin)
855 * is higher than one of the split windows. */
856 if (!do_equal
&& p_ea
&& size
== 0
857 #ifdef FEAT_VERTSPLIT
860 && oldwin
->w_frame
->fr_parent
!= NULL
)
862 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
865 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
866 && (frp
->fr_win
->w_height
> new_size
867 || frp
->fr_win
->w_height
> oldwin_height
- new_size
879 * allocate new window structure and link it in the window list
881 if ((flags
& WSP_TOP
) == 0
882 && ((flags
& WSP_BOT
)
883 || (flags
& WSP_BELOW
)
884 || (!(flags
& WSP_ABOVE
)
886 #ifdef FEAT_VERTSPLIT
887 (flags
& WSP_VERT
) ? p_spr
:
891 /* new window below/right of current one */
893 wp
= win_alloc(oldwin
, FALSE
);
895 win_append(oldwin
, wp
);
900 wp
= win_alloc(oldwin
->w_prev
, FALSE
);
902 win_append(oldwin
->w_prev
, wp
);
911 if (wp
->w_frame
== NULL
)
917 /* make the contents of the new window the same as the current one */
918 win_init(wp
, curwin
, flags
);
922 * Reorganise the tree of frames to insert the new window.
924 if (flags
& (WSP_TOP
| WSP_BOT
))
926 #ifdef FEAT_VERTSPLIT
927 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
928 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
930 if (topframe
->fr_layout
== FR_COL
)
933 curfrp
= topframe
->fr_child
;
935 while (curfrp
->fr_next
!= NULL
)
936 curfrp
= curfrp
->fr_next
;
940 before
= (flags
& WSP_TOP
);
944 curfrp
= oldwin
->w_frame
;
945 if (flags
& WSP_BELOW
)
947 else if (flags
& WSP_ABOVE
)
950 #ifdef FEAT_VERTSPLIT
951 if (flags
& WSP_VERT
)
957 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
959 /* Need to create a new frame in the tree to make a branch. */
960 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
962 curfrp
->fr_layout
= layout
;
963 frp
->fr_parent
= curfrp
;
966 curfrp
->fr_child
= frp
;
967 curfrp
->fr_win
= NULL
;
969 if (frp
->fr_win
!= NULL
)
970 oldwin
->w_frame
= frp
;
972 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
973 frp
->fr_parent
= curfrp
;
979 frp
= newwin
->w_frame
;
980 frp
->fr_parent
= curfrp
->fr_parent
;
982 /* Insert the new frame at the right place in the frame list. */
984 frame_insert(curfrp
, frp
);
986 frame_append(curfrp
, frp
);
988 #ifdef FEAT_VERTSPLIT
989 if (flags
& WSP_VERT
)
991 wp
->w_p_scr
= curwin
->w_p_scr
;
994 win_new_height(oldwin
, oldwin
->w_height
- 1);
995 oldwin
->w_status_height
= need_status
;
997 if (flags
& (WSP_TOP
| WSP_BOT
))
999 /* set height and row of new window to full height */
1000 wp
->w_winrow
= tabline_height();
1001 win_new_height(wp
, curfrp
->fr_height
- (p_ls
> 0));
1002 wp
->w_status_height
= (p_ls
> 0);
1006 /* height and row of new window is same as current window */
1007 wp
->w_winrow
= oldwin
->w_winrow
;
1008 win_new_height(wp
, oldwin
->w_height
);
1009 wp
->w_status_height
= oldwin
->w_status_height
;
1011 frp
->fr_height
= curfrp
->fr_height
;
1013 /* "new_size" of the current window goes to the new window, use
1014 * one column for the vertical separator */
1015 win_new_width(wp
, new_size
);
1017 wp
->w_vsep_width
= 1;
1020 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1021 oldwin
->w_vsep_width
= 1;
1023 if (flags
& (WSP_TOP
| WSP_BOT
))
1025 if (flags
& WSP_BOT
)
1026 frame_add_vsep(curfrp
);
1027 /* Set width of neighbor frame */
1028 frame_new_width(curfrp
, curfrp
->fr_width
1029 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
1033 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
1034 if (before
) /* new window left of current one */
1036 wp
->w_wincol
= oldwin
->w_wincol
;
1037 oldwin
->w_wincol
+= new_size
+ 1;
1039 else /* new window right of current one */
1040 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
1041 frame_fix_width(oldwin
);
1042 frame_fix_width(wp
);
1047 /* width and column of new window is same as current window */
1048 #ifdef FEAT_VERTSPLIT
1049 if (flags
& (WSP_TOP
| WSP_BOT
))
1052 win_new_width(wp
, Columns
);
1053 wp
->w_vsep_width
= 0;
1057 wp
->w_wincol
= oldwin
->w_wincol
;
1058 win_new_width(wp
, oldwin
->w_width
);
1059 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1061 frp
->fr_width
= curfrp
->fr_width
;
1064 /* "new_size" of the current window goes to the new window, use
1065 * one row for the status line */
1066 win_new_height(wp
, new_size
);
1067 if (flags
& (WSP_TOP
| WSP_BOT
))
1068 frame_new_height(curfrp
, curfrp
->fr_height
1069 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1071 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1072 if (before
) /* new window above current one */
1074 wp
->w_winrow
= oldwin
->w_winrow
;
1075 wp
->w_status_height
= STATUS_HEIGHT
;
1076 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1078 else /* new window below current one */
1080 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1081 wp
->w_status_height
= oldwin
->w_status_height
;
1082 oldwin
->w_status_height
= STATUS_HEIGHT
;
1084 #ifdef FEAT_VERTSPLIT
1085 if (flags
& WSP_BOT
)
1086 frame_add_statusline(curfrp
);
1088 frame_fix_height(wp
);
1089 frame_fix_height(oldwin
);
1092 if (flags
& (WSP_TOP
| WSP_BOT
))
1093 (void)win_comp_pos();
1096 * Both windows need redrawing
1098 redraw_win_later(wp
, NOT_VALID
);
1099 wp
->w_redr_status
= TRUE
;
1100 redraw_win_later(oldwin
, NOT_VALID
);
1101 oldwin
->w_redr_status
= TRUE
;
1107 msg_clr_eos_force(); /* Old command/ruler may still be there */
1110 msg_col
= 0; /* put position back at start of line */
1114 * equalize the window sizes.
1116 if (do_equal
|| dir
!= 0)
1118 #ifdef FEAT_VERTSPLIT
1119 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1120 : dir
== 'h' ? 'b' :
1124 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1125 * size was given. */
1126 #ifdef FEAT_VERTSPLIT
1127 if (flags
& WSP_VERT
)
1134 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1136 gui_init_which_components(NULL
);
1148 * make the new window the current window
1150 win_enter(wp
, FALSE
);
1151 #ifdef FEAT_VERTSPLIT
1152 if (flags
& WSP_VERT
)
1163 * Initialize window "newp" from window "oldp".
1164 * Used when splitting a window and when creating a new tab page.
1165 * The windows will both edit the same buffer.
1166 * WSP_NEWLOC may be specified in flags to prevent the location list from
1170 win_init(newp
, oldp
, flags
)
1177 newp
->w_buffer
= oldp
->w_buffer
;
1178 oldp
->w_buffer
->b_nwindows
++;
1179 newp
->w_cursor
= oldp
->w_cursor
;
1181 newp
->w_curswant
= oldp
->w_curswant
;
1182 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1183 newp
->w_topline
= oldp
->w_topline
;
1185 newp
->w_topfill
= oldp
->w_topfill
;
1187 newp
->w_leftcol
= oldp
->w_leftcol
;
1188 newp
->w_pcmark
= oldp
->w_pcmark
;
1189 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1190 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1191 newp
->w_wrow
= oldp
->w_wrow
;
1192 newp
->w_fraction
= oldp
->w_fraction
;
1193 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1194 #ifdef FEAT_JUMPLIST
1195 copy_jumplist(oldp
, newp
);
1197 #ifdef FEAT_QUICKFIX
1198 if (flags
& WSP_NEWLOC
)
1200 /* Don't copy the location list. */
1201 newp
->w_llist
= NULL
;
1202 newp
->w_llist_ref
= NULL
;
1205 copy_loclist(oldp
, newp
);
1207 if (oldp
->w_localdir
!= NULL
)
1208 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1210 /* copy tagstack and folds */
1211 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1213 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1214 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1215 newp
->w_tagstack
[i
].tagname
=
1216 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1218 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1219 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1220 # ifdef FEAT_FOLDING
1221 copyFoldingState(oldp
, newp
);
1224 win_init_some(newp
, oldp
);
1228 * Initialize window "newp" from window"old".
1229 * Only the essential things are copied.
1232 win_init_some(newp
, oldp
)
1236 /* Use the same argument list. */
1237 newp
->w_alist
= oldp
->w_alist
;
1238 ++newp
->w_alist
->al_refcount
;
1239 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1241 /* copy options from existing window */
1242 win_copy_options(oldp
, newp
);
1245 #endif /* FEAT_WINDOWS */
1247 #if defined(FEAT_WINDOWS) || defined(PROTO)
1249 * Check if "win" is a pointer to an existing window.
1259 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1266 * Return the number of windows.
1274 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1280 * Make "count" windows on the screen.
1281 * Return actual number of windows on the screen.
1282 * Must be called when there is just one window, filling the whole screen
1283 * (excluding the command line).
1286 make_windows(count
, vertical
)
1288 int vertical UNUSED
; /* split windows vertically if TRUE */
1293 #ifdef FEAT_VERTSPLIT
1296 /* Each windows needs at least 'winminwidth' lines and a separator
1298 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1299 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1304 /* Each window needs at least 'winminheight' lines and a status line. */
1305 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1306 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1311 if (count
> maxcount
)
1315 * add status line now, otherwise first window will be too big
1322 * Don't execute autocommands while creating the windows. Must do that
1323 * when putting the buffers in the windows.
1328 /* todo is number of windows left to create */
1329 for (todo
= count
- 1; todo
> 0; --todo
)
1330 #ifdef FEAT_VERTSPLIT
1333 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1334 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1340 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1341 * STATUS_HEIGHT
) / (todo
+ 1)
1342 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1350 /* return actual number of windows */
1351 return (count
- todo
);
1355 * Exchange current and next window
1358 win_exchange(Prenum
)
1367 if (lastwin
== firstwin
) /* just one window */
1374 need_mouse_correct
= TRUE
;
1378 * find window to exchange with
1382 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1383 while (frp
!= NULL
&& --Prenum
> 0)
1386 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1387 frp
= curwin
->w_frame
->fr_next
;
1388 else /* Swap last window in row/col with previous */
1389 frp
= curwin
->w_frame
->fr_prev
;
1391 /* We can only exchange a window with another window, not with a frame
1392 * containing windows. */
1393 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1398 * 1. remove curwin from the list. Remember after which window it was in wp2
1399 * 2. insert curwin before wp in the list
1401 * 3. remove wp from the list
1402 * 4. insert wp after wp2
1403 * 5. exchange the status line height and vsep width.
1405 wp2
= curwin
->w_prev
;
1406 frp2
= curwin
->w_frame
->fr_prev
;
1407 if (wp
->w_prev
!= curwin
)
1409 win_remove(curwin
, NULL
);
1410 frame_remove(curwin
->w_frame
);
1411 win_append(wp
->w_prev
, curwin
);
1412 frame_insert(frp
, curwin
->w_frame
);
1416 win_remove(wp
, NULL
);
1417 frame_remove(wp
->w_frame
);
1418 win_append(wp2
, wp
);
1420 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1422 frame_append(frp2
, wp
->w_frame
);
1424 temp
= curwin
->w_status_height
;
1425 curwin
->w_status_height
= wp
->w_status_height
;
1426 wp
->w_status_height
= temp
;
1427 #ifdef FEAT_VERTSPLIT
1428 temp
= curwin
->w_vsep_width
;
1429 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1430 wp
->w_vsep_width
= temp
;
1432 /* If the windows are not in the same frame, exchange the sizes to avoid
1433 * messing up the window layout. Otherwise fix the frame sizes. */
1434 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1436 temp
= curwin
->w_height
;
1437 curwin
->w_height
= wp
->w_height
;
1438 wp
->w_height
= temp
;
1439 temp
= curwin
->w_width
;
1440 curwin
->w_width
= wp
->w_width
;
1445 frame_fix_height(curwin
);
1446 frame_fix_height(wp
);
1447 frame_fix_width(curwin
);
1448 frame_fix_width(wp
);
1452 (void)win_comp_pos(); /* recompute window positions */
1454 win_enter(wp
, TRUE
);
1455 redraw_later(CLEAR
);
1459 * rotate windows: if upwards TRUE the second window becomes the first one
1460 * if upwards FALSE the first window becomes the second one
1463 win_rotate(upwards
, count
)
1472 if (firstwin
== lastwin
) /* nothing to do */
1479 need_mouse_correct
= TRUE
;
1482 #ifdef FEAT_VERTSPLIT
1483 /* Check if all frames in this row/col have one window. */
1484 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1486 if (frp
->fr_win
== NULL
)
1488 EMSG(_("E443: Cannot rotate when another window is split"));
1495 if (upwards
) /* first window becomes last window */
1497 /* remove first window/frame from the list */
1498 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1500 win_remove(wp1
, NULL
);
1503 /* find last frame and append removed window/frame after it */
1504 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1506 win_append(frp
->fr_win
, wp1
);
1507 frame_append(frp
, wp1
->w_frame
);
1509 wp2
= frp
->fr_win
; /* previously last window */
1511 else /* last window becomes first window */
1513 /* find last window/frame in the list and remove it */
1514 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1518 wp2
= wp1
->w_prev
; /* will become last window */
1519 win_remove(wp1
, NULL
);
1522 /* append the removed window/frame before the first in the list */
1523 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1524 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1527 /* exchange status height and vsep width of old and new last window */
1528 n
= wp2
->w_status_height
;
1529 wp2
->w_status_height
= wp1
->w_status_height
;
1530 wp1
->w_status_height
= n
;
1531 frame_fix_height(wp1
);
1532 frame_fix_height(wp2
);
1533 #ifdef FEAT_VERTSPLIT
1534 n
= wp2
->w_vsep_width
;
1535 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1536 wp1
->w_vsep_width
= n
;
1537 frame_fix_width(wp1
);
1538 frame_fix_width(wp2
);
1541 /* recompute w_winrow and w_wincol for all windows */
1542 (void)win_comp_pos();
1545 redraw_later(CLEAR
);
1549 * Move the current window to the very top/bottom/left/right of the screen.
1552 win_totop(size
, flags
)
1557 int height
= curwin
->w_height
;
1559 if (lastwin
== firstwin
)
1565 /* Remove the window and frame from the tree of frames. */
1566 (void)winframe_remove(curwin
, &dir
, NULL
);
1567 win_remove(curwin
, NULL
);
1568 last_status(FALSE
); /* may need to remove last status line */
1569 (void)win_comp_pos(); /* recompute window positions */
1571 /* Split a window on the desired side and put the window there. */
1572 (void)win_split_ins(size
, flags
, curwin
, dir
);
1573 if (!(flags
& WSP_VERT
))
1575 win_setheight(height
);
1577 win_equal(curwin
, TRUE
, 'v');
1580 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1581 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1582 * scrollbars. Have to update them anyway. */
1583 gui_may_update_scrollbars();
1588 * Move window "win1" to below/right of "win2" and make "win1" the current
1589 * window. Only works within the same frame!
1592 win_move_after(win1
, win2
)
1597 /* check if the arguments are reasonable */
1601 /* check if there is something to do */
1602 if (win2
->w_next
!= win1
)
1604 /* may need move the status line/vertical separator of the last window
1606 if (win1
== lastwin
)
1608 height
= win1
->w_prev
->w_status_height
;
1609 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1610 win1
->w_status_height
= height
;
1611 #ifdef FEAT_VERTSPLIT
1612 if (win1
->w_prev
->w_vsep_width
== 1)
1614 /* Remove the vertical separator from the last-but-one window,
1615 * add it to the last window. Adjust the frame widths. */
1616 win1
->w_prev
->w_vsep_width
= 0;
1617 win1
->w_prev
->w_frame
->fr_width
-= 1;
1618 win1
->w_vsep_width
= 1;
1619 win1
->w_frame
->fr_width
+= 1;
1623 else if (win2
== lastwin
)
1625 height
= win1
->w_status_height
;
1626 win1
->w_status_height
= win2
->w_status_height
;
1627 win2
->w_status_height
= height
;
1628 #ifdef FEAT_VERTSPLIT
1629 if (win1
->w_vsep_width
== 1)
1631 /* Remove the vertical separator from win1, add it to the last
1632 * window, win2. Adjust the frame widths. */
1633 win2
->w_vsep_width
= 1;
1634 win2
->w_frame
->fr_width
+= 1;
1635 win1
->w_vsep_width
= 0;
1636 win1
->w_frame
->fr_width
-= 1;
1640 win_remove(win1
, NULL
);
1641 frame_remove(win1
->w_frame
);
1642 win_append(win2
, win1
);
1643 frame_append(win2
->w_frame
, win1
->w_frame
);
1645 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1646 redraw_later(NOT_VALID
);
1648 win_enter(win1
, FALSE
);
1652 * Make all windows the same height.
1653 * 'next_curwin' will soon be the current window, make sure it has enough
1657 win_equal(next_curwin
, current
, dir
)
1658 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1659 int current
; /* do only frame with current window */
1660 int dir
; /* 'v' for vertically, 'h' for horizontally,
1661 'b' for both, 0 for using p_ead */
1664 #ifdef FEAT_VERTSPLIT
1669 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1670 topframe
, dir
, 0, tabline_height(),
1671 (int)Columns
, topframe
->fr_height
);
1675 * Set a frame to a new position and height, spreading the available room
1676 * equally over contained frames.
1677 * The window "next_curwin" (if not NULL) should at least get the size from
1678 * 'winheight' and 'winwidth' if possible.
1681 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1682 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1683 int current
; /* do only frame with current window */
1684 frame_T
*topfr
; /* frame to set size off */
1685 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1686 int col
; /* horizontal position for frame */
1687 int row
; /* vertical position for frame */
1688 int width
; /* new width of frame */
1689 int height
; /* new height of frame */
1693 int wincount
, totwincount
= 0;
1695 int next_curwin_size
= 0;
1698 int has_next_curwin
= 0;
1701 if (topfr
->fr_layout
== FR_LEAF
)
1703 /* Set the width/height of this frame.
1704 * Redraw when size or position changes */
1705 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1706 #ifdef FEAT_VERTSPLIT
1707 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1711 topfr
->fr_win
->w_winrow
= row
;
1712 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1713 #ifdef FEAT_VERTSPLIT
1714 topfr
->fr_win
->w_wincol
= col
;
1715 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1717 redraw_all_later(CLEAR
);
1720 #ifdef FEAT_VERTSPLIT
1721 else if (topfr
->fr_layout
== FR_ROW
)
1723 topfr
->fr_width
= width
;
1724 topfr
->fr_height
= height
;
1726 if (dir
!= 'v') /* equalize frame widths */
1728 /* Compute the maximum number of windows horizontally in this
1730 n
= frame_minwidth(topfr
, NOWIN
);
1731 /* add one for the rightmost window, it doesn't have a separator */
1732 if (col
+ width
== Columns
)
1736 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1737 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1740 * Compute width for "next_curwin" window and room available for
1742 * "m" is the minimal width when counting p_wiw for "next_curwin".
1744 m
= frame_minwidth(topfr
, next_curwin
);
1748 next_curwin_size
= p_wiw
+ room
;
1753 next_curwin_size
= -1;
1754 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1756 /* If 'winfixwidth' set keep the window width if
1758 * Watch out for this window being the next_curwin. */
1759 if (frame_fixed_width(fr
))
1761 n
= frame_minwidth(fr
, NOWIN
);
1762 new_size
= fr
->fr_width
;
1763 if (frame_has_win(fr
, next_curwin
))
1765 room
+= p_wiw
- p_wmw
;
1766 next_curwin_size
= 0;
1767 if (new_size
< p_wiw
)
1771 /* These windows don't use up room. */
1772 totwincount
-= (n
+ (fr
->fr_next
== NULL
1773 ? extra_sep
: 0)) / (p_wmw
+ 1);
1774 room
-= new_size
- n
;
1780 fr
->fr_newwidth
= new_size
;
1783 if (next_curwin_size
== -1)
1785 if (!has_next_curwin
)
1786 next_curwin_size
= 0;
1787 else if (totwincount
> 1
1788 && (room
+ (totwincount
- 2))
1789 / (totwincount
- 1) > p_wiw
)
1791 /* Can make all windows wider than 'winwidth', spread
1792 * the room equally. */
1793 next_curwin_size
= (room
+ p_wiw
1794 + (totwincount
- 1) * p_wmw
1795 + (totwincount
- 1)) / totwincount
;
1796 room
-= next_curwin_size
- p_wiw
;
1799 next_curwin_size
= p_wiw
;
1803 if (has_next_curwin
)
1804 --totwincount
; /* don't count curwin */
1807 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1811 if (fr
->fr_next
== NULL
)
1812 /* last frame gets all that remains (avoid roundoff error) */
1814 else if (dir
== 'v')
1815 new_size
= fr
->fr_width
;
1816 else if (frame_fixed_width(fr
))
1818 new_size
= fr
->fr_newwidth
;
1819 wincount
= 0; /* doesn't count as a sizeable window */
1823 /* Compute the maximum number of windows horiz. in "fr". */
1824 n
= frame_minwidth(fr
, NOWIN
);
1825 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1827 m
= frame_minwidth(fr
, next_curwin
);
1828 if (has_next_curwin
)
1829 hnc
= frame_has_win(fr
, next_curwin
);
1832 if (hnc
) /* don't count next_curwin */
1834 if (totwincount
== 0)
1837 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1839 if (hnc
) /* add next_curwin size */
1841 next_curwin_size
-= p_wiw
- (m
- n
);
1842 new_size
+= next_curwin_size
;
1843 room
-= new_size
- next_curwin_size
;
1850 /* Skip frame that is full width when splitting or closing a
1851 * window, unless equalizing all frames. */
1852 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1853 || (new_size
!= fr
->fr_width
)
1854 || frame_has_win(fr
, next_curwin
))
1855 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1859 totwincount
-= wincount
;
1863 else /* topfr->fr_layout == FR_COL */
1865 #ifdef FEAT_VERTSPLIT
1866 topfr
->fr_width
= width
;
1868 topfr
->fr_height
= height
;
1870 if (dir
!= 'h') /* equalize frame heights */
1872 /* Compute maximum number of windows vertically in this frame. */
1873 n
= frame_minheight(topfr
, NOWIN
);
1874 /* add one for the bottom window if it doesn't have a statusline */
1875 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1879 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1880 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1883 * Compute height for "next_curwin" window and room available for
1885 * "m" is the minimal height when counting p_wh for "next_curwin".
1887 m
= frame_minheight(topfr
, next_curwin
);
1891 /* The room is less then 'winheight', use all space for the
1892 * current window. */
1893 next_curwin_size
= p_wh
+ room
;
1898 next_curwin_size
= -1;
1899 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1901 /* If 'winfixheight' set keep the window height if
1903 * Watch out for this window being the next_curwin. */
1904 if (frame_fixed_height(fr
))
1906 n
= frame_minheight(fr
, NOWIN
);
1907 new_size
= fr
->fr_height
;
1908 if (frame_has_win(fr
, next_curwin
))
1910 room
+= p_wh
- p_wmh
;
1911 next_curwin_size
= 0;
1912 if (new_size
< p_wh
)
1916 /* These windows don't use up room. */
1917 totwincount
-= (n
+ (fr
->fr_next
== NULL
1918 ? extra_sep
: 0)) / (p_wmh
+ 1);
1919 room
-= new_size
- n
;
1925 fr
->fr_newheight
= new_size
;
1928 if (next_curwin_size
== -1)
1930 if (!has_next_curwin
)
1931 next_curwin_size
= 0;
1932 else if (totwincount
> 1
1933 && (room
+ (totwincount
- 2))
1934 / (totwincount
- 1) > p_wh
)
1936 /* can make all windows higher than 'winheight',
1937 * spread the room equally. */
1938 next_curwin_size
= (room
+ p_wh
1939 + (totwincount
- 1) * p_wmh
1940 + (totwincount
- 1)) / totwincount
;
1941 room
-= next_curwin_size
- p_wh
;
1944 next_curwin_size
= p_wh
;
1948 if (has_next_curwin
)
1949 --totwincount
; /* don't count curwin */
1952 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1956 if (fr
->fr_next
== NULL
)
1957 /* last frame gets all that remains (avoid roundoff error) */
1959 else if (dir
== 'h')
1960 new_size
= fr
->fr_height
;
1961 else if (frame_fixed_height(fr
))
1963 new_size
= fr
->fr_newheight
;
1964 wincount
= 0; /* doesn't count as a sizeable window */
1968 /* Compute the maximum number of windows vert. in "fr". */
1969 n
= frame_minheight(fr
, NOWIN
);
1970 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1972 m
= frame_minheight(fr
, next_curwin
);
1973 if (has_next_curwin
)
1974 hnc
= frame_has_win(fr
, next_curwin
);
1977 if (hnc
) /* don't count next_curwin */
1979 if (totwincount
== 0)
1982 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1984 if (hnc
) /* add next_curwin size */
1986 next_curwin_size
-= p_wh
- (m
- n
);
1987 new_size
+= next_curwin_size
;
1988 room
-= new_size
- next_curwin_size
;
1994 /* Skip frame that is full width when splitting or closing a
1995 * window, unless equalizing all frames. */
1996 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1997 || (new_size
!= fr
->fr_height
)
1998 || frame_has_win(fr
, next_curwin
))
1999 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
2003 totwincount
-= wincount
;
2009 * close all windows for buffer 'buf'
2012 close_windows(buf
, keep_curwin
)
2014 int keep_curwin
; /* don't close "curwin" */
2017 tabpage_T
*tp
, *nexttp
;
2018 int h
= tabline_height();
2020 ++RedrawingDisabled
;
2022 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2024 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2026 win_close(wp
, FALSE
);
2028 /* Start all over, autocommands may change the window layout. */
2035 /* Also check windows in other tab pages. */
2036 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2038 nexttp
= tp
->tp_next
;
2040 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2041 if (wp
->w_buffer
== buf
)
2043 win_close_othertab(wp
, FALSE
, tp
);
2045 /* Start all over, the tab page may be closed and
2046 * autocommands may change the window layout. */
2047 nexttp
= first_tabpage
;
2052 --RedrawingDisabled
;
2054 if (h
!= tabline_height())
2059 * Return TRUE if the current window is the only window that exists (ignoring
2061 * Returns FALSE if there is a window, possibly in another tab page.
2066 return (one_window() && first_tabpage
->tp_next
== NULL
);
2070 * Return TRUE if there is only one window other than "aucmd_win" in the
2078 int seen_one
= FALSE
;
2082 if (wp
!= aucmd_win
)
2091 return firstwin
== lastwin
;
2096 * Close window "win". Only works for the current tab page.
2097 * If "free_buf" is TRUE related buffer may be unloaded.
2099 * called by :quit, :close, :xit, :wq and findtag()
2102 win_close(win
, free_buf
)
2108 int other_buffer
= FALSE
;
2110 int close_curwin
= FALSE
;
2112 int help_window
= FALSE
;
2113 tabpage_T
*prev_curtab
= curtab
;
2117 EMSG(_("E444: Cannot close last window"));
2122 if (win
== aucmd_win
)
2124 EMSG(_("E813: Cannot close autocmd window"));
2127 if ((firstwin
== aucmd_win
|| lastwin
== aucmd_win
) && one_window())
2129 EMSG(_("E814: Cannot close window, only autocmd window would remain"));
2135 * When closing the last window in a tab page first go to another tab
2136 * page and then close the window and the tab page. This avoids that
2137 * curwin and curtab are not invalid while we are freeing memory, they may
2138 * be used in GUI events.
2140 if (firstwin
== lastwin
)
2142 goto_tabpage_tp(alt_tabpage());
2143 redraw_tabline
= TRUE
;
2145 /* Safety check: Autocommands may have closed the window when jumping
2146 * to the other tab page. */
2147 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2149 int h
= tabline_height();
2151 win_close_othertab(win
, free_buf
, prev_curtab
);
2152 if (h
!= tabline_height())
2158 /* When closing the help window, try restoring a snapshot after closing
2159 * the window. Otherwise clear the snapshot, it's now invalid. */
2160 if (win
->w_buffer
->b_help
)
2163 clear_snapshot(curtab
, SNAP_HELP_IDX
);
2169 * Guess which window is going to be the new current window.
2170 * This may change because of the autocommands (sigh).
2172 wp
= frame2win(win_altframe(win
, NULL
));
2175 * Be careful: If autocommands delete the window, return now.
2177 if (wp
->w_buffer
!= curbuf
)
2179 other_buffer
= TRUE
;
2180 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2181 if (!win_valid(win
) || last_window())
2184 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2185 if (!win_valid(win
) || last_window())
2188 /* autocmds may abort script processing */
2196 /* Avoid trouble with scrollbars that are going to be deleted in
2203 * Close the link to the buffer.
2205 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2207 /* Autocommands may have closed the window already, or closed the only
2208 * other window or moved to another tab page. */
2209 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2212 /* Free the memory used for the window. */
2213 wp
= win_free_mem(win
, &dir
, NULL
);
2215 /* Make sure curwin isn't invalid. It can cause severe trouble when
2216 * printing an error message. For win_equal() curbuf needs to be valid
2221 #ifdef FEAT_QUICKFIX
2222 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2225 * If the cursor goes to the preview or the quickfix window, try
2226 * finding another window to go to.
2230 if (wp
->w_next
== NULL
)
2236 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2244 curbuf
= curwin
->w_buffer
;
2245 close_curwin
= TRUE
;
2248 #ifdef FEAT_VERTSPLIT
2249 && (*p_ead
== 'b' || *p_ead
== dir
)
2252 win_equal(curwin
, TRUE
,
2253 #ifdef FEAT_VERTSPLIT
2263 win_enter_ext(wp
, FALSE
, TRUE
);
2266 /* careful: after this wp and win may be invalid! */
2267 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2272 * If last window has a status line now and we don't want one,
2273 * remove the status line.
2277 /* After closing the help window, try restoring the window layout from
2278 * before it was opened. */
2280 restore_snapshot(SNAP_HELP_IDX
, close_curwin
);
2282 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2283 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2284 if (gui
.in_use
&& !win_hasvertsplit())
2285 gui_init_which_components(NULL
);
2288 redraw_all_later(NOT_VALID
);
2292 * Close window "win" in tab page "tp", which is not the current tab page.
2293 * This may be the last window ih that tab page and result in closing the tab,
2294 * thus "tp" may become invalid!
2295 * Caller must check if buffer is hidden and whether the tabline needs to be
2299 win_close_othertab(win
, free_buf
, tp
)
2306 tabpage_T
*ptp
= NULL
;
2307 int free_tp
= FALSE
;
2309 /* Close the link to the buffer. */
2310 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2312 /* Careful: Autocommands may have closed the tab page or made it the
2313 * current tab page. */
2314 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2316 if (ptp
== NULL
|| tp
== curtab
)
2319 /* Autocommands may have closed the window already. */
2320 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2325 /* When closing the last window in a tab page remove the tab page. */
2326 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2328 if (tp
== first_tabpage
)
2329 first_tabpage
= tp
->tp_next
;
2332 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2337 EMSG2(_(e_intern2
), "win_close_othertab()");
2340 ptp
->tp_next
= tp
->tp_next
;
2345 /* Free the memory used for the window. */
2346 win_free_mem(win
, &dir
, tp
);
2353 * Free the memory used for a window.
2354 * Returns a pointer to the window that got the freed up space.
2357 win_free_mem(win
, dirp
, tp
)
2359 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2360 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2365 /* Remove the window and its frame from the tree of frames. */
2367 wp
= winframe_remove(win
, dirp
, tp
);
2371 /* When deleting the current window of another tab page select a new
2372 * current window. */
2373 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2379 #if defined(EXITFREE) || defined(PROTO)
2385 # ifdef FEAT_WINDOWS
2386 while (first_tabpage
->tp_next
!= NULL
)
2387 tabpage_close(TRUE
);
2390 # ifdef FEAT_AUTOCMD
2391 if (aucmd_win
!= NULL
)
2393 (void)win_free_mem(aucmd_win
, &dummy
, NULL
);
2398 while (firstwin
!= NULL
)
2399 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2404 * Remove a window and its frame from the tree of frames.
2405 * Returns a pointer to the window that got the freed up space.
2408 winframe_remove(win
, dirp
, tp
)
2410 int *dirp UNUSED
; /* set to 'v' or 'h' for direction if 'ea' */
2411 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2413 frame_T
*frp
, *frp2
, *frp3
;
2414 frame_T
*frp_close
= win
->w_frame
;
2418 * If there is only one window there is nothing to remove.
2420 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2424 * Remove the window from its frame.
2426 frp2
= win_altframe(win
, tp
);
2427 wp
= frame2win(frp2
);
2429 /* Remove this frame from the list of frames. */
2430 frame_remove(frp_close
);
2432 #ifdef FEAT_VERTSPLIT
2433 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2436 /* When 'winfixheight' is set, try to find another frame in the column
2437 * (as close to the closed frame as possible) to distribute the height
2439 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2441 frp
= frp_close
->fr_prev
;
2442 frp3
= frp_close
->fr_next
;
2443 while (frp
!= NULL
|| frp3
!= NULL
)
2447 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2457 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2463 frp3
= frp3
->fr_next
;
2467 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2468 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2469 #ifdef FEAT_VERTSPLIT
2474 /* When 'winfixwidth' is set, try to find another frame in the column
2475 * (as close to the closed frame as possible) to distribute the width
2477 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2479 frp
= frp_close
->fr_prev
;
2480 frp3
= frp_close
->fr_next
;
2481 while (frp
!= NULL
|| frp3
!= NULL
)
2485 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2495 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2501 frp3
= frp3
->fr_next
;
2505 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2506 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2511 /* If rows/columns go to a window below/right its positions need to be
2512 * updated. Can only be done after the sizes have been updated. */
2513 if (frp2
== frp_close
->fr_next
)
2515 int row
= win
->w_winrow
;
2516 int col
= W_WINCOL(win
);
2518 frame_comp_pos(frp2
, &row
, &col
);
2521 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2523 /* There is no other frame in this list, move its info to the parent
2525 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2526 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2527 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2528 frp
->fr_parent
= frp2
->fr_parent
;
2529 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2530 if (frp2
->fr_win
!= NULL
)
2531 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2532 frp
= frp2
->fr_parent
;
2535 frp2
= frp
->fr_parent
;
2536 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2538 /* The frame above the parent has the same layout, have to merge
2539 * the frames into this list. */
2540 if (frp2
->fr_child
== frp
)
2541 frp2
->fr_child
= frp
->fr_child
;
2542 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2543 if (frp
->fr_prev
!= NULL
)
2544 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2545 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2547 frp3
->fr_parent
= frp2
;
2548 if (frp3
->fr_next
== NULL
)
2550 frp3
->fr_next
= frp
->fr_next
;
2551 if (frp
->fr_next
!= NULL
)
2552 frp
->fr_next
->fr_prev
= frp3
;
2564 * Find out which frame is going to get the freed up space when "win" is
2566 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2567 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2568 * This makes opening a window and closing it immediately keep the same window
2572 win_altframe(win
, tp
)
2574 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2579 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2580 /* Last window in this tab page, will go to next tab page. */
2581 return alt_tabpage()->tp_curwin
->w_frame
;
2584 #ifdef FEAT_VERTSPLIT
2585 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2590 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2591 return frp
->fr_next
;
2592 return frp
->fr_prev
;
2596 * Return the tabpage that will be used if the current one is closed.
2603 /* Use the next tab page if possible. */
2604 if (curtab
->tp_next
!= NULL
)
2605 return curtab
->tp_next
;
2607 /* Find the last but one tab page. */
2608 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2614 * Find the left-upper window in frame "frp".
2620 while (frp
->fr_win
== NULL
)
2621 frp
= frp
->fr_child
;
2626 * Return TRUE if frame "frp" contains window "wp".
2629 frame_has_win(frp
, wp
)
2635 if (frp
->fr_layout
== FR_LEAF
)
2636 return frp
->fr_win
== wp
;
2638 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2639 if (frame_has_win(p
, wp
))
2645 * Set a new height for a frame. Recursively sets the height for contained
2646 * frames and windows. Caller must take care of positions.
2649 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2652 int topfirst
; /* resize topmost contained frame first */
2653 int wfh
; /* obey 'winfixheight' when there is a choice;
2654 may cause the height not to be set */
2660 if (topfrp
->fr_win
!= NULL
)
2662 /* Simple case: just one window. */
2663 win_new_height(topfrp
->fr_win
,
2664 height
- topfrp
->fr_win
->w_status_height
);
2666 #ifdef FEAT_VERTSPLIT
2667 else if (topfrp
->fr_layout
== FR_ROW
)
2671 /* All frames in this row get the same new height. */
2672 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2674 frame_new_height(frp
, height
, topfirst
, wfh
);
2675 if (frp
->fr_height
> height
)
2677 /* Could not fit the windows, make the whole row higher. */
2678 height
= frp
->fr_height
;
2683 while (frp
!= NULL
);
2686 else /* fr_layout == FR_COL */
2688 /* Complicated case: Resize a column of frames. Resize the bottom
2689 * frame first, frames above that when needed. */
2691 frp
= topfrp
->fr_child
;
2693 /* Advance past frames with one window with 'wfh' set. */
2694 while (frame_fixed_height(frp
))
2698 return; /* no frame without 'wfh', give up */
2702 /* Find the bottom frame of this column */
2703 while (frp
->fr_next
!= NULL
)
2706 /* Advance back for frames with one window with 'wfh' set. */
2707 while (frame_fixed_height(frp
))
2711 extra_lines
= height
- topfrp
->fr_height
;
2712 if (extra_lines
< 0)
2714 /* reduce height of contained frames, bottom or top frame first */
2717 h
= frame_minheight(frp
, NULL
);
2718 if (frp
->fr_height
+ extra_lines
< h
)
2720 extra_lines
+= frp
->fr_height
- h
;
2721 frame_new_height(frp
, h
, topfirst
, wfh
);
2725 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2733 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2739 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2741 /* Increase "height" if we could not reduce enough frames. */
2743 height
-= extra_lines
;
2746 else if (extra_lines
> 0)
2748 /* increase height of bottom or top frame */
2749 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2752 topfrp
->fr_height
= height
;
2756 * Return TRUE if height of frame "frp" should not be changed because of
2757 * the 'winfixheight' option.
2760 frame_fixed_height(frp
)
2763 /* frame with one window: fixed height if 'winfixheight' set. */
2764 if (frp
->fr_win
!= NULL
)
2765 return frp
->fr_win
->w_p_wfh
;
2767 if (frp
->fr_layout
== FR_ROW
)
2769 /* The frame is fixed height if one of the frames in the row is fixed
2771 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2772 if (frame_fixed_height(frp
))
2777 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2778 * frames in the row are fixed height. */
2779 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2780 if (!frame_fixed_height(frp
))
2785 #ifdef FEAT_VERTSPLIT
2787 * Return TRUE if width of frame "frp" should not be changed because of
2788 * the 'winfixwidth' option.
2791 frame_fixed_width(frp
)
2794 /* frame with one window: fixed width if 'winfixwidth' set. */
2795 if (frp
->fr_win
!= NULL
)
2796 return frp
->fr_win
->w_p_wfw
;
2798 if (frp
->fr_layout
== FR_COL
)
2800 /* The frame is fixed width if one of the frames in the row is fixed
2802 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2803 if (frame_fixed_width(frp
))
2808 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2809 * frames in the row are fixed width. */
2810 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2811 if (!frame_fixed_width(frp
))
2817 * Add a status line to windows at the bottom of "frp".
2818 * Note: Does not check if there is room!
2821 frame_add_statusline(frp
)
2826 if (frp
->fr_layout
== FR_LEAF
)
2829 if (wp
->w_status_height
== 0)
2831 if (wp
->w_height
> 0) /* don't make it negative */
2833 wp
->w_status_height
= STATUS_HEIGHT
;
2836 else if (frp
->fr_layout
== FR_ROW
)
2838 /* Handle all the frames in the row. */
2839 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2840 frame_add_statusline(frp
);
2842 else /* frp->fr_layout == FR_COL */
2844 /* Only need to handle the last frame in the column. */
2845 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2847 frame_add_statusline(frp
);
2852 * Set width of a frame. Handles recursively going through contained frames.
2853 * May remove separator line for windows at the right side (for win_close()).
2856 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2859 int leftfirst
; /* resize leftmost contained frame first */
2860 int wfw
; /* obey 'winfixwidth' when there is a choice;
2861 may cause the width not to be set */
2868 if (topfrp
->fr_layout
== FR_LEAF
)
2870 /* Simple case: just one window. */
2871 wp
= topfrp
->fr_win
;
2872 /* Find out if there are any windows right of this one. */
2873 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2874 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2876 if (frp
->fr_parent
== NULL
)
2877 wp
->w_vsep_width
= 0;
2878 win_new_width(wp
, width
- wp
->w_vsep_width
);
2880 else if (topfrp
->fr_layout
== FR_COL
)
2884 /* All frames in this column get the same new width. */
2885 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2887 frame_new_width(frp
, width
, leftfirst
, wfw
);
2888 if (frp
->fr_width
> width
)
2890 /* Could not fit the windows, make whole column wider. */
2891 width
= frp
->fr_width
;
2895 } while (frp
!= NULL
);
2897 else /* fr_layout == FR_ROW */
2899 /* Complicated case: Resize a row of frames. Resize the rightmost
2900 * frame first, frames left of it when needed. */
2902 frp
= topfrp
->fr_child
;
2904 /* Advance past frames with one window with 'wfw' set. */
2905 while (frame_fixed_width(frp
))
2909 return; /* no frame without 'wfw', give up */
2913 /* Find the rightmost frame of this row */
2914 while (frp
->fr_next
!= NULL
)
2917 /* Advance back for frames with one window with 'wfw' set. */
2918 while (frame_fixed_width(frp
))
2922 extra_cols
= width
- topfrp
->fr_width
;
2925 /* reduce frame width, rightmost frame first */
2928 w
= frame_minwidth(frp
, NULL
);
2929 if (frp
->fr_width
+ extra_cols
< w
)
2931 extra_cols
+= frp
->fr_width
- w
;
2932 frame_new_width(frp
, w
, leftfirst
, wfw
);
2936 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2944 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2950 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2952 /* Increase "width" if we could not reduce enough frames. */
2954 width
-= extra_cols
;
2957 else if (extra_cols
> 0)
2959 /* increase width of rightmost frame */
2960 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2963 topfrp
->fr_width
= width
;
2967 * Add the vertical separator to windows at the right side of "frp".
2968 * Note: Does not check if there is room!
2976 if (frp
->fr_layout
== FR_LEAF
)
2979 if (wp
->w_vsep_width
== 0)
2981 if (wp
->w_width
> 0) /* don't make it negative */
2983 wp
->w_vsep_width
= 1;
2986 else if (frp
->fr_layout
== FR_COL
)
2988 /* Handle all the frames in the column. */
2989 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2990 frame_add_vsep(frp
);
2992 else /* frp->fr_layout == FR_ROW */
2994 /* Only need to handle the last frame in the row. */
2995 frp
= frp
->fr_child
;
2996 while (frp
->fr_next
!= NULL
)
2998 frame_add_vsep(frp
);
3003 * Set frame width from the window it contains.
3009 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
3014 * Set frame height from the window it contains.
3017 frame_fix_height(wp
)
3020 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
3024 * Compute the minimal height for frame "topfrp".
3025 * Uses the 'winminheight' option.
3026 * When "next_curwin" isn't NULL, use p_wh for this window.
3027 * When "next_curwin" is NOWIN, don't use at least one line for the current
3031 frame_minheight(topfrp
, next_curwin
)
3037 #ifdef FEAT_VERTSPLIT
3041 if (topfrp
->fr_win
!= NULL
)
3043 if (topfrp
->fr_win
== next_curwin
)
3044 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
3047 /* window: minimal height of the window plus status line */
3048 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
3049 /* Current window is minimal one line high */
3050 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3054 #ifdef FEAT_VERTSPLIT
3055 else if (topfrp
->fr_layout
== FR_ROW
)
3057 /* get the minimal height from each frame in this row */
3059 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3061 n
= frame_minheight(frp
, next_curwin
);
3069 /* Add up the minimal heights for all frames in this column. */
3071 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3072 m
+= frame_minheight(frp
, next_curwin
);
3078 #ifdef FEAT_VERTSPLIT
3080 * Compute the minimal width for frame "topfrp".
3081 * When "next_curwin" isn't NULL, use p_wiw for this window.
3082 * When "next_curwin" is NOWIN, don't use at least one column for the current
3086 frame_minwidth(topfrp
, next_curwin
)
3088 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3093 if (topfrp
->fr_win
!= NULL
)
3095 if (topfrp
->fr_win
== next_curwin
)
3096 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3099 /* window: minimal width of the window plus separator column */
3100 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3101 /* Current window is minimal one column wide */
3102 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3106 else if (topfrp
->fr_layout
== FR_COL
)
3108 /* get the minimal width from each frame in this column */
3110 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3112 n
= frame_minwidth(frp
, next_curwin
);
3119 /* Add up the minimal widths for all frames in this row. */
3121 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3122 m
+= frame_minwidth(frp
, next_curwin
);
3131 * Try to close all windows except current one.
3132 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3133 * used and the buffer was modified.
3135 * Used by ":bdel" and ":only".
3138 close_others(message
, forceit
)
3140 int forceit
; /* always hide all other windows */
3157 /* Be very careful here: autocommands may change the window layout. */
3158 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3160 nextwp
= wp
->w_next
;
3161 if (wp
!= curwin
) /* don't close current window */
3164 /* Check if it's allowed to abandon this window */
3165 r
= can_abandon(wp
->w_buffer
, forceit
);
3167 if (!win_valid(wp
)) /* autocommands messed wp up */
3175 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3176 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3178 dialog_changed(wp
->w_buffer
, FALSE
);
3179 # ifdef FEAT_AUTOCMD
3180 if (!win_valid(wp
)) /* autocommands messed wp up */
3187 if (bufIsChanged(wp
->w_buffer
))
3191 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3195 if (message
&& lastwin
!= firstwin
)
3196 EMSG(_("E445: Other window contains changes"));
3199 #endif /* FEAT_WINDOWS */
3202 * Init the current window "curwin".
3203 * Called when a new file is being edited.
3208 win_init_empty(curwin
);
3215 redraw_win_later(wp
, NOT_VALID
);
3216 wp
->w_lines_valid
= 0;
3217 wp
->w_cursor
.lnum
= 1;
3218 wp
->w_curswant
= wp
->w_cursor
.col
= 0;
3219 #ifdef FEAT_VIRTUALEDIT
3220 wp
->w_cursor
.coladd
= 0;
3222 wp
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3223 wp
->w_pcmark
.col
= 0;
3224 wp
->w_prev_pcmark
.lnum
= 0;
3225 wp
->w_prev_pcmark
.col
= 0;
3233 wp
->w_farsi
= W_CONV
+ W_R_L
;
3235 wp
->w_farsi
= W_CONV
;
3240 * Allocate the first window and put an empty buffer in it.
3241 * Called from main().
3242 * Return FAIL when something goes wrong (out of memory).
3247 if (win_alloc_firstwin(NULL
) == FAIL
)
3251 first_tabpage
= alloc_tabpage();
3252 if (first_tabpage
== NULL
)
3254 first_tabpage
->tp_topframe
= topframe
;
3255 curtab
= first_tabpage
;
3261 #if defined(FEAT_AUTOCMD) || defined(PROTO)
3263 * Init "aucmd_win". This can only be done after the first
3264 * window is fully initialized, thus it can't be in win_alloc_first().
3267 win_alloc_aucmd_win()
3269 aucmd_win
= win_alloc(NULL
, TRUE
);
3270 if (aucmd_win
!= NULL
)
3272 win_init_some(aucmd_win
, curwin
);
3273 # ifdef FEAT_SCROLLBIND
3274 aucmd_win
->w_p_scb
= FALSE
;
3276 new_frame(aucmd_win
);
3282 * Allocate the first window or the first window in a new tab page.
3283 * When "oldwin" is NULL create an empty buffer for it.
3284 * When "oldwin" is not NULL copy info from it to the new window (only with
3286 * Return FAIL when something goes wrong (out of memory).
3289 win_alloc_firstwin(oldwin
)
3292 curwin
= win_alloc(NULL
, FALSE
);
3295 /* Very first window, need to create an empty buffer for it and
3296 * initialize from scratch. */
3297 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3298 if (curwin
== NULL
|| curbuf
== NULL
)
3300 curwin
->w_buffer
= curbuf
;
3301 curbuf
->b_nwindows
= 1; /* there is one window */
3303 curwin
->w_alist
= &global_alist
;
3305 curwin_init(); /* init current window */
3310 /* First window in new tab page, initialize it from "oldwin". */
3311 win_init(curwin
, oldwin
, 0);
3313 # ifdef FEAT_SCROLLBIND
3314 /* We don't want scroll-binding in the first window. */
3315 curwin
->w_p_scb
= FALSE
;
3321 if (curwin
->w_frame
== NULL
)
3323 topframe
= curwin
->w_frame
;
3324 #ifdef FEAT_VERTSPLIT
3325 topframe
->fr_width
= Columns
;
3327 topframe
->fr_height
= Rows
- p_ch
;
3328 topframe
->fr_win
= curwin
;
3334 * Create a frame for window "wp".
3337 new_frame(win_T
*wp
)
3339 frame_T
*frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3344 frp
->fr_layout
= FR_LEAF
;
3350 * Initialize the window and frame size to the maximum.
3355 firstwin
->w_height
= ROWS_AVAIL
;
3356 topframe
->fr_height
= ROWS_AVAIL
;
3357 #ifdef FEAT_VERTSPLIT
3358 firstwin
->w_width
= Columns
;
3359 topframe
->fr_width
= Columns
;
3363 #if defined(FEAT_WINDOWS) || defined(PROTO)
3366 * Allocate a new tabpage_T and init the values.
3367 * Returns NULL when out of memory.
3374 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3380 for (i
= 0; i
< 3; i
++)
3381 tp
->tp_prev_which_scrollbars
[i
] = -1;
3384 tp
->tp_diff_invalid
= TRUE
;
3387 /* init t: variables */
3388 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3390 tp
->tp_ch_used
= p_ch
;
3404 for (idx
= 0; idx
< SNAP_COUNT
; ++idx
)
3405 clear_snapshot(tp
, idx
);
3407 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3413 * Create a new Tab page with one window.
3414 * It will edit the current buffer, like after ":split".
3415 * When "after" is 0 put it just after the current Tab page.
3416 * Otherwise put it just before tab page "after".
3417 * Return FAIL or OK.
3420 win_new_tabpage(after
)
3423 tabpage_T
*tp
= curtab
;
3427 newtp
= alloc_tabpage();
3431 /* Remember the current windows in this Tab page. */
3432 if (leave_tabpage(curbuf
) == FAIL
)
3439 /* Create a new empty window. */
3440 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3442 /* Make the new Tab page the new topframe. */
3445 /* New tab page becomes the first one. */
3446 newtp
->tp_next
= first_tabpage
;
3447 first_tabpage
= newtp
;
3453 /* Put new tab page before tab page "after". */
3455 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3456 && n
< after
; tp
= tp
->tp_next
)
3459 newtp
->tp_next
= tp
->tp_next
;
3460 tp
->tp_next
= newtp
;
3463 firstwin
->w_winrow
= tabline_height();
3464 win_comp_scroll(curwin
);
3466 newtp
->tp_topframe
= topframe
;
3469 #if defined(FEAT_GUI)
3470 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3471 * scrollbars. Have to update them anyway. */
3472 gui_may_update_scrollbars();
3475 redraw_all_later(CLEAR
);
3477 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3478 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3483 /* Failed, get back the previous Tab page */
3484 enter_tabpage(curtab
, curbuf
);
3489 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3490 * like with ":split".
3491 * Returns OK if a new tab page was created, FAIL otherwise.
3496 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3500 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3501 postponed_split_tab
= 0;
3502 return win_new_tabpage(n
);
3508 * Create up to "maxcount" tabpages with empty windows.
3509 * Returns the number of resulting tab pages.
3512 make_tabpages(maxcount
)
3515 int count
= maxcount
;
3518 /* Limit to 'tabpagemax' tabs. */
3524 * Don't execute autocommands while creating the tab pages. Must do that
3525 * when putting the buffers in the windows.
3530 for (todo
= count
- 1; todo
> 0; --todo
)
3531 if (win_new_tabpage(0) == FAIL
)
3538 /* return actual number of tab pages */
3539 return (count
- todo
);
3543 * Return TRUE when "tpc" points to a valid tab page.
3551 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3558 * Find tab page "n" (first one is 1). Returns NULL when not found.
3567 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3573 * Get index of tab page "tp". First one has index 1.
3574 * When not found returns number of tab pages plus one.
3583 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3589 * Prepare for leaving the current tab page.
3590 * When autocomands change "curtab" we don't leave the tab page and return
3592 * Careful: When OK is returned need to get a new tab page very very soon!
3595 leave_tabpage(new_curbuf
)
3596 buf_T
*new_curbuf UNUSED
; /* what is going to be the new curbuf,
3599 tabpage_T
*tp
= curtab
;
3602 reset_VIsual_and_resel(); /* stop Visual mode */
3605 if (new_curbuf
!= curbuf
)
3607 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3611 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3614 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3618 #if defined(FEAT_GUI)
3619 /* Remove the scrollbars. They may be added back later. */
3621 gui_remove_scrollbars();
3623 tp
->tp_curwin
= curwin
;
3624 tp
->tp_prevwin
= prevwin
;
3625 tp
->tp_firstwin
= firstwin
;
3626 tp
->tp_lastwin
= lastwin
;
3627 tp
->tp_old_Rows
= Rows
;
3628 tp
->tp_old_Columns
= Columns
;
3635 * Start using tab page "tp".
3636 * Only to be used after leave_tabpage() or freeing the current tab page.
3639 enter_tabpage(tp
, old_curbuf
)
3641 buf_T
*old_curbuf UNUSED
;
3643 int old_off
= tp
->tp_firstwin
->w_winrow
;
3644 win_T
*next_prevwin
= tp
->tp_prevwin
;
3647 firstwin
= tp
->tp_firstwin
;
3648 lastwin
= tp
->tp_lastwin
;
3649 topframe
= tp
->tp_topframe
;
3651 /* We would like doing the TabEnter event first, but we don't have a
3652 * valid current window yet, which may break some commands.
3653 * This triggers autocommands, thus may make "tp" invalid. */
3654 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3655 prevwin
= next_prevwin
;
3658 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3660 if (old_curbuf
!= curbuf
)
3661 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3664 last_status(FALSE
); /* status line may appear or disappear */
3665 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3666 must_redraw
= CLEAR
; /* need to redraw everything */
3668 diff_need_scrollbind
= TRUE
;
3671 /* The tabpage line may have appeared or disappeared, may need to resize
3672 * the frames for that. When the Vim window was resized need to update
3673 * frame sizes too. Use the stored value of p_ch, so that it can be
3674 * different for each tab page. */
3675 p_ch
= curtab
->tp_ch_used
;
3676 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3677 #ifdef FEAT_GUI_TABLINE
3678 && !gui_use_tabline()
3682 #ifdef FEAT_VERTSPLIT
3683 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3684 shell_new_columns(); /* update window widths */
3687 #if defined(FEAT_GUI)
3688 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3689 * scrollbars. Have to update them anyway. */
3690 gui_may_update_scrollbars();
3693 redraw_all_later(CLEAR
);
3697 * Go to tab page "n". For ":tab N" and "Ngt".
3698 * When "n" is 9999 go to the last tab page.
3710 /* Not allowed when editing the command line. */
3712 if (cmdwin_type
!= 0)
3720 /* If there is only one it can't work. */
3721 if (first_tabpage
->tp_next
== NULL
)
3730 /* No count, go to next tab page, wrap around end. */
3731 if (curtab
->tp_next
== NULL
)
3734 tp
= curtab
->tp_next
;
3738 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3741 for (i
= n
; i
< 0; ++i
)
3743 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3751 /* Go to last tab page. */
3752 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3757 /* Go to tab page "n". */
3758 tp
= find_tabpage(n
);
3766 goto_tabpage_tp(tp
);
3768 #ifdef FEAT_GUI_TABLINE
3769 if (gui_use_tabline())
3770 gui_mch_set_curtab(tabpage_index(curtab
));
3775 * Go to tabpage "tp".
3776 * Note: doesn't update the GUI tab.
3782 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3784 if (valid_tabpage(tp
))
3785 enter_tabpage(tp
, curbuf
);
3787 enter_tabpage(curtab
, curbuf
);
3792 * Enter window "wp" in tab page "tp".
3793 * Also updates the GUI tab.
3796 goto_tabpage_win(tp
, wp
)
3800 goto_tabpage_tp(tp
);
3801 if (curtab
== tp
&& win_valid(wp
))
3803 win_enter(wp
, TRUE
);
3804 # ifdef FEAT_GUI_TABLINE
3805 if (gui_use_tabline())
3806 gui_mch_set_curtab(tabpage_index(curtab
));
3812 * Move the current tab page to before tab page "nr".
3821 if (first_tabpage
->tp_next
== NULL
)
3824 /* Remove the current tab page from the list of tab pages. */
3825 if (curtab
== first_tabpage
)
3826 first_tabpage
= curtab
->tp_next
;
3829 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3830 if (tp
->tp_next
== curtab
)
3832 if (tp
== NULL
) /* "cannot happen" */
3834 tp
->tp_next
= curtab
->tp_next
;
3837 /* Re-insert it at the specified position. */
3840 curtab
->tp_next
= first_tabpage
;
3841 first_tabpage
= curtab
;
3845 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3847 curtab
->tp_next
= tp
->tp_next
;
3848 tp
->tp_next
= curtab
;
3851 /* Need to redraw the tabline. Tab page contents doesn't change. */
3852 redraw_tabline
= TRUE
;
3857 * Go to another window.
3858 * When jumping to another buffer, stop Visual mode. Do this before
3859 * changing windows so we can yank the selection into the '*' register.
3860 * When jumping to another window on the same buffer, adjust its cursor
3861 * position to keep the same Visual area.
3874 if (curbuf_locked())
3879 if (wp
->w_buffer
!= curbuf
)
3880 reset_VIsual_and_resel();
3881 else if (VIsual_active
)
3882 wp
->w_cursor
= curwin
->w_cursor
;
3886 need_mouse_correct
= TRUE
;
3888 win_enter(wp
, TRUE
);
3891 #if defined(FEAT_PERL) || defined(PROTO)
3893 * Find window number "winnr" (counting top to bottom).
3901 # ifdef FEAT_WINDOWS
3902 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3912 #ifdef FEAT_VERTSPLIT
3914 * Move to window above or below "count" times.
3917 win_goto_ver(up
, count
)
3918 int up
; /* TRUE to go to win above */
3925 foundfr
= curwin
->w_frame
;
3929 * First go upwards in the tree of frames until we find a upwards or
3930 * downwards neighbor.
3941 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3947 * Now go downwards to find the bottom or top frame in it.
3951 if (nfr
->fr_layout
== FR_LEAF
)
3957 if (nfr
->fr_layout
== FR_ROW
)
3959 /* Find the frame at the cursor row. */
3960 while (fr
->fr_next
!= NULL
3961 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3962 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3965 if (nfr
->fr_layout
== FR_COL
&& up
)
3966 while (fr
->fr_next
!= NULL
)
3972 if (foundfr
!= NULL
)
3973 win_goto(foundfr
->fr_win
);
3977 * Move to left or right window.
3980 win_goto_hor(left
, count
)
3981 int left
; /* TRUE to go to left win */
3988 foundfr
= curwin
->w_frame
;
3992 * First go upwards in the tree of frames until we find a left or
4004 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
4010 * Now go downwards to find the leftmost or rightmost frame in it.
4014 if (nfr
->fr_layout
== FR_LEAF
)
4020 if (nfr
->fr_layout
== FR_COL
)
4022 /* Find the frame at the cursor row. */
4023 while (fr
->fr_next
!= NULL
4024 && frame2win(fr
)->w_winrow
+ fr
->fr_height
4025 <= curwin
->w_winrow
+ curwin
->w_wrow
)
4028 if (nfr
->fr_layout
== FR_ROW
&& left
)
4029 while (fr
->fr_next
!= NULL
)
4035 if (foundfr
!= NULL
)
4036 win_goto(foundfr
->fr_win
);
4041 * Make window "wp" the current window.
4044 win_enter(wp
, undo_sync
)
4048 win_enter_ext(wp
, undo_sync
, FALSE
);
4052 * Make window wp the current window.
4053 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
4054 * been closed and isn't valid.
4057 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
4063 int other_buffer
= FALSE
;
4066 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
4070 if (!curwin_invalid
)
4073 * Be careful: If autocommands delete the window, return now.
4075 if (wp
->w_buffer
!= curbuf
)
4077 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4078 other_buffer
= TRUE
;
4082 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4086 /* autocmds may abort script processing */
4093 /* sync undo before leaving the current buffer */
4094 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4096 /* may have to copy the buffer options when 'cpo' contains 'S' */
4097 if (wp
->w_buffer
!= curbuf
)
4098 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4099 if (!curwin_invalid
)
4101 prevwin
= curwin
; /* remember for CTRL-W p */
4102 curwin
->w_redr_status
= TRUE
;
4105 curbuf
= wp
->w_buffer
;
4107 #ifdef FEAT_VIRTUALEDIT
4108 if (!virtual_active())
4109 curwin
->w_cursor
.coladd
= 0;
4111 changed_line_abv_curs(); /* assume cursor position needs updating */
4113 if (curwin
->w_localdir
!= NULL
)
4115 /* Window has a local directory: Save current directory as global
4116 * directory (unless that was done already) and change to the local
4118 if (globaldir
== NULL
)
4120 char_u cwd
[MAXPATHL
];
4122 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4123 globaldir
= vim_strsave(cwd
);
4125 if (mch_chdir((char *)curwin
->w_localdir
) == 0)
4126 shorten_fnames(TRUE
);
4128 else if (globaldir
!= NULL
)
4130 /* Window doesn't have a local directory and we are not in the global
4131 * directory: Change to the global directory. */
4132 ignored
= mch_chdir((char *)globaldir
);
4133 vim_free(globaldir
);
4135 shorten_fnames(TRUE
);
4139 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4141 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4147 curwin
->w_redr_status
= TRUE
;
4148 redraw_tabline
= TRUE
;
4150 redraw_later(VALID
); /* causes status line redraw */
4152 /* set window height to desired minimal value */
4153 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4154 win_setheight((int)p_wh
);
4155 else if (curwin
->w_height
== 0)
4158 #ifdef FEAT_VERTSPLIT
4159 /* set window width to desired minimal value */
4160 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4161 win_setwidth((int)p_wiw
);
4165 setmouse(); /* in case jumped to/from help buffer */
4168 /* Change directories when the 'acd' option is set. */
4172 #endif /* FEAT_WINDOWS */
4174 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4176 * Jump to the first open window that contains buffer "buf", if one exists.
4177 * Returns a pointer to the window found, otherwise NULL.
4180 buf_jump_open_win(buf
)
4183 # ifdef FEAT_WINDOWS
4186 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4187 if (wp
->w_buffer
== buf
)
4190 win_enter(wp
, FALSE
);
4193 if (curwin
->w_buffer
== buf
)
4200 * Jump to the first open window in any tab page that contains buffer "buf",
4202 * Returns a pointer to the window found, otherwise NULL.
4205 buf_jump_open_tab(buf
)
4208 # ifdef FEAT_WINDOWS
4212 /* First try the current tab page. */
4213 wp
= buf_jump_open_win(buf
);
4217 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4220 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4221 if (wp
->w_buffer
== buf
)
4225 goto_tabpage_win(tp
, wp
);
4227 wp
= NULL
; /* something went wrong */
4234 if (curwin
->w_buffer
== buf
)
4242 * Allocate a window structure and link it in the window list when "hidden" is
4246 win_alloc(after
, hidden
)
4247 win_T
*after UNUSED
;
4253 * allocate window structure and linesizes arrays
4255 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4256 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4265 /* Don't execute autocommands while the window is not properly
4266 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4271 * link the window in the window list
4275 win_append(after
, newwin
);
4277 #ifdef FEAT_VERTSPLIT
4278 newwin
->w_wincol
= 0;
4279 newwin
->w_width
= Columns
;
4282 /* position the display and the cursor at the top of the file. */
4283 newwin
->w_topline
= 1;
4285 newwin
->w_topfill
= 0;
4287 newwin
->w_botline
= 2;
4288 newwin
->w_cursor
.lnum
= 1;
4289 #ifdef FEAT_SCROLLBIND
4290 newwin
->w_scbind_pos
= 1;
4293 /* We won't calculate w_fraction until resizing the window */
4294 newwin
->w_fraction
= 0;
4295 newwin
->w_prev_fraction_row
= -1;
4300 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4302 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4303 SBAR_RIGHT
, newwin
);
4307 /* init w: variables */
4308 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4311 foldInitWin(newwin
);
4316 #ifdef FEAT_SEARCH_EXTRA
4317 newwin
->w_match_head
= NULL
;
4318 newwin
->w_next_match_id
= 4;
4324 #if defined(FEAT_WINDOWS) || defined(PROTO)
4327 * remove window 'wp' from the window list and free the structure
4332 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4340 /* reduce the reference count to the argument list. */
4341 alist_unlink(wp
->w_alist
);
4344 /* Don't execute autocommands while the window is halfway being deleted.
4345 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4349 #ifdef FEAT_MZSCHEME
4350 mzscheme_window_free(wp
);
4358 python_window_free(wp
);
4362 tcl_window_free(wp
);
4366 ruby_window_free(wp
);
4369 clear_winopt(&wp
->w_onebuf_opt
);
4370 clear_winopt(&wp
->w_allbuf_opt
);
4373 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4380 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4381 vim_free(wp
->w_tagstack
[i
].tagname
);
4383 vim_free(wp
->w_localdir
);
4385 #ifdef FEAT_SEARCH_EXTRA
4389 #ifdef FEAT_JUMPLIST
4393 #ifdef FEAT_QUICKFIX
4400 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4401 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4403 #endif /* FEAT_GUI */
4406 if (wp
!= aucmd_win
)
4417 * Append window "wp" in the window list after window "after".
4420 win_append(after
, wp
)
4425 if (after
== NULL
) /* after NULL is in front of the first */
4428 before
= after
->w_next
;
4430 wp
->w_next
= before
;
4439 before
->w_prev
= wp
;
4443 * Remove a window from the window list.
4448 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4450 if (wp
->w_prev
!= NULL
)
4451 wp
->w_prev
->w_next
= wp
->w_next
;
4452 else if (tp
== NULL
)
4453 firstwin
= wp
->w_next
;
4455 tp
->tp_firstwin
= wp
->w_next
;
4456 if (wp
->w_next
!= NULL
)
4457 wp
->w_next
->w_prev
= wp
->w_prev
;
4458 else if (tp
== NULL
)
4459 lastwin
= wp
->w_prev
;
4461 tp
->tp_lastwin
= wp
->w_prev
;
4465 * Append frame "frp" in a frame list after frame "after".
4468 frame_append(after
, frp
)
4469 frame_T
*after
, *frp
;
4471 frp
->fr_next
= after
->fr_next
;
4472 after
->fr_next
= frp
;
4473 if (frp
->fr_next
!= NULL
)
4474 frp
->fr_next
->fr_prev
= frp
;
4475 frp
->fr_prev
= after
;
4479 * Insert frame "frp" in a frame list before frame "before".
4482 frame_insert(before
, frp
)
4483 frame_T
*before
, *frp
;
4485 frp
->fr_next
= before
;
4486 frp
->fr_prev
= before
->fr_prev
;
4487 before
->fr_prev
= frp
;
4488 if (frp
->fr_prev
!= NULL
)
4489 frp
->fr_prev
->fr_next
= frp
;
4491 frp
->fr_parent
->fr_child
= frp
;
4495 * Remove a frame from a frame list.
4501 if (frp
->fr_prev
!= NULL
)
4502 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4504 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4505 if (frp
->fr_next
!= NULL
)
4506 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4509 #endif /* FEAT_WINDOWS */
4512 * Allocate w_lines[] for window "wp".
4513 * Return FAIL for failure, OK for success.
4519 wp
->w_lines_valid
= 0;
4520 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4521 if (wp
->w_lines
== NULL
)
4527 * free lsize arrays for a window
4533 vim_free(wp
->w_lines
);
4538 * Called from win_new_shellsize() after Rows changed.
4539 * This only does the current tab page, others must be done when made active.
4544 int h
= (int)ROWS_AVAIL
;
4546 if (firstwin
== NULL
) /* not initialized yet */
4549 if (h
< frame_minheight(topframe
, NULL
))
4550 h
= frame_minheight(topframe
, NULL
);
4552 /* First try setting the heights of windows with 'winfixheight'. If
4553 * that doesn't result in the right height, forget about that option. */
4554 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4555 if (topframe
->fr_height
!= h
)
4556 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4558 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4562 win_new_height(firstwin
, h
);
4566 curtab
->tp_ch_used
= p_ch
;
4570 /* Disabled: don't want making the screen smaller make a window larger. */
4572 win_equal(curwin
, FALSE
, 'v');
4576 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4578 * Called from win_new_shellsize() after Columns changed.
4583 if (firstwin
== NULL
) /* not initialized yet */
4586 /* First try setting the widths of windows with 'winfixwidth'. If that
4587 * doesn't result in the right width, forget about that option. */
4588 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4589 if (topframe
->fr_width
!= Columns
)
4590 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4592 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4594 /* Disabled: don't want making the screen smaller make a window larger. */
4596 win_equal(curwin
, FALSE
, 'h');
4601 #if defined(FEAT_CMDWIN) || defined(PROTO)
4603 * Save the size of all windows in "gap".
4612 ga_init2(gap
, (int)sizeof(int), 1);
4613 if (ga_grow(gap
, win_count() * 2) == OK
)
4614 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4616 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4617 wp
->w_width
+ wp
->w_vsep_width
;
4618 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4623 * Restore window sizes, but only if the number of windows is still the same.
4624 * Does not free the growarray.
4627 win_size_restore(gap
)
4633 if (win_count() * 2 == gap
->ga_len
)
4636 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4638 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4639 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4641 /* recompute the window positions */
4642 (void)win_comp_pos();
4645 #endif /* FEAT_CMDWIN */
4647 #if defined(FEAT_WINDOWS) || defined(PROTO)
4649 * Update the position for all windows, using the width and height of the
4651 * Returns the row just after the last window.
4656 int row
= tabline_height();
4659 frame_comp_pos(topframe
, &row
, &col
);
4664 * Update the position of the windows in frame "topfrp", using the width and
4665 * height of the frames.
4666 * "*row" and "*col" are the top-left position of the frame. They are updated
4667 * to the bottom-right position plus one.
4670 frame_comp_pos(topfrp
, row
, col
)
4677 #ifdef FEAT_VERTSPLIT
4682 wp
= topfrp
->fr_win
;
4685 if (wp
->w_winrow
!= *row
4686 #ifdef FEAT_VERTSPLIT
4687 || wp
->w_wincol
!= *col
4691 /* position changed, redraw */
4692 wp
->w_winrow
= *row
;
4693 #ifdef FEAT_VERTSPLIT
4694 wp
->w_wincol
= *col
;
4696 redraw_win_later(wp
, NOT_VALID
);
4697 wp
->w_redr_status
= TRUE
;
4699 *row
+= wp
->w_height
+ wp
->w_status_height
;
4700 #ifdef FEAT_VERTSPLIT
4701 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4706 #ifdef FEAT_VERTSPLIT
4710 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4712 #ifdef FEAT_VERTSPLIT
4713 if (topfrp
->fr_layout
== FR_ROW
)
4714 *row
= startrow
; /* all frames are at the same row */
4716 *col
= startcol
; /* all frames are at the same col */
4718 frame_comp_pos(frp
, row
, col
);
4723 #endif /* FEAT_WINDOWS */
4726 * Set current window height and take care of repositioning other windows to
4730 win_setheight(height
)
4733 win_setheight_win(height
, curwin
);
4737 * Set the window height of window "win" and take care of repositioning other
4738 * windows to fit around it.
4741 win_setheight_win(height
, win
)
4749 /* Always keep current window at least one line high, even when
4750 * 'winminheight' is zero. */
4760 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4762 /* recompute the window positions */
4763 row
= win_comp_pos();
4765 if (height
> topframe
->fr_height
)
4766 height
= topframe
->fr_height
;
4767 win
->w_height
= height
;
4772 * If there is extra space created between the last window and the command
4775 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4776 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4781 redraw_all_later(NOT_VALID
);
4784 #if defined(FEAT_WINDOWS) || defined(PROTO)
4787 * Set the height of a frame to "height" and take care that all frames and
4788 * windows inside it are resized. Also resize frames on the left and right if
4789 * the are in the same FR_ROW frame.
4792 * If the frame is part of a FR_COL frame, try fitting the frame in that
4793 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4794 * go to containing frames to resize them and make room.
4795 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4796 * Check for the minimal height of the FR_ROW frame.
4797 * At the top level we can also use change the command line height.
4800 frame_setheight(curfrp
, height
)
4804 int room
; /* total number of lines available */
4805 int take
; /* number of lines taken from other windows */
4806 int room_cmdline
; /* lines available from cmdline */
4812 /* If the height already is the desired value, nothing to do. */
4813 if (curfrp
->fr_height
== height
)
4816 if (curfrp
->fr_parent
== NULL
)
4818 /* topframe: can only change the command line */
4819 if (height
> ROWS_AVAIL
)
4820 height
= ROWS_AVAIL
;
4822 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4824 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4826 /* Row of frames: Also need to resize frames left and right of this
4827 * one. First check for the minimal height of these. */
4828 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4831 frame_setheight(curfrp
->fr_parent
, height
);
4836 * Column of frames: try to change only frames in this column.
4838 #ifdef FEAT_VERTSPLIT
4841 * 1: compute room available, if it's not enough try resizing the
4843 * 2: compute the room available and adjust the height to it.
4844 * Try not to reduce the height of a window with 'winfixheight' set.
4846 for (run
= 1; run
<= 2; ++run
)
4853 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4857 && frp
->fr_win
!= NULL
4858 && frp
->fr_win
->w_p_wfh
)
4859 room_reserved
+= frp
->fr_height
;
4860 room
+= frp
->fr_height
;
4862 room
-= frame_minheight(frp
, NULL
);
4864 #ifdef FEAT_VERTSPLIT
4865 if (curfrp
->fr_width
!= Columns
)
4870 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4871 + lastwin
->w_height
+ lastwin
->w_status_height
);
4872 if (room_cmdline
< 0)
4876 if (height
<= room
+ room_cmdline
)
4878 #ifdef FEAT_VERTSPLIT
4879 if (run
== 2 || curfrp
->fr_width
== Columns
)
4882 if (height
> room
+ room_cmdline
)
4883 height
= room
+ room_cmdline
;
4886 #ifdef FEAT_VERTSPLIT
4887 frame_setheight(curfrp
->fr_parent
, height
4888 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4894 * Compute the number of lines we will take from others frames (can be
4897 take
= height
- curfrp
->fr_height
;
4899 /* If there is not enough room, also reduce the height of a window
4900 * with 'winfixheight' set. */
4901 if (height
> room
+ room_cmdline
- room_reserved
)
4902 room_reserved
= room
+ room_cmdline
- height
;
4903 /* If there is only a 'winfixheight' window and making the
4904 * window smaller, need to make the other window taller. */
4905 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4908 if (take
> 0 && room_cmdline
> 0)
4910 /* use lines from cmdline first */
4911 if (take
< room_cmdline
)
4912 room_cmdline
= take
;
4913 take
-= room_cmdline
;
4914 topframe
->fr_height
+= room_cmdline
;
4918 * set the current frame to the new height
4920 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4923 * First take lines from the frames after the current frame. If
4924 * that is not enough, takes lines from frames above the current
4927 for (run
= 0; run
< 2; ++run
)
4930 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4932 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4933 while (frp
!= NULL
&& take
!= 0)
4935 h
= frame_minheight(frp
, NULL
);
4936 if (room_reserved
> 0
4937 && frp
->fr_win
!= NULL
4938 && frp
->fr_win
->w_p_wfh
)
4940 if (room_reserved
>= frp
->fr_height
)
4941 room_reserved
-= frp
->fr_height
;
4944 if (frp
->fr_height
- room_reserved
> take
)
4945 room_reserved
= frp
->fr_height
- take
;
4946 take
-= frp
->fr_height
- room_reserved
;
4947 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4953 if (frp
->fr_height
- take
< h
)
4955 take
-= frp
->fr_height
- h
;
4956 frame_new_height(frp
, h
, FALSE
, FALSE
);
4960 frame_new_height(frp
, frp
->fr_height
- take
,
4974 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4976 * Set current window width and take care of repositioning other windows to
4983 win_setwidth_win(width
, curwin
);
4987 win_setwidth_win(width
, wp
)
4991 /* Always keep current window at least one column wide, even when
4992 * 'winminwidth' is zero. */
5001 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
5003 /* recompute the window positions */
5004 (void)win_comp_pos();
5006 redraw_all_later(NOT_VALID
);
5010 * Set the width of a frame to "width" and take care that all frames and
5011 * windows inside it are resized. Also resize frames above and below if the
5012 * are in the same FR_ROW frame.
5014 * Strategy is similar to frame_setheight().
5017 frame_setwidth(curfrp
, width
)
5021 int room
; /* total number of lines available */
5022 int take
; /* number of lines taken from other windows */
5028 /* If the width already is the desired value, nothing to do. */
5029 if (curfrp
->fr_width
== width
)
5032 if (curfrp
->fr_parent
== NULL
)
5033 /* topframe: can't change width */
5036 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
5038 /* Column of frames: Also need to resize frames above and below of
5039 * this one. First check for the minimal width of these. */
5040 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
5043 frame_setwidth(curfrp
->fr_parent
, width
);
5048 * Row of frames: try to change only frames in this row.
5051 * 1: compute room available, if it's not enough try resizing the
5053 * 2: compute the room available and adjust the width to it.
5055 for (run
= 1; run
<= 2; ++run
)
5059 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
5063 && frp
->fr_win
!= NULL
5064 && frp
->fr_win
->w_p_wfw
)
5065 room_reserved
+= frp
->fr_width
;
5066 room
+= frp
->fr_width
;
5068 room
-= frame_minwidth(frp
, NULL
);
5073 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
5079 frame_setwidth(curfrp
->fr_parent
, width
5080 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
5084 * Compute the number of lines we will take from others frames (can be
5087 take
= width
- curfrp
->fr_width
;
5089 /* If there is not enough room, also reduce the width of a window
5090 * with 'winfixwidth' set. */
5091 if (width
> room
- room_reserved
)
5092 room_reserved
= room
- width
;
5093 /* If there is only a 'winfixwidth' window and making the
5094 * window smaller, need to make the other window narrower. */
5095 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
5099 * set the current frame to the new width
5101 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
5104 * First take lines from the frames right of the current frame. If
5105 * that is not enough, takes lines from frames left of the current
5108 for (run
= 0; run
< 2; ++run
)
5111 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5113 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5114 while (frp
!= NULL
&& take
!= 0)
5116 w
= frame_minwidth(frp
, NULL
);
5117 if (room_reserved
> 0
5118 && frp
->fr_win
!= NULL
5119 && frp
->fr_win
->w_p_wfw
)
5121 if (room_reserved
>= frp
->fr_width
)
5122 room_reserved
-= frp
->fr_width
;
5125 if (frp
->fr_width
- room_reserved
> take
)
5126 room_reserved
= frp
->fr_width
- take
;
5127 take
-= frp
->fr_width
- room_reserved
;
5128 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5134 if (frp
->fr_width
- take
< w
)
5136 take
-= frp
->fr_width
- w
;
5137 frame_new_width(frp
, w
, FALSE
, FALSE
);
5141 frame_new_width(frp
, frp
->fr_width
- take
,
5154 #endif /* FEAT_VERTSPLIT */
5157 * Check 'winminheight' for a valid value.
5166 /* loop until there is a 'winminheight' that is possible */
5169 /* TODO: handle vertical splits */
5171 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5172 room
+= wp
->w_height
- p_wmh
;
5187 * Status line of dragwin is dragged "offset" lines down (negative is up).
5190 win_drag_status_line(dragwin
, offset
)
5198 int up
; /* if TRUE, drag status line up, otherwise down */
5201 fr
= dragwin
->w_frame
;
5203 if (fr
!= topframe
) /* more than one window */
5206 /* When the parent frame is not a column of frames, its parent should
5208 if (fr
->fr_layout
!= FR_COL
)
5211 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5216 /* If this is the last frame in a column, may want to resize the parent
5217 * frame instead (go two up to skip a row of frames). */
5218 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5227 if (offset
< 0) /* drag up */
5231 /* sum up the room of the current frame and above it */
5234 /* only one window */
5235 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5240 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5242 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5247 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5249 else /* drag down */
5253 * Only dragging the last status line can reduce p_ch.
5255 room
= Rows
- cmdline_row
;
5256 if (curfr
->fr_next
== NULL
)
5262 /* sum up the room of frames below of the current one */
5263 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5264 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5265 fr
= curfr
; /* put fr at window that grows */
5268 if (room
< offset
) /* Not enough room */
5269 offset
= room
; /* Move as far as we can */
5274 * Grow frame fr by "offset" lines.
5275 * Doesn't happen when dragging the last status line up.
5278 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5281 fr
= curfr
; /* current frame gets smaller */
5283 fr
= curfr
->fr_next
; /* next frame gets smaller */
5286 * Now make the other frames smaller.
5288 while (fr
!= NULL
&& offset
> 0)
5290 n
= frame_minheight(fr
, NULL
);
5291 if (fr
->fr_height
- offset
<= n
)
5293 offset
-= fr
->fr_height
- n
;
5294 frame_new_height(fr
, n
, !up
, FALSE
);
5298 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5306 row
= win_comp_pos();
5307 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5309 p_ch
= Rows
- cmdline_row
;
5312 curtab
->tp_ch_used
= p_ch
;
5313 redraw_all_later(SOME_VALID
);
5317 #ifdef FEAT_VERTSPLIT
5319 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5322 win_drag_vsep_line(dragwin
, offset
)
5329 int left
; /* if TRUE, drag separator line left, otherwise right */
5332 fr
= dragwin
->w_frame
;
5333 if (fr
== topframe
) /* only one window (cannot happen?) */
5337 /* When the parent frame is not a row of frames, its parent should be. */
5338 if (fr
->fr_layout
!= FR_ROW
)
5340 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5346 /* If this is the last frame in a row, may want to resize a parent
5348 while (curfr
->fr_next
== NULL
)
5361 if (offset
< 0) /* drag left */
5365 /* sum up the room of the current frame and left of it */
5367 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5369 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5373 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5375 else /* drag right */
5378 /* sum up the room of frames right of the current one */
5380 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5381 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5382 fr
= curfr
; /* put fr at window that grows */
5385 if (room
< offset
) /* Not enough room */
5386 offset
= room
; /* Move as far as we can */
5387 if (offset
<= 0) /* No room at all, quit. */
5390 /* grow frame fr by offset lines */
5391 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5393 /* shrink other frames: current and at the left or at the right */
5395 fr
= curfr
; /* current frame gets smaller */
5397 fr
= curfr
->fr_next
; /* next frame gets smaller */
5399 while (fr
!= NULL
&& offset
> 0)
5401 n
= frame_minwidth(fr
, NULL
);
5402 if (fr
->fr_width
- offset
<= n
)
5404 offset
-= fr
->fr_width
- n
;
5405 frame_new_width(fr
, n
, !left
, FALSE
);
5409 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5417 (void)win_comp_pos();
5418 redraw_all_later(NOT_VALID
);
5420 #endif /* FEAT_VERTSPLIT */
5421 #endif /* FEAT_MOUSE */
5423 #endif /* FEAT_WINDOWS */
5426 * Set the height of a window.
5427 * This takes care of the things inside the window, not what happens to the
5428 * window position, the frame or to other windows.
5431 win_new_height(wp
, height
)
5436 int sline
, line_size
;
5437 #define FRACTION_MULT 16384L
5439 /* Don't want a negative height. Happens when splitting a tiny window.
5440 * Will equalize heights soon to fix it. */
5443 if (wp
->w_height
== height
)
5444 return; /* nothing to do */
5446 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5447 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5448 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5450 wp
->w_height
= height
;
5453 /* Don't change w_topline when height is zero. Don't set w_topline when
5454 * 'scrollbind' is set and this isn't the current window. */
5456 #ifdef FEAT_SCROLLBIND
5457 && (!wp
->w_p_scb
|| wp
== curwin
)
5462 * Find a value for w_topline that shows the cursor at the same
5463 * relative position in the window as before (more or less).
5465 lnum
= wp
->w_cursor
.lnum
;
5466 if (lnum
< 1) /* can happen when starting up */
5468 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5469 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5470 sline
= wp
->w_wrow
- line_size
;
5474 /* Make sure the whole cursor line is visible, if possible. */
5475 int rows
= plines_win(wp
, lnum
, FALSE
);
5477 if (sline
> wp
->w_height
- rows
)
5479 sline
= wp
->w_height
- rows
;
5480 wp
->w_wrow
-= rows
- line_size
;
5487 * Cursor line would go off top of screen if w_wrow was this high.
5488 * Make cursor line the first line in the window. If not enough
5489 * room use w_skipcol;
5491 wp
->w_wrow
= line_size
;
5492 if (wp
->w_wrow
>= wp
->w_height
5493 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5495 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5497 while (wp
->w_wrow
>= wp
->w_height
)
5499 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5507 while (sline
> 0 && lnum
> 1)
5510 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5513 /* first line in buffer is folded */
5521 if (lnum
== wp
->w_topline
)
5522 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5526 line_size
= plines_win(wp
, lnum
, TRUE
);
5533 * Line we want at top would go off top of screen. Use next
5537 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5540 wp
->w_wrow
-= line_size
+ sline
;
5544 /* First line of file reached, use that as topline. */
5546 wp
->w_wrow
-= sline
;
5549 set_topline(wp
, lnum
);
5556 curs_columns(FALSE
); /* validate w_wrow */
5558 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5560 win_comp_scroll(wp
);
5561 redraw_win_later(wp
, SOME_VALID
);
5563 wp
->w_redr_status
= TRUE
;
5565 invalidate_botline_win(wp
);
5568 #ifdef FEAT_VERTSPLIT
5570 * Set the width of a window.
5573 win_new_width(wp
, width
)
5577 wp
->w_width
= width
;
5578 wp
->w_lines_valid
= 0;
5579 changed_line_abv_curs_win(wp
);
5580 invalidate_botline_win(wp
);
5584 curs_columns(TRUE
); /* validate w_wrow */
5586 redraw_win_later(wp
, NOT_VALID
);
5587 wp
->w_redr_status
= TRUE
;
5595 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5596 if (wp
->w_p_scr
== 0)
5601 * command_height: called whenever p_ch has been changed
5609 int old_p_ch
= curtab
->tp_ch_used
;
5611 /* Use the value of p_ch that we remembered. This is needed for when the
5612 * GUI starts up, we can't be sure in what order things happen. And when
5613 * p_ch was changed in another tab page. */
5614 curtab
->tp_ch_used
= p_ch
;
5616 /* Find bottom frame with width of screen. */
5617 frp
= lastwin
->w_frame
;
5618 # ifdef FEAT_VERTSPLIT
5619 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5620 frp
= frp
->fr_parent
;
5623 /* Avoid changing the height of a window with 'winfixheight' set. */
5624 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5625 && frp
->fr_win
->w_p_wfh
)
5628 if (starting
!= NO_SCREEN
)
5630 cmdline_row
= Rows
- p_ch
;
5632 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5634 while (p_ch
> old_p_ch
)
5640 curtab
->tp_ch_used
= p_ch
;
5641 cmdline_row
= Rows
- p_ch
;
5644 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5645 if (h
> p_ch
- old_p_ch
)
5646 h
= p_ch
- old_p_ch
;
5648 frame_add_height(frp
, -h
);
5652 /* Recompute window positions. */
5653 (void)win_comp_pos();
5655 /* clear the lines added to cmdline */
5657 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5658 (int)Columns
, ' ', ' ', 0);
5659 msg_row
= cmdline_row
;
5660 redraw_cmdline
= TRUE
;
5664 if (msg_row
< cmdline_row
)
5665 msg_row
= cmdline_row
;
5666 redraw_cmdline
= TRUE
;
5668 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5670 /* Recompute window positions. */
5671 if (frp
!= lastwin
->w_frame
)
5672 (void)win_comp_pos();
5674 cmdline_row
= Rows
- p_ch
;
5675 win_setheight(cmdline_row
);
5679 #if defined(FEAT_WINDOWS) || defined(PROTO)
5681 * Resize frame "frp" to be "n" lines higher (negative for less high).
5682 * Also resize the frames it is contained in.
5685 frame_add_height(frp
, n
)
5689 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5692 frp
= frp
->fr_parent
;
5695 frp
->fr_height
+= n
;
5700 * Add or remove a status line for the bottom window(s), according to the
5701 * value of 'laststatus'.
5704 last_status(morewin
)
5705 int morewin
; /* pretend there are two or more windows */
5707 /* Don't make a difference between horizontal or vertical split. */
5708 last_status_rec(topframe
, (p_ls
== 2
5709 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5713 last_status_rec(fr
, statusline
)
5720 if (fr
->fr_layout
== FR_LEAF
)
5723 if (wp
->w_status_height
!= 0 && !statusline
)
5725 /* remove status line */
5726 win_new_height(wp
, wp
->w_height
+ 1);
5727 wp
->w_status_height
= 0;
5730 else if (wp
->w_status_height
== 0 && statusline
)
5732 /* Find a frame to take a line from. */
5734 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5741 /* In a column of frames: go to frame above. If already at
5742 * the top or in a row of frames: go to parent. */
5743 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5748 wp
->w_status_height
= 1;
5751 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5752 frame_fix_height(wp
);
5753 (void)win_comp_pos();
5756 win_new_height(wp
, wp
->w_height
- 1);
5758 redraw_all_later(SOME_VALID
);
5761 #ifdef FEAT_VERTSPLIT
5762 else if (fr
->fr_layout
== FR_ROW
)
5764 /* vertically split windows, set status line for each one */
5765 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5766 last_status_rec(fp
, statusline
);
5771 /* horizontally split window, set status line for last one */
5772 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5774 last_status_rec(fp
, statusline
);
5779 * Return the number of lines used by the tab page line.
5784 #ifdef FEAT_GUI_TABLINE
5785 /* When the GUI has the tabline then this always returns zero. */
5786 if (gui_use_tabline())
5792 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5797 #endif /* FEAT_WINDOWS */
5799 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5801 * Get the file name at the cursor.
5802 * If Visual mode is active, use the selected text if it's in one line.
5803 * Returns the name in allocated memory, NULL for failure.
5806 grab_file_name(count
, file_lnum
)
5808 linenr_T
*file_lnum
;
5816 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5818 return find_file_name_in_path(ptr
, len
,
5819 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5822 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5828 * Return the file name under or after the cursor.
5830 * The 'path' option is searched if the file name is not absolute.
5831 * The string returned has been alloc'ed and should be freed by the caller.
5832 * NULL is returned if the file name or file is not found.
5835 * FNAME_MESS give error messages
5836 * FNAME_EXP expand to path
5837 * FNAME_HYP check for hypertext link
5838 * FNAME_INCL apply "includeexpr"
5841 file_name_at_cursor(options
, count
, file_lnum
)
5844 linenr_T
*file_lnum
;
5846 return file_name_in_line(ml_get_curline(),
5847 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5852 * Return the name of the file under or after ptr[col].
5853 * Otherwise like file_name_at_cursor().
5856 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5861 char_u
*rel_fname
; /* file we are searching relative to */
5862 linenr_T
*file_lnum
; /* line number after the file name */
5868 * search forward for what could be the start of a file name
5871 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5873 if (*ptr
== NUL
) /* nothing found */
5875 if (options
& FNAME_MESS
)
5876 EMSG(_("E446: No file name under cursor"));
5881 * Search backward for first char of the file name.
5882 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5887 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5891 if (vim_isfilec(ptr
[-1])
5892 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5899 * Search forward for the last char of the file name.
5900 * Also allow "://" when ':' is not in 'isfname'.
5903 while (vim_isfilec(ptr
[len
])
5904 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5907 len
+= (*mb_ptr2len
)(ptr
+ len
);
5913 * If there is trailing punctuation, remove it.
5914 * But don't remove "..", could be a directory name.
5916 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5917 && ptr
[len
- 2] != '.')
5920 if (file_lnum
!= NULL
)
5924 /* Get the number after the file name and a separator character */
5930 ++p
; /* skip the separator */
5933 *file_lnum
= (int)getdigits(&p
);
5937 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5940 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5941 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5944 eval_includeexpr(ptr
, len
)
5950 set_vim_var_string(VV_FNAME
, ptr
, len
);
5951 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5952 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5953 set_vim_var_string(VV_FNAME
, NULL
, 0);
5959 * Return the name of the file ptr[len] in 'path'.
5960 * Otherwise like file_name_at_cursor().
5963 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5968 char_u
*rel_fname
; /* file we are searching relative to */
5972 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5973 char_u
*tofree
= NULL
;
5975 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5977 tofree
= eval_includeexpr(ptr
, len
);
5981 len
= (int)STRLEN(ptr
);
5986 if (options
& FNAME_EXP
)
5988 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5991 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5993 * If the file could not be found in a normal way, try applying
5994 * 'includeexpr' (unless done already).
5996 if (file_name
== NULL
5997 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5999 tofree
= eval_includeexpr(ptr
, len
);
6003 len
= (int)STRLEN(ptr
);
6004 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
6009 if (file_name
== NULL
&& (options
& FNAME_MESS
))
6013 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
6017 /* Repeat finding the file "count" times. This matters when it
6018 * appears several times in the path. */
6019 while (file_name
!= NULL
&& --count
> 0)
6021 vim_free(file_name
);
6022 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
6026 file_name
= vim_strnsave(ptr
, len
);
6028 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
6034 #endif /* FEAT_SEARCHPATH */
6037 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
6038 * Also check for ":\\", which MS Internet Explorer accepts, return
6045 if (STRNCMP(p
, "://", (size_t)3) == 0)
6047 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
6048 return URL_BACKSLASH
;
6053 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
6054 * Return URL_BACKSLASH for "name:\\".
6055 * Return zero otherwise.
6058 path_with_url(fname
)
6063 for (p
= fname
; isalpha(*p
); ++p
)
6065 return path_is_url(p
);
6069 * Return TRUE if "name" is a full (absolute) path name or URL.
6075 return (path_with_url(name
) != 0 || mch_isFullName(name
));
6079 * Get absolute file name into buffer "buf[len]".
6081 * return FAIL for failure, OK otherwise
6084 vim_FullName(fname
, buf
, len
, force
)
6085 char_u
*fname
, *buf
;
6087 int force
; /* force expansion even when already absolute */
6096 url
= path_with_url(fname
);
6098 retval
= mch_FullName(fname
, buf
, len
, force
);
6099 if (url
|| retval
== FAIL
)
6101 /* something failed; use the file name (truncate when too long) */
6102 vim_strncpy(buf
, fname
, len
- 1);
6104 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6111 * Return the minimal number of rows that is needed on the screen to display
6112 * the current number of windows.
6123 if (firstwin
== NULL
) /* not initialized yet */
6128 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6130 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6134 total
+= tabline_height();
6136 total
= 1; /* at least one window should have a line! */
6138 total
+= 1; /* count the room for the command line */
6143 * Return TRUE if there is only one window (in the current tab page), not
6144 * counting a help or preview window, unless it is the current window.
6145 * Does not count "aucmd_win".
6154 /* If there is another tab page there always is another window. */
6155 if (first_tabpage
->tp_next
!= NULL
)
6158 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6159 if ((!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6160 # ifdef FEAT_QUICKFIX
6164 # ifdef FEAT_AUTOCMD
6169 return (count
<= 1);
6175 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6177 * Correct the cursor line number in other windows. Used after changing the
6178 * current buffer, and before applying autocommands.
6179 * When "do_curwin" is TRUE, also check current window.
6182 check_lnums(do_curwin
)
6190 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6191 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6197 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6198 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6199 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6200 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6205 #if defined(FEAT_WINDOWS) || defined(PROTO)
6208 * A snapshot of the window sizes, to restore them after closing the help
6210 * Only these fields are used:
6216 * fr_win (only valid for the old curwin, NULL otherwise)
6220 * Create a snapshot of the current frame sizes.
6226 clear_snapshot(curtab
, idx
);
6227 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
[idx
]);
6231 make_snapshot_rec(fr
, frp
)
6235 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6238 (*frp
)->fr_layout
= fr
->fr_layout
;
6239 # ifdef FEAT_VERTSPLIT
6240 (*frp
)->fr_width
= fr
->fr_width
;
6242 (*frp
)->fr_height
= fr
->fr_height
;
6243 if (fr
->fr_next
!= NULL
)
6244 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6245 if (fr
->fr_child
!= NULL
)
6246 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6247 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6248 (*frp
)->fr_win
= curwin
;
6252 * Remove any existing snapshot.
6255 clear_snapshot(tp
, idx
)
6259 clear_snapshot_rec(tp
->tp_snapshot
[idx
]);
6260 tp
->tp_snapshot
[idx
] = NULL
;
6264 clear_snapshot_rec(fr
)
6269 clear_snapshot_rec(fr
->fr_next
);
6270 clear_snapshot_rec(fr
->fr_child
);
6276 * Restore a previously created snapshot, if there is any.
6277 * This is only done if the screen size didn't change and the window layout is
6281 restore_snapshot(idx
, close_curwin
)
6283 int close_curwin
; /* closing current window */
6287 if (curtab
->tp_snapshot
[idx
] != NULL
6288 # ifdef FEAT_VERTSPLIT
6289 && curtab
->tp_snapshot
[idx
]->fr_width
== topframe
->fr_width
6291 && curtab
->tp_snapshot
[idx
]->fr_height
== topframe
->fr_height
6292 && check_snapshot_rec(curtab
->tp_snapshot
[idx
], topframe
) == OK
)
6294 wp
= restore_snapshot_rec(curtab
->tp_snapshot
[idx
], topframe
);
6296 if (wp
!= NULL
&& close_curwin
)
6298 redraw_all_later(CLEAR
);
6300 clear_snapshot(curtab
, idx
);
6304 * Check if frames "sn" and "fr" have the same layout, same following frames
6305 * and same children.
6308 check_snapshot_rec(sn
, fr
)
6312 if (sn
->fr_layout
!= fr
->fr_layout
6313 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6314 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6315 || (sn
->fr_next
!= NULL
6316 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6317 || (sn
->fr_child
!= NULL
6318 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6324 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6325 * following frames and children.
6326 * Returns a pointer to the old current window, or NULL.
6329 restore_snapshot_rec(sn
, fr
)
6336 fr
->fr_height
= sn
->fr_height
;
6337 # ifdef FEAT_VERTSPLIT
6338 fr
->fr_width
= sn
->fr_width
;
6340 if (fr
->fr_layout
== FR_LEAF
)
6342 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6343 # ifdef FEAT_VERTSPLIT
6344 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6348 if (sn
->fr_next
!= NULL
)
6350 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6354 if (sn
->fr_child
!= NULL
)
6356 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6365 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6367 * Return TRUE if there is any vertically split window.
6374 if (topframe
->fr_layout
== FR_ROW
)
6377 if (topframe
->fr_layout
== FR_COL
)
6378 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6379 if (fr
->fr_layout
== FR_ROW
)
6386 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6388 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6389 * highlighted with the group 'grp' with priority 'prio'.
6390 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6391 * If no particular ID is desired, -1 must be specified for 'id'.
6392 * Return ID of added match, -1 on failure.
6395 match_add(wp
, grp
, pat
, prio
, id
)
6408 if (*grp
== NUL
|| *pat
== NUL
)
6410 if (id
< -1 || id
== 0)
6412 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6417 cur
= wp
->w_match_head
;
6422 EMSGN("E801: ID already taken: %ld", id
);
6428 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6430 EMSG2(_(e_nogroup
), grp
);
6433 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6435 EMSG2(_(e_invarg2
), pat
);
6439 /* Find available match ID. */
6442 cur
= wp
->w_match_head
;
6443 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6446 id
= wp
->w_next_match_id
;
6447 wp
->w_next_match_id
++;
6450 /* Build new match. */
6451 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6454 m
->pattern
= vim_strsave(pat
);
6456 m
->match
.regprog
= regprog
;
6457 m
->match
.rmm_ic
= FALSE
;
6458 m
->match
.rmm_maxcol
= 0;
6460 /* Insert new match. The match list is in ascending order with regard to
6461 * the match priorities. */
6462 cur
= wp
->w_match_head
;
6464 while (cur
!= NULL
&& prio
>= cur
->priority
)
6470 wp
->w_match_head
= m
;
6475 redraw_later(SOME_VALID
);
6480 * Delete match with ID 'id' in the match list of window 'wp'.
6481 * Print error messages if 'perr' is TRUE.
6484 match_delete(wp
, id
, perr
)
6489 matchitem_T
*cur
= wp
->w_match_head
;
6490 matchitem_T
*prev
= cur
;
6495 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6499 while (cur
!= NULL
&& cur
->id
!= id
)
6507 EMSGN("E803: ID not found: %ld", id
);
6511 wp
->w_match_head
= cur
->next
;
6513 prev
->next
= cur
->next
;
6514 vim_free(cur
->match
.regprog
);
6515 vim_free(cur
->pattern
);
6517 redraw_later(SOME_VALID
);
6522 * Delete all matches in the match list of window 'wp'.
6530 while (wp
->w_match_head
!= NULL
)
6532 m
= wp
->w_match_head
->next
;
6533 vim_free(wp
->w_match_head
->match
.regprog
);
6534 vim_free(wp
->w_match_head
->pattern
);
6535 vim_free(wp
->w_match_head
);
6536 wp
->w_match_head
= m
;
6538 redraw_later(SOME_VALID
);
6542 * Get match from ID 'id' in window 'wp'.
6543 * Return NULL if match not found.
6550 matchitem_T
*cur
= wp
->w_match_head
;
6552 while (cur
!= NULL
&& cur
->id
!= id
)