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 #ifdef FEAT_GUI_MACVIM
1101 /* The view may have moved, so clear all or display may get corrupted. */
1102 redraw_win_later(oldwin
, CLEAR
);
1104 redraw_win_later(oldwin
, NOT_VALID
);
1106 oldwin
->w_redr_status
= TRUE
;
1112 msg_clr_eos_force(); /* Old command/ruler may still be there */
1115 msg_col
= 0; /* put position back at start of line */
1119 * equalize the window sizes.
1121 if (do_equal
|| dir
!= 0)
1123 #ifdef FEAT_VERTSPLIT
1124 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1125 : dir
== 'h' ? 'b' :
1129 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1130 * size was given. */
1131 #ifdef FEAT_VERTSPLIT
1132 if (flags
& WSP_VERT
)
1139 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1141 gui_init_which_components(NULL
);
1153 * make the new window the current window
1155 win_enter(wp
, FALSE
);
1156 #ifdef FEAT_VERTSPLIT
1157 if (flags
& WSP_VERT
)
1168 * Initialize window "newp" from window "oldp".
1169 * Used when splitting a window and when creating a new tab page.
1170 * The windows will both edit the same buffer.
1171 * WSP_NEWLOC may be specified in flags to prevent the location list from
1175 win_init(newp
, oldp
, flags
)
1182 newp
->w_buffer
= oldp
->w_buffer
;
1183 oldp
->w_buffer
->b_nwindows
++;
1184 newp
->w_cursor
= oldp
->w_cursor
;
1186 newp
->w_curswant
= oldp
->w_curswant
;
1187 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1188 newp
->w_topline
= oldp
->w_topline
;
1190 newp
->w_topfill
= oldp
->w_topfill
;
1192 newp
->w_leftcol
= oldp
->w_leftcol
;
1193 newp
->w_pcmark
= oldp
->w_pcmark
;
1194 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1195 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1196 newp
->w_wrow
= oldp
->w_wrow
;
1197 newp
->w_fraction
= oldp
->w_fraction
;
1198 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1199 #ifdef FEAT_JUMPLIST
1200 copy_jumplist(oldp
, newp
);
1202 #ifdef FEAT_QUICKFIX
1203 if (flags
& WSP_NEWLOC
)
1205 /* Don't copy the location list. */
1206 newp
->w_llist
= NULL
;
1207 newp
->w_llist_ref
= NULL
;
1210 copy_loclist(oldp
, newp
);
1212 if (oldp
->w_localdir
!= NULL
)
1213 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1215 /* copy tagstack and folds */
1216 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1218 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1219 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1220 newp
->w_tagstack
[i
].tagname
=
1221 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1223 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1224 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1225 # ifdef FEAT_FOLDING
1226 copyFoldingState(oldp
, newp
);
1229 win_init_some(newp
, oldp
);
1233 * Initialize window "newp" from window"old".
1234 * Only the essential things are copied.
1237 win_init_some(newp
, oldp
)
1241 /* Use the same argument list. */
1242 newp
->w_alist
= oldp
->w_alist
;
1243 ++newp
->w_alist
->al_refcount
;
1244 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1246 /* copy options from existing window */
1247 win_copy_options(oldp
, newp
);
1250 #endif /* FEAT_WINDOWS */
1252 #if defined(FEAT_WINDOWS) || defined(PROTO)
1254 * Check if "win" is a pointer to an existing window.
1264 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1271 * Return the number of windows.
1279 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1285 * Make "count" windows on the screen.
1286 * Return actual number of windows on the screen.
1287 * Must be called when there is just one window, filling the whole screen
1288 * (excluding the command line).
1291 make_windows(count
, vertical
)
1293 int vertical UNUSED
; /* split windows vertically if TRUE */
1298 #ifdef FEAT_VERTSPLIT
1301 /* Each windows needs at least 'winminwidth' lines and a separator
1303 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1304 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1309 /* Each window needs at least 'winminheight' lines and a status line. */
1310 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1311 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1316 if (count
> maxcount
)
1320 * add status line now, otherwise first window will be too big
1327 * Don't execute autocommands while creating the windows. Must do that
1328 * when putting the buffers in the windows.
1333 /* todo is number of windows left to create */
1334 for (todo
= count
- 1; todo
> 0; --todo
)
1335 #ifdef FEAT_VERTSPLIT
1338 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1339 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1345 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1346 * STATUS_HEIGHT
) / (todo
+ 1)
1347 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1355 /* return actual number of windows */
1356 return (count
- todo
);
1360 * Exchange current and next window
1363 win_exchange(Prenum
)
1372 if (lastwin
== firstwin
) /* just one window */
1379 need_mouse_correct
= TRUE
;
1383 * find window to exchange with
1387 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1388 while (frp
!= NULL
&& --Prenum
> 0)
1391 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1392 frp
= curwin
->w_frame
->fr_next
;
1393 else /* Swap last window in row/col with previous */
1394 frp
= curwin
->w_frame
->fr_prev
;
1396 /* We can only exchange a window with another window, not with a frame
1397 * containing windows. */
1398 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1403 * 1. remove curwin from the list. Remember after which window it was in wp2
1404 * 2. insert curwin before wp in the list
1406 * 3. remove wp from the list
1407 * 4. insert wp after wp2
1408 * 5. exchange the status line height and vsep width.
1410 wp2
= curwin
->w_prev
;
1411 frp2
= curwin
->w_frame
->fr_prev
;
1412 if (wp
->w_prev
!= curwin
)
1414 win_remove(curwin
, NULL
);
1415 frame_remove(curwin
->w_frame
);
1416 win_append(wp
->w_prev
, curwin
);
1417 frame_insert(frp
, curwin
->w_frame
);
1421 win_remove(wp
, NULL
);
1422 frame_remove(wp
->w_frame
);
1423 win_append(wp2
, wp
);
1425 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1427 frame_append(frp2
, wp
->w_frame
);
1429 temp
= curwin
->w_status_height
;
1430 curwin
->w_status_height
= wp
->w_status_height
;
1431 wp
->w_status_height
= temp
;
1432 #ifdef FEAT_VERTSPLIT
1433 temp
= curwin
->w_vsep_width
;
1434 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1435 wp
->w_vsep_width
= temp
;
1437 /* If the windows are not in the same frame, exchange the sizes to avoid
1438 * messing up the window layout. Otherwise fix the frame sizes. */
1439 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1441 temp
= curwin
->w_height
;
1442 curwin
->w_height
= wp
->w_height
;
1443 wp
->w_height
= temp
;
1444 temp
= curwin
->w_width
;
1445 curwin
->w_width
= wp
->w_width
;
1450 frame_fix_height(curwin
);
1451 frame_fix_height(wp
);
1452 frame_fix_width(curwin
);
1453 frame_fix_width(wp
);
1457 (void)win_comp_pos(); /* recompute window positions */
1459 win_enter(wp
, TRUE
);
1460 redraw_later(CLEAR
);
1464 * rotate windows: if upwards TRUE the second window becomes the first one
1465 * if upwards FALSE the first window becomes the second one
1468 win_rotate(upwards
, count
)
1477 if (firstwin
== lastwin
) /* nothing to do */
1484 need_mouse_correct
= TRUE
;
1487 #ifdef FEAT_VERTSPLIT
1488 /* Check if all frames in this row/col have one window. */
1489 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1491 if (frp
->fr_win
== NULL
)
1493 EMSG(_("E443: Cannot rotate when another window is split"));
1500 if (upwards
) /* first window becomes last window */
1502 /* remove first window/frame from the list */
1503 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1505 win_remove(wp1
, NULL
);
1508 /* find last frame and append removed window/frame after it */
1509 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1511 win_append(frp
->fr_win
, wp1
);
1512 frame_append(frp
, wp1
->w_frame
);
1514 wp2
= frp
->fr_win
; /* previously last window */
1516 else /* last window becomes first window */
1518 /* find last window/frame in the list and remove it */
1519 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1523 wp2
= wp1
->w_prev
; /* will become last window */
1524 win_remove(wp1
, NULL
);
1527 /* append the removed window/frame before the first in the list */
1528 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1529 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1532 /* exchange status height and vsep width of old and new last window */
1533 n
= wp2
->w_status_height
;
1534 wp2
->w_status_height
= wp1
->w_status_height
;
1535 wp1
->w_status_height
= n
;
1536 frame_fix_height(wp1
);
1537 frame_fix_height(wp2
);
1538 #ifdef FEAT_VERTSPLIT
1539 n
= wp2
->w_vsep_width
;
1540 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1541 wp1
->w_vsep_width
= n
;
1542 frame_fix_width(wp1
);
1543 frame_fix_width(wp2
);
1546 /* recompute w_winrow and w_wincol for all windows */
1547 (void)win_comp_pos();
1550 redraw_later(CLEAR
);
1554 * Move the current window to the very top/bottom/left/right of the screen.
1557 win_totop(size
, flags
)
1562 int height
= curwin
->w_height
;
1564 if (lastwin
== firstwin
)
1570 /* Remove the window and frame from the tree of frames. */
1571 (void)winframe_remove(curwin
, &dir
, NULL
);
1572 win_remove(curwin
, NULL
);
1573 last_status(FALSE
); /* may need to remove last status line */
1574 (void)win_comp_pos(); /* recompute window positions */
1576 /* Split a window on the desired side and put the window there. */
1577 (void)win_split_ins(size
, flags
, curwin
, dir
);
1578 if (!(flags
& WSP_VERT
))
1580 win_setheight(height
);
1582 win_equal(curwin
, TRUE
, 'v');
1585 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1586 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1587 * scrollbars. Have to update them anyway. */
1588 gui_may_update_scrollbars();
1593 * Move window "win1" to below/right of "win2" and make "win1" the current
1594 * window. Only works within the same frame!
1597 win_move_after(win1
, win2
)
1602 /* check if the arguments are reasonable */
1606 /* check if there is something to do */
1607 if (win2
->w_next
!= win1
)
1609 /* may need move the status line/vertical separator of the last window
1611 if (win1
== lastwin
)
1613 height
= win1
->w_prev
->w_status_height
;
1614 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1615 win1
->w_status_height
= height
;
1616 #ifdef FEAT_VERTSPLIT
1617 if (win1
->w_prev
->w_vsep_width
== 1)
1619 /* Remove the vertical separator from the last-but-one window,
1620 * add it to the last window. Adjust the frame widths. */
1621 win1
->w_prev
->w_vsep_width
= 0;
1622 win1
->w_prev
->w_frame
->fr_width
-= 1;
1623 win1
->w_vsep_width
= 1;
1624 win1
->w_frame
->fr_width
+= 1;
1628 else if (win2
== lastwin
)
1630 height
= win1
->w_status_height
;
1631 win1
->w_status_height
= win2
->w_status_height
;
1632 win2
->w_status_height
= height
;
1633 #ifdef FEAT_VERTSPLIT
1634 if (win1
->w_vsep_width
== 1)
1636 /* Remove the vertical separator from win1, add it to the last
1637 * window, win2. Adjust the frame widths. */
1638 win2
->w_vsep_width
= 1;
1639 win2
->w_frame
->fr_width
+= 1;
1640 win1
->w_vsep_width
= 0;
1641 win1
->w_frame
->fr_width
-= 1;
1645 win_remove(win1
, NULL
);
1646 frame_remove(win1
->w_frame
);
1647 win_append(win2
, win1
);
1648 frame_append(win2
->w_frame
, win1
->w_frame
);
1650 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1651 redraw_later(NOT_VALID
);
1653 win_enter(win1
, FALSE
);
1657 * Make all windows the same height.
1658 * 'next_curwin' will soon be the current window, make sure it has enough
1662 win_equal(next_curwin
, current
, dir
)
1663 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1664 int current
; /* do only frame with current window */
1665 int dir
; /* 'v' for vertically, 'h' for horizontally,
1666 'b' for both, 0 for using p_ead */
1669 #ifdef FEAT_VERTSPLIT
1674 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1675 topframe
, dir
, 0, tabline_height(),
1676 (int)Columns
, topframe
->fr_height
);
1680 * Set a frame to a new position and height, spreading the available room
1681 * equally over contained frames.
1682 * The window "next_curwin" (if not NULL) should at least get the size from
1683 * 'winheight' and 'winwidth' if possible.
1686 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1687 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1688 int current
; /* do only frame with current window */
1689 frame_T
*topfr
; /* frame to set size off */
1690 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1691 int col
; /* horizontal position for frame */
1692 int row
; /* vertical position for frame */
1693 int width
; /* new width of frame */
1694 int height
; /* new height of frame */
1698 int wincount
, totwincount
= 0;
1700 int next_curwin_size
= 0;
1703 int has_next_curwin
= 0;
1706 if (topfr
->fr_layout
== FR_LEAF
)
1708 /* Set the width/height of this frame.
1709 * Redraw when size or position changes */
1710 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1711 #ifdef FEAT_VERTSPLIT
1712 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1716 topfr
->fr_win
->w_winrow
= row
;
1717 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1718 #ifdef FEAT_VERTSPLIT
1719 topfr
->fr_win
->w_wincol
= col
;
1720 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1722 redraw_all_later(CLEAR
);
1725 #ifdef FEAT_VERTSPLIT
1726 else if (topfr
->fr_layout
== FR_ROW
)
1728 topfr
->fr_width
= width
;
1729 topfr
->fr_height
= height
;
1731 if (dir
!= 'v') /* equalize frame widths */
1733 /* Compute the maximum number of windows horizontally in this
1735 n
= frame_minwidth(topfr
, NOWIN
);
1736 /* add one for the rightmost window, it doesn't have a separator */
1737 if (col
+ width
== Columns
)
1741 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1742 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1745 * Compute width for "next_curwin" window and room available for
1747 * "m" is the minimal width when counting p_wiw for "next_curwin".
1749 m
= frame_minwidth(topfr
, next_curwin
);
1753 next_curwin_size
= p_wiw
+ room
;
1758 next_curwin_size
= -1;
1759 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1761 /* If 'winfixwidth' set keep the window width if
1763 * Watch out for this window being the next_curwin. */
1764 if (frame_fixed_width(fr
))
1766 n
= frame_minwidth(fr
, NOWIN
);
1767 new_size
= fr
->fr_width
;
1768 if (frame_has_win(fr
, next_curwin
))
1770 room
+= p_wiw
- p_wmw
;
1771 next_curwin_size
= 0;
1772 if (new_size
< p_wiw
)
1776 /* These windows don't use up room. */
1777 totwincount
-= (n
+ (fr
->fr_next
== NULL
1778 ? extra_sep
: 0)) / (p_wmw
+ 1);
1779 room
-= new_size
- n
;
1785 fr
->fr_newwidth
= new_size
;
1788 if (next_curwin_size
== -1)
1790 if (!has_next_curwin
)
1791 next_curwin_size
= 0;
1792 else if (totwincount
> 1
1793 && (room
+ (totwincount
- 2))
1794 / (totwincount
- 1) > p_wiw
)
1796 /* Can make all windows wider than 'winwidth', spread
1797 * the room equally. */
1798 next_curwin_size
= (room
+ p_wiw
1799 + (totwincount
- 1) * p_wmw
1800 + (totwincount
- 1)) / totwincount
;
1801 room
-= next_curwin_size
- p_wiw
;
1804 next_curwin_size
= p_wiw
;
1808 if (has_next_curwin
)
1809 --totwincount
; /* don't count curwin */
1812 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1816 if (fr
->fr_next
== NULL
)
1817 /* last frame gets all that remains (avoid roundoff error) */
1819 else if (dir
== 'v')
1820 new_size
= fr
->fr_width
;
1821 else if (frame_fixed_width(fr
))
1823 new_size
= fr
->fr_newwidth
;
1824 wincount
= 0; /* doesn't count as a sizeable window */
1828 /* Compute the maximum number of windows horiz. in "fr". */
1829 n
= frame_minwidth(fr
, NOWIN
);
1830 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1832 m
= frame_minwidth(fr
, next_curwin
);
1833 if (has_next_curwin
)
1834 hnc
= frame_has_win(fr
, next_curwin
);
1837 if (hnc
) /* don't count next_curwin */
1839 if (totwincount
== 0)
1842 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1844 if (hnc
) /* add next_curwin size */
1846 next_curwin_size
-= p_wiw
- (m
- n
);
1847 new_size
+= next_curwin_size
;
1848 room
-= new_size
- next_curwin_size
;
1855 /* Skip frame that is full width when splitting or closing a
1856 * window, unless equalizing all frames. */
1857 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1858 || (new_size
!= fr
->fr_width
)
1859 || frame_has_win(fr
, next_curwin
))
1860 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1864 totwincount
-= wincount
;
1868 else /* topfr->fr_layout == FR_COL */
1870 #ifdef FEAT_VERTSPLIT
1871 topfr
->fr_width
= width
;
1873 topfr
->fr_height
= height
;
1875 if (dir
!= 'h') /* equalize frame heights */
1877 /* Compute maximum number of windows vertically in this frame. */
1878 n
= frame_minheight(topfr
, NOWIN
);
1879 /* add one for the bottom window if it doesn't have a statusline */
1880 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1884 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1885 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1888 * Compute height for "next_curwin" window and room available for
1890 * "m" is the minimal height when counting p_wh for "next_curwin".
1892 m
= frame_minheight(topfr
, next_curwin
);
1896 /* The room is less then 'winheight', use all space for the
1897 * current window. */
1898 next_curwin_size
= p_wh
+ room
;
1903 next_curwin_size
= -1;
1904 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1906 /* If 'winfixheight' set keep the window height if
1908 * Watch out for this window being the next_curwin. */
1909 if (frame_fixed_height(fr
))
1911 n
= frame_minheight(fr
, NOWIN
);
1912 new_size
= fr
->fr_height
;
1913 if (frame_has_win(fr
, next_curwin
))
1915 room
+= p_wh
- p_wmh
;
1916 next_curwin_size
= 0;
1917 if (new_size
< p_wh
)
1921 /* These windows don't use up room. */
1922 totwincount
-= (n
+ (fr
->fr_next
== NULL
1923 ? extra_sep
: 0)) / (p_wmh
+ 1);
1924 room
-= new_size
- n
;
1930 fr
->fr_newheight
= new_size
;
1933 if (next_curwin_size
== -1)
1935 if (!has_next_curwin
)
1936 next_curwin_size
= 0;
1937 else if (totwincount
> 1
1938 && (room
+ (totwincount
- 2))
1939 / (totwincount
- 1) > p_wh
)
1941 /* can make all windows higher than 'winheight',
1942 * spread the room equally. */
1943 next_curwin_size
= (room
+ p_wh
1944 + (totwincount
- 1) * p_wmh
1945 + (totwincount
- 1)) / totwincount
;
1946 room
-= next_curwin_size
- p_wh
;
1949 next_curwin_size
= p_wh
;
1953 if (has_next_curwin
)
1954 --totwincount
; /* don't count curwin */
1957 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1961 if (fr
->fr_next
== NULL
)
1962 /* last frame gets all that remains (avoid roundoff error) */
1964 else if (dir
== 'h')
1965 new_size
= fr
->fr_height
;
1966 else if (frame_fixed_height(fr
))
1968 new_size
= fr
->fr_newheight
;
1969 wincount
= 0; /* doesn't count as a sizeable window */
1973 /* Compute the maximum number of windows vert. in "fr". */
1974 n
= frame_minheight(fr
, NOWIN
);
1975 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1977 m
= frame_minheight(fr
, next_curwin
);
1978 if (has_next_curwin
)
1979 hnc
= frame_has_win(fr
, next_curwin
);
1982 if (hnc
) /* don't count next_curwin */
1984 if (totwincount
== 0)
1987 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1989 if (hnc
) /* add next_curwin size */
1991 next_curwin_size
-= p_wh
- (m
- n
);
1992 new_size
+= next_curwin_size
;
1993 room
-= new_size
- next_curwin_size
;
1999 /* Skip frame that is full width when splitting or closing a
2000 * window, unless equalizing all frames. */
2001 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
2002 || (new_size
!= fr
->fr_height
)
2003 || frame_has_win(fr
, next_curwin
))
2004 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
2008 totwincount
-= wincount
;
2014 * close all windows for buffer 'buf'
2017 close_windows(buf
, keep_curwin
)
2019 int keep_curwin
; /* don't close "curwin" */
2022 tabpage_T
*tp
, *nexttp
;
2023 int h
= tabline_height();
2025 ++RedrawingDisabled
;
2027 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2029 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2031 win_close(wp
, FALSE
);
2033 /* Start all over, autocommands may change the window layout. */
2040 /* Also check windows in other tab pages. */
2041 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2043 nexttp
= tp
->tp_next
;
2045 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2046 if (wp
->w_buffer
== buf
)
2048 win_close_othertab(wp
, FALSE
, tp
);
2050 /* Start all over, the tab page may be closed and
2051 * autocommands may change the window layout. */
2052 nexttp
= first_tabpage
;
2057 --RedrawingDisabled
;
2059 if (h
!= tabline_height())
2064 * Return TRUE if the current window is the only window that exists (ignoring
2066 * Returns FALSE if there is a window, possibly in another tab page.
2071 return (one_window() && first_tabpage
->tp_next
== NULL
);
2075 * Return TRUE if there is only one window other than "aucmd_win" in the
2083 int seen_one
= FALSE
;
2087 if (wp
!= aucmd_win
)
2096 return firstwin
== lastwin
;
2101 * Close window "win". Only works for the current tab page.
2102 * If "free_buf" is TRUE related buffer may be unloaded.
2104 * called by :quit, :close, :xit, :wq and findtag()
2107 win_close(win
, free_buf
)
2113 int other_buffer
= FALSE
;
2115 int close_curwin
= FALSE
;
2117 int help_window
= FALSE
;
2118 tabpage_T
*prev_curtab
= curtab
;
2122 EMSG(_("E444: Cannot close last window"));
2127 if (win
== aucmd_win
)
2129 EMSG(_("E813: Cannot close autocmd window"));
2132 if ((firstwin
== aucmd_win
|| lastwin
== aucmd_win
) && one_window())
2134 EMSG(_("E814: Cannot close window, only autocmd window would remain"));
2140 * When closing the last window in a tab page first go to another tab
2141 * page and then close the window and the tab page. This avoids that
2142 * curwin and curtab are not invalid while we are freeing memory, they may
2143 * be used in GUI events.
2145 if (firstwin
== lastwin
)
2147 goto_tabpage_tp(alt_tabpage());
2148 redraw_tabline
= TRUE
;
2150 /* Safety check: Autocommands may have closed the window when jumping
2151 * to the other tab page. */
2152 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2154 int h
= tabline_height();
2156 win_close_othertab(win
, free_buf
, prev_curtab
);
2157 if (h
!= tabline_height())
2163 /* When closing the help window, try restoring a snapshot after closing
2164 * the window. Otherwise clear the snapshot, it's now invalid. */
2165 if (win
->w_buffer
->b_help
)
2168 clear_snapshot(curtab
, SNAP_HELP_IDX
);
2174 * Guess which window is going to be the new current window.
2175 * This may change because of the autocommands (sigh).
2177 wp
= frame2win(win_altframe(win
, NULL
));
2180 * Be careful: If autocommands delete the window, return now.
2182 if (wp
->w_buffer
!= curbuf
)
2184 other_buffer
= TRUE
;
2185 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2186 if (!win_valid(win
) || last_window())
2189 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2190 if (!win_valid(win
) || last_window())
2193 /* autocmds may abort script processing */
2201 /* Avoid trouble with scrollbars that are going to be deleted in
2208 * Close the link to the buffer.
2210 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2212 /* Autocommands may have closed the window already, or closed the only
2213 * other window or moved to another tab page. */
2214 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2217 /* Free the memory used for the window. */
2218 wp
= win_free_mem(win
, &dir
, NULL
);
2220 /* Make sure curwin isn't invalid. It can cause severe trouble when
2221 * printing an error message. For win_equal() curbuf needs to be valid
2226 #ifdef FEAT_QUICKFIX
2227 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2230 * If the cursor goes to the preview or the quickfix window, try
2231 * finding another window to go to.
2235 if (wp
->w_next
== NULL
)
2241 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2249 curbuf
= curwin
->w_buffer
;
2250 close_curwin
= TRUE
;
2253 #ifdef FEAT_VERTSPLIT
2254 && (*p_ead
== 'b' || *p_ead
== dir
)
2257 win_equal(curwin
, TRUE
,
2258 #ifdef FEAT_VERTSPLIT
2268 win_enter_ext(wp
, FALSE
, TRUE
);
2271 /* careful: after this wp and win may be invalid! */
2272 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2277 * If last window has a status line now and we don't want one,
2278 * remove the status line.
2282 /* After closing the help window, try restoring the window layout from
2283 * before it was opened. */
2285 restore_snapshot(SNAP_HELP_IDX
, close_curwin
);
2287 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2288 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2289 if (gui
.in_use
&& !win_hasvertsplit())
2290 gui_init_which_components(NULL
);
2293 redraw_all_later(NOT_VALID
);
2297 * Close window "win" in tab page "tp", which is not the current tab page.
2298 * This may be the last window ih that tab page and result in closing the tab,
2299 * thus "tp" may become invalid!
2300 * Caller must check if buffer is hidden and whether the tabline needs to be
2304 win_close_othertab(win
, free_buf
, tp
)
2311 tabpage_T
*ptp
= NULL
;
2313 /* Close the link to the buffer. */
2314 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2316 /* Careful: Autocommands may have closed the tab page or made it the
2317 * current tab page. */
2318 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2320 if (ptp
== NULL
|| tp
== curtab
)
2323 /* Autocommands may have closed the window already. */
2324 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2329 /* Free the memory used for the window. */
2330 wp
= win_free_mem(win
, &dir
, tp
);
2332 /* When closing the last window in a tab page remove the tab page. */
2335 if (tp
== first_tabpage
)
2336 first_tabpage
= tp
->tp_next
;
2339 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2344 EMSG2(_(e_intern2
), "win_close_othertab()");
2347 ptp
->tp_next
= tp
->tp_next
;
2354 * Free the memory used for a window.
2355 * Returns a pointer to the window that got the freed up space.
2358 win_free_mem(win
, dirp
, tp
)
2360 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2361 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2366 /* Remove the window and its frame from the tree of frames. */
2368 wp
= winframe_remove(win
, dirp
, tp
);
2372 /* When deleting the current window of another tab page select a new
2373 * current window. */
2374 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2380 #if defined(EXITFREE) || defined(PROTO)
2386 # ifdef FEAT_WINDOWS
2387 while (first_tabpage
->tp_next
!= NULL
)
2388 tabpage_close(TRUE
);
2391 # ifdef FEAT_AUTOCMD
2392 if (aucmd_win
!= NULL
)
2394 (void)win_free_mem(aucmd_win
, &dummy
, NULL
);
2399 while (firstwin
!= NULL
)
2400 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2405 * Remove a window and its frame from the tree of frames.
2406 * Returns a pointer to the window that got the freed up space.
2409 winframe_remove(win
, dirp
, tp
)
2411 int *dirp UNUSED
; /* set to 'v' or 'h' for direction if 'ea' */
2412 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2414 frame_T
*frp
, *frp2
, *frp3
;
2415 frame_T
*frp_close
= win
->w_frame
;
2419 * If there is only one window there is nothing to remove.
2421 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2425 * Remove the window from its frame.
2427 frp2
= win_altframe(win
, tp
);
2428 wp
= frame2win(frp2
);
2430 /* Remove this frame from the list of frames. */
2431 frame_remove(frp_close
);
2433 #ifdef FEAT_VERTSPLIT
2434 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2437 /* When 'winfixheight' is set, try to find another frame in the column
2438 * (as close to the closed frame as possible) to distribute the height
2440 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2442 frp
= frp_close
->fr_prev
;
2443 frp3
= frp_close
->fr_next
;
2444 while (frp
!= NULL
|| frp3
!= NULL
)
2448 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2458 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2464 frp3
= frp3
->fr_next
;
2468 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2469 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2470 #ifdef FEAT_VERTSPLIT
2475 /* When 'winfixwidth' is set, try to find another frame in the column
2476 * (as close to the closed frame as possible) to distribute the width
2478 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2480 frp
= frp_close
->fr_prev
;
2481 frp3
= frp_close
->fr_next
;
2482 while (frp
!= NULL
|| frp3
!= NULL
)
2486 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2496 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2502 frp3
= frp3
->fr_next
;
2506 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2507 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2512 /* If rows/columns go to a window below/right its positions need to be
2513 * updated. Can only be done after the sizes have been updated. */
2514 if (frp2
== frp_close
->fr_next
)
2516 int row
= win
->w_winrow
;
2517 int col
= W_WINCOL(win
);
2519 frame_comp_pos(frp2
, &row
, &col
);
2522 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2524 /* There is no other frame in this list, move its info to the parent
2526 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2527 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2528 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2529 frp
->fr_parent
= frp2
->fr_parent
;
2530 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2531 if (frp2
->fr_win
!= NULL
)
2532 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2533 frp
= frp2
->fr_parent
;
2536 frp2
= frp
->fr_parent
;
2537 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2539 /* The frame above the parent has the same layout, have to merge
2540 * the frames into this list. */
2541 if (frp2
->fr_child
== frp
)
2542 frp2
->fr_child
= frp
->fr_child
;
2543 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2544 if (frp
->fr_prev
!= NULL
)
2545 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2546 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2548 frp3
->fr_parent
= frp2
;
2549 if (frp3
->fr_next
== NULL
)
2551 frp3
->fr_next
= frp
->fr_next
;
2552 if (frp
->fr_next
!= NULL
)
2553 frp
->fr_next
->fr_prev
= frp3
;
2565 * Find out which frame is going to get the freed up space when "win" is
2567 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2568 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2569 * This makes opening a window and closing it immediately keep the same window
2573 win_altframe(win
, tp
)
2575 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2580 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2581 /* Last window in this tab page, will go to next tab page. */
2582 return alt_tabpage()->tp_curwin
->w_frame
;
2585 #ifdef FEAT_VERTSPLIT
2586 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2591 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2592 return frp
->fr_next
;
2593 return frp
->fr_prev
;
2597 * Return the tabpage that will be used if the current one is closed.
2604 /* Use the next tab page if possible. */
2605 if (curtab
->tp_next
!= NULL
)
2606 return curtab
->tp_next
;
2608 /* Find the last but one tab page. */
2609 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2615 * Find the left-upper window in frame "frp".
2621 while (frp
->fr_win
== NULL
)
2622 frp
= frp
->fr_child
;
2627 * Return TRUE if frame "frp" contains window "wp".
2630 frame_has_win(frp
, wp
)
2636 if (frp
->fr_layout
== FR_LEAF
)
2637 return frp
->fr_win
== wp
;
2639 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2640 if (frame_has_win(p
, wp
))
2646 * Set a new height for a frame. Recursively sets the height for contained
2647 * frames and windows. Caller must take care of positions.
2650 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2653 int topfirst
; /* resize topmost contained frame first */
2654 int wfh
; /* obey 'winfixheight' when there is a choice;
2655 may cause the height not to be set */
2661 if (topfrp
->fr_win
!= NULL
)
2663 /* Simple case: just one window. */
2664 win_new_height(topfrp
->fr_win
,
2665 height
- topfrp
->fr_win
->w_status_height
);
2667 #ifdef FEAT_VERTSPLIT
2668 else if (topfrp
->fr_layout
== FR_ROW
)
2672 /* All frames in this row get the same new height. */
2673 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2675 frame_new_height(frp
, height
, topfirst
, wfh
);
2676 if (frp
->fr_height
> height
)
2678 /* Could not fit the windows, make the whole row higher. */
2679 height
= frp
->fr_height
;
2684 while (frp
!= NULL
);
2687 else /* fr_layout == FR_COL */
2689 /* Complicated case: Resize a column of frames. Resize the bottom
2690 * frame first, frames above that when needed. */
2692 frp
= topfrp
->fr_child
;
2694 /* Advance past frames with one window with 'wfh' set. */
2695 while (frame_fixed_height(frp
))
2699 return; /* no frame without 'wfh', give up */
2703 /* Find the bottom frame of this column */
2704 while (frp
->fr_next
!= NULL
)
2707 /* Advance back for frames with one window with 'wfh' set. */
2708 while (frame_fixed_height(frp
))
2712 extra_lines
= height
- topfrp
->fr_height
;
2713 if (extra_lines
< 0)
2715 /* reduce height of contained frames, bottom or top frame first */
2718 h
= frame_minheight(frp
, NULL
);
2719 if (frp
->fr_height
+ extra_lines
< h
)
2721 extra_lines
+= frp
->fr_height
- h
;
2722 frame_new_height(frp
, h
, topfirst
, wfh
);
2726 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2734 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2740 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2742 /* Increase "height" if we could not reduce enough frames. */
2744 height
-= extra_lines
;
2747 else if (extra_lines
> 0)
2749 /* increase height of bottom or top frame */
2750 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2753 topfrp
->fr_height
= height
;
2757 * Return TRUE if height of frame "frp" should not be changed because of
2758 * the 'winfixheight' option.
2761 frame_fixed_height(frp
)
2764 /* frame with one window: fixed height if 'winfixheight' set. */
2765 if (frp
->fr_win
!= NULL
)
2766 return frp
->fr_win
->w_p_wfh
;
2768 if (frp
->fr_layout
== FR_ROW
)
2770 /* The frame is fixed height if one of the frames in the row is fixed
2772 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2773 if (frame_fixed_height(frp
))
2778 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2779 * frames in the row are fixed height. */
2780 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2781 if (!frame_fixed_height(frp
))
2786 #ifdef FEAT_VERTSPLIT
2788 * Return TRUE if width of frame "frp" should not be changed because of
2789 * the 'winfixwidth' option.
2792 frame_fixed_width(frp
)
2795 /* frame with one window: fixed width if 'winfixwidth' set. */
2796 if (frp
->fr_win
!= NULL
)
2797 return frp
->fr_win
->w_p_wfw
;
2799 if (frp
->fr_layout
== FR_COL
)
2801 /* The frame is fixed width if one of the frames in the row is fixed
2803 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2804 if (frame_fixed_width(frp
))
2809 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2810 * frames in the row are fixed width. */
2811 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2812 if (!frame_fixed_width(frp
))
2818 * Add a status line to windows at the bottom of "frp".
2819 * Note: Does not check if there is room!
2822 frame_add_statusline(frp
)
2827 if (frp
->fr_layout
== FR_LEAF
)
2830 if (wp
->w_status_height
== 0)
2832 if (wp
->w_height
> 0) /* don't make it negative */
2834 wp
->w_status_height
= STATUS_HEIGHT
;
2837 else if (frp
->fr_layout
== FR_ROW
)
2839 /* Handle all the frames in the row. */
2840 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2841 frame_add_statusline(frp
);
2843 else /* frp->fr_layout == FR_COL */
2845 /* Only need to handle the last frame in the column. */
2846 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2848 frame_add_statusline(frp
);
2853 * Set width of a frame. Handles recursively going through contained frames.
2854 * May remove separator line for windows at the right side (for win_close()).
2857 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2860 int leftfirst
; /* resize leftmost contained frame first */
2861 int wfw
; /* obey 'winfixwidth' when there is a choice;
2862 may cause the width not to be set */
2869 if (topfrp
->fr_layout
== FR_LEAF
)
2871 /* Simple case: just one window. */
2872 wp
= topfrp
->fr_win
;
2873 /* Find out if there are any windows right of this one. */
2874 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2875 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2877 if (frp
->fr_parent
== NULL
)
2878 wp
->w_vsep_width
= 0;
2879 win_new_width(wp
, width
- wp
->w_vsep_width
);
2881 else if (topfrp
->fr_layout
== FR_COL
)
2885 /* All frames in this column get the same new width. */
2886 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2888 frame_new_width(frp
, width
, leftfirst
, wfw
);
2889 if (frp
->fr_width
> width
)
2891 /* Could not fit the windows, make whole column wider. */
2892 width
= frp
->fr_width
;
2896 } while (frp
!= NULL
);
2898 else /* fr_layout == FR_ROW */
2900 /* Complicated case: Resize a row of frames. Resize the rightmost
2901 * frame first, frames left of it when needed. */
2903 frp
= topfrp
->fr_child
;
2905 /* Advance past frames with one window with 'wfw' set. */
2906 while (frame_fixed_width(frp
))
2910 return; /* no frame without 'wfw', give up */
2914 /* Find the rightmost frame of this row */
2915 while (frp
->fr_next
!= NULL
)
2918 /* Advance back for frames with one window with 'wfw' set. */
2919 while (frame_fixed_width(frp
))
2923 extra_cols
= width
- topfrp
->fr_width
;
2926 /* reduce frame width, rightmost frame first */
2929 w
= frame_minwidth(frp
, NULL
);
2930 if (frp
->fr_width
+ extra_cols
< w
)
2932 extra_cols
+= frp
->fr_width
- w
;
2933 frame_new_width(frp
, w
, leftfirst
, wfw
);
2937 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2945 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2951 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2953 /* Increase "width" if we could not reduce enough frames. */
2955 width
-= extra_cols
;
2958 else if (extra_cols
> 0)
2960 /* increase width of rightmost frame */
2961 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2964 topfrp
->fr_width
= width
;
2968 * Add the vertical separator to windows at the right side of "frp".
2969 * Note: Does not check if there is room!
2977 if (frp
->fr_layout
== FR_LEAF
)
2980 if (wp
->w_vsep_width
== 0)
2982 if (wp
->w_width
> 0) /* don't make it negative */
2984 wp
->w_vsep_width
= 1;
2987 else if (frp
->fr_layout
== FR_COL
)
2989 /* Handle all the frames in the column. */
2990 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2991 frame_add_vsep(frp
);
2993 else /* frp->fr_layout == FR_ROW */
2995 /* Only need to handle the last frame in the row. */
2996 frp
= frp
->fr_child
;
2997 while (frp
->fr_next
!= NULL
)
2999 frame_add_vsep(frp
);
3004 * Set frame width from the window it contains.
3010 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
3015 * Set frame height from the window it contains.
3018 frame_fix_height(wp
)
3021 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
3025 * Compute the minimal height for frame "topfrp".
3026 * Uses the 'winminheight' option.
3027 * When "next_curwin" isn't NULL, use p_wh for this window.
3028 * When "next_curwin" is NOWIN, don't use at least one line for the current
3032 frame_minheight(topfrp
, next_curwin
)
3038 #ifdef FEAT_VERTSPLIT
3042 if (topfrp
->fr_win
!= NULL
)
3044 if (topfrp
->fr_win
== next_curwin
)
3045 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
3048 /* window: minimal height of the window plus status line */
3049 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
3050 /* Current window is minimal one line high */
3051 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3055 #ifdef FEAT_VERTSPLIT
3056 else if (topfrp
->fr_layout
== FR_ROW
)
3058 /* get the minimal height from each frame in this row */
3060 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3062 n
= frame_minheight(frp
, next_curwin
);
3070 /* Add up the minimal heights for all frames in this column. */
3072 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3073 m
+= frame_minheight(frp
, next_curwin
);
3079 #ifdef FEAT_VERTSPLIT
3081 * Compute the minimal width for frame "topfrp".
3082 * When "next_curwin" isn't NULL, use p_wiw for this window.
3083 * When "next_curwin" is NOWIN, don't use at least one column for the current
3087 frame_minwidth(topfrp
, next_curwin
)
3089 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3094 if (topfrp
->fr_win
!= NULL
)
3096 if (topfrp
->fr_win
== next_curwin
)
3097 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3100 /* window: minimal width of the window plus separator column */
3101 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3102 /* Current window is minimal one column wide */
3103 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3107 else if (topfrp
->fr_layout
== FR_COL
)
3109 /* get the minimal width from each frame in this column */
3111 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3113 n
= frame_minwidth(frp
, next_curwin
);
3120 /* Add up the minimal widths for all frames in this row. */
3122 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3123 m
+= frame_minwidth(frp
, next_curwin
);
3132 * Try to close all windows except current one.
3133 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3134 * used and the buffer was modified.
3136 * Used by ":bdel" and ":only".
3139 close_others(message
, forceit
)
3141 int forceit
; /* always hide all other windows */
3158 /* Be very careful here: autocommands may change the window layout. */
3159 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3161 nextwp
= wp
->w_next
;
3162 if (wp
!= curwin
) /* don't close current window */
3165 /* Check if it's allowed to abandon this window */
3166 r
= can_abandon(wp
->w_buffer
, forceit
);
3168 if (!win_valid(wp
)) /* autocommands messed wp up */
3176 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3177 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3179 dialog_changed(wp
->w_buffer
, FALSE
);
3180 # ifdef FEAT_AUTOCMD
3181 if (!win_valid(wp
)) /* autocommands messed wp up */
3188 if (bufIsChanged(wp
->w_buffer
))
3192 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3196 if (message
&& lastwin
!= firstwin
)
3197 EMSG(_("E445: Other window contains changes"));
3200 #endif /* FEAT_WINDOWS */
3203 * Init the current window "curwin".
3204 * Called when a new file is being edited.
3209 win_init_empty(curwin
);
3216 redraw_win_later(wp
, NOT_VALID
);
3217 wp
->w_lines_valid
= 0;
3218 wp
->w_cursor
.lnum
= 1;
3219 wp
->w_curswant
= wp
->w_cursor
.col
= 0;
3220 #ifdef FEAT_VIRTUALEDIT
3221 wp
->w_cursor
.coladd
= 0;
3223 wp
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3224 wp
->w_pcmark
.col
= 0;
3225 wp
->w_prev_pcmark
.lnum
= 0;
3226 wp
->w_prev_pcmark
.col
= 0;
3234 wp
->w_farsi
= W_CONV
+ W_R_L
;
3236 wp
->w_farsi
= W_CONV
;
3241 * Allocate the first window and put an empty buffer in it.
3242 * Called from main().
3243 * Return FAIL when something goes wrong (out of memory).
3248 if (win_alloc_firstwin(NULL
) == FAIL
)
3252 first_tabpage
= alloc_tabpage();
3253 if (first_tabpage
== NULL
)
3255 first_tabpage
->tp_topframe
= topframe
;
3256 curtab
= first_tabpage
;
3262 #if defined(FEAT_AUTOCMD) || defined(PROTO)
3264 * Init "aucmd_win". This can only be done after the first
3265 * window is fully initialized, thus it can't be in win_alloc_first().
3268 win_alloc_aucmd_win()
3270 aucmd_win
= win_alloc(NULL
, TRUE
);
3271 if (aucmd_win
!= NULL
)
3273 win_init_some(aucmd_win
, curwin
);
3274 # ifdef FEAT_SCROLLBIND
3275 aucmd_win
->w_p_scb
= FALSE
;
3277 new_frame(aucmd_win
);
3283 * Allocate the first window or the first window in a new tab page.
3284 * When "oldwin" is NULL create an empty buffer for it.
3285 * When "oldwin" is not NULL copy info from it to the new window (only with
3287 * Return FAIL when something goes wrong (out of memory).
3290 win_alloc_firstwin(oldwin
)
3293 curwin
= win_alloc(NULL
, FALSE
);
3296 /* Very first window, need to create an empty buffer for it and
3297 * initialize from scratch. */
3298 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3299 if (curwin
== NULL
|| curbuf
== NULL
)
3301 curwin
->w_buffer
= curbuf
;
3302 curbuf
->b_nwindows
= 1; /* there is one window */
3304 curwin
->w_alist
= &global_alist
;
3306 curwin_init(); /* init current window */
3311 /* First window in new tab page, initialize it from "oldwin". */
3312 win_init(curwin
, oldwin
, 0);
3314 # ifdef FEAT_SCROLLBIND
3315 /* We don't want scroll-binding in the first window. */
3316 curwin
->w_p_scb
= FALSE
;
3322 if (curwin
->w_frame
== NULL
)
3324 topframe
= curwin
->w_frame
;
3325 #ifdef FEAT_VERTSPLIT
3326 topframe
->fr_width
= Columns
;
3328 topframe
->fr_height
= Rows
- p_ch
;
3329 topframe
->fr_win
= curwin
;
3335 * Create a frame for window "wp".
3338 new_frame(win_T
*wp
)
3340 frame_T
*frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3345 frp
->fr_layout
= FR_LEAF
;
3351 * Initialize the window and frame size to the maximum.
3356 firstwin
->w_height
= ROWS_AVAIL
;
3357 topframe
->fr_height
= ROWS_AVAIL
;
3358 #ifdef FEAT_VERTSPLIT
3359 firstwin
->w_width
= Columns
;
3360 topframe
->fr_width
= Columns
;
3364 #if defined(FEAT_WINDOWS) || defined(PROTO)
3367 * Allocate a new tabpage_T and init the values.
3368 * Returns NULL when out of memory.
3375 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3381 for (i
= 0; i
< 3; i
++)
3382 tp
->tp_prev_which_scrollbars
[i
] = -1;
3385 tp
->tp_diff_invalid
= TRUE
;
3388 /* init t: variables */
3389 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3391 tp
->tp_ch_used
= p_ch
;
3405 for (idx
= 0; idx
< SNAP_COUNT
; ++idx
)
3406 clear_snapshot(tp
, idx
);
3408 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3414 * Create a new Tab page with one window.
3415 * It will edit the current buffer, like after ":split".
3416 * When "after" is 0 put it just after the current Tab page.
3417 * Otherwise put it just before tab page "after".
3418 * Return FAIL or OK.
3421 win_new_tabpage(after
)
3424 tabpage_T
*tp
= curtab
;
3428 newtp
= alloc_tabpage();
3432 /* Remember the current windows in this Tab page. */
3433 if (leave_tabpage(curbuf
) == FAIL
)
3440 /* Create a new empty window. */
3441 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3443 /* Make the new Tab page the new topframe. */
3446 /* New tab page becomes the first one. */
3447 newtp
->tp_next
= first_tabpage
;
3448 first_tabpage
= newtp
;
3454 /* Put new tab page before tab page "after". */
3456 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3457 && n
< after
; tp
= tp
->tp_next
)
3460 newtp
->tp_next
= tp
->tp_next
;
3461 tp
->tp_next
= newtp
;
3464 firstwin
->w_winrow
= tabline_height();
3465 win_comp_scroll(curwin
);
3467 newtp
->tp_topframe
= topframe
;
3470 #if defined(FEAT_GUI)
3471 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3472 * scrollbars. Have to update them anyway. */
3473 gui_may_update_scrollbars();
3476 redraw_all_later(CLEAR
);
3478 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3479 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3484 /* Failed, get back the previous Tab page */
3485 enter_tabpage(curtab
, curbuf
);
3490 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3491 * like with ":split".
3492 * Returns OK if a new tab page was created, FAIL otherwise.
3497 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3501 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3502 postponed_split_tab
= 0;
3503 return win_new_tabpage(n
);
3509 * Create up to "maxcount" tabpages with empty windows.
3510 * Returns the number of resulting tab pages.
3513 make_tabpages(maxcount
)
3516 int count
= maxcount
;
3519 /* Limit to 'tabpagemax' tabs. */
3525 * Don't execute autocommands while creating the tab pages. Must do that
3526 * when putting the buffers in the windows.
3531 for (todo
= count
- 1; todo
> 0; --todo
)
3532 if (win_new_tabpage(0) == FAIL
)
3539 /* return actual number of tab pages */
3540 return (count
- todo
);
3544 * Return TRUE when "tpc" points to a valid tab page.
3552 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3559 * Find tab page "n" (first one is 1). Returns NULL when not found.
3568 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3574 * Get index of tab page "tp". First one has index 1.
3575 * When not found returns number of tab pages plus one.
3584 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3590 * Prepare for leaving the current tab page.
3591 * When autocomands change "curtab" we don't leave the tab page and return
3593 * Careful: When OK is returned need to get a new tab page very very soon!
3596 leave_tabpage(new_curbuf
)
3597 buf_T
*new_curbuf UNUSED
; /* what is going to be the new curbuf,
3600 tabpage_T
*tp
= curtab
;
3603 reset_VIsual_and_resel(); /* stop Visual mode */
3606 if (new_curbuf
!= curbuf
)
3608 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3612 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3615 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3619 #if defined(FEAT_GUI)
3620 /* Remove the scrollbars. They may be added back later. */
3622 gui_remove_scrollbars();
3624 tp
->tp_curwin
= curwin
;
3625 tp
->tp_prevwin
= prevwin
;
3626 tp
->tp_firstwin
= firstwin
;
3627 tp
->tp_lastwin
= lastwin
;
3628 tp
->tp_old_Rows
= Rows
;
3629 tp
->tp_old_Columns
= Columns
;
3636 * Start using tab page "tp".
3637 * Only to be used after leave_tabpage() or freeing the current tab page.
3640 enter_tabpage(tp
, old_curbuf
)
3642 buf_T
*old_curbuf UNUSED
;
3644 int old_off
= tp
->tp_firstwin
->w_winrow
;
3645 win_T
*next_prevwin
= tp
->tp_prevwin
;
3648 firstwin
= tp
->tp_firstwin
;
3649 lastwin
= tp
->tp_lastwin
;
3650 topframe
= tp
->tp_topframe
;
3652 /* We would like doing the TabEnter event first, but we don't have a
3653 * valid current window yet, which may break some commands.
3654 * This triggers autocommands, thus may make "tp" invalid. */
3655 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3656 prevwin
= next_prevwin
;
3659 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3661 if (old_curbuf
!= curbuf
)
3662 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3665 last_status(FALSE
); /* status line may appear or disappear */
3666 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3667 must_redraw
= CLEAR
; /* need to redraw everything */
3669 diff_need_scrollbind
= TRUE
;
3672 /* The tabpage line may have appeared or disappeared, may need to resize
3673 * the frames for that. When the Vim window was resized need to update
3674 * frame sizes too. Use the stored value of p_ch, so that it can be
3675 * different for each tab page. */
3676 p_ch
= curtab
->tp_ch_used
;
3677 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3678 #ifdef FEAT_GUI_TABLINE
3679 && !gui_use_tabline()
3683 #ifdef FEAT_VERTSPLIT
3684 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3685 shell_new_columns(); /* update window widths */
3688 #if defined(FEAT_GUI)
3689 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3690 * scrollbars. Have to update them anyway. */
3691 gui_may_update_scrollbars();
3694 redraw_all_later(CLEAR
);
3698 * Go to tab page "n". For ":tab N" and "Ngt".
3699 * When "n" is 9999 go to the last tab page.
3711 /* Not allowed when editing the command line. */
3713 if (cmdwin_type
!= 0)
3721 /* If there is only one it can't work. */
3722 if (first_tabpage
->tp_next
== NULL
)
3731 /* No count, go to next tab page, wrap around end. */
3732 if (curtab
->tp_next
== NULL
)
3735 tp
= curtab
->tp_next
;
3739 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3742 for (i
= n
; i
< 0; ++i
)
3744 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3752 /* Go to last tab page. */
3753 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3758 /* Go to tab page "n". */
3759 tp
= find_tabpage(n
);
3767 goto_tabpage_tp(tp
);
3769 #ifdef FEAT_GUI_TABLINE
3770 if (gui_use_tabline())
3771 gui_mch_set_curtab(tabpage_index(curtab
));
3776 * Go to tabpage "tp".
3777 * Note: doesn't update the GUI tab.
3783 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3785 if (valid_tabpage(tp
))
3786 enter_tabpage(tp
, curbuf
);
3788 enter_tabpage(curtab
, curbuf
);
3793 * Enter window "wp" in tab page "tp".
3794 * Also updates the GUI tab.
3797 goto_tabpage_win(tp
, wp
)
3801 goto_tabpage_tp(tp
);
3802 if (curtab
== tp
&& win_valid(wp
))
3804 win_enter(wp
, TRUE
);
3805 # ifdef FEAT_GUI_TABLINE
3806 if (gui_use_tabline())
3807 gui_mch_set_curtab(tabpage_index(curtab
));
3813 * Move the current tab page to before tab page "nr".
3822 if (first_tabpage
->tp_next
== NULL
)
3825 /* Remove the current tab page from the list of tab pages. */
3826 if (curtab
== first_tabpage
)
3827 first_tabpage
= curtab
->tp_next
;
3830 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3831 if (tp
->tp_next
== curtab
)
3833 if (tp
== NULL
) /* "cannot happen" */
3835 tp
->tp_next
= curtab
->tp_next
;
3838 /* Re-insert it at the specified position. */
3841 curtab
->tp_next
= first_tabpage
;
3842 first_tabpage
= curtab
;
3846 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3848 curtab
->tp_next
= tp
->tp_next
;
3849 tp
->tp_next
= curtab
;
3852 /* Need to redraw the tabline. Tab page contents doesn't change. */
3853 redraw_tabline
= TRUE
;
3858 * Go to another window.
3859 * When jumping to another buffer, stop Visual mode. Do this before
3860 * changing windows so we can yank the selection into the '*' register.
3861 * When jumping to another window on the same buffer, adjust its cursor
3862 * position to keep the same Visual area.
3875 if (curbuf_locked())
3880 if (wp
->w_buffer
!= curbuf
)
3881 reset_VIsual_and_resel();
3882 else if (VIsual_active
)
3883 wp
->w_cursor
= curwin
->w_cursor
;
3887 need_mouse_correct
= TRUE
;
3889 win_enter(wp
, TRUE
);
3892 #if defined(FEAT_PERL) || defined(PROTO)
3894 * Find window number "winnr" (counting top to bottom).
3902 # ifdef FEAT_WINDOWS
3903 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3913 #ifdef FEAT_VERTSPLIT
3915 * Move to window above or below "count" times.
3918 win_goto_ver(up
, count
)
3919 int up
; /* TRUE to go to win above */
3926 foundfr
= curwin
->w_frame
;
3930 * First go upwards in the tree of frames until we find a upwards or
3931 * downwards neighbor.
3942 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3948 * Now go downwards to find the bottom or top frame in it.
3952 if (nfr
->fr_layout
== FR_LEAF
)
3958 if (nfr
->fr_layout
== FR_ROW
)
3960 /* Find the frame at the cursor row. */
3961 while (fr
->fr_next
!= NULL
3962 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3963 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3966 if (nfr
->fr_layout
== FR_COL
&& up
)
3967 while (fr
->fr_next
!= NULL
)
3973 if (foundfr
!= NULL
)
3974 win_goto(foundfr
->fr_win
);
3978 * Move to left or right window.
3981 win_goto_hor(left
, count
)
3982 int left
; /* TRUE to go to left win */
3989 foundfr
= curwin
->w_frame
;
3993 * First go upwards in the tree of frames until we find a left or
4005 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
4011 * Now go downwards to find the leftmost or rightmost frame in it.
4015 if (nfr
->fr_layout
== FR_LEAF
)
4021 if (nfr
->fr_layout
== FR_COL
)
4023 /* Find the frame at the cursor row. */
4024 while (fr
->fr_next
!= NULL
4025 && frame2win(fr
)->w_winrow
+ fr
->fr_height
4026 <= curwin
->w_winrow
+ curwin
->w_wrow
)
4029 if (nfr
->fr_layout
== FR_ROW
&& left
)
4030 while (fr
->fr_next
!= NULL
)
4036 if (foundfr
!= NULL
)
4037 win_goto(foundfr
->fr_win
);
4042 * Make window "wp" the current window.
4045 win_enter(wp
, undo_sync
)
4049 win_enter_ext(wp
, undo_sync
, FALSE
);
4053 * Make window wp the current window.
4054 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
4055 * been closed and isn't valid.
4058 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
4064 int other_buffer
= FALSE
;
4067 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
4071 if (!curwin_invalid
)
4074 * Be careful: If autocommands delete the window, return now.
4076 if (wp
->w_buffer
!= curbuf
)
4078 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4079 other_buffer
= TRUE
;
4083 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4087 /* autocmds may abort script processing */
4094 /* sync undo before leaving the current buffer */
4095 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4097 /* may have to copy the buffer options when 'cpo' contains 'S' */
4098 if (wp
->w_buffer
!= curbuf
)
4099 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4100 if (!curwin_invalid
)
4102 prevwin
= curwin
; /* remember for CTRL-W p */
4103 curwin
->w_redr_status
= TRUE
;
4106 curbuf
= wp
->w_buffer
;
4108 #ifdef FEAT_VIRTUALEDIT
4109 if (!virtual_active())
4110 curwin
->w_cursor
.coladd
= 0;
4112 changed_line_abv_curs(); /* assume cursor position needs updating */
4114 if (curwin
->w_localdir
!= NULL
)
4116 /* Window has a local directory: Save current directory as global
4117 * directory (unless that was done already) and change to the local
4119 if (globaldir
== NULL
)
4121 char_u cwd
[MAXPATHL
];
4123 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4124 globaldir
= vim_strsave(cwd
);
4126 if (mch_chdir((char *)curwin
->w_localdir
) == 0)
4127 shorten_fnames(TRUE
);
4129 else if (globaldir
!= NULL
)
4131 /* Window doesn't have a local directory and we are not in the global
4132 * directory: Change to the global directory. */
4133 ignored
= mch_chdir((char *)globaldir
);
4134 vim_free(globaldir
);
4136 shorten_fnames(TRUE
);
4140 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4142 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4148 curwin
->w_redr_status
= TRUE
;
4149 redraw_tabline
= TRUE
;
4151 redraw_later(VALID
); /* causes status line redraw */
4153 /* set window height to desired minimal value */
4154 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4155 win_setheight((int)p_wh
);
4156 else if (curwin
->w_height
== 0)
4159 #ifdef FEAT_VERTSPLIT
4160 /* set window width to desired minimal value */
4161 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4162 win_setwidth((int)p_wiw
);
4166 setmouse(); /* in case jumped to/from help buffer */
4169 /* Change directories when the 'acd' option is set. */
4173 #endif /* FEAT_WINDOWS */
4175 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4177 * Jump to the first open window that contains buffer "buf", if one exists.
4178 * Returns a pointer to the window found, otherwise NULL.
4181 buf_jump_open_win(buf
)
4184 # ifdef FEAT_WINDOWS
4187 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4188 if (wp
->w_buffer
== buf
)
4191 win_enter(wp
, FALSE
);
4194 if (curwin
->w_buffer
== buf
)
4201 * Jump to the first open window in any tab page that contains buffer "buf",
4203 * Returns a pointer to the window found, otherwise NULL.
4206 buf_jump_open_tab(buf
)
4209 # ifdef FEAT_WINDOWS
4213 /* First try the current tab page. */
4214 wp
= buf_jump_open_win(buf
);
4218 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4221 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4222 if (wp
->w_buffer
== buf
)
4226 goto_tabpage_win(tp
, wp
);
4228 wp
= NULL
; /* something went wrong */
4235 if (curwin
->w_buffer
== buf
)
4243 * Allocate a window structure and link it in the window list when "hidden" is
4247 win_alloc(after
, hidden
)
4248 win_T
*after UNUSED
;
4254 * allocate window structure and linesizes arrays
4256 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4257 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4266 /* Don't execute autocommands while the window is not properly
4267 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4272 * link the window in the window list
4276 win_append(after
, newwin
);
4278 #ifdef FEAT_VERTSPLIT
4279 newwin
->w_wincol
= 0;
4280 newwin
->w_width
= Columns
;
4283 /* position the display and the cursor at the top of the file. */
4284 newwin
->w_topline
= 1;
4286 newwin
->w_topfill
= 0;
4288 newwin
->w_botline
= 2;
4289 newwin
->w_cursor
.lnum
= 1;
4290 #ifdef FEAT_SCROLLBIND
4291 newwin
->w_scbind_pos
= 1;
4294 /* We won't calculate w_fraction until resizing the window */
4295 newwin
->w_fraction
= 0;
4296 newwin
->w_prev_fraction_row
= -1;
4301 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4303 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4304 SBAR_RIGHT
, newwin
);
4308 /* init w: variables */
4309 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4312 foldInitWin(newwin
);
4317 #ifdef FEAT_SEARCH_EXTRA
4318 newwin
->w_match_head
= NULL
;
4319 newwin
->w_next_match_id
= 4;
4325 #if defined(FEAT_WINDOWS) || defined(PROTO)
4328 * remove window 'wp' from the window list and free the structure
4333 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4341 /* reduce the reference count to the argument list. */
4342 alist_unlink(wp
->w_alist
);
4345 /* Don't execute autocommands while the window is halfway being deleted.
4346 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4350 #ifdef FEAT_MZSCHEME
4351 mzscheme_window_free(wp
);
4359 python_window_free(wp
);
4363 tcl_window_free(wp
);
4367 ruby_window_free(wp
);
4370 clear_winopt(&wp
->w_onebuf_opt
);
4371 clear_winopt(&wp
->w_allbuf_opt
);
4374 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4381 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4382 vim_free(wp
->w_tagstack
[i
].tagname
);
4384 vim_free(wp
->w_localdir
);
4386 #ifdef FEAT_SEARCH_EXTRA
4390 #ifdef FEAT_JUMPLIST
4394 #ifdef FEAT_QUICKFIX
4401 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4402 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4404 #endif /* FEAT_GUI */
4407 if (wp
!= aucmd_win
)
4418 * Append window "wp" in the window list after window "after".
4421 win_append(after
, wp
)
4426 if (after
== NULL
) /* after NULL is in front of the first */
4429 before
= after
->w_next
;
4431 wp
->w_next
= before
;
4440 before
->w_prev
= wp
;
4444 * Remove a window from the window list.
4449 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4451 if (wp
->w_prev
!= NULL
)
4452 wp
->w_prev
->w_next
= wp
->w_next
;
4453 else if (tp
== NULL
)
4454 firstwin
= wp
->w_next
;
4456 tp
->tp_firstwin
= wp
->w_next
;
4457 if (wp
->w_next
!= NULL
)
4458 wp
->w_next
->w_prev
= wp
->w_prev
;
4459 else if (tp
== NULL
)
4460 lastwin
= wp
->w_prev
;
4462 tp
->tp_lastwin
= wp
->w_prev
;
4466 * Append frame "frp" in a frame list after frame "after".
4469 frame_append(after
, frp
)
4470 frame_T
*after
, *frp
;
4472 frp
->fr_next
= after
->fr_next
;
4473 after
->fr_next
= frp
;
4474 if (frp
->fr_next
!= NULL
)
4475 frp
->fr_next
->fr_prev
= frp
;
4476 frp
->fr_prev
= after
;
4480 * Insert frame "frp" in a frame list before frame "before".
4483 frame_insert(before
, frp
)
4484 frame_T
*before
, *frp
;
4486 frp
->fr_next
= before
;
4487 frp
->fr_prev
= before
->fr_prev
;
4488 before
->fr_prev
= frp
;
4489 if (frp
->fr_prev
!= NULL
)
4490 frp
->fr_prev
->fr_next
= frp
;
4492 frp
->fr_parent
->fr_child
= frp
;
4496 * Remove a frame from a frame list.
4502 if (frp
->fr_prev
!= NULL
)
4503 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4505 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4506 if (frp
->fr_next
!= NULL
)
4507 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4510 #endif /* FEAT_WINDOWS */
4513 * Allocate w_lines[] for window "wp".
4514 * Return FAIL for failure, OK for success.
4520 wp
->w_lines_valid
= 0;
4521 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4522 if (wp
->w_lines
== NULL
)
4528 * free lsize arrays for a window
4534 vim_free(wp
->w_lines
);
4539 * Called from win_new_shellsize() after Rows changed.
4540 * This only does the current tab page, others must be done when made active.
4545 int h
= (int)ROWS_AVAIL
;
4547 if (firstwin
== NULL
) /* not initialized yet */
4550 if (h
< frame_minheight(topframe
, NULL
))
4551 h
= frame_minheight(topframe
, NULL
);
4553 /* First try setting the heights of windows with 'winfixheight'. If
4554 * that doesn't result in the right height, forget about that option. */
4555 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4556 if (topframe
->fr_height
!= h
)
4557 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4559 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4563 win_new_height(firstwin
, h
);
4567 curtab
->tp_ch_used
= p_ch
;
4571 /* Disabled: don't want making the screen smaller make a window larger. */
4573 win_equal(curwin
, FALSE
, 'v');
4577 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4579 * Called from win_new_shellsize() after Columns changed.
4584 if (firstwin
== NULL
) /* not initialized yet */
4587 /* First try setting the widths of windows with 'winfixwidth'. If that
4588 * doesn't result in the right width, forget about that option. */
4589 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4590 if (topframe
->fr_width
!= Columns
)
4591 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4593 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4595 /* Disabled: don't want making the screen smaller make a window larger. */
4597 win_equal(curwin
, FALSE
, 'h');
4602 #if defined(FEAT_CMDWIN) || defined(PROTO)
4604 * Save the size of all windows in "gap".
4613 ga_init2(gap
, (int)sizeof(int), 1);
4614 if (ga_grow(gap
, win_count() * 2) == OK
)
4615 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4617 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4618 wp
->w_width
+ wp
->w_vsep_width
;
4619 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4624 * Restore window sizes, but only if the number of windows is still the same.
4625 * Does not free the growarray.
4628 win_size_restore(gap
)
4634 if (win_count() * 2 == gap
->ga_len
)
4637 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4639 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4640 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4642 /* recompute the window positions */
4643 (void)win_comp_pos();
4646 #endif /* FEAT_CMDWIN */
4648 #if defined(FEAT_WINDOWS) || defined(PROTO)
4650 * Update the position for all windows, using the width and height of the
4652 * Returns the row just after the last window.
4657 int row
= tabline_height();
4660 frame_comp_pos(topframe
, &row
, &col
);
4665 * Update the position of the windows in frame "topfrp", using the width and
4666 * height of the frames.
4667 * "*row" and "*col" are the top-left position of the frame. They are updated
4668 * to the bottom-right position plus one.
4671 frame_comp_pos(topfrp
, row
, col
)
4678 #ifdef FEAT_VERTSPLIT
4683 wp
= topfrp
->fr_win
;
4686 if (wp
->w_winrow
!= *row
4687 #ifdef FEAT_VERTSPLIT
4688 || wp
->w_wincol
!= *col
4692 /* position changed, redraw */
4693 wp
->w_winrow
= *row
;
4694 #ifdef FEAT_VERTSPLIT
4695 wp
->w_wincol
= *col
;
4697 redraw_win_later(wp
, NOT_VALID
);
4698 wp
->w_redr_status
= TRUE
;
4700 *row
+= wp
->w_height
+ wp
->w_status_height
;
4701 #ifdef FEAT_VERTSPLIT
4702 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4707 #ifdef FEAT_VERTSPLIT
4711 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4713 #ifdef FEAT_VERTSPLIT
4714 if (topfrp
->fr_layout
== FR_ROW
)
4715 *row
= startrow
; /* all frames are at the same row */
4717 *col
= startcol
; /* all frames are at the same col */
4719 frame_comp_pos(frp
, row
, col
);
4724 #endif /* FEAT_WINDOWS */
4727 * Set current window height and take care of repositioning other windows to
4731 win_setheight(height
)
4734 win_setheight_win(height
, curwin
);
4738 * Set the window height of window "win" and take care of repositioning other
4739 * windows to fit around it.
4742 win_setheight_win(height
, win
)
4750 /* Always keep current window at least one line high, even when
4751 * 'winminheight' is zero. */
4761 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4763 /* recompute the window positions */
4764 row
= win_comp_pos();
4766 if (height
> topframe
->fr_height
)
4767 height
= topframe
->fr_height
;
4768 win
->w_height
= height
;
4773 * If there is extra space created between the last window and the command
4776 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4777 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4782 redraw_all_later(NOT_VALID
);
4785 #if defined(FEAT_WINDOWS) || defined(PROTO)
4788 * Set the height of a frame to "height" and take care that all frames and
4789 * windows inside it are resized. Also resize frames on the left and right if
4790 * the are in the same FR_ROW frame.
4793 * If the frame is part of a FR_COL frame, try fitting the frame in that
4794 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4795 * go to containing frames to resize them and make room.
4796 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4797 * Check for the minimal height of the FR_ROW frame.
4798 * At the top level we can also use change the command line height.
4801 frame_setheight(curfrp
, height
)
4805 int room
; /* total number of lines available */
4806 int take
; /* number of lines taken from other windows */
4807 int room_cmdline
; /* lines available from cmdline */
4813 /* If the height already is the desired value, nothing to do. */
4814 if (curfrp
->fr_height
== height
)
4817 if (curfrp
->fr_parent
== NULL
)
4819 /* topframe: can only change the command line */
4820 if (height
> ROWS_AVAIL
)
4821 height
= ROWS_AVAIL
;
4823 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4825 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4827 /* Row of frames: Also need to resize frames left and right of this
4828 * one. First check for the minimal height of these. */
4829 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4832 frame_setheight(curfrp
->fr_parent
, height
);
4837 * Column of frames: try to change only frames in this column.
4839 #ifdef FEAT_VERTSPLIT
4842 * 1: compute room available, if it's not enough try resizing the
4844 * 2: compute the room available and adjust the height to it.
4845 * Try not to reduce the height of a window with 'winfixheight' set.
4847 for (run
= 1; run
<= 2; ++run
)
4854 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4858 && frp
->fr_win
!= NULL
4859 && frp
->fr_win
->w_p_wfh
)
4860 room_reserved
+= frp
->fr_height
;
4861 room
+= frp
->fr_height
;
4863 room
-= frame_minheight(frp
, NULL
);
4865 #ifdef FEAT_VERTSPLIT
4866 if (curfrp
->fr_width
!= Columns
)
4871 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4872 + lastwin
->w_height
+ lastwin
->w_status_height
);
4873 if (room_cmdline
< 0)
4877 if (height
<= room
+ room_cmdline
)
4879 #ifdef FEAT_VERTSPLIT
4880 if (run
== 2 || curfrp
->fr_width
== Columns
)
4883 if (height
> room
+ room_cmdline
)
4884 height
= room
+ room_cmdline
;
4887 #ifdef FEAT_VERTSPLIT
4888 frame_setheight(curfrp
->fr_parent
, height
4889 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4895 * Compute the number of lines we will take from others frames (can be
4898 take
= height
- curfrp
->fr_height
;
4900 /* If there is not enough room, also reduce the height of a window
4901 * with 'winfixheight' set. */
4902 if (height
> room
+ room_cmdline
- room_reserved
)
4903 room_reserved
= room
+ room_cmdline
- height
;
4904 /* If there is only a 'winfixheight' window and making the
4905 * window smaller, need to make the other window taller. */
4906 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4909 if (take
> 0 && room_cmdline
> 0)
4911 /* use lines from cmdline first */
4912 if (take
< room_cmdline
)
4913 room_cmdline
= take
;
4914 take
-= room_cmdline
;
4915 topframe
->fr_height
+= room_cmdline
;
4919 * set the current frame to the new height
4921 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4924 * First take lines from the frames after the current frame. If
4925 * that is not enough, takes lines from frames above the current
4928 for (run
= 0; run
< 2; ++run
)
4931 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4933 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4934 while (frp
!= NULL
&& take
!= 0)
4936 h
= frame_minheight(frp
, NULL
);
4937 if (room_reserved
> 0
4938 && frp
->fr_win
!= NULL
4939 && frp
->fr_win
->w_p_wfh
)
4941 if (room_reserved
>= frp
->fr_height
)
4942 room_reserved
-= frp
->fr_height
;
4945 if (frp
->fr_height
- room_reserved
> take
)
4946 room_reserved
= frp
->fr_height
- take
;
4947 take
-= frp
->fr_height
- room_reserved
;
4948 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4954 if (frp
->fr_height
- take
< h
)
4956 take
-= frp
->fr_height
- h
;
4957 frame_new_height(frp
, h
, FALSE
, FALSE
);
4961 frame_new_height(frp
, frp
->fr_height
- take
,
4975 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4977 * Set current window width and take care of repositioning other windows to
4984 win_setwidth_win(width
, curwin
);
4988 win_setwidth_win(width
, wp
)
4992 /* Always keep current window at least one column wide, even when
4993 * 'winminwidth' is zero. */
5002 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
5004 /* recompute the window positions */
5005 (void)win_comp_pos();
5007 redraw_all_later(NOT_VALID
);
5011 * Set the width of a frame to "width" and take care that all frames and
5012 * windows inside it are resized. Also resize frames above and below if the
5013 * are in the same FR_ROW frame.
5015 * Strategy is similar to frame_setheight().
5018 frame_setwidth(curfrp
, width
)
5022 int room
; /* total number of lines available */
5023 int take
; /* number of lines taken from other windows */
5029 /* If the width already is the desired value, nothing to do. */
5030 if (curfrp
->fr_width
== width
)
5033 if (curfrp
->fr_parent
== NULL
)
5034 /* topframe: can't change width */
5037 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
5039 /* Column of frames: Also need to resize frames above and below of
5040 * this one. First check for the minimal width of these. */
5041 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
5044 frame_setwidth(curfrp
->fr_parent
, width
);
5049 * Row of frames: try to change only frames in this row.
5052 * 1: compute room available, if it's not enough try resizing the
5054 * 2: compute the room available and adjust the width to it.
5056 for (run
= 1; run
<= 2; ++run
)
5060 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
5064 && frp
->fr_win
!= NULL
5065 && frp
->fr_win
->w_p_wfw
)
5066 room_reserved
+= frp
->fr_width
;
5067 room
+= frp
->fr_width
;
5069 room
-= frame_minwidth(frp
, NULL
);
5074 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
5080 frame_setwidth(curfrp
->fr_parent
, width
5081 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
5085 * Compute the number of lines we will take from others frames (can be
5088 take
= width
- curfrp
->fr_width
;
5090 /* If there is not enough room, also reduce the width of a window
5091 * with 'winfixwidth' set. */
5092 if (width
> room
- room_reserved
)
5093 room_reserved
= room
- width
;
5094 /* If there is only a 'winfixwidth' window and making the
5095 * window smaller, need to make the other window narrower. */
5096 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
5100 * set the current frame to the new width
5102 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
5105 * First take lines from the frames right of the current frame. If
5106 * that is not enough, takes lines from frames left of the current
5109 for (run
= 0; run
< 2; ++run
)
5112 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5114 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5115 while (frp
!= NULL
&& take
!= 0)
5117 w
= frame_minwidth(frp
, NULL
);
5118 if (room_reserved
> 0
5119 && frp
->fr_win
!= NULL
5120 && frp
->fr_win
->w_p_wfw
)
5122 if (room_reserved
>= frp
->fr_width
)
5123 room_reserved
-= frp
->fr_width
;
5126 if (frp
->fr_width
- room_reserved
> take
)
5127 room_reserved
= frp
->fr_width
- take
;
5128 take
-= frp
->fr_width
- room_reserved
;
5129 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5135 if (frp
->fr_width
- take
< w
)
5137 take
-= frp
->fr_width
- w
;
5138 frame_new_width(frp
, w
, FALSE
, FALSE
);
5142 frame_new_width(frp
, frp
->fr_width
- take
,
5155 #endif /* FEAT_VERTSPLIT */
5158 * Check 'winminheight' for a valid value.
5167 /* loop until there is a 'winminheight' that is possible */
5170 /* TODO: handle vertical splits */
5172 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5173 room
+= wp
->w_height
- p_wmh
;
5188 * Status line of dragwin is dragged "offset" lines down (negative is up).
5191 win_drag_status_line(dragwin
, offset
)
5199 int up
; /* if TRUE, drag status line up, otherwise down */
5202 fr
= dragwin
->w_frame
;
5204 if (fr
!= topframe
) /* more than one window */
5207 /* When the parent frame is not a column of frames, its parent should
5209 if (fr
->fr_layout
!= FR_COL
)
5212 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5217 /* If this is the last frame in a column, may want to resize the parent
5218 * frame instead (go two up to skip a row of frames). */
5219 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5228 if (offset
< 0) /* drag up */
5232 /* sum up the room of the current frame and above it */
5235 /* only one window */
5236 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5241 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5243 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5248 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5250 else /* drag down */
5254 * Only dragging the last status line can reduce p_ch.
5256 room
= Rows
- cmdline_row
;
5257 if (curfr
->fr_next
== NULL
)
5263 /* sum up the room of frames below of the current one */
5264 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5265 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5266 fr
= curfr
; /* put fr at window that grows */
5269 if (room
< offset
) /* Not enough room */
5270 offset
= room
; /* Move as far as we can */
5275 * Grow frame fr by "offset" lines.
5276 * Doesn't happen when dragging the last status line up.
5279 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5282 fr
= curfr
; /* current frame gets smaller */
5284 fr
= curfr
->fr_next
; /* next frame gets smaller */
5287 * Now make the other frames smaller.
5289 while (fr
!= NULL
&& offset
> 0)
5291 n
= frame_minheight(fr
, NULL
);
5292 if (fr
->fr_height
- offset
<= n
)
5294 offset
-= fr
->fr_height
- n
;
5295 frame_new_height(fr
, n
, !up
, FALSE
);
5299 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5307 row
= win_comp_pos();
5308 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5310 p_ch
= Rows
- cmdline_row
;
5313 curtab
->tp_ch_used
= p_ch
;
5314 redraw_all_later(SOME_VALID
);
5318 #ifdef FEAT_VERTSPLIT
5320 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5323 win_drag_vsep_line(dragwin
, offset
)
5330 int left
; /* if TRUE, drag separator line left, otherwise right */
5333 fr
= dragwin
->w_frame
;
5334 if (fr
== topframe
) /* only one window (cannot happen?) */
5338 /* When the parent frame is not a row of frames, its parent should be. */
5339 if (fr
->fr_layout
!= FR_ROW
)
5341 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5347 /* If this is the last frame in a row, may want to resize a parent
5349 while (curfr
->fr_next
== NULL
)
5362 if (offset
< 0) /* drag left */
5366 /* sum up the room of the current frame and left of it */
5368 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5370 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5374 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5376 else /* drag right */
5379 /* sum up the room of frames right of the current one */
5381 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5382 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5383 fr
= curfr
; /* put fr at window that grows */
5386 if (room
< offset
) /* Not enough room */
5387 offset
= room
; /* Move as far as we can */
5388 if (offset
<= 0) /* No room at all, quit. */
5391 /* grow frame fr by offset lines */
5392 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5394 /* shrink other frames: current and at the left or at the right */
5396 fr
= curfr
; /* current frame gets smaller */
5398 fr
= curfr
->fr_next
; /* next frame gets smaller */
5400 while (fr
!= NULL
&& offset
> 0)
5402 n
= frame_minwidth(fr
, NULL
);
5403 if (fr
->fr_width
- offset
<= n
)
5405 offset
-= fr
->fr_width
- n
;
5406 frame_new_width(fr
, n
, !left
, FALSE
);
5410 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5418 (void)win_comp_pos();
5419 redraw_all_later(NOT_VALID
);
5421 #endif /* FEAT_VERTSPLIT */
5422 #endif /* FEAT_MOUSE */
5424 #endif /* FEAT_WINDOWS */
5427 * Set the height of a window.
5428 * This takes care of the things inside the window, not what happens to the
5429 * window position, the frame or to other windows.
5432 win_new_height(wp
, height
)
5437 int sline
, line_size
;
5438 #define FRACTION_MULT 16384L
5440 /* Don't want a negative height. Happens when splitting a tiny window.
5441 * Will equalize heights soon to fix it. */
5444 if (wp
->w_height
== height
)
5445 return; /* nothing to do */
5447 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5448 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5449 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5451 wp
->w_height
= height
;
5454 /* Don't change w_topline when height is zero. Don't set w_topline when
5455 * 'scrollbind' is set and this isn't the current window. */
5457 #ifdef FEAT_SCROLLBIND
5458 && (!wp
->w_p_scb
|| wp
== curwin
)
5463 * Find a value for w_topline that shows the cursor at the same
5464 * relative position in the window as before (more or less).
5466 lnum
= wp
->w_cursor
.lnum
;
5467 if (lnum
< 1) /* can happen when starting up */
5469 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5470 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5471 sline
= wp
->w_wrow
- line_size
;
5475 /* Make sure the whole cursor line is visible, if possible. */
5476 int rows
= plines_win(wp
, lnum
, FALSE
);
5478 if (sline
> wp
->w_height
- rows
)
5480 sline
= wp
->w_height
- rows
;
5481 wp
->w_wrow
-= rows
- line_size
;
5488 * Cursor line would go off top of screen if w_wrow was this high.
5489 * Make cursor line the first line in the window. If not enough
5490 * room use w_skipcol;
5492 wp
->w_wrow
= line_size
;
5493 if (wp
->w_wrow
>= wp
->w_height
5494 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5496 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5498 while (wp
->w_wrow
>= wp
->w_height
)
5500 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5508 while (sline
> 0 && lnum
> 1)
5511 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5514 /* first line in buffer is folded */
5522 if (lnum
== wp
->w_topline
)
5523 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5527 line_size
= plines_win(wp
, lnum
, TRUE
);
5534 * Line we want at top would go off top of screen. Use next
5538 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5541 wp
->w_wrow
-= line_size
+ sline
;
5545 /* First line of file reached, use that as topline. */
5547 wp
->w_wrow
-= sline
;
5550 set_topline(wp
, lnum
);
5557 curs_columns(FALSE
); /* validate w_wrow */
5559 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5561 win_comp_scroll(wp
);
5562 redraw_win_later(wp
, SOME_VALID
);
5564 wp
->w_redr_status
= TRUE
;
5566 invalidate_botline_win(wp
);
5569 #ifdef FEAT_VERTSPLIT
5571 * Set the width of a window.
5574 win_new_width(wp
, width
)
5578 wp
->w_width
= width
;
5579 wp
->w_lines_valid
= 0;
5580 changed_line_abv_curs_win(wp
);
5581 invalidate_botline_win(wp
);
5585 curs_columns(TRUE
); /* validate w_wrow */
5587 #ifdef FEAT_GUI_MACVIM
5588 /* The view may have moved, so clear all or display may get corrupted. */
5589 redraw_win_later(wp
, CLEAR
);
5591 redraw_win_later(wp
, NOT_VALID
);
5593 wp
->w_redr_status
= TRUE
;
5601 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5602 if (wp
->w_p_scr
== 0)
5607 * command_height: called whenever p_ch has been changed
5615 int old_p_ch
= curtab
->tp_ch_used
;
5617 /* Use the value of p_ch that we remembered. This is needed for when the
5618 * GUI starts up, we can't be sure in what order things happen. And when
5619 * p_ch was changed in another tab page. */
5620 curtab
->tp_ch_used
= p_ch
;
5622 /* Find bottom frame with width of screen. */
5623 frp
= lastwin
->w_frame
;
5624 # ifdef FEAT_VERTSPLIT
5625 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5626 frp
= frp
->fr_parent
;
5629 /* Avoid changing the height of a window with 'winfixheight' set. */
5630 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5631 && frp
->fr_win
->w_p_wfh
)
5634 if (starting
!= NO_SCREEN
)
5636 cmdline_row
= Rows
- p_ch
;
5638 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5640 while (p_ch
> old_p_ch
)
5646 curtab
->tp_ch_used
= p_ch
;
5647 cmdline_row
= Rows
- p_ch
;
5650 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5651 if (h
> p_ch
- old_p_ch
)
5652 h
= p_ch
- old_p_ch
;
5654 frame_add_height(frp
, -h
);
5658 /* Recompute window positions. */
5659 (void)win_comp_pos();
5661 /* clear the lines added to cmdline */
5663 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5664 (int)Columns
, ' ', ' ', 0);
5665 msg_row
= cmdline_row
;
5666 redraw_cmdline
= TRUE
;
5670 if (msg_row
< cmdline_row
)
5671 msg_row
= cmdline_row
;
5672 redraw_cmdline
= TRUE
;
5674 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5676 /* Recompute window positions. */
5677 if (frp
!= lastwin
->w_frame
)
5678 (void)win_comp_pos();
5680 cmdline_row
= Rows
- p_ch
;
5681 win_setheight(cmdline_row
);
5685 #if defined(FEAT_WINDOWS) || defined(PROTO)
5687 * Resize frame "frp" to be "n" lines higher (negative for less high).
5688 * Also resize the frames it is contained in.
5691 frame_add_height(frp
, n
)
5695 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5698 frp
= frp
->fr_parent
;
5701 frp
->fr_height
+= n
;
5706 * Add or remove a status line for the bottom window(s), according to the
5707 * value of 'laststatus'.
5710 last_status(morewin
)
5711 int morewin
; /* pretend there are two or more windows */
5713 /* Don't make a difference between horizontal or vertical split. */
5714 last_status_rec(topframe
, (p_ls
== 2
5715 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5719 last_status_rec(fr
, statusline
)
5726 if (fr
->fr_layout
== FR_LEAF
)
5729 if (wp
->w_status_height
!= 0 && !statusline
)
5731 /* remove status line */
5732 win_new_height(wp
, wp
->w_height
+ 1);
5733 wp
->w_status_height
= 0;
5736 else if (wp
->w_status_height
== 0 && statusline
)
5738 /* Find a frame to take a line from. */
5740 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5747 /* In a column of frames: go to frame above. If already at
5748 * the top or in a row of frames: go to parent. */
5749 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5754 wp
->w_status_height
= 1;
5757 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5758 frame_fix_height(wp
);
5759 (void)win_comp_pos();
5762 win_new_height(wp
, wp
->w_height
- 1);
5764 redraw_all_later(SOME_VALID
);
5767 #ifdef FEAT_VERTSPLIT
5768 else if (fr
->fr_layout
== FR_ROW
)
5770 /* vertically split windows, set status line for each one */
5771 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5772 last_status_rec(fp
, statusline
);
5777 /* horizontally split window, set status line for last one */
5778 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5780 last_status_rec(fp
, statusline
);
5785 * Return the number of lines used by the tab page line.
5790 #ifdef FEAT_GUI_TABLINE
5791 /* When the GUI has the tabline then this always returns zero. */
5792 if (gui_use_tabline())
5798 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5803 #endif /* FEAT_WINDOWS */
5805 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5807 * Get the file name at the cursor.
5808 * If Visual mode is active, use the selected text if it's in one line.
5809 * Returns the name in allocated memory, NULL for failure.
5812 grab_file_name(count
, file_lnum
)
5814 linenr_T
*file_lnum
;
5822 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5824 return find_file_name_in_path(ptr
, len
,
5825 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5828 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5834 * Return the file name under or after the cursor.
5836 * The 'path' option is searched if the file name is not absolute.
5837 * The string returned has been alloc'ed and should be freed by the caller.
5838 * NULL is returned if the file name or file is not found.
5841 * FNAME_MESS give error messages
5842 * FNAME_EXP expand to path
5843 * FNAME_HYP check for hypertext link
5844 * FNAME_INCL apply "includeexpr"
5847 file_name_at_cursor(options
, count
, file_lnum
)
5850 linenr_T
*file_lnum
;
5852 return file_name_in_line(ml_get_curline(),
5853 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5858 * Return the name of the file under or after ptr[col].
5859 * Otherwise like file_name_at_cursor().
5862 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5867 char_u
*rel_fname
; /* file we are searching relative to */
5868 linenr_T
*file_lnum
; /* line number after the file name */
5874 * search forward for what could be the start of a file name
5877 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5879 if (*ptr
== NUL
) /* nothing found */
5881 if (options
& FNAME_MESS
)
5882 EMSG(_("E446: No file name under cursor"));
5887 * Search backward for first char of the file name.
5888 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5893 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5897 if (vim_isfilec(ptr
[-1])
5898 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5905 * Search forward for the last char of the file name.
5906 * Also allow "://" when ':' is not in 'isfname'.
5909 while (vim_isfilec(ptr
[len
])
5910 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5913 len
+= (*mb_ptr2len
)(ptr
+ len
);
5919 * If there is trailing punctuation, remove it.
5920 * But don't remove "..", could be a directory name.
5922 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5923 && ptr
[len
- 2] != '.')
5926 if (file_lnum
!= NULL
)
5930 /* Get the number after the file name and a separator character */
5936 ++p
; /* skip the separator */
5939 *file_lnum
= (int)getdigits(&p
);
5943 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5946 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5947 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5950 eval_includeexpr(ptr
, len
)
5956 set_vim_var_string(VV_FNAME
, ptr
, len
);
5957 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5958 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5959 set_vim_var_string(VV_FNAME
, NULL
, 0);
5965 * Return the name of the file ptr[len] in 'path'.
5966 * Otherwise like file_name_at_cursor().
5969 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5974 char_u
*rel_fname
; /* file we are searching relative to */
5978 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5979 char_u
*tofree
= NULL
;
5981 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5983 tofree
= eval_includeexpr(ptr
, len
);
5987 len
= (int)STRLEN(ptr
);
5992 if (options
& FNAME_EXP
)
5994 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5997 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5999 * If the file could not be found in a normal way, try applying
6000 * 'includeexpr' (unless done already).
6002 if (file_name
== NULL
6003 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
6005 tofree
= eval_includeexpr(ptr
, len
);
6009 len
= (int)STRLEN(ptr
);
6010 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
6015 if (file_name
== NULL
&& (options
& FNAME_MESS
))
6019 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
6023 /* Repeat finding the file "count" times. This matters when it
6024 * appears several times in the path. */
6025 while (file_name
!= NULL
&& --count
> 0)
6027 vim_free(file_name
);
6028 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
6032 file_name
= vim_strnsave(ptr
, len
);
6034 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
6040 #endif /* FEAT_SEARCHPATH */
6043 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
6044 * Also check for ":\\", which MS Internet Explorer accepts, return
6051 if (STRNCMP(p
, "://", (size_t)3) == 0)
6053 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
6054 return URL_BACKSLASH
;
6059 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
6060 * Return URL_BACKSLASH for "name:\\".
6061 * Return zero otherwise.
6064 path_with_url(fname
)
6069 for (p
= fname
; isalpha(*p
); ++p
)
6071 return path_is_url(p
);
6075 * Return TRUE if "name" is a full (absolute) path name or URL.
6081 return (path_with_url(name
) != 0 || mch_isFullName(name
));
6085 * Get absolute file name into buffer "buf[len]".
6087 * return FAIL for failure, OK otherwise
6090 vim_FullName(fname
, buf
, len
, force
)
6091 char_u
*fname
, *buf
;
6093 int force
; /* force expansion even when already absolute */
6102 url
= path_with_url(fname
);
6104 retval
= mch_FullName(fname
, buf
, len
, force
);
6105 if (url
|| retval
== FAIL
)
6107 /* something failed; use the file name (truncate when too long) */
6108 vim_strncpy(buf
, fname
, len
- 1);
6110 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6117 * Return the minimal number of rows that is needed on the screen to display
6118 * the current number of windows.
6129 if (firstwin
== NULL
) /* not initialized yet */
6134 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6136 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6140 total
+= tabline_height();
6142 total
= 1; /* at least one window should have a line! */
6144 total
+= 1; /* count the room for the command line */
6149 * Return TRUE if there is only one window (in the current tab page), not
6150 * counting a help or preview window, unless it is the current window.
6151 * Does not count "aucmd_win".
6160 /* If there is another tab page there always is another window. */
6161 if (first_tabpage
->tp_next
!= NULL
)
6164 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6165 if ((!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6166 # ifdef FEAT_QUICKFIX
6170 # ifdef FEAT_AUTOCMD
6175 return (count
<= 1);
6181 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6183 * Correct the cursor line number in other windows. Used after changing the
6184 * current buffer, and before applying autocommands.
6185 * When "do_curwin" is TRUE, also check current window.
6188 check_lnums(do_curwin
)
6196 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6197 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6203 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6204 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6205 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6206 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6211 #if defined(FEAT_WINDOWS) || defined(PROTO)
6214 * A snapshot of the window sizes, to restore them after closing the help
6216 * Only these fields are used:
6222 * fr_win (only valid for the old curwin, NULL otherwise)
6226 * Create a snapshot of the current frame sizes.
6232 clear_snapshot(curtab
, idx
);
6233 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
[idx
]);
6237 make_snapshot_rec(fr
, frp
)
6241 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6244 (*frp
)->fr_layout
= fr
->fr_layout
;
6245 # ifdef FEAT_VERTSPLIT
6246 (*frp
)->fr_width
= fr
->fr_width
;
6248 (*frp
)->fr_height
= fr
->fr_height
;
6249 if (fr
->fr_next
!= NULL
)
6250 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6251 if (fr
->fr_child
!= NULL
)
6252 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6253 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6254 (*frp
)->fr_win
= curwin
;
6258 * Remove any existing snapshot.
6261 clear_snapshot(tp
, idx
)
6265 clear_snapshot_rec(tp
->tp_snapshot
[idx
]);
6266 tp
->tp_snapshot
[idx
] = NULL
;
6270 clear_snapshot_rec(fr
)
6275 clear_snapshot_rec(fr
->fr_next
);
6276 clear_snapshot_rec(fr
->fr_child
);
6282 * Restore a previously created snapshot, if there is any.
6283 * This is only done if the screen size didn't change and the window layout is
6287 restore_snapshot(idx
, close_curwin
)
6289 int close_curwin
; /* closing current window */
6293 if (curtab
->tp_snapshot
[idx
] != NULL
6294 # ifdef FEAT_VERTSPLIT
6295 && curtab
->tp_snapshot
[idx
]->fr_width
== topframe
->fr_width
6297 && curtab
->tp_snapshot
[idx
]->fr_height
== topframe
->fr_height
6298 && check_snapshot_rec(curtab
->tp_snapshot
[idx
], topframe
) == OK
)
6300 wp
= restore_snapshot_rec(curtab
->tp_snapshot
[idx
], topframe
);
6302 if (wp
!= NULL
&& close_curwin
)
6304 redraw_all_later(CLEAR
);
6306 clear_snapshot(curtab
, idx
);
6310 * Check if frames "sn" and "fr" have the same layout, same following frames
6311 * and same children.
6314 check_snapshot_rec(sn
, fr
)
6318 if (sn
->fr_layout
!= fr
->fr_layout
6319 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6320 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6321 || (sn
->fr_next
!= NULL
6322 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6323 || (sn
->fr_child
!= NULL
6324 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6330 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6331 * following frames and children.
6332 * Returns a pointer to the old current window, or NULL.
6335 restore_snapshot_rec(sn
, fr
)
6342 fr
->fr_height
= sn
->fr_height
;
6343 # ifdef FEAT_VERTSPLIT
6344 fr
->fr_width
= sn
->fr_width
;
6346 if (fr
->fr_layout
== FR_LEAF
)
6348 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6349 # ifdef FEAT_VERTSPLIT
6350 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6354 if (sn
->fr_next
!= NULL
)
6356 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6360 if (sn
->fr_child
!= NULL
)
6362 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6371 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6373 * Return TRUE if there is any vertically split window.
6380 if (topframe
->fr_layout
== FR_ROW
)
6383 if (topframe
->fr_layout
== FR_COL
)
6384 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6385 if (fr
->fr_layout
== FR_ROW
)
6392 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6394 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6395 * highlighted with the group 'grp' with priority 'prio'.
6396 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6397 * If no particular ID is desired, -1 must be specified for 'id'.
6398 * Return ID of added match, -1 on failure.
6401 match_add(wp
, grp
, pat
, prio
, id
)
6414 if (*grp
== NUL
|| *pat
== NUL
)
6416 if (id
< -1 || id
== 0)
6418 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6423 cur
= wp
->w_match_head
;
6428 EMSGN("E801: ID already taken: %ld", id
);
6434 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6436 EMSG2(_(e_nogroup
), grp
);
6439 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6441 EMSG2(_(e_invarg2
), pat
);
6445 /* Find available match ID. */
6448 cur
= wp
->w_match_head
;
6449 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6452 id
= wp
->w_next_match_id
;
6453 wp
->w_next_match_id
++;
6456 /* Build new match. */
6457 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6460 m
->pattern
= vim_strsave(pat
);
6462 m
->match
.regprog
= regprog
;
6463 m
->match
.rmm_ic
= FALSE
;
6464 m
->match
.rmm_maxcol
= 0;
6466 /* Insert new match. The match list is in ascending order with regard to
6467 * the match priorities. */
6468 cur
= wp
->w_match_head
;
6470 while (cur
!= NULL
&& prio
>= cur
->priority
)
6476 wp
->w_match_head
= m
;
6481 redraw_later(SOME_VALID
);
6486 * Delete match with ID 'id' in the match list of window 'wp'.
6487 * Print error messages if 'perr' is TRUE.
6490 match_delete(wp
, id
, perr
)
6495 matchitem_T
*cur
= wp
->w_match_head
;
6496 matchitem_T
*prev
= cur
;
6501 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6505 while (cur
!= NULL
&& cur
->id
!= id
)
6513 EMSGN("E803: ID not found: %ld", id
);
6517 wp
->w_match_head
= cur
->next
;
6519 prev
->next
= cur
->next
;
6520 vim_free(cur
->match
.regprog
);
6521 vim_free(cur
->pattern
);
6523 redraw_later(SOME_VALID
);
6528 * Delete all matches in the match list of window 'wp'.
6536 while (wp
->w_match_head
!= NULL
)
6538 m
= wp
->w_match_head
->next
;
6539 vim_free(wp
->w_match_head
->match
.regprog
);
6540 vim_free(wp
->w_match_head
->pattern
);
6541 vim_free(wp
->w_match_head
);
6542 wp
->w_match_head
= m
;
6544 redraw_later(SOME_VALID
);
6548 * Get match from ID 'id' in window 'wp'.
6549 * Return NULL if match not found.
6556 matchitem_T
*cur
= wp
->w_match_head
;
6558 while (cur
!= NULL
&& cur
->id
!= id
)