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
;
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 wp
->w_height
= 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 wp
->w_height
= 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 wp
->w_width
= 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 wp
->w_width
= Columns
;
1053 wp
->w_vsep_width
= 0;
1057 wp
->w_wincol
= oldwin
->w_wincol
;
1058 wp
->w_width
= oldwin
->w_width
;
1059 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1061 frp
->fr_width
= curfrp
->fr_width
;
1064 /* "new_size" of the current window goes to the new window, use
1065 * one row for the status line */
1066 win_new_height(wp
, new_size
);
1067 if (flags
& (WSP_TOP
| WSP_BOT
))
1068 frame_new_height(curfrp
, curfrp
->fr_height
1069 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1071 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1072 if (before
) /* new window above current one */
1074 wp
->w_winrow
= oldwin
->w_winrow
;
1075 wp
->w_status_height
= STATUS_HEIGHT
;
1076 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1078 else /* new window below current one */
1080 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1081 wp
->w_status_height
= oldwin
->w_status_height
;
1082 oldwin
->w_status_height
= STATUS_HEIGHT
;
1084 #ifdef FEAT_VERTSPLIT
1085 if (flags
& WSP_BOT
)
1086 frame_add_statusline(curfrp
);
1088 frame_fix_height(wp
);
1089 frame_fix_height(oldwin
);
1092 if (flags
& (WSP_TOP
| WSP_BOT
))
1093 (void)win_comp_pos();
1096 * Both windows need redrawing
1098 redraw_win_later(wp
, NOT_VALID
);
1099 wp
->w_redr_status
= TRUE
;
1100 redraw_win_later(oldwin
, NOT_VALID
);
1101 oldwin
->w_redr_status
= TRUE
;
1107 msg_clr_eos_force(); /* Old command/ruler may still be there */
1110 msg_col
= 0; /* put position back at start of line */
1114 * make the new window the current window and redraw
1116 if (do_equal
|| dir
!= 0)
1118 #ifdef FEAT_VERTSPLIT
1119 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1120 : dir
== 'h' ? 'b' :
1124 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1125 * size was given. */
1126 #ifdef FEAT_VERTSPLIT
1127 if (flags
& WSP_VERT
)
1134 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1136 gui_init_which_components(NULL
);
1146 win_enter(wp
, FALSE
);
1147 #ifdef FEAT_VERTSPLIT
1148 if (flags
& WSP_VERT
)
1159 * Initialize window "newp" from window "oldp".
1160 * Used when splitting a window and when creating a new tab page.
1161 * The windows will both edit the same buffer.
1162 * WSP_NEWLOC may be specified in flags to prevent the location list from
1166 win_init(newp
, oldp
, flags
)
1173 newp
->w_buffer
= oldp
->w_buffer
;
1174 oldp
->w_buffer
->b_nwindows
++;
1175 newp
->w_cursor
= oldp
->w_cursor
;
1177 newp
->w_curswant
= oldp
->w_curswant
;
1178 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1179 newp
->w_topline
= oldp
->w_topline
;
1181 newp
->w_topfill
= oldp
->w_topfill
;
1183 newp
->w_leftcol
= oldp
->w_leftcol
;
1184 newp
->w_pcmark
= oldp
->w_pcmark
;
1185 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1186 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1187 newp
->w_wrow
= oldp
->w_wrow
;
1188 newp
->w_fraction
= oldp
->w_fraction
;
1189 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1190 #ifdef FEAT_JUMPLIST
1191 copy_jumplist(oldp
, newp
);
1193 #ifdef FEAT_QUICKFIX
1194 if (flags
& WSP_NEWLOC
)
1196 /* Don't copy the location list. */
1197 newp
->w_llist
= NULL
;
1198 newp
->w_llist_ref
= NULL
;
1201 copy_loclist(oldp
, newp
);
1203 if (oldp
->w_localdir
!= NULL
)
1204 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1206 /* copy tagstack and folds */
1207 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1209 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1210 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1211 newp
->w_tagstack
[i
].tagname
=
1212 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1214 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1215 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1216 # ifdef FEAT_FOLDING
1217 copyFoldingState(oldp
, newp
);
1220 win_init_some(newp
, oldp
);
1224 * Initialize window "newp" from window"old".
1225 * Only the essential things are copied.
1228 win_init_some(newp
, oldp
)
1232 /* Use the same argument list. */
1233 newp
->w_alist
= oldp
->w_alist
;
1234 ++newp
->w_alist
->al_refcount
;
1235 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1237 /* copy options from existing window */
1238 win_copy_options(oldp
, newp
);
1241 #endif /* FEAT_WINDOWS */
1243 #if defined(FEAT_WINDOWS) || defined(PROTO)
1245 * Check if "win" is a pointer to an existing window.
1255 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1262 * Return the number of windows.
1270 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1276 * Make "count" windows on the screen.
1277 * Return actual number of windows on the screen.
1278 * Must be called when there is just one window, filling the whole screen
1279 * (excluding the command line).
1282 make_windows(count
, vertical
)
1284 int vertical UNUSED
; /* split windows vertically if TRUE */
1289 #ifdef FEAT_VERTSPLIT
1292 /* Each windows needs at least 'winminwidth' lines and a separator
1294 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1295 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1300 /* Each window needs at least 'winminheight' lines and a status line. */
1301 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1302 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1307 if (count
> maxcount
)
1311 * add status line now, otherwise first window will be too big
1318 * Don't execute autocommands while creating the windows. Must do that
1319 * when putting the buffers in the windows.
1324 /* todo is number of windows left to create */
1325 for (todo
= count
- 1; todo
> 0; --todo
)
1326 #ifdef FEAT_VERTSPLIT
1329 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1330 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1336 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1337 * STATUS_HEIGHT
) / (todo
+ 1)
1338 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1346 /* return actual number of windows */
1347 return (count
- todo
);
1351 * Exchange current and next window
1354 win_exchange(Prenum
)
1363 if (lastwin
== firstwin
) /* just one window */
1370 need_mouse_correct
= TRUE
;
1374 * find window to exchange with
1378 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1379 while (frp
!= NULL
&& --Prenum
> 0)
1382 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1383 frp
= curwin
->w_frame
->fr_next
;
1384 else /* Swap last window in row/col with previous */
1385 frp
= curwin
->w_frame
->fr_prev
;
1387 /* We can only exchange a window with another window, not with a frame
1388 * containing windows. */
1389 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1394 * 1. remove curwin from the list. Remember after which window it was in wp2
1395 * 2. insert curwin before wp in the list
1397 * 3. remove wp from the list
1398 * 4. insert wp after wp2
1399 * 5. exchange the status line height and vsep width.
1401 wp2
= curwin
->w_prev
;
1402 frp2
= curwin
->w_frame
->fr_prev
;
1403 if (wp
->w_prev
!= curwin
)
1405 win_remove(curwin
, NULL
);
1406 frame_remove(curwin
->w_frame
);
1407 win_append(wp
->w_prev
, curwin
);
1408 frame_insert(frp
, curwin
->w_frame
);
1412 win_remove(wp
, NULL
);
1413 frame_remove(wp
->w_frame
);
1414 win_append(wp2
, wp
);
1416 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1418 frame_append(frp2
, wp
->w_frame
);
1420 temp
= curwin
->w_status_height
;
1421 curwin
->w_status_height
= wp
->w_status_height
;
1422 wp
->w_status_height
= temp
;
1423 #ifdef FEAT_VERTSPLIT
1424 temp
= curwin
->w_vsep_width
;
1425 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1426 wp
->w_vsep_width
= temp
;
1428 /* If the windows are not in the same frame, exchange the sizes to avoid
1429 * messing up the window layout. Otherwise fix the frame sizes. */
1430 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1432 temp
= curwin
->w_height
;
1433 curwin
->w_height
= wp
->w_height
;
1434 wp
->w_height
= temp
;
1435 temp
= curwin
->w_width
;
1436 curwin
->w_width
= wp
->w_width
;
1441 frame_fix_height(curwin
);
1442 frame_fix_height(wp
);
1443 frame_fix_width(curwin
);
1444 frame_fix_width(wp
);
1448 (void)win_comp_pos(); /* recompute window positions */
1450 win_enter(wp
, TRUE
);
1451 redraw_later(CLEAR
);
1455 * rotate windows: if upwards TRUE the second window becomes the first one
1456 * if upwards FALSE the first window becomes the second one
1459 win_rotate(upwards
, count
)
1468 if (firstwin
== lastwin
) /* nothing to do */
1475 need_mouse_correct
= TRUE
;
1478 #ifdef FEAT_VERTSPLIT
1479 /* Check if all frames in this row/col have one window. */
1480 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1482 if (frp
->fr_win
== NULL
)
1484 EMSG(_("E443: Cannot rotate when another window is split"));
1491 if (upwards
) /* first window becomes last window */
1493 /* remove first window/frame from the list */
1494 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1496 win_remove(wp1
, NULL
);
1499 /* find last frame and append removed window/frame after it */
1500 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1502 win_append(frp
->fr_win
, wp1
);
1503 frame_append(frp
, wp1
->w_frame
);
1505 wp2
= frp
->fr_win
; /* previously last window */
1507 else /* last window becomes first window */
1509 /* find last window/frame in the list and remove it */
1510 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1514 wp2
= wp1
->w_prev
; /* will become last window */
1515 win_remove(wp1
, NULL
);
1518 /* append the removed window/frame before the first in the list */
1519 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1520 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1523 /* exchange status height and vsep width of old and new last window */
1524 n
= wp2
->w_status_height
;
1525 wp2
->w_status_height
= wp1
->w_status_height
;
1526 wp1
->w_status_height
= n
;
1527 frame_fix_height(wp1
);
1528 frame_fix_height(wp2
);
1529 #ifdef FEAT_VERTSPLIT
1530 n
= wp2
->w_vsep_width
;
1531 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1532 wp1
->w_vsep_width
= n
;
1533 frame_fix_width(wp1
);
1534 frame_fix_width(wp2
);
1537 /* recompute w_winrow and w_wincol for all windows */
1538 (void)win_comp_pos();
1541 redraw_later(CLEAR
);
1545 * Move the current window to the very top/bottom/left/right of the screen.
1548 win_totop(size
, flags
)
1553 int height
= curwin
->w_height
;
1555 if (lastwin
== firstwin
)
1561 /* Remove the window and frame from the tree of frames. */
1562 (void)winframe_remove(curwin
, &dir
, NULL
);
1563 win_remove(curwin
, NULL
);
1564 last_status(FALSE
); /* may need to remove last status line */
1565 (void)win_comp_pos(); /* recompute window positions */
1567 /* Split a window on the desired side and put the window there. */
1568 (void)win_split_ins(size
, flags
, curwin
, dir
);
1569 if (!(flags
& WSP_VERT
))
1571 win_setheight(height
);
1573 win_equal(curwin
, TRUE
, 'v');
1576 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1577 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1578 * scrollbars. Have to update them anyway. */
1579 gui_may_update_scrollbars();
1584 * Move window "win1" to below/right of "win2" and make "win1" the current
1585 * window. Only works within the same frame!
1588 win_move_after(win1
, win2
)
1593 /* check if the arguments are reasonable */
1597 /* check if there is something to do */
1598 if (win2
->w_next
!= win1
)
1600 /* may need move the status line/vertical separator of the last window
1602 if (win1
== lastwin
)
1604 height
= win1
->w_prev
->w_status_height
;
1605 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1606 win1
->w_status_height
= height
;
1607 #ifdef FEAT_VERTSPLIT
1608 if (win1
->w_prev
->w_vsep_width
== 1)
1610 /* Remove the vertical separator from the last-but-one window,
1611 * add it to the last window. Adjust the frame widths. */
1612 win1
->w_prev
->w_vsep_width
= 0;
1613 win1
->w_prev
->w_frame
->fr_width
-= 1;
1614 win1
->w_vsep_width
= 1;
1615 win1
->w_frame
->fr_width
+= 1;
1619 else if (win2
== lastwin
)
1621 height
= win1
->w_status_height
;
1622 win1
->w_status_height
= win2
->w_status_height
;
1623 win2
->w_status_height
= height
;
1624 #ifdef FEAT_VERTSPLIT
1625 if (win1
->w_vsep_width
== 1)
1627 /* Remove the vertical separator from win1, add it to the last
1628 * window, win2. Adjust the frame widths. */
1629 win2
->w_vsep_width
= 1;
1630 win2
->w_frame
->fr_width
+= 1;
1631 win1
->w_vsep_width
= 0;
1632 win1
->w_frame
->fr_width
-= 1;
1636 win_remove(win1
, NULL
);
1637 frame_remove(win1
->w_frame
);
1638 win_append(win2
, win1
);
1639 frame_append(win2
->w_frame
, win1
->w_frame
);
1641 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1642 redraw_later(NOT_VALID
);
1644 win_enter(win1
, FALSE
);
1648 * Make all windows the same height.
1649 * 'next_curwin' will soon be the current window, make sure it has enough
1653 win_equal(next_curwin
, current
, dir
)
1654 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1655 int current
; /* do only frame with current window */
1656 int dir
; /* 'v' for vertically, 'h' for horizontally,
1657 'b' for both, 0 for using p_ead */
1660 #ifdef FEAT_VERTSPLIT
1665 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1666 topframe
, dir
, 0, tabline_height(),
1667 (int)Columns
, topframe
->fr_height
);
1671 * Set a frame to a new position and height, spreading the available room
1672 * equally over contained frames.
1673 * The window "next_curwin" (if not NULL) should at least get the size from
1674 * 'winheight' and 'winwidth' if possible.
1677 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1678 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1679 int current
; /* do only frame with current window */
1680 frame_T
*topfr
; /* frame to set size off */
1681 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1682 int col
; /* horizontal position for frame */
1683 int row
; /* vertical position for frame */
1684 int width
; /* new width of frame */
1685 int height
; /* new height of frame */
1689 int wincount
, totwincount
= 0;
1691 int next_curwin_size
= 0;
1694 int has_next_curwin
= 0;
1697 if (topfr
->fr_layout
== FR_LEAF
)
1699 /* Set the width/height of this frame.
1700 * Redraw when size or position changes */
1701 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1702 #ifdef FEAT_VERTSPLIT
1703 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1707 topfr
->fr_win
->w_winrow
= row
;
1708 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1709 #ifdef FEAT_VERTSPLIT
1710 topfr
->fr_win
->w_wincol
= col
;
1711 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1713 redraw_all_later(CLEAR
);
1716 #ifdef FEAT_VERTSPLIT
1717 else if (topfr
->fr_layout
== FR_ROW
)
1719 topfr
->fr_width
= width
;
1720 topfr
->fr_height
= height
;
1722 if (dir
!= 'v') /* equalize frame widths */
1724 /* Compute the maximum number of windows horizontally in this
1726 n
= frame_minwidth(topfr
, NOWIN
);
1727 /* add one for the rightmost window, it doesn't have a separator */
1728 if (col
+ width
== Columns
)
1732 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1733 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1736 * Compute width for "next_curwin" window and room available for
1738 * "m" is the minimal width when counting p_wiw for "next_curwin".
1740 m
= frame_minwidth(topfr
, next_curwin
);
1744 next_curwin_size
= p_wiw
+ room
;
1749 next_curwin_size
= -1;
1750 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1752 /* If 'winfixwidth' set keep the window width if
1754 * Watch out for this window being the next_curwin. */
1755 if (frame_fixed_width(fr
))
1757 n
= frame_minwidth(fr
, NOWIN
);
1758 new_size
= fr
->fr_width
;
1759 if (frame_has_win(fr
, next_curwin
))
1761 room
+= p_wiw
- p_wmw
;
1762 next_curwin_size
= 0;
1763 if (new_size
< p_wiw
)
1767 /* These windows don't use up room. */
1768 totwincount
-= (n
+ (fr
->fr_next
== NULL
1769 ? extra_sep
: 0)) / (p_wmw
+ 1);
1770 room
-= new_size
- n
;
1776 fr
->fr_newwidth
= new_size
;
1779 if (next_curwin_size
== -1)
1781 if (!has_next_curwin
)
1782 next_curwin_size
= 0;
1783 else if (totwincount
> 1
1784 && (room
+ (totwincount
- 2))
1785 / (totwincount
- 1) > p_wiw
)
1787 /* Can make all windows wider than 'winwidth', spread
1788 * the room equally. */
1789 next_curwin_size
= (room
+ p_wiw
1790 + (totwincount
- 1) * p_wmw
1791 + (totwincount
- 1)) / totwincount
;
1792 room
-= next_curwin_size
- p_wiw
;
1795 next_curwin_size
= p_wiw
;
1799 if (has_next_curwin
)
1800 --totwincount
; /* don't count curwin */
1803 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1807 if (fr
->fr_next
== NULL
)
1808 /* last frame gets all that remains (avoid roundoff error) */
1810 else if (dir
== 'v')
1811 new_size
= fr
->fr_width
;
1812 else if (frame_fixed_width(fr
))
1814 new_size
= fr
->fr_newwidth
;
1815 wincount
= 0; /* doesn't count as a sizeable window */
1819 /* Compute the maximum number of windows horiz. in "fr". */
1820 n
= frame_minwidth(fr
, NOWIN
);
1821 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1823 m
= frame_minwidth(fr
, next_curwin
);
1824 if (has_next_curwin
)
1825 hnc
= frame_has_win(fr
, next_curwin
);
1828 if (hnc
) /* don't count next_curwin */
1830 if (totwincount
== 0)
1833 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1835 if (hnc
) /* add next_curwin size */
1837 next_curwin_size
-= p_wiw
- (m
- n
);
1838 new_size
+= next_curwin_size
;
1839 room
-= new_size
- next_curwin_size
;
1846 /* Skip frame that is full width when splitting or closing a
1847 * window, unless equalizing all frames. */
1848 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1849 || (new_size
!= fr
->fr_width
)
1850 || frame_has_win(fr
, next_curwin
))
1851 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1855 totwincount
-= wincount
;
1859 else /* topfr->fr_layout == FR_COL */
1861 #ifdef FEAT_VERTSPLIT
1862 topfr
->fr_width
= width
;
1864 topfr
->fr_height
= height
;
1866 if (dir
!= 'h') /* equalize frame heights */
1868 /* Compute maximum number of windows vertically in this frame. */
1869 n
= frame_minheight(topfr
, NOWIN
);
1870 /* add one for the bottom window if it doesn't have a statusline */
1871 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1875 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1876 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1879 * Compute height for "next_curwin" window and room available for
1881 * "m" is the minimal height when counting p_wh for "next_curwin".
1883 m
= frame_minheight(topfr
, next_curwin
);
1887 /* The room is less then 'winheight', use all space for the
1888 * current window. */
1889 next_curwin_size
= p_wh
+ room
;
1894 next_curwin_size
= -1;
1895 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1897 /* If 'winfixheight' set keep the window height if
1899 * Watch out for this window being the next_curwin. */
1900 if (frame_fixed_height(fr
))
1902 n
= frame_minheight(fr
, NOWIN
);
1903 new_size
= fr
->fr_height
;
1904 if (frame_has_win(fr
, next_curwin
))
1906 room
+= p_wh
- p_wmh
;
1907 next_curwin_size
= 0;
1908 if (new_size
< p_wh
)
1912 /* These windows don't use up room. */
1913 totwincount
-= (n
+ (fr
->fr_next
== NULL
1914 ? extra_sep
: 0)) / (p_wmh
+ 1);
1915 room
-= new_size
- n
;
1921 fr
->fr_newheight
= new_size
;
1924 if (next_curwin_size
== -1)
1926 if (!has_next_curwin
)
1927 next_curwin_size
= 0;
1928 else if (totwincount
> 1
1929 && (room
+ (totwincount
- 2))
1930 / (totwincount
- 1) > p_wh
)
1932 /* can make all windows higher than 'winheight',
1933 * spread the room equally. */
1934 next_curwin_size
= (room
+ p_wh
1935 + (totwincount
- 1) * p_wmh
1936 + (totwincount
- 1)) / totwincount
;
1937 room
-= next_curwin_size
- p_wh
;
1940 next_curwin_size
= p_wh
;
1944 if (has_next_curwin
)
1945 --totwincount
; /* don't count curwin */
1948 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1952 if (fr
->fr_next
== NULL
)
1953 /* last frame gets all that remains (avoid roundoff error) */
1955 else if (dir
== 'h')
1956 new_size
= fr
->fr_height
;
1957 else if (frame_fixed_height(fr
))
1959 new_size
= fr
->fr_newheight
;
1960 wincount
= 0; /* doesn't count as a sizeable window */
1964 /* Compute the maximum number of windows vert. in "fr". */
1965 n
= frame_minheight(fr
, NOWIN
);
1966 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1968 m
= frame_minheight(fr
, next_curwin
);
1969 if (has_next_curwin
)
1970 hnc
= frame_has_win(fr
, next_curwin
);
1973 if (hnc
) /* don't count next_curwin */
1975 if (totwincount
== 0)
1978 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1980 if (hnc
) /* add next_curwin size */
1982 next_curwin_size
-= p_wh
- (m
- n
);
1983 new_size
+= next_curwin_size
;
1984 room
-= new_size
- next_curwin_size
;
1990 /* Skip frame that is full width when splitting or closing a
1991 * window, unless equalizing all frames. */
1992 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1993 || (new_size
!= fr
->fr_height
)
1994 || frame_has_win(fr
, next_curwin
))
1995 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1999 totwincount
-= wincount
;
2005 * close all windows for buffer 'buf'
2008 close_windows(buf
, keep_curwin
)
2010 int keep_curwin
; /* don't close "curwin" */
2013 tabpage_T
*tp
, *nexttp
;
2014 int h
= tabline_height();
2016 ++RedrawingDisabled
;
2018 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2020 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2022 win_close(wp
, FALSE
);
2024 /* Start all over, autocommands may change the window layout. */
2031 /* Also check windows in other tab pages. */
2032 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2034 nexttp
= tp
->tp_next
;
2036 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2037 if (wp
->w_buffer
== buf
)
2039 win_close_othertab(wp
, FALSE
, tp
);
2041 /* Start all over, the tab page may be closed and
2042 * autocommands may change the window layout. */
2043 nexttp
= first_tabpage
;
2048 --RedrawingDisabled
;
2050 if (h
!= tabline_height())
2055 * Return TRUE if the current window is the only window that exists (ignoring
2057 * Returns FALSE if there is a window, possibly in another tab page.
2062 return (one_window() && first_tabpage
->tp_next
== NULL
);
2066 * Return TRUE if there is only one window other than "aucmd_win" in the
2074 int seen_one
= FALSE
;
2078 if (wp
!= aucmd_win
)
2087 return firstwin
== lastwin
;
2092 * Close window "win". Only works for the current tab page.
2093 * If "free_buf" is TRUE related buffer may be unloaded.
2095 * called by :quit, :close, :xit, :wq and findtag()
2098 win_close(win
, free_buf
)
2104 int other_buffer
= FALSE
;
2106 int close_curwin
= FALSE
;
2108 int help_window
= FALSE
;
2109 tabpage_T
*prev_curtab
= curtab
;
2113 EMSG(_("E444: Cannot close last window"));
2118 if (win
== aucmd_win
)
2120 EMSG(_("E813: Cannot close autocmd window"));
2123 if ((firstwin
== aucmd_win
|| lastwin
== aucmd_win
) && one_window())
2125 EMSG(_("E814: Cannot close window, only autocmd window would remain"));
2131 * When closing the last window in a tab page first go to another tab
2132 * page and then close the window and the tab page. This avoids that
2133 * curwin and curtab are not invalid while we are freeing memory, they may
2134 * be used in GUI events.
2136 if (firstwin
== lastwin
)
2138 goto_tabpage_tp(alt_tabpage());
2139 redraw_tabline
= TRUE
;
2141 /* Safety check: Autocommands may have closed the window when jumping
2142 * to the other tab page. */
2143 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2145 int h
= tabline_height();
2147 win_close_othertab(win
, free_buf
, prev_curtab
);
2148 if (h
!= tabline_height())
2154 /* When closing the help window, try restoring a snapshot after closing
2155 * the window. Otherwise clear the snapshot, it's now invalid. */
2156 if (win
->w_buffer
->b_help
)
2159 clear_snapshot(curtab
, SNAP_HELP_IDX
);
2165 * Guess which window is going to be the new current window.
2166 * This may change because of the autocommands (sigh).
2168 wp
= frame2win(win_altframe(win
, NULL
));
2171 * Be careful: If autocommands delete the window, return now.
2173 if (wp
->w_buffer
!= curbuf
)
2175 other_buffer
= TRUE
;
2176 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2177 if (!win_valid(win
) || last_window())
2180 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2181 if (!win_valid(win
) || last_window())
2184 /* autocmds may abort script processing */
2192 /* Avoid trouble with scrollbars that are going to be deleted in
2199 * Close the link to the buffer.
2201 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2203 /* Autocommands may have closed the window already, or closed the only
2204 * other window or moved to another tab page. */
2205 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2208 /* Free the memory used for the window. */
2209 wp
= win_free_mem(win
, &dir
, NULL
);
2211 /* Make sure curwin isn't invalid. It can cause severe trouble when
2212 * printing an error message. For win_equal() curbuf needs to be valid
2217 #ifdef FEAT_QUICKFIX
2218 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2221 * If the cursor goes to the preview or the quickfix window, try
2222 * finding another window to go to.
2226 if (wp
->w_next
== NULL
)
2232 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2240 curbuf
= curwin
->w_buffer
;
2241 close_curwin
= TRUE
;
2244 #ifdef FEAT_VERTSPLIT
2245 && (*p_ead
== 'b' || *p_ead
== dir
)
2248 win_equal(curwin
, TRUE
,
2249 #ifdef FEAT_VERTSPLIT
2259 win_enter_ext(wp
, FALSE
, TRUE
);
2262 /* careful: after this wp and win may be invalid! */
2263 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2268 * If last window has a status line now and we don't want one,
2269 * remove the status line.
2273 /* After closing the help window, try restoring the window layout from
2274 * before it was opened. */
2276 restore_snapshot(SNAP_HELP_IDX
, close_curwin
);
2278 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2279 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2280 if (gui
.in_use
&& !win_hasvertsplit())
2281 gui_init_which_components(NULL
);
2284 redraw_all_later(NOT_VALID
);
2288 * Close window "win" in tab page "tp", which is not the current tab page.
2289 * This may be the last window ih that tab page and result in closing the tab,
2290 * thus "tp" may become invalid!
2291 * Caller must check if buffer is hidden and whether the tabline needs to be
2295 win_close_othertab(win
, free_buf
, tp
)
2302 tabpage_T
*ptp
= NULL
;
2304 /* Close the link to the buffer. */
2305 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2307 /* Careful: Autocommands may have closed the tab page or made it the
2308 * current tab page. */
2309 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2311 if (ptp
== NULL
|| tp
== curtab
)
2314 /* Autocommands may have closed the window already. */
2315 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2320 /* Free the memory used for the window. */
2321 wp
= win_free_mem(win
, &dir
, tp
);
2323 /* When closing the last window in a tab page remove the tab page. */
2326 if (tp
== first_tabpage
)
2327 first_tabpage
= tp
->tp_next
;
2330 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2335 EMSG2(_(e_intern2
), "win_close_othertab()");
2338 ptp
->tp_next
= tp
->tp_next
;
2345 * Free the memory used for a window.
2346 * Returns a pointer to the window that got the freed up space.
2349 win_free_mem(win
, dirp
, tp
)
2351 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2352 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2357 /* Remove the window and its frame from the tree of frames. */
2359 wp
= winframe_remove(win
, dirp
, tp
);
2363 /* When deleting the current window of another tab page select a new
2364 * current window. */
2365 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2371 #if defined(EXITFREE) || defined(PROTO)
2377 # ifdef FEAT_WINDOWS
2378 while (first_tabpage
->tp_next
!= NULL
)
2379 tabpage_close(TRUE
);
2382 # ifdef FEAT_AUTOCMD
2383 if (aucmd_win
!= NULL
)
2385 (void)win_free_mem(aucmd_win
, &dummy
, NULL
);
2390 while (firstwin
!= NULL
)
2391 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2396 * Remove a window and its frame from the tree of frames.
2397 * Returns a pointer to the window that got the freed up space.
2400 winframe_remove(win
, dirp
, tp
)
2402 int *dirp UNUSED
; /* set to 'v' or 'h' for direction if 'ea' */
2403 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2405 frame_T
*frp
, *frp2
, *frp3
;
2406 frame_T
*frp_close
= win
->w_frame
;
2410 * If there is only one window there is nothing to remove.
2412 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2416 * Remove the window from its frame.
2418 frp2
= win_altframe(win
, tp
);
2419 wp
= frame2win(frp2
);
2421 /* Remove this frame from the list of frames. */
2422 frame_remove(frp_close
);
2424 #ifdef FEAT_VERTSPLIT
2425 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2428 /* When 'winfixheight' is set, try to find another frame in the column
2429 * (as close to the closed frame as possible) to distribute the height
2431 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2433 frp
= frp_close
->fr_prev
;
2434 frp3
= frp_close
->fr_next
;
2435 while (frp
!= NULL
|| frp3
!= NULL
)
2439 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2449 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2455 frp3
= frp3
->fr_next
;
2459 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2460 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2461 #ifdef FEAT_VERTSPLIT
2466 /* When 'winfixwidth' is set, try to find another frame in the column
2467 * (as close to the closed frame as possible) to distribute the width
2469 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2471 frp
= frp_close
->fr_prev
;
2472 frp3
= frp_close
->fr_next
;
2473 while (frp
!= NULL
|| frp3
!= NULL
)
2477 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2487 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2493 frp3
= frp3
->fr_next
;
2497 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2498 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2503 /* If rows/columns go to a window below/right its positions need to be
2504 * updated. Can only be done after the sizes have been updated. */
2505 if (frp2
== frp_close
->fr_next
)
2507 int row
= win
->w_winrow
;
2508 int col
= W_WINCOL(win
);
2510 frame_comp_pos(frp2
, &row
, &col
);
2513 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2515 /* There is no other frame in this list, move its info to the parent
2517 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2518 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2519 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2520 frp
->fr_parent
= frp2
->fr_parent
;
2521 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2522 if (frp2
->fr_win
!= NULL
)
2523 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2524 frp
= frp2
->fr_parent
;
2527 frp2
= frp
->fr_parent
;
2528 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2530 /* The frame above the parent has the same layout, have to merge
2531 * the frames into this list. */
2532 if (frp2
->fr_child
== frp
)
2533 frp2
->fr_child
= frp
->fr_child
;
2534 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2535 if (frp
->fr_prev
!= NULL
)
2536 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2537 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2539 frp3
->fr_parent
= frp2
;
2540 if (frp3
->fr_next
== NULL
)
2542 frp3
->fr_next
= frp
->fr_next
;
2543 if (frp
->fr_next
!= NULL
)
2544 frp
->fr_next
->fr_prev
= frp3
;
2556 * Find out which frame is going to get the freed up space when "win" is
2558 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2559 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2560 * This makes opening a window and closing it immediately keep the same window
2564 win_altframe(win
, tp
)
2566 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2571 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2572 /* Last window in this tab page, will go to next tab page. */
2573 return alt_tabpage()->tp_curwin
->w_frame
;
2576 #ifdef FEAT_VERTSPLIT
2577 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2582 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2583 return frp
->fr_next
;
2584 return frp
->fr_prev
;
2588 * Return the tabpage that will be used if the current one is closed.
2595 /* Use the next tab page if possible. */
2596 if (curtab
->tp_next
!= NULL
)
2597 return curtab
->tp_next
;
2599 /* Find the last but one tab page. */
2600 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2606 * Find the left-upper window in frame "frp".
2612 while (frp
->fr_win
== NULL
)
2613 frp
= frp
->fr_child
;
2618 * Return TRUE if frame "frp" contains window "wp".
2621 frame_has_win(frp
, wp
)
2627 if (frp
->fr_layout
== FR_LEAF
)
2628 return frp
->fr_win
== wp
;
2630 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2631 if (frame_has_win(p
, wp
))
2637 * Set a new height for a frame. Recursively sets the height for contained
2638 * frames and windows. Caller must take care of positions.
2641 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2644 int topfirst
; /* resize topmost contained frame first */
2645 int wfh
; /* obey 'winfixheight' when there is a choice;
2646 may cause the height not to be set */
2652 if (topfrp
->fr_win
!= NULL
)
2654 /* Simple case: just one window. */
2655 win_new_height(topfrp
->fr_win
,
2656 height
- topfrp
->fr_win
->w_status_height
);
2658 #ifdef FEAT_VERTSPLIT
2659 else if (topfrp
->fr_layout
== FR_ROW
)
2663 /* All frames in this row get the same new height. */
2664 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2666 frame_new_height(frp
, height
, topfirst
, wfh
);
2667 if (frp
->fr_height
> height
)
2669 /* Could not fit the windows, make the whole row higher. */
2670 height
= frp
->fr_height
;
2675 while (frp
!= NULL
);
2678 else /* fr_layout == FR_COL */
2680 /* Complicated case: Resize a column of frames. Resize the bottom
2681 * frame first, frames above that when needed. */
2683 frp
= topfrp
->fr_child
;
2685 /* Advance past frames with one window with 'wfh' set. */
2686 while (frame_fixed_height(frp
))
2690 return; /* no frame without 'wfh', give up */
2694 /* Find the bottom frame of this column */
2695 while (frp
->fr_next
!= NULL
)
2698 /* Advance back for frames with one window with 'wfh' set. */
2699 while (frame_fixed_height(frp
))
2703 extra_lines
= height
- topfrp
->fr_height
;
2704 if (extra_lines
< 0)
2706 /* reduce height of contained frames, bottom or top frame first */
2709 h
= frame_minheight(frp
, NULL
);
2710 if (frp
->fr_height
+ extra_lines
< h
)
2712 extra_lines
+= frp
->fr_height
- h
;
2713 frame_new_height(frp
, h
, topfirst
, wfh
);
2717 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2725 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2731 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2733 /* Increase "height" if we could not reduce enough frames. */
2735 height
-= extra_lines
;
2738 else if (extra_lines
> 0)
2740 /* increase height of bottom or top frame */
2741 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2744 topfrp
->fr_height
= height
;
2748 * Return TRUE if height of frame "frp" should not be changed because of
2749 * the 'winfixheight' option.
2752 frame_fixed_height(frp
)
2755 /* frame with one window: fixed height if 'winfixheight' set. */
2756 if (frp
->fr_win
!= NULL
)
2757 return frp
->fr_win
->w_p_wfh
;
2759 if (frp
->fr_layout
== FR_ROW
)
2761 /* The frame is fixed height if one of the frames in the row is fixed
2763 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2764 if (frame_fixed_height(frp
))
2769 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2770 * frames in the row are fixed height. */
2771 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2772 if (!frame_fixed_height(frp
))
2777 #ifdef FEAT_VERTSPLIT
2779 * Return TRUE if width of frame "frp" should not be changed because of
2780 * the 'winfixwidth' option.
2783 frame_fixed_width(frp
)
2786 /* frame with one window: fixed width if 'winfixwidth' set. */
2787 if (frp
->fr_win
!= NULL
)
2788 return frp
->fr_win
->w_p_wfw
;
2790 if (frp
->fr_layout
== FR_COL
)
2792 /* The frame is fixed width if one of the frames in the row is fixed
2794 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2795 if (frame_fixed_width(frp
))
2800 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2801 * frames in the row are fixed width. */
2802 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2803 if (!frame_fixed_width(frp
))
2809 * Add a status line to windows at the bottom of "frp".
2810 * Note: Does not check if there is room!
2813 frame_add_statusline(frp
)
2818 if (frp
->fr_layout
== FR_LEAF
)
2821 if (wp
->w_status_height
== 0)
2823 if (wp
->w_height
> 0) /* don't make it negative */
2825 wp
->w_status_height
= STATUS_HEIGHT
;
2828 else if (frp
->fr_layout
== FR_ROW
)
2830 /* Handle all the frames in the row. */
2831 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2832 frame_add_statusline(frp
);
2834 else /* frp->fr_layout == FR_COL */
2836 /* Only need to handle the last frame in the column. */
2837 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2839 frame_add_statusline(frp
);
2844 * Set width of a frame. Handles recursively going through contained frames.
2845 * May remove separator line for windows at the right side (for win_close()).
2848 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2851 int leftfirst
; /* resize leftmost contained frame first */
2852 int wfw
; /* obey 'winfixwidth' when there is a choice;
2853 may cause the width not to be set */
2860 if (topfrp
->fr_layout
== FR_LEAF
)
2862 /* Simple case: just one window. */
2863 wp
= topfrp
->fr_win
;
2864 /* Find out if there are any windows right of this one. */
2865 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2866 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2868 if (frp
->fr_parent
== NULL
)
2869 wp
->w_vsep_width
= 0;
2870 win_new_width(wp
, width
- wp
->w_vsep_width
);
2872 else if (topfrp
->fr_layout
== FR_COL
)
2876 /* All frames in this column get the same new width. */
2877 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2879 frame_new_width(frp
, width
, leftfirst
, wfw
);
2880 if (frp
->fr_width
> width
)
2882 /* Could not fit the windows, make whole column wider. */
2883 width
= frp
->fr_width
;
2887 } while (frp
!= NULL
);
2889 else /* fr_layout == FR_ROW */
2891 /* Complicated case: Resize a row of frames. Resize the rightmost
2892 * frame first, frames left of it when needed. */
2894 frp
= topfrp
->fr_child
;
2896 /* Advance past frames with one window with 'wfw' set. */
2897 while (frame_fixed_width(frp
))
2901 return; /* no frame without 'wfw', give up */
2905 /* Find the rightmost frame of this row */
2906 while (frp
->fr_next
!= NULL
)
2909 /* Advance back for frames with one window with 'wfw' set. */
2910 while (frame_fixed_width(frp
))
2914 extra_cols
= width
- topfrp
->fr_width
;
2917 /* reduce frame width, rightmost frame first */
2920 w
= frame_minwidth(frp
, NULL
);
2921 if (frp
->fr_width
+ extra_cols
< w
)
2923 extra_cols
+= frp
->fr_width
- w
;
2924 frame_new_width(frp
, w
, leftfirst
, wfw
);
2928 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2936 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2942 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2944 /* Increase "width" if we could not reduce enough frames. */
2946 width
-= extra_cols
;
2949 else if (extra_cols
> 0)
2951 /* increase width of rightmost frame */
2952 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2955 topfrp
->fr_width
= width
;
2959 * Add the vertical separator to windows at the right side of "frp".
2960 * Note: Does not check if there is room!
2968 if (frp
->fr_layout
== FR_LEAF
)
2971 if (wp
->w_vsep_width
== 0)
2973 if (wp
->w_width
> 0) /* don't make it negative */
2975 wp
->w_vsep_width
= 1;
2978 else if (frp
->fr_layout
== FR_COL
)
2980 /* Handle all the frames in the column. */
2981 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2982 frame_add_vsep(frp
);
2984 else /* frp->fr_layout == FR_ROW */
2986 /* Only need to handle the last frame in the row. */
2987 frp
= frp
->fr_child
;
2988 while (frp
->fr_next
!= NULL
)
2990 frame_add_vsep(frp
);
2995 * Set frame width from the window it contains.
3001 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
3006 * Set frame height from the window it contains.
3009 frame_fix_height(wp
)
3012 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
3016 * Compute the minimal height for frame "topfrp".
3017 * Uses the 'winminheight' option.
3018 * When "next_curwin" isn't NULL, use p_wh for this window.
3019 * When "next_curwin" is NOWIN, don't use at least one line for the current
3023 frame_minheight(topfrp
, next_curwin
)
3029 #ifdef FEAT_VERTSPLIT
3033 if (topfrp
->fr_win
!= NULL
)
3035 if (topfrp
->fr_win
== next_curwin
)
3036 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
3039 /* window: minimal height of the window plus status line */
3040 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
3041 /* Current window is minimal one line high */
3042 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3046 #ifdef FEAT_VERTSPLIT
3047 else if (topfrp
->fr_layout
== FR_ROW
)
3049 /* get the minimal height from each frame in this row */
3051 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3053 n
= frame_minheight(frp
, next_curwin
);
3061 /* Add up the minimal heights for all frames in this column. */
3063 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3064 m
+= frame_minheight(frp
, next_curwin
);
3070 #ifdef FEAT_VERTSPLIT
3072 * Compute the minimal width for frame "topfrp".
3073 * When "next_curwin" isn't NULL, use p_wiw for this window.
3074 * When "next_curwin" is NOWIN, don't use at least one column for the current
3078 frame_minwidth(topfrp
, next_curwin
)
3080 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3085 if (topfrp
->fr_win
!= NULL
)
3087 if (topfrp
->fr_win
== next_curwin
)
3088 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3091 /* window: minimal width of the window plus separator column */
3092 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3093 /* Current window is minimal one column wide */
3094 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3098 else if (topfrp
->fr_layout
== FR_COL
)
3100 /* get the minimal width from each frame in this column */
3102 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3104 n
= frame_minwidth(frp
, next_curwin
);
3111 /* Add up the minimal widths for all frames in this row. */
3113 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3114 m
+= frame_minwidth(frp
, next_curwin
);
3123 * Try to close all windows except current one.
3124 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3125 * used and the buffer was modified.
3127 * Used by ":bdel" and ":only".
3130 close_others(message
, forceit
)
3132 int forceit
; /* always hide all other windows */
3149 /* Be very careful here: autocommands may change the window layout. */
3150 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3152 nextwp
= wp
->w_next
;
3153 if (wp
!= curwin
) /* don't close current window */
3156 /* Check if it's allowed to abandon this window */
3157 r
= can_abandon(wp
->w_buffer
, forceit
);
3159 if (!win_valid(wp
)) /* autocommands messed wp up */
3167 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3168 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3170 dialog_changed(wp
->w_buffer
, FALSE
);
3171 # ifdef FEAT_AUTOCMD
3172 if (!win_valid(wp
)) /* autocommands messed wp up */
3179 if (bufIsChanged(wp
->w_buffer
))
3183 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3187 if (message
&& lastwin
!= firstwin
)
3188 EMSG(_("E445: Other window contains changes"));
3191 #endif /* FEAT_WINDOWS */
3194 * Init the current window "curwin".
3195 * Called when a new file is being edited.
3200 win_init_empty(curwin
);
3207 redraw_win_later(wp
, NOT_VALID
);
3208 wp
->w_lines_valid
= 0;
3209 wp
->w_cursor
.lnum
= 1;
3210 wp
->w_curswant
= wp
->w_cursor
.col
= 0;
3211 #ifdef FEAT_VIRTUALEDIT
3212 wp
->w_cursor
.coladd
= 0;
3214 wp
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3215 wp
->w_pcmark
.col
= 0;
3216 wp
->w_prev_pcmark
.lnum
= 0;
3217 wp
->w_prev_pcmark
.col
= 0;
3225 wp
->w_farsi
= W_CONV
+ W_R_L
;
3227 wp
->w_farsi
= W_CONV
;
3232 * Allocate the first window and put an empty buffer in it.
3233 * Called from main().
3234 * Return FAIL when something goes wrong (out of memory).
3239 if (win_alloc_firstwin(NULL
) == FAIL
)
3243 first_tabpage
= alloc_tabpage();
3244 if (first_tabpage
== NULL
)
3246 first_tabpage
->tp_topframe
= topframe
;
3247 curtab
= first_tabpage
;
3253 #if defined(FEAT_AUTOCMD) || defined(PROTO)
3255 * Init "aucmd_win". This can only be done after the first
3256 * window is fully initialized, thus it can't be in win_alloc_first().
3259 win_alloc_aucmd_win()
3261 aucmd_win
= win_alloc(NULL
, TRUE
);
3262 if (aucmd_win
!= NULL
)
3264 win_init_some(aucmd_win
, curwin
);
3265 # ifdef FEAT_SCROLLBIND
3266 aucmd_win
->w_p_scb
= FALSE
;
3268 new_frame(aucmd_win
);
3274 * Allocate the first window or the first window in a new tab page.
3275 * When "oldwin" is NULL create an empty buffer for it.
3276 * When "oldwin" is not NULL copy info from it to the new window (only with
3278 * Return FAIL when something goes wrong (out of memory).
3281 win_alloc_firstwin(oldwin
)
3284 curwin
= win_alloc(NULL
, FALSE
);
3287 /* Very first window, need to create an empty buffer for it and
3288 * initialize from scratch. */
3289 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3290 if (curwin
== NULL
|| curbuf
== NULL
)
3292 curwin
->w_buffer
= curbuf
;
3293 curbuf
->b_nwindows
= 1; /* there is one window */
3295 curwin
->w_alist
= &global_alist
;
3297 curwin_init(); /* init current window */
3302 /* First window in new tab page, initialize it from "oldwin". */
3303 win_init(curwin
, oldwin
, 0);
3305 # ifdef FEAT_SCROLLBIND
3306 /* We don't want scroll-binding in the first window. */
3307 curwin
->w_p_scb
= FALSE
;
3313 if (curwin
->w_frame
== NULL
)
3315 topframe
= curwin
->w_frame
;
3316 #ifdef FEAT_VERTSPLIT
3317 topframe
->fr_width
= Columns
;
3319 topframe
->fr_height
= Rows
- p_ch
;
3320 topframe
->fr_win
= curwin
;
3326 * Create a frame for window "wp".
3329 new_frame(win_T
*wp
)
3331 frame_T
*frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3336 frp
->fr_layout
= FR_LEAF
;
3342 * Initialize the window and frame size to the maximum.
3347 firstwin
->w_height
= ROWS_AVAIL
;
3348 topframe
->fr_height
= ROWS_AVAIL
;
3349 #ifdef FEAT_VERTSPLIT
3350 firstwin
->w_width
= Columns
;
3351 topframe
->fr_width
= Columns
;
3355 #if defined(FEAT_WINDOWS) || defined(PROTO)
3358 * Allocate a new tabpage_T and init the values.
3359 * Returns NULL when out of memory.
3366 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3372 for (i
= 0; i
< 3; i
++)
3373 tp
->tp_prev_which_scrollbars
[i
] = -1;
3376 tp
->tp_diff_invalid
= TRUE
;
3379 /* init t: variables */
3380 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3382 tp
->tp_ch_used
= p_ch
;
3396 for (idx
= 0; idx
< SNAP_COUNT
; ++idx
)
3397 clear_snapshot(tp
, idx
);
3399 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3405 * Create a new Tab page with one window.
3406 * It will edit the current buffer, like after ":split".
3407 * When "after" is 0 put it just after the current Tab page.
3408 * Otherwise put it just before tab page "after".
3409 * Return FAIL or OK.
3412 win_new_tabpage(after
)
3415 tabpage_T
*tp
= curtab
;
3419 newtp
= alloc_tabpage();
3423 /* Remember the current windows in this Tab page. */
3424 if (leave_tabpage(curbuf
) == FAIL
)
3431 /* Create a new empty window. */
3432 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3434 /* Make the new Tab page the new topframe. */
3437 /* New tab page becomes the first one. */
3438 newtp
->tp_next
= first_tabpage
;
3439 first_tabpage
= newtp
;
3445 /* Put new tab page before tab page "after". */
3447 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3448 && n
< after
; tp
= tp
->tp_next
)
3451 newtp
->tp_next
= tp
->tp_next
;
3452 tp
->tp_next
= newtp
;
3455 firstwin
->w_winrow
= tabline_height();
3456 win_comp_scroll(curwin
);
3458 newtp
->tp_topframe
= topframe
;
3461 #if defined(FEAT_GUI)
3462 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3463 * scrollbars. Have to update them anyway. */
3464 gui_may_update_scrollbars();
3467 redraw_all_later(CLEAR
);
3469 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3470 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3475 /* Failed, get back the previous Tab page */
3476 enter_tabpage(curtab
, curbuf
);
3481 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3482 * like with ":split".
3483 * Returns OK if a new tab page was created, FAIL otherwise.
3488 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3492 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3493 postponed_split_tab
= 0;
3494 return win_new_tabpage(n
);
3500 * Create up to "maxcount" tabpages with empty windows.
3501 * Returns the number of resulting tab pages.
3504 make_tabpages(maxcount
)
3507 int count
= maxcount
;
3510 /* Limit to 'tabpagemax' tabs. */
3516 * Don't execute autocommands while creating the tab pages. Must do that
3517 * when putting the buffers in the windows.
3522 for (todo
= count
- 1; todo
> 0; --todo
)
3523 if (win_new_tabpage(0) == FAIL
)
3530 /* return actual number of tab pages */
3531 return (count
- todo
);
3535 * Return TRUE when "tpc" points to a valid tab page.
3543 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3550 * Find tab page "n" (first one is 1). Returns NULL when not found.
3559 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3565 * Get index of tab page "tp". First one has index 1.
3566 * When not found returns number of tab pages plus one.
3575 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3581 * Prepare for leaving the current tab page.
3582 * When autocomands change "curtab" we don't leave the tab page and return
3584 * Careful: When OK is returned need to get a new tab page very very soon!
3587 leave_tabpage(new_curbuf
)
3588 buf_T
*new_curbuf UNUSED
; /* what is going to be the new curbuf,
3591 tabpage_T
*tp
= curtab
;
3594 reset_VIsual_and_resel(); /* stop Visual mode */
3597 if (new_curbuf
!= curbuf
)
3599 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3603 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3606 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3610 #if defined(FEAT_GUI)
3611 /* Remove the scrollbars. They may be added back later. */
3613 gui_remove_scrollbars();
3615 tp
->tp_curwin
= curwin
;
3616 tp
->tp_prevwin
= prevwin
;
3617 tp
->tp_firstwin
= firstwin
;
3618 tp
->tp_lastwin
= lastwin
;
3619 tp
->tp_old_Rows
= Rows
;
3620 tp
->tp_old_Columns
= Columns
;
3627 * Start using tab page "tp".
3628 * Only to be used after leave_tabpage() or freeing the current tab page.
3631 enter_tabpage(tp
, old_curbuf
)
3633 buf_T
*old_curbuf UNUSED
;
3635 int old_off
= tp
->tp_firstwin
->w_winrow
;
3636 win_T
*next_prevwin
= tp
->tp_prevwin
;
3639 firstwin
= tp
->tp_firstwin
;
3640 lastwin
= tp
->tp_lastwin
;
3641 topframe
= tp
->tp_topframe
;
3643 /* We would like doing the TabEnter event first, but we don't have a
3644 * valid current window yet, which may break some commands.
3645 * This triggers autocommands, thus may make "tp" invalid. */
3646 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3647 prevwin
= next_prevwin
;
3650 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3652 if (old_curbuf
!= curbuf
)
3653 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3656 last_status(FALSE
); /* status line may appear or disappear */
3657 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3658 must_redraw
= CLEAR
; /* need to redraw everything */
3660 diff_need_scrollbind
= TRUE
;
3663 /* The tabpage line may have appeared or disappeared, may need to resize
3664 * the frames for that. When the Vim window was resized need to update
3665 * frame sizes too. Use the stored value of p_ch, so that it can be
3666 * different for each tab page. */
3667 p_ch
= curtab
->tp_ch_used
;
3668 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3669 #ifdef FEAT_GUI_TABLINE
3670 && !gui_use_tabline()
3674 #ifdef FEAT_VERTSPLIT
3675 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3676 shell_new_columns(); /* update window widths */
3679 #if defined(FEAT_GUI)
3680 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3681 * scrollbars. Have to update them anyway. */
3682 gui_may_update_scrollbars();
3685 redraw_all_later(CLEAR
);
3689 * Go to tab page "n". For ":tab N" and "Ngt".
3690 * When "n" is 9999 go to the last tab page.
3702 /* Not allowed when editing the command line. */
3704 if (cmdwin_type
!= 0)
3712 /* If there is only one it can't work. */
3713 if (first_tabpage
->tp_next
== NULL
)
3722 /* No count, go to next tab page, wrap around end. */
3723 if (curtab
->tp_next
== NULL
)
3726 tp
= curtab
->tp_next
;
3730 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3733 for (i
= n
; i
< 0; ++i
)
3735 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3743 /* Go to last tab page. */
3744 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3749 /* Go to tab page "n". */
3750 tp
= find_tabpage(n
);
3758 goto_tabpage_tp(tp
);
3760 #ifdef FEAT_GUI_TABLINE
3761 if (gui_use_tabline())
3762 gui_mch_set_curtab(tabpage_index(curtab
));
3767 * Go to tabpage "tp".
3768 * Note: doesn't update the GUI tab.
3774 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3776 if (valid_tabpage(tp
))
3777 enter_tabpage(tp
, curbuf
);
3779 enter_tabpage(curtab
, curbuf
);
3784 * Enter window "wp" in tab page "tp".
3785 * Also updates the GUI tab.
3788 goto_tabpage_win(tp
, wp
)
3792 goto_tabpage_tp(tp
);
3793 if (curtab
== tp
&& win_valid(wp
))
3795 win_enter(wp
, TRUE
);
3796 # ifdef FEAT_GUI_TABLINE
3797 if (gui_use_tabline())
3798 gui_mch_set_curtab(tabpage_index(curtab
));
3804 * Move the current tab page to before tab page "nr".
3813 if (first_tabpage
->tp_next
== NULL
)
3816 /* Remove the current tab page from the list of tab pages. */
3817 if (curtab
== first_tabpage
)
3818 first_tabpage
= curtab
->tp_next
;
3821 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3822 if (tp
->tp_next
== curtab
)
3824 if (tp
== NULL
) /* "cannot happen" */
3826 tp
->tp_next
= curtab
->tp_next
;
3829 /* Re-insert it at the specified position. */
3832 curtab
->tp_next
= first_tabpage
;
3833 first_tabpage
= curtab
;
3837 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3839 curtab
->tp_next
= tp
->tp_next
;
3840 tp
->tp_next
= curtab
;
3843 /* Need to redraw the tabline. Tab page contents doesn't change. */
3844 redraw_tabline
= TRUE
;
3849 * Go to another window.
3850 * When jumping to another buffer, stop Visual mode. Do this before
3851 * changing windows so we can yank the selection into the '*' register.
3852 * When jumping to another window on the same buffer, adjust its cursor
3853 * position to keep the same Visual area.
3866 if (curbuf_locked())
3871 if (wp
->w_buffer
!= curbuf
)
3872 reset_VIsual_and_resel();
3873 else if (VIsual_active
)
3874 wp
->w_cursor
= curwin
->w_cursor
;
3878 need_mouse_correct
= TRUE
;
3880 win_enter(wp
, TRUE
);
3883 #if defined(FEAT_PERL) || defined(PROTO)
3885 * Find window number "winnr" (counting top to bottom).
3893 # ifdef FEAT_WINDOWS
3894 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3904 #ifdef FEAT_VERTSPLIT
3906 * Move to window above or below "count" times.
3909 win_goto_ver(up
, count
)
3910 int up
; /* TRUE to go to win above */
3917 foundfr
= curwin
->w_frame
;
3921 * First go upwards in the tree of frames until we find a upwards or
3922 * downwards neighbor.
3933 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3939 * Now go downwards to find the bottom or top frame in it.
3943 if (nfr
->fr_layout
== FR_LEAF
)
3949 if (nfr
->fr_layout
== FR_ROW
)
3951 /* Find the frame at the cursor row. */
3952 while (fr
->fr_next
!= NULL
3953 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3954 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3957 if (nfr
->fr_layout
== FR_COL
&& up
)
3958 while (fr
->fr_next
!= NULL
)
3964 if (foundfr
!= NULL
)
3965 win_goto(foundfr
->fr_win
);
3969 * Move to left or right window.
3972 win_goto_hor(left
, count
)
3973 int left
; /* TRUE to go to left win */
3980 foundfr
= curwin
->w_frame
;
3984 * First go upwards in the tree of frames until we find a left or
3996 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
4002 * Now go downwards to find the leftmost or rightmost frame in it.
4006 if (nfr
->fr_layout
== FR_LEAF
)
4012 if (nfr
->fr_layout
== FR_COL
)
4014 /* Find the frame at the cursor row. */
4015 while (fr
->fr_next
!= NULL
4016 && frame2win(fr
)->w_winrow
+ fr
->fr_height
4017 <= curwin
->w_winrow
+ curwin
->w_wrow
)
4020 if (nfr
->fr_layout
== FR_ROW
&& left
)
4021 while (fr
->fr_next
!= NULL
)
4027 if (foundfr
!= NULL
)
4028 win_goto(foundfr
->fr_win
);
4033 * Make window "wp" the current window.
4036 win_enter(wp
, undo_sync
)
4040 win_enter_ext(wp
, undo_sync
, FALSE
);
4044 * Make window wp the current window.
4045 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
4046 * been closed and isn't valid.
4049 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
4055 int other_buffer
= FALSE
;
4058 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
4062 if (!curwin_invalid
)
4065 * Be careful: If autocommands delete the window, return now.
4067 if (wp
->w_buffer
!= curbuf
)
4069 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4070 other_buffer
= TRUE
;
4074 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4078 /* autocmds may abort script processing */
4085 /* sync undo before leaving the current buffer */
4086 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4088 /* may have to copy the buffer options when 'cpo' contains 'S' */
4089 if (wp
->w_buffer
!= curbuf
)
4090 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4091 if (!curwin_invalid
)
4093 prevwin
= curwin
; /* remember for CTRL-W p */
4094 curwin
->w_redr_status
= TRUE
;
4097 curbuf
= wp
->w_buffer
;
4099 #ifdef FEAT_VIRTUALEDIT
4100 if (!virtual_active())
4101 curwin
->w_cursor
.coladd
= 0;
4103 changed_line_abv_curs(); /* assume cursor position needs updating */
4105 if (curwin
->w_localdir
!= NULL
)
4107 /* Window has a local directory: Save current directory as global
4108 * directory (unless that was done already) and change to the local
4110 if (globaldir
== NULL
)
4112 char_u cwd
[MAXPATHL
];
4114 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4115 globaldir
= vim_strsave(cwd
);
4117 if (mch_chdir((char *)curwin
->w_localdir
) == 0)
4118 shorten_fnames(TRUE
);
4120 else if (globaldir
!= NULL
)
4122 /* Window doesn't have a local directory and we are not in the global
4123 * directory: Change to the global directory. */
4124 ignored
= mch_chdir((char *)globaldir
);
4125 vim_free(globaldir
);
4127 shorten_fnames(TRUE
);
4131 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4133 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4139 curwin
->w_redr_status
= TRUE
;
4140 redraw_tabline
= TRUE
;
4142 redraw_later(VALID
); /* causes status line redraw */
4144 /* set window height to desired minimal value */
4145 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4146 win_setheight((int)p_wh
);
4147 else if (curwin
->w_height
== 0)
4150 #ifdef FEAT_VERTSPLIT
4151 /* set window width to desired minimal value */
4152 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4153 win_setwidth((int)p_wiw
);
4157 setmouse(); /* in case jumped to/from help buffer */
4160 /* Change directories when the 'acd' option is set. */
4164 #endif /* FEAT_WINDOWS */
4166 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4168 * Jump to the first open window that contains buffer "buf", if one exists.
4169 * Returns a pointer to the window found, otherwise NULL.
4172 buf_jump_open_win(buf
)
4175 # ifdef FEAT_WINDOWS
4178 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4179 if (wp
->w_buffer
== buf
)
4182 win_enter(wp
, FALSE
);
4185 if (curwin
->w_buffer
== buf
)
4192 * Jump to the first open window in any tab page that contains buffer "buf",
4194 * Returns a pointer to the window found, otherwise NULL.
4197 buf_jump_open_tab(buf
)
4200 # ifdef FEAT_WINDOWS
4204 /* First try the current tab page. */
4205 wp
= buf_jump_open_win(buf
);
4209 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4212 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4213 if (wp
->w_buffer
== buf
)
4217 goto_tabpage_win(tp
, wp
);
4219 wp
= NULL
; /* something went wrong */
4226 if (curwin
->w_buffer
== buf
)
4234 * Allocate a window structure and link it in the window list when "hidden" is
4238 win_alloc(after
, hidden
)
4239 win_T
*after UNUSED
;
4245 * allocate window structure and linesizes arrays
4247 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4248 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4257 /* Don't execute autocommands while the window is not properly
4258 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4263 * link the window in the window list
4267 win_append(after
, newwin
);
4269 #ifdef FEAT_VERTSPLIT
4270 newwin
->w_wincol
= 0;
4271 newwin
->w_width
= Columns
;
4274 /* position the display and the cursor at the top of the file. */
4275 newwin
->w_topline
= 1;
4277 newwin
->w_topfill
= 0;
4279 newwin
->w_botline
= 2;
4280 newwin
->w_cursor
.lnum
= 1;
4281 #ifdef FEAT_SCROLLBIND
4282 newwin
->w_scbind_pos
= 1;
4285 /* We won't calculate w_fraction until resizing the window */
4286 newwin
->w_fraction
= 0;
4287 newwin
->w_prev_fraction_row
= -1;
4292 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4294 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4295 SBAR_RIGHT
, newwin
);
4299 /* init w: variables */
4300 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4303 foldInitWin(newwin
);
4308 #ifdef FEAT_SEARCH_EXTRA
4309 newwin
->w_match_head
= NULL
;
4310 newwin
->w_next_match_id
= 4;
4316 #if defined(FEAT_WINDOWS) || defined(PROTO)
4319 * remove window 'wp' from the window list and free the structure
4324 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4332 /* reduce the reference count to the argument list. */
4333 alist_unlink(wp
->w_alist
);
4336 /* Don't execute autocommands while the window is halfway being deleted.
4337 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4341 #ifdef FEAT_MZSCHEME
4342 mzscheme_window_free(wp
);
4350 python_window_free(wp
);
4354 tcl_window_free(wp
);
4358 ruby_window_free(wp
);
4361 clear_winopt(&wp
->w_onebuf_opt
);
4362 clear_winopt(&wp
->w_allbuf_opt
);
4365 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4372 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4373 vim_free(wp
->w_tagstack
[i
].tagname
);
4375 vim_free(wp
->w_localdir
);
4377 #ifdef FEAT_SEARCH_EXTRA
4381 #ifdef FEAT_JUMPLIST
4385 #ifdef FEAT_QUICKFIX
4392 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4393 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4395 #endif /* FEAT_GUI */
4398 if (wp
!= aucmd_win
)
4409 * Append window "wp" in the window list after window "after".
4412 win_append(after
, wp
)
4417 if (after
== NULL
) /* after NULL is in front of the first */
4420 before
= after
->w_next
;
4422 wp
->w_next
= before
;
4431 before
->w_prev
= wp
;
4435 * Remove a window from the window list.
4440 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4442 if (wp
->w_prev
!= NULL
)
4443 wp
->w_prev
->w_next
= wp
->w_next
;
4444 else if (tp
== NULL
)
4445 firstwin
= wp
->w_next
;
4447 tp
->tp_firstwin
= wp
->w_next
;
4448 if (wp
->w_next
!= NULL
)
4449 wp
->w_next
->w_prev
= wp
->w_prev
;
4450 else if (tp
== NULL
)
4451 lastwin
= wp
->w_prev
;
4453 tp
->tp_lastwin
= wp
->w_prev
;
4457 * Append frame "frp" in a frame list after frame "after".
4460 frame_append(after
, frp
)
4461 frame_T
*after
, *frp
;
4463 frp
->fr_next
= after
->fr_next
;
4464 after
->fr_next
= frp
;
4465 if (frp
->fr_next
!= NULL
)
4466 frp
->fr_next
->fr_prev
= frp
;
4467 frp
->fr_prev
= after
;
4471 * Insert frame "frp" in a frame list before frame "before".
4474 frame_insert(before
, frp
)
4475 frame_T
*before
, *frp
;
4477 frp
->fr_next
= before
;
4478 frp
->fr_prev
= before
->fr_prev
;
4479 before
->fr_prev
= frp
;
4480 if (frp
->fr_prev
!= NULL
)
4481 frp
->fr_prev
->fr_next
= frp
;
4483 frp
->fr_parent
->fr_child
= frp
;
4487 * Remove a frame from a frame list.
4493 if (frp
->fr_prev
!= NULL
)
4494 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4496 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4497 if (frp
->fr_next
!= NULL
)
4498 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4501 #endif /* FEAT_WINDOWS */
4504 * Allocate w_lines[] for window "wp".
4505 * Return FAIL for failure, OK for success.
4511 wp
->w_lines_valid
= 0;
4512 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4513 if (wp
->w_lines
== NULL
)
4519 * free lsize arrays for a window
4525 vim_free(wp
->w_lines
);
4530 * Called from win_new_shellsize() after Rows changed.
4531 * This only does the current tab page, others must be done when made active.
4536 int h
= (int)ROWS_AVAIL
;
4538 if (firstwin
== NULL
) /* not initialized yet */
4541 if (h
< frame_minheight(topframe
, NULL
))
4542 h
= frame_minheight(topframe
, NULL
);
4544 /* First try setting the heights of windows with 'winfixheight'. If
4545 * that doesn't result in the right height, forget about that option. */
4546 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4547 if (topframe
->fr_height
!= h
)
4548 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4550 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4554 win_new_height(firstwin
, h
);
4558 curtab
->tp_ch_used
= p_ch
;
4562 /* Disabled: don't want making the screen smaller make a window larger. */
4564 win_equal(curwin
, FALSE
, 'v');
4568 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4570 * Called from win_new_shellsize() after Columns changed.
4575 if (firstwin
== NULL
) /* not initialized yet */
4578 /* First try setting the widths of windows with 'winfixwidth'. If that
4579 * doesn't result in the right width, forget about that option. */
4580 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4581 if (topframe
->fr_width
!= Columns
)
4582 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4584 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4586 /* Disabled: don't want making the screen smaller make a window larger. */
4588 win_equal(curwin
, FALSE
, 'h');
4593 #if defined(FEAT_CMDWIN) || defined(PROTO)
4595 * Save the size of all windows in "gap".
4604 ga_init2(gap
, (int)sizeof(int), 1);
4605 if (ga_grow(gap
, win_count() * 2) == OK
)
4606 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4608 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4609 wp
->w_width
+ wp
->w_vsep_width
;
4610 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4615 * Restore window sizes, but only if the number of windows is still the same.
4616 * Does not free the growarray.
4619 win_size_restore(gap
)
4625 if (win_count() * 2 == gap
->ga_len
)
4628 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4630 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4631 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4633 /* recompute the window positions */
4634 (void)win_comp_pos();
4637 #endif /* FEAT_CMDWIN */
4639 #if defined(FEAT_WINDOWS) || defined(PROTO)
4641 * Update the position for all windows, using the width and height of the
4643 * Returns the row just after the last window.
4648 int row
= tabline_height();
4651 frame_comp_pos(topframe
, &row
, &col
);
4656 * Update the position of the windows in frame "topfrp", using the width and
4657 * height of the frames.
4658 * "*row" and "*col" are the top-left position of the frame. They are updated
4659 * to the bottom-right position plus one.
4662 frame_comp_pos(topfrp
, row
, col
)
4669 #ifdef FEAT_VERTSPLIT
4674 wp
= topfrp
->fr_win
;
4677 if (wp
->w_winrow
!= *row
4678 #ifdef FEAT_VERTSPLIT
4679 || wp
->w_wincol
!= *col
4683 /* position changed, redraw */
4684 wp
->w_winrow
= *row
;
4685 #ifdef FEAT_VERTSPLIT
4686 wp
->w_wincol
= *col
;
4688 redraw_win_later(wp
, NOT_VALID
);
4689 wp
->w_redr_status
= TRUE
;
4691 *row
+= wp
->w_height
+ wp
->w_status_height
;
4692 #ifdef FEAT_VERTSPLIT
4693 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4698 #ifdef FEAT_VERTSPLIT
4702 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4704 #ifdef FEAT_VERTSPLIT
4705 if (topfrp
->fr_layout
== FR_ROW
)
4706 *row
= startrow
; /* all frames are at the same row */
4708 *col
= startcol
; /* all frames are at the same col */
4710 frame_comp_pos(frp
, row
, col
);
4715 #endif /* FEAT_WINDOWS */
4718 * Set current window height and take care of repositioning other windows to
4722 win_setheight(height
)
4725 win_setheight_win(height
, curwin
);
4729 * Set the window height of window "win" and take care of repositioning other
4730 * windows to fit around it.
4733 win_setheight_win(height
, win
)
4741 /* Always keep current window at least one line high, even when
4742 * 'winminheight' is zero. */
4752 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4754 /* recompute the window positions */
4755 row
= win_comp_pos();
4757 if (height
> topframe
->fr_height
)
4758 height
= topframe
->fr_height
;
4759 win
->w_height
= height
;
4764 * If there is extra space created between the last window and the command
4767 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4768 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4773 redraw_all_later(NOT_VALID
);
4776 #if defined(FEAT_WINDOWS) || defined(PROTO)
4779 * Set the height of a frame to "height" and take care that all frames and
4780 * windows inside it are resized. Also resize frames on the left and right if
4781 * the are in the same FR_ROW frame.
4784 * If the frame is part of a FR_COL frame, try fitting the frame in that
4785 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4786 * go to containing frames to resize them and make room.
4787 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4788 * Check for the minimal height of the FR_ROW frame.
4789 * At the top level we can also use change the command line height.
4792 frame_setheight(curfrp
, height
)
4796 int room
; /* total number of lines available */
4797 int take
; /* number of lines taken from other windows */
4798 int room_cmdline
; /* lines available from cmdline */
4804 /* If the height already is the desired value, nothing to do. */
4805 if (curfrp
->fr_height
== height
)
4808 if (curfrp
->fr_parent
== NULL
)
4810 /* topframe: can only change the command line */
4811 if (height
> ROWS_AVAIL
)
4812 height
= ROWS_AVAIL
;
4814 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4816 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4818 /* Row of frames: Also need to resize frames left and right of this
4819 * one. First check for the minimal height of these. */
4820 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4823 frame_setheight(curfrp
->fr_parent
, height
);
4828 * Column of frames: try to change only frames in this column.
4830 #ifdef FEAT_VERTSPLIT
4833 * 1: compute room available, if it's not enough try resizing the
4835 * 2: compute the room available and adjust the height to it.
4836 * Try not to reduce the height of a window with 'winfixheight' set.
4838 for (run
= 1; run
<= 2; ++run
)
4845 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4849 && frp
->fr_win
!= NULL
4850 && frp
->fr_win
->w_p_wfh
)
4851 room_reserved
+= frp
->fr_height
;
4852 room
+= frp
->fr_height
;
4854 room
-= frame_minheight(frp
, NULL
);
4856 #ifdef FEAT_VERTSPLIT
4857 if (curfrp
->fr_width
!= Columns
)
4862 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4863 + lastwin
->w_height
+ lastwin
->w_status_height
);
4864 if (room_cmdline
< 0)
4868 if (height
<= room
+ room_cmdline
)
4870 #ifdef FEAT_VERTSPLIT
4871 if (run
== 2 || curfrp
->fr_width
== Columns
)
4874 if (height
> room
+ room_cmdline
)
4875 height
= room
+ room_cmdline
;
4878 #ifdef FEAT_VERTSPLIT
4879 frame_setheight(curfrp
->fr_parent
, height
4880 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4886 * Compute the number of lines we will take from others frames (can be
4889 take
= height
- curfrp
->fr_height
;
4891 /* If there is not enough room, also reduce the height of a window
4892 * with 'winfixheight' set. */
4893 if (height
> room
+ room_cmdline
- room_reserved
)
4894 room_reserved
= room
+ room_cmdline
- height
;
4895 /* If there is only a 'winfixheight' window and making the
4896 * window smaller, need to make the other window taller. */
4897 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4900 if (take
> 0 && room_cmdline
> 0)
4902 /* use lines from cmdline first */
4903 if (take
< room_cmdline
)
4904 room_cmdline
= take
;
4905 take
-= room_cmdline
;
4906 topframe
->fr_height
+= room_cmdline
;
4910 * set the current frame to the new height
4912 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4915 * First take lines from the frames after the current frame. If
4916 * that is not enough, takes lines from frames above the current
4919 for (run
= 0; run
< 2; ++run
)
4922 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4924 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4925 while (frp
!= NULL
&& take
!= 0)
4927 h
= frame_minheight(frp
, NULL
);
4928 if (room_reserved
> 0
4929 && frp
->fr_win
!= NULL
4930 && frp
->fr_win
->w_p_wfh
)
4932 if (room_reserved
>= frp
->fr_height
)
4933 room_reserved
-= frp
->fr_height
;
4936 if (frp
->fr_height
- room_reserved
> take
)
4937 room_reserved
= frp
->fr_height
- take
;
4938 take
-= frp
->fr_height
- room_reserved
;
4939 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4945 if (frp
->fr_height
- take
< h
)
4947 take
-= frp
->fr_height
- h
;
4948 frame_new_height(frp
, h
, FALSE
, FALSE
);
4952 frame_new_height(frp
, frp
->fr_height
- take
,
4966 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4968 * Set current window width and take care of repositioning other windows to
4975 win_setwidth_win(width
, curwin
);
4979 win_setwidth_win(width
, wp
)
4983 /* Always keep current window at least one column wide, even when
4984 * 'winminwidth' is zero. */
4993 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4995 /* recompute the window positions */
4996 (void)win_comp_pos();
4998 redraw_all_later(NOT_VALID
);
5002 * Set the width of a frame to "width" and take care that all frames and
5003 * windows inside it are resized. Also resize frames above and below if the
5004 * are in the same FR_ROW frame.
5006 * Strategy is similar to frame_setheight().
5009 frame_setwidth(curfrp
, width
)
5013 int room
; /* total number of lines available */
5014 int take
; /* number of lines taken from other windows */
5020 /* If the width already is the desired value, nothing to do. */
5021 if (curfrp
->fr_width
== width
)
5024 if (curfrp
->fr_parent
== NULL
)
5025 /* topframe: can't change width */
5028 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
5030 /* Column of frames: Also need to resize frames above and below of
5031 * this one. First check for the minimal width of these. */
5032 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
5035 frame_setwidth(curfrp
->fr_parent
, width
);
5040 * Row of frames: try to change only frames in this row.
5043 * 1: compute room available, if it's not enough try resizing the
5045 * 2: compute the room available and adjust the width to it.
5047 for (run
= 1; run
<= 2; ++run
)
5051 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
5055 && frp
->fr_win
!= NULL
5056 && frp
->fr_win
->w_p_wfw
)
5057 room_reserved
+= frp
->fr_width
;
5058 room
+= frp
->fr_width
;
5060 room
-= frame_minwidth(frp
, NULL
);
5065 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
5071 frame_setwidth(curfrp
->fr_parent
, width
5072 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
5076 * Compute the number of lines we will take from others frames (can be
5079 take
= width
- curfrp
->fr_width
;
5081 /* If there is not enough room, also reduce the width of a window
5082 * with 'winfixwidth' set. */
5083 if (width
> room
- room_reserved
)
5084 room_reserved
= room
- width
;
5085 /* If there is only a 'winfixwidth' window and making the
5086 * window smaller, need to make the other window narrower. */
5087 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
5091 * set the current frame to the new width
5093 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
5096 * First take lines from the frames right of the current frame. If
5097 * that is not enough, takes lines from frames left of the current
5100 for (run
= 0; run
< 2; ++run
)
5103 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5105 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5106 while (frp
!= NULL
&& take
!= 0)
5108 w
= frame_minwidth(frp
, NULL
);
5109 if (room_reserved
> 0
5110 && frp
->fr_win
!= NULL
5111 && frp
->fr_win
->w_p_wfw
)
5113 if (room_reserved
>= frp
->fr_width
)
5114 room_reserved
-= frp
->fr_width
;
5117 if (frp
->fr_width
- room_reserved
> take
)
5118 room_reserved
= frp
->fr_width
- take
;
5119 take
-= frp
->fr_width
- room_reserved
;
5120 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5126 if (frp
->fr_width
- take
< w
)
5128 take
-= frp
->fr_width
- w
;
5129 frame_new_width(frp
, w
, FALSE
, FALSE
);
5133 frame_new_width(frp
, frp
->fr_width
- take
,
5146 #endif /* FEAT_VERTSPLIT */
5149 * Check 'winminheight' for a valid value.
5158 /* loop until there is a 'winminheight' that is possible */
5161 /* TODO: handle vertical splits */
5163 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5164 room
+= wp
->w_height
- p_wmh
;
5179 * Status line of dragwin is dragged "offset" lines down (negative is up).
5182 win_drag_status_line(dragwin
, offset
)
5190 int up
; /* if TRUE, drag status line up, otherwise down */
5193 fr
= dragwin
->w_frame
;
5195 if (fr
!= topframe
) /* more than one window */
5198 /* When the parent frame is not a column of frames, its parent should
5200 if (fr
->fr_layout
!= FR_COL
)
5203 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5208 /* If this is the last frame in a column, may want to resize the parent
5209 * frame instead (go two up to skip a row of frames). */
5210 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5219 if (offset
< 0) /* drag up */
5223 /* sum up the room of the current frame and above it */
5226 /* only one window */
5227 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5232 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5234 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5239 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5241 else /* drag down */
5245 * Only dragging the last status line can reduce p_ch.
5247 room
= Rows
- cmdline_row
;
5248 if (curfr
->fr_next
== NULL
)
5254 /* sum up the room of frames below of the current one */
5255 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5256 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5257 fr
= curfr
; /* put fr at window that grows */
5260 if (room
< offset
) /* Not enough room */
5261 offset
= room
; /* Move as far as we can */
5266 * Grow frame fr by "offset" lines.
5267 * Doesn't happen when dragging the last status line up.
5270 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5273 fr
= curfr
; /* current frame gets smaller */
5275 fr
= curfr
->fr_next
; /* next frame gets smaller */
5278 * Now make the other frames smaller.
5280 while (fr
!= NULL
&& offset
> 0)
5282 n
= frame_minheight(fr
, NULL
);
5283 if (fr
->fr_height
- offset
<= n
)
5285 offset
-= fr
->fr_height
- n
;
5286 frame_new_height(fr
, n
, !up
, FALSE
);
5290 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5298 row
= win_comp_pos();
5299 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5301 p_ch
= Rows
- cmdline_row
;
5304 curtab
->tp_ch_used
= p_ch
;
5305 redraw_all_later(SOME_VALID
);
5309 #ifdef FEAT_VERTSPLIT
5311 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5314 win_drag_vsep_line(dragwin
, offset
)
5321 int left
; /* if TRUE, drag separator line left, otherwise right */
5324 fr
= dragwin
->w_frame
;
5325 if (fr
== topframe
) /* only one window (cannot happen?) */
5329 /* When the parent frame is not a row of frames, its parent should be. */
5330 if (fr
->fr_layout
!= FR_ROW
)
5332 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5338 /* If this is the last frame in a row, may want to resize a parent
5340 while (curfr
->fr_next
== NULL
)
5353 if (offset
< 0) /* drag left */
5357 /* sum up the room of the current frame and left of it */
5359 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5361 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5365 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5367 else /* drag right */
5370 /* sum up the room of frames right of the current one */
5372 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5373 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5374 fr
= curfr
; /* put fr at window that grows */
5377 if (room
< offset
) /* Not enough room */
5378 offset
= room
; /* Move as far as we can */
5379 if (offset
<= 0) /* No room at all, quit. */
5382 /* grow frame fr by offset lines */
5383 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5385 /* shrink other frames: current and at the left or at the right */
5387 fr
= curfr
; /* current frame gets smaller */
5389 fr
= curfr
->fr_next
; /* next frame gets smaller */
5391 while (fr
!= NULL
&& offset
> 0)
5393 n
= frame_minwidth(fr
, NULL
);
5394 if (fr
->fr_width
- offset
<= n
)
5396 offset
-= fr
->fr_width
- n
;
5397 frame_new_width(fr
, n
, !left
, FALSE
);
5401 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5409 (void)win_comp_pos();
5410 redraw_all_later(NOT_VALID
);
5412 #endif /* FEAT_VERTSPLIT */
5413 #endif /* FEAT_MOUSE */
5415 #endif /* FEAT_WINDOWS */
5418 * Set the height of a window.
5419 * This takes care of the things inside the window, not what happens to the
5420 * window position, the frame or to other windows.
5423 win_new_height(wp
, height
)
5428 int sline
, line_size
;
5429 #define FRACTION_MULT 16384L
5431 /* Don't want a negative height. Happens when splitting a tiny window.
5432 * Will equalize heights soon to fix it. */
5435 if (wp
->w_height
== height
)
5436 return; /* nothing to do */
5438 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5439 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5440 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5442 wp
->w_height
= height
;
5445 /* Don't change w_topline when height is zero. Don't set w_topline when
5446 * 'scrollbind' is set and this isn't the current window. */
5448 #ifdef FEAT_SCROLLBIND
5449 && (!wp
->w_p_scb
|| wp
== curwin
)
5454 * Find a value for w_topline that shows the cursor at the same
5455 * relative position in the window as before (more or less).
5457 lnum
= wp
->w_cursor
.lnum
;
5458 if (lnum
< 1) /* can happen when starting up */
5460 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5461 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5462 sline
= wp
->w_wrow
- line_size
;
5466 /* Make sure the whole cursor line is visible, if possible. */
5467 int rows
= plines_win(wp
, lnum
, FALSE
);
5469 if (sline
> wp
->w_height
- rows
)
5471 sline
= wp
->w_height
- rows
;
5472 wp
->w_wrow
-= rows
- line_size
;
5479 * Cursor line would go off top of screen if w_wrow was this high.
5480 * Make cursor line the first line in the window. If not enough
5481 * room use w_skipcol;
5483 wp
->w_wrow
= line_size
;
5484 if (wp
->w_wrow
>= wp
->w_height
5485 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5487 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5489 while (wp
->w_wrow
>= wp
->w_height
)
5491 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5499 while (sline
> 0 && lnum
> 1)
5502 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5505 /* first line in buffer is folded */
5513 if (lnum
== wp
->w_topline
)
5514 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5518 line_size
= plines_win(wp
, lnum
, TRUE
);
5525 * Line we want at top would go off top of screen. Use next
5529 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5532 wp
->w_wrow
-= line_size
+ sline
;
5536 /* First line of file reached, use that as topline. */
5538 wp
->w_wrow
-= sline
;
5541 set_topline(wp
, lnum
);
5548 curs_columns(FALSE
); /* validate w_wrow */
5550 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5552 win_comp_scroll(wp
);
5553 redraw_win_later(wp
, SOME_VALID
);
5555 wp
->w_redr_status
= TRUE
;
5557 invalidate_botline_win(wp
);
5560 #ifdef FEAT_VERTSPLIT
5562 * Set the width of a window.
5565 win_new_width(wp
, width
)
5569 wp
->w_width
= width
;
5570 wp
->w_lines_valid
= 0;
5571 changed_line_abv_curs_win(wp
);
5572 invalidate_botline_win(wp
);
5576 curs_columns(TRUE
); /* validate w_wrow */
5578 redraw_win_later(wp
, NOT_VALID
);
5579 wp
->w_redr_status
= TRUE
;
5587 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5588 if (wp
->w_p_scr
== 0)
5593 * command_height: called whenever p_ch has been changed
5601 int old_p_ch
= curtab
->tp_ch_used
;
5603 /* Use the value of p_ch that we remembered. This is needed for when the
5604 * GUI starts up, we can't be sure in what order things happen. And when
5605 * p_ch was changed in another tab page. */
5606 curtab
->tp_ch_used
= p_ch
;
5608 /* Find bottom frame with width of screen. */
5609 frp
= lastwin
->w_frame
;
5610 # ifdef FEAT_VERTSPLIT
5611 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5612 frp
= frp
->fr_parent
;
5615 /* Avoid changing the height of a window with 'winfixheight' set. */
5616 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5617 && frp
->fr_win
->w_p_wfh
)
5620 if (starting
!= NO_SCREEN
)
5622 cmdline_row
= Rows
- p_ch
;
5624 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5626 while (p_ch
> old_p_ch
)
5632 curtab
->tp_ch_used
= p_ch
;
5633 cmdline_row
= Rows
- p_ch
;
5636 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5637 if (h
> p_ch
- old_p_ch
)
5638 h
= p_ch
- old_p_ch
;
5640 frame_add_height(frp
, -h
);
5644 /* Recompute window positions. */
5645 (void)win_comp_pos();
5647 /* clear the lines added to cmdline */
5649 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5650 (int)Columns
, ' ', ' ', 0);
5651 msg_row
= cmdline_row
;
5652 redraw_cmdline
= TRUE
;
5656 if (msg_row
< cmdline_row
)
5657 msg_row
= cmdline_row
;
5658 redraw_cmdline
= TRUE
;
5660 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5662 /* Recompute window positions. */
5663 if (frp
!= lastwin
->w_frame
)
5664 (void)win_comp_pos();
5666 cmdline_row
= Rows
- p_ch
;
5667 win_setheight(cmdline_row
);
5671 #if defined(FEAT_WINDOWS) || defined(PROTO)
5673 * Resize frame "frp" to be "n" lines higher (negative for less high).
5674 * Also resize the frames it is contained in.
5677 frame_add_height(frp
, n
)
5681 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5684 frp
= frp
->fr_parent
;
5687 frp
->fr_height
+= n
;
5692 * Add or remove a status line for the bottom window(s), according to the
5693 * value of 'laststatus'.
5696 last_status(morewin
)
5697 int morewin
; /* pretend there are two or more windows */
5699 /* Don't make a difference between horizontal or vertical split. */
5700 last_status_rec(topframe
, (p_ls
== 2
5701 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5705 last_status_rec(fr
, statusline
)
5712 if (fr
->fr_layout
== FR_LEAF
)
5715 if (wp
->w_status_height
!= 0 && !statusline
)
5717 /* remove status line */
5718 win_new_height(wp
, wp
->w_height
+ 1);
5719 wp
->w_status_height
= 0;
5722 else if (wp
->w_status_height
== 0 && statusline
)
5724 /* Find a frame to take a line from. */
5726 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5733 /* In a column of frames: go to frame above. If already at
5734 * the top or in a row of frames: go to parent. */
5735 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5740 wp
->w_status_height
= 1;
5743 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5744 frame_fix_height(wp
);
5745 (void)win_comp_pos();
5748 win_new_height(wp
, wp
->w_height
- 1);
5750 redraw_all_later(SOME_VALID
);
5753 #ifdef FEAT_VERTSPLIT
5754 else if (fr
->fr_layout
== FR_ROW
)
5756 /* vertically split windows, set status line for each one */
5757 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5758 last_status_rec(fp
, statusline
);
5763 /* horizontally split window, set status line for last one */
5764 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5766 last_status_rec(fp
, statusline
);
5771 * Return the number of lines used by the tab page line.
5776 #ifdef FEAT_GUI_TABLINE
5777 /* When the GUI has the tabline then this always returns zero. */
5778 if (gui_use_tabline())
5784 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5789 #endif /* FEAT_WINDOWS */
5791 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5793 * Get the file name at the cursor.
5794 * If Visual mode is active, use the selected text if it's in one line.
5795 * Returns the name in allocated memory, NULL for failure.
5798 grab_file_name(count
, file_lnum
)
5800 linenr_T
*file_lnum
;
5808 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5810 return find_file_name_in_path(ptr
, len
,
5811 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5814 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5820 * Return the file name under or after the cursor.
5822 * The 'path' option is searched if the file name is not absolute.
5823 * The string returned has been alloc'ed and should be freed by the caller.
5824 * NULL is returned if the file name or file is not found.
5827 * FNAME_MESS give error messages
5828 * FNAME_EXP expand to path
5829 * FNAME_HYP check for hypertext link
5830 * FNAME_INCL apply "includeexpr"
5833 file_name_at_cursor(options
, count
, file_lnum
)
5836 linenr_T
*file_lnum
;
5838 return file_name_in_line(ml_get_curline(),
5839 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5844 * Return the name of the file under or after ptr[col].
5845 * Otherwise like file_name_at_cursor().
5848 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5853 char_u
*rel_fname
; /* file we are searching relative to */
5854 linenr_T
*file_lnum
; /* line number after the file name */
5860 * search forward for what could be the start of a file name
5863 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5865 if (*ptr
== NUL
) /* nothing found */
5867 if (options
& FNAME_MESS
)
5868 EMSG(_("E446: No file name under cursor"));
5873 * Search backward for first char of the file name.
5874 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5879 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5883 if (vim_isfilec(ptr
[-1])
5884 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5891 * Search forward for the last char of the file name.
5892 * Also allow "://" when ':' is not in 'isfname'.
5895 while (vim_isfilec(ptr
[len
])
5896 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5899 len
+= (*mb_ptr2len
)(ptr
+ len
);
5905 * If there is trailing punctuation, remove it.
5906 * But don't remove "..", could be a directory name.
5908 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5909 && ptr
[len
- 2] != '.')
5912 if (file_lnum
!= NULL
)
5916 /* Get the number after the file name and a separator character */
5922 ++p
; /* skip the separator */
5925 *file_lnum
= (int)getdigits(&p
);
5929 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5932 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5933 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5936 eval_includeexpr(ptr
, len
)
5942 set_vim_var_string(VV_FNAME
, ptr
, len
);
5943 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5944 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5945 set_vim_var_string(VV_FNAME
, NULL
, 0);
5951 * Return the name of the file ptr[len] in 'path'.
5952 * Otherwise like file_name_at_cursor().
5955 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5960 char_u
*rel_fname
; /* file we are searching relative to */
5964 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5965 char_u
*tofree
= NULL
;
5967 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5969 tofree
= eval_includeexpr(ptr
, len
);
5973 len
= (int)STRLEN(ptr
);
5978 if (options
& FNAME_EXP
)
5980 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5983 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5985 * If the file could not be found in a normal way, try applying
5986 * 'includeexpr' (unless done already).
5988 if (file_name
== NULL
5989 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5991 tofree
= eval_includeexpr(ptr
, len
);
5995 len
= (int)STRLEN(ptr
);
5996 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
6001 if (file_name
== NULL
&& (options
& FNAME_MESS
))
6005 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
6009 /* Repeat finding the file "count" times. This matters when it
6010 * appears several times in the path. */
6011 while (file_name
!= NULL
&& --count
> 0)
6013 vim_free(file_name
);
6014 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
6018 file_name
= vim_strnsave(ptr
, len
);
6020 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
6026 #endif /* FEAT_SEARCHPATH */
6029 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
6030 * Also check for ":\\", which MS Internet Explorer accepts, return
6037 if (STRNCMP(p
, "://", (size_t)3) == 0)
6039 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
6040 return URL_BACKSLASH
;
6045 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
6046 * Return URL_BACKSLASH for "name:\\".
6047 * Return zero otherwise.
6050 path_with_url(fname
)
6055 for (p
= fname
; isalpha(*p
); ++p
)
6057 return path_is_url(p
);
6061 * Return TRUE if "name" is a full (absolute) path name or URL.
6067 return (path_with_url(name
) != 0 || mch_isFullName(name
));
6071 * Get absolute file name into buffer "buf[len]".
6073 * return FAIL for failure, OK otherwise
6076 vim_FullName(fname
, buf
, len
, force
)
6077 char_u
*fname
, *buf
;
6079 int force
; /* force expansion even when already absolute */
6088 url
= path_with_url(fname
);
6090 retval
= mch_FullName(fname
, buf
, len
, force
);
6091 if (url
|| retval
== FAIL
)
6093 /* something failed; use the file name (truncate when too long) */
6094 vim_strncpy(buf
, fname
, len
- 1);
6096 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6103 * Return the minimal number of rows that is needed on the screen to display
6104 * the current number of windows.
6115 if (firstwin
== NULL
) /* not initialized yet */
6120 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6122 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6126 total
+= tabline_height();
6128 total
= 1; /* at least one window should have a line! */
6130 total
+= 1; /* count the room for the command line */
6135 * Return TRUE if there is only one window (in the current tab page), not
6136 * counting a help or preview window, unless it is the current window.
6137 * Does not count "aucmd_win".
6146 /* If there is another tab page there always is another window. */
6147 if (first_tabpage
->tp_next
!= NULL
)
6150 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6151 if ((!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6152 # ifdef FEAT_QUICKFIX
6156 # ifdef FEAT_AUTOCMD
6161 return (count
<= 1);
6167 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6169 * Correct the cursor line number in other windows. Used after changing the
6170 * current buffer, and before applying autocommands.
6171 * When "do_curwin" is TRUE, also check current window.
6174 check_lnums(do_curwin
)
6182 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6183 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6189 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6190 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6191 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6192 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6197 #if defined(FEAT_WINDOWS) || defined(PROTO)
6200 * A snapshot of the window sizes, to restore them after closing the help
6202 * Only these fields are used:
6208 * fr_win (only valid for the old curwin, NULL otherwise)
6212 * Create a snapshot of the current frame sizes.
6218 clear_snapshot(curtab
, idx
);
6219 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
[idx
]);
6223 make_snapshot_rec(fr
, frp
)
6227 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6230 (*frp
)->fr_layout
= fr
->fr_layout
;
6231 # ifdef FEAT_VERTSPLIT
6232 (*frp
)->fr_width
= fr
->fr_width
;
6234 (*frp
)->fr_height
= fr
->fr_height
;
6235 if (fr
->fr_next
!= NULL
)
6236 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6237 if (fr
->fr_child
!= NULL
)
6238 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6239 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6240 (*frp
)->fr_win
= curwin
;
6244 * Remove any existing snapshot.
6247 clear_snapshot(tp
, idx
)
6251 clear_snapshot_rec(tp
->tp_snapshot
[idx
]);
6252 tp
->tp_snapshot
[idx
] = NULL
;
6256 clear_snapshot_rec(fr
)
6261 clear_snapshot_rec(fr
->fr_next
);
6262 clear_snapshot_rec(fr
->fr_child
);
6268 * Restore a previously created snapshot, if there is any.
6269 * This is only done if the screen size didn't change and the window layout is
6273 restore_snapshot(idx
, close_curwin
)
6275 int close_curwin
; /* closing current window */
6279 if (curtab
->tp_snapshot
[idx
] != NULL
6280 # ifdef FEAT_VERTSPLIT
6281 && curtab
->tp_snapshot
[idx
]->fr_width
== topframe
->fr_width
6283 && curtab
->tp_snapshot
[idx
]->fr_height
== topframe
->fr_height
6284 && check_snapshot_rec(curtab
->tp_snapshot
[idx
], topframe
) == OK
)
6286 wp
= restore_snapshot_rec(curtab
->tp_snapshot
[idx
], topframe
);
6288 if (wp
!= NULL
&& close_curwin
)
6290 redraw_all_later(CLEAR
);
6292 clear_snapshot(curtab
, idx
);
6296 * Check if frames "sn" and "fr" have the same layout, same following frames
6297 * and same children.
6300 check_snapshot_rec(sn
, fr
)
6304 if (sn
->fr_layout
!= fr
->fr_layout
6305 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6306 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6307 || (sn
->fr_next
!= NULL
6308 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6309 || (sn
->fr_child
!= NULL
6310 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6316 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6317 * following frames and children.
6318 * Returns a pointer to the old current window, or NULL.
6321 restore_snapshot_rec(sn
, fr
)
6328 fr
->fr_height
= sn
->fr_height
;
6329 # ifdef FEAT_VERTSPLIT
6330 fr
->fr_width
= sn
->fr_width
;
6332 if (fr
->fr_layout
== FR_LEAF
)
6334 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6335 # ifdef FEAT_VERTSPLIT
6336 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6340 if (sn
->fr_next
!= NULL
)
6342 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6346 if (sn
->fr_child
!= NULL
)
6348 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6357 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6359 * Return TRUE if there is any vertically split window.
6366 if (topframe
->fr_layout
== FR_ROW
)
6369 if (topframe
->fr_layout
== FR_COL
)
6370 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6371 if (fr
->fr_layout
== FR_ROW
)
6378 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6380 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6381 * highlighted with the group 'grp' with priority 'prio'.
6382 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6383 * If no particular ID is desired, -1 must be specified for 'id'.
6384 * Return ID of added match, -1 on failure.
6387 match_add(wp
, grp
, pat
, prio
, id
)
6400 if (*grp
== NUL
|| *pat
== NUL
)
6402 if (id
< -1 || id
== 0)
6404 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6409 cur
= wp
->w_match_head
;
6414 EMSGN("E801: ID already taken: %ld", id
);
6420 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6422 EMSG2(_(e_nogroup
), grp
);
6425 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6427 EMSG2(_(e_invarg2
), pat
);
6431 /* Find available match ID. */
6434 cur
= wp
->w_match_head
;
6435 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6438 id
= wp
->w_next_match_id
;
6439 wp
->w_next_match_id
++;
6442 /* Build new match. */
6443 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6446 m
->pattern
= vim_strsave(pat
);
6448 m
->match
.regprog
= regprog
;
6449 m
->match
.rmm_ic
= FALSE
;
6450 m
->match
.rmm_maxcol
= 0;
6452 /* Insert new match. The match list is in ascending order with regard to
6453 * the match priorities. */
6454 cur
= wp
->w_match_head
;
6456 while (cur
!= NULL
&& prio
>= cur
->priority
)
6462 wp
->w_match_head
= m
;
6467 redraw_later(SOME_VALID
);
6472 * Delete match with ID 'id' in the match list of window 'wp'.
6473 * Print error messages if 'perr' is TRUE.
6476 match_delete(wp
, id
, perr
)
6481 matchitem_T
*cur
= wp
->w_match_head
;
6482 matchitem_T
*prev
= cur
;
6487 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6491 while (cur
!= NULL
&& cur
->id
!= id
)
6499 EMSGN("E803: ID not found: %ld", id
);
6503 wp
->w_match_head
= cur
->next
;
6505 prev
->next
= cur
->next
;
6506 vim_free(cur
->match
.regprog
);
6507 vim_free(cur
->pattern
);
6509 redraw_later(SOME_VALID
);
6514 * Delete all matches in the match list of window 'wp'.
6522 while (wp
->w_match_head
!= NULL
)
6524 m
= wp
->w_match_head
->next
;
6525 vim_free(wp
->w_match_head
->match
.regprog
);
6526 vim_free(wp
->w_match_head
->pattern
);
6527 vim_free(wp
->w_match_head
);
6528 wp
->w_match_head
= m
;
6530 redraw_later(SOME_VALID
);
6534 * Get match from ID 'id' in window 'wp'.
6535 * Return NULL if match not found.
6542 matchitem_T
*cur
= wp
->w_match_head
;
6544 while (cur
!= NULL
&& cur
->id
!= id
)