1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read a list of people who contributed.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
12 static int path_is_url
__ARGS((char_u
*p
));
13 #if defined(FEAT_WINDOWS) || defined(PROTO)
14 static int win_split_ins
__ARGS((int size
, int flags
, win_T
*newwin
, int dir
));
15 static void win_init
__ARGS((win_T
*newp
, win_T
*oldp
));
16 static void frame_comp_pos
__ARGS((frame_T
*topfrp
, int *row
, int *col
));
17 static void frame_setheight
__ARGS((frame_T
*curfrp
, int height
));
19 static void frame_setwidth
__ARGS((frame_T
*curfrp
, int width
));
21 static void win_exchange
__ARGS((long));
22 static void win_rotate
__ARGS((int, int));
23 static void win_totop
__ARGS((int size
, int flags
));
24 static void win_equal_rec
__ARGS((win_T
*next_curwin
, int current
, frame_T
*topfr
, int dir
, int col
, int row
, int width
, int height
));
25 static int last_window
__ARGS((void));
26 static win_T
*win_free_mem
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
27 static win_T
*winframe_remove
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
28 static frame_T
*win_altframe
__ARGS((win_T
*win
, tabpage_T
*tp
));
29 static tabpage_T
*alt_tabpage
__ARGS((void));
30 static win_T
*frame2win
__ARGS((frame_T
*frp
));
31 static int frame_has_win
__ARGS((frame_T
*frp
, win_T
*wp
));
32 static void frame_new_height
__ARGS((frame_T
*topfrp
, int height
, int topfirst
, int wfh
));
33 static int frame_fixed_height
__ARGS((frame_T
*frp
));
35 static int frame_fixed_width
__ARGS((frame_T
*frp
));
36 static void frame_add_statusline
__ARGS((frame_T
*frp
));
37 static void frame_new_width
__ARGS((frame_T
*topfrp
, int width
, int leftfirst
, int wfw
));
38 static void frame_add_vsep
__ARGS((frame_T
*frp
));
39 static int frame_minwidth
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
40 static void frame_fix_width
__ARGS((win_T
*wp
));
43 static int win_alloc_firstwin
__ARGS((win_T
*oldwin
));
44 #if defined(FEAT_WINDOWS) || defined(PROTO)
45 static tabpage_T
*alloc_tabpage
__ARGS((void));
46 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
47 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
48 static void frame_fix_height
__ARGS((win_T
*wp
));
49 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
50 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
51 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
52 static void win_append
__ARGS((win_T
*, win_T
*));
53 static void win_remove
__ARGS((win_T
*, tabpage_T
*tp
));
54 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
55 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
56 static void frame_remove
__ARGS((frame_T
*frp
));
58 static void win_new_width
__ARGS((win_T
*wp
, int width
));
59 static void win_goto_ver
__ARGS((int up
, long count
));
60 static void win_goto_hor
__ARGS((int left
, long count
));
62 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
63 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
65 static void make_snapshot
__ARGS((void));
66 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
67 static void clear_snapshot
__ARGS((tabpage_T
*tp
));
68 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
69 static void restore_snapshot
__ARGS((int close_curwin
));
70 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
71 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
73 #endif /* FEAT_WINDOWS */
75 static win_T
*win_alloc
__ARGS((win_T
*after
));
76 static void win_new_height
__ARGS((win_T
*, int));
78 #define URL_SLASH 1 /* path_is_url() has found "://" */
79 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
81 #define NOWIN (win_T *)-1 /* non-existing window */
84 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
86 # define ROWS_AVAIL (Rows - p_ch)
89 #if defined(FEAT_WINDOWS) || defined(PROTO)
91 static char *m_onlyone
= N_("Already only one window");
94 * all CTRL-W window commands are handled here, called from normal_cmd().
97 do_window(nchar
, Prenum
, xchar
)
100 int xchar
; /* extra char from ":wincmd gx" or NUL */
104 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
109 int type
= FIND_DEFINE
;
120 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
122 # define CHECK_CMDWIN
127 /* split current window in two parts, horizontally */
133 reset_VIsual_and_resel(); /* stop Visual mode */
136 /* When splitting the quickfix window open a new buffer in it,
137 * don't replicate the quickfix buffer. */
138 if (bt_quickfix(curbuf
))
142 need_mouse_correct
= TRUE
;
144 win_split((int)Prenum
, 0);
147 #ifdef FEAT_VERTSPLIT
148 /* split current window in two parts, vertically */
153 reset_VIsual_and_resel(); /* stop Visual mode */
155 # ifdef FEAT_QUICKFIX
156 /* When splitting the quickfix window open a new buffer in it,
157 * don't replicate the quickfix buffer. */
158 if (bt_quickfix(curbuf
))
162 need_mouse_correct
= TRUE
;
164 win_split((int)Prenum
, WSP_VERT
);
168 /* split current window and edit alternate file */
173 reset_VIsual_and_resel(); /* stop Visual mode */
175 STRCPY(cbuf
, "split #");
177 vim_snprintf((char *)cbuf
+ 7, sizeof(cbuf
) - 7,
179 do_cmdline_cmd(cbuf
);
182 /* open new window */
187 reset_VIsual_and_resel(); /* stop Visual mode */
194 vim_snprintf((char *)cbuf
, sizeof(cbuf
) - 5, "%ld", Prenum
);
197 #if defined(FEAT_VERTSPLIT) && defined(FEAT_QUICKFIX)
198 if (nchar
== 'v' || nchar
== Ctrl_V
)
202 do_cmdline_cmd(cbuf
);
205 /* quit current window */
209 reset_VIsual_and_resel(); /* stop Visual mode */
211 do_cmdline_cmd((char_u
*)"quit");
214 /* close current window */
218 reset_VIsual_and_resel(); /* stop Visual mode */
220 do_cmdline_cmd((char_u
*)"close");
223 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
224 /* close preview window */
229 reset_VIsual_and_resel(); /* stop Visual mode */
231 do_cmdline_cmd((char_u
*)"pclose");
234 /* cursor to preview window */
236 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
240 EMSG(_("E441: There is no preview window"));
246 /* close all but current window */
251 reset_VIsual_and_resel(); /* stop Visual mode */
253 do_cmdline_cmd((char_u
*)"only");
256 /* cursor to next window with wrap around */
259 /* cursor to previous window with wrap around */
262 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
266 if (Prenum
) /* go to specified window */
268 for (wp
= firstwin
; --Prenum
> 0; )
270 if (wp
->w_next
== NULL
)
278 if (nchar
== 'W') /* go to previous window */
282 wp
= lastwin
; /* wrap around */
284 else /* go to next window */
288 wp
= firstwin
; /* wrap around */
295 /* cursor to window below */
300 #ifdef FEAT_VERTSPLIT
301 win_goto_ver(FALSE
, Prenum1
);
303 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
310 /* cursor to window above */
315 #ifdef FEAT_VERTSPLIT
316 win_goto_ver(TRUE
, Prenum1
);
318 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
325 #ifdef FEAT_VERTSPLIT
326 /* cursor to left window */
332 win_goto_hor(TRUE
, Prenum1
);
335 /* cursor to right window */
340 win_goto_hor(FALSE
, Prenum1
);
344 /* move window to new tab page */
346 if (firstwin
== lastwin
)
350 tabpage_T
*oldtab
= curtab
;
353 /* First create a new tab with the window, then go back to
354 * the old tab and close the window there. */
356 if (win_new_tabpage((int)Prenum
) == OK
357 && valid_tabpage(oldtab
))
360 goto_tabpage_tp(oldtab
);
362 win_close(curwin
, FALSE
);
363 if (valid_tabpage(newtab
))
364 goto_tabpage_tp(newtab
);
369 /* cursor to top-left window */
375 /* cursor to bottom-right window */
381 /* cursor to last accessed (previous) window */
390 /* exchange current and next window */
394 win_exchange(Prenum
);
397 /* rotate windows downwards */
402 reset_VIsual_and_resel(); /* stop Visual mode */
404 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
407 /* rotate windows upwards */
411 reset_VIsual_and_resel(); /* stop Visual mode */
413 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
416 /* move window to the very top/bottom/left/right */
419 #ifdef FEAT_VERTSPLIT
424 win_totop((int)Prenum
,
425 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
426 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
429 /* make all windows the same height */
432 need_mouse_correct
= TRUE
;
434 win_equal(NULL
, FALSE
, 'b');
437 /* increase current window height */
440 need_mouse_correct
= TRUE
;
442 win_setheight(curwin
->w_height
+ (int)Prenum1
);
445 /* decrease current window height */
448 need_mouse_correct
= TRUE
;
450 win_setheight(curwin
->w_height
- (int)Prenum1
);
453 /* set current window height */
457 need_mouse_correct
= TRUE
;
459 win_setheight(Prenum
? (int)Prenum
: 9999);
462 #ifdef FEAT_VERTSPLIT
463 /* increase current window width */
466 need_mouse_correct
= TRUE
;
468 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
471 /* decrease current window width */
474 need_mouse_correct
= TRUE
;
476 win_setwidth(curwin
->w_width
- (int)Prenum1
);
479 /* set current window width */
482 need_mouse_correct
= TRUE
;
484 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
488 /* jump to tag and split window if tag exists (in preview window) */
489 #if defined(FEAT_QUICKFIX)
493 g_do_tagpreview
= Prenum
;
495 g_do_tagpreview
= p_pvh
;
502 reset_VIsual_and_resel(); /* stop Visual mode */
505 postponed_split
= Prenum
;
507 postponed_split
= -1;
509 /* Execute the command right here, required when
510 * "wincmd ]" was used in a function. */
511 do_nv_ident(Ctrl_RSB
, NUL
);
514 #ifdef FEAT_SEARCHPATH
515 /* edit file name under cursor in a new window */
522 ptr
= grab_file_name(Prenum1
, &lnum
);
526 need_mouse_correct
= TRUE
;
529 if (win_split(0, 0) == OK
)
531 # ifdef FEAT_SCROLLBIND
532 curwin
->w_p_scb
= FALSE
;
534 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
, ECMD_HIDE
);
535 if (nchar
== 'F' && lnum
>= 0)
537 curwin
->w_cursor
.lnum
= lnum
;
539 beginline(BL_SOL
| BL_FIX
);
548 /* Go to the first occurrence of the identifier under cursor along path in a
551 case 'i': /* Go to any match */
555 case 'd': /* Go to definition, using 'define' */
558 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
560 find_pattern_in_path(ptr
, 0, len
, TRUE
,
561 Prenum
== 0 ? TRUE
: FALSE
, type
,
562 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
563 curwin
->w_set_curswant
= TRUE
;
569 #if defined(FEAT_QUICKFIX)
571 * In a quickfix window a <CR> jumps to the error under the
572 * cursor in a new window.
574 if (bt_quickfix(curbuf
))
576 sprintf((char *)cbuf
, "split +%ld%s",
577 (long)curwin
->w_cursor
.lnum
,
578 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
579 do_cmdline_cmd(cbuf
);
585 /* CTRL-W g extended commands */
589 #ifdef USE_ON_FLY_SCROLL
590 dont_scroll
= TRUE
; /* disallow scrolling here */
593 ++allow_keys
; /* no mapping for xchar, but allow key codes */
595 xchar
= plain_vgetc();
597 LANGMAP_ADJUST(xchar
, TRUE
);
601 #ifdef FEAT_CMDL_INFO
602 (void)add_to_showcmd(xchar
);
606 #if defined(FEAT_QUICKFIX)
610 g_do_tagpreview
= Prenum
;
612 g_do_tagpreview
= p_pvh
;
618 reset_VIsual_and_resel(); /* stop Visual mode */
621 postponed_split
= Prenum
;
623 postponed_split
= -1;
625 /* Execute the command right here, required when
626 * "wincmd g}" was used in a function. */
627 do_nv_ident('g', xchar
);
630 #ifdef FEAT_SEARCHPATH
631 case 'f': /* CTRL-W gf: "gf" in a new tab page */
632 case 'F': /* CTRL-W gF: "gF" in a new tab page */
643 default: beep_flush();
649 * split the current window, implements CTRL-W s and :split
651 * "size" is the height or width for the new window, 0 to use half of current
655 * WSP_ROOM: require enough room for new window
656 * WSP_VERT: vertical split.
657 * WSP_TOP: open window at the top-left of the shell (help window).
658 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
659 * WSP_HELP: creating the help window, keep layout snapshot
661 * return FAIL for failure, OK otherwise
664 win_split(size
, flags
)
668 /* When the ":tab" modifier was used open a new tab page instead. */
669 if (may_open_tabpage() == OK
)
672 /* Add flags from ":vertical", ":topleft" and ":botright". */
673 flags
|= cmdmod
.split
;
674 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
676 EMSG(_("E442: Can't split topleft and botright at the same time"));
680 /* When creating the help window make a snapshot of the window layout.
681 * Otherwise clear the snapshot, it's now invalid. */
682 if (flags
& WSP_HELP
)
685 clear_snapshot(curtab
);
687 return win_split_ins(size
, flags
, NULL
, 0);
691 * When "newwin" is NULL: split the current window in two.
692 * When "newwin" is not NULL: insert this window at the far
693 * top/left/right/bottom.
694 * return FAIL for failure, OK otherwise
697 win_split_ins(size
, flags
, newwin
, dir
)
708 int do_equal
= FALSE
;
711 int oldwin_height
= 0;
713 frame_T
*frp
, *curfrp
;
718 else if (flags
& WSP_BOT
)
723 /* add a status line when p_ls == 1 and splitting the first window */
724 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
726 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
731 need_status
= STATUS_HEIGHT
;
735 /* May be needed for the scrollbars that are going to change. */
740 #ifdef FEAT_VERTSPLIT
741 if (flags
& WSP_VERT
)
746 * Check if we are able to split the current window and compute its
750 if (flags
& WSP_ROOM
)
751 needed
+= p_wiw
- p_wmw
;
752 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
754 available
= topframe
->fr_width
;
755 needed
+= frame_minwidth(topframe
, NULL
);
758 available
= oldwin
->w_width
;
759 if (available
< needed
&& newwin
== NULL
)
765 new_size
= oldwin
->w_width
/ 2;
766 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
767 new_size
= oldwin
->w_width
- p_wmw
- 1;
768 if (new_size
< p_wmw
)
771 /* if it doesn't fit in the current window, need win_equal() */
772 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
775 /* We don't like to take lines for the new window from a
776 * 'winfixwidth' window. Take them from a window to the left or right
777 * instead, if possible. */
779 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
781 /* Only make all windows the same width if one of them (except oldwin)
782 * is wider than one of the split windows. */
783 if (!do_equal
&& p_ea
&& size
== 0 && *p_ead
!= 'v'
784 && oldwin
->w_frame
->fr_parent
!= NULL
)
786 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
789 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
790 && (frp
->fr_win
->w_width
> new_size
791 || frp
->fr_win
->w_width
> oldwin
->w_width
792 - new_size
- STATUS_HEIGHT
))
807 * Check if we are able to split the current window and compute its
810 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
811 if (flags
& WSP_ROOM
)
812 needed
+= p_wh
- p_wmh
;
813 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
815 available
= topframe
->fr_height
;
816 needed
+= frame_minheight(topframe
, NULL
);
820 available
= oldwin
->w_height
;
823 if (available
< needed
&& newwin
== NULL
)
828 oldwin_height
= oldwin
->w_height
;
831 oldwin
->w_status_height
= STATUS_HEIGHT
;
832 oldwin_height
-= STATUS_HEIGHT
;
835 new_size
= oldwin_height
/ 2;
837 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
838 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
839 if (new_size
< p_wmh
)
842 /* if it doesn't fit in the current window, need win_equal() */
843 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
846 /* We don't like to take lines for the new window from a
847 * 'winfixheight' window. Take them from a window above or below
848 * instead, if possible. */
851 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
853 oldwin_height
= oldwin
->w_height
;
855 oldwin_height
-= STATUS_HEIGHT
;
858 /* Only make all windows the same height if one of them (except oldwin)
859 * is higher than one of the split windows. */
860 if (!do_equal
&& p_ea
&& size
== 0
861 #ifdef FEAT_VERTSPLIT
864 && oldwin
->w_frame
->fr_parent
!= NULL
)
866 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
869 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
870 && (frp
->fr_win
->w_height
> new_size
871 || frp
->fr_win
->w_height
> oldwin_height
- new_size
883 * allocate new window structure and link it in the window list
885 if ((flags
& WSP_TOP
) == 0
886 && ((flags
& WSP_BOT
)
887 || (flags
& WSP_BELOW
)
888 || (!(flags
& WSP_ABOVE
)
890 #ifdef FEAT_VERTSPLIT
891 (flags
& WSP_VERT
) ? p_spr
:
895 /* new window below/right of current one */
897 wp
= win_alloc(oldwin
);
899 win_append(oldwin
, wp
);
904 wp
= win_alloc(oldwin
->w_prev
);
906 win_append(oldwin
->w_prev
, wp
);
914 /* make the contents of the new window the same as the current one */
915 win_init(wp
, curwin
);
919 * Reorganise the tree of frames to insert the new window.
921 if (flags
& (WSP_TOP
| WSP_BOT
))
923 #ifdef FEAT_VERTSPLIT
924 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
925 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
927 if (topframe
->fr_layout
== FR_COL
)
930 curfrp
= topframe
->fr_child
;
932 while (curfrp
->fr_next
!= NULL
)
933 curfrp
= curfrp
->fr_next
;
937 before
= (flags
& WSP_TOP
);
941 curfrp
= oldwin
->w_frame
;
942 if (flags
& WSP_BELOW
)
944 else if (flags
& WSP_ABOVE
)
947 #ifdef FEAT_VERTSPLIT
948 if (flags
& WSP_VERT
)
954 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
956 /* Need to create a new frame in the tree to make a branch. */
957 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
959 curfrp
->fr_layout
= layout
;
960 frp
->fr_parent
= curfrp
;
963 curfrp
->fr_child
= frp
;
964 curfrp
->fr_win
= NULL
;
966 if (frp
->fr_win
!= NULL
)
967 oldwin
->w_frame
= frp
;
969 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
970 frp
->fr_parent
= curfrp
;
975 /* Create a frame for the new window. */
976 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
977 frp
->fr_layout
= FR_LEAF
;
982 frp
= newwin
->w_frame
;
983 frp
->fr_parent
= curfrp
->fr_parent
;
985 /* Insert the new frame at the right place in the frame list. */
987 frame_insert(curfrp
, frp
);
989 frame_append(curfrp
, frp
);
991 #ifdef FEAT_VERTSPLIT
992 if (flags
& WSP_VERT
)
994 wp
->w_p_scr
= curwin
->w_p_scr
;
998 oldwin
->w_status_height
= need_status
;
1000 if (flags
& (WSP_TOP
| WSP_BOT
))
1002 /* set height and row of new window to full height */
1003 wp
->w_winrow
= tabline_height();
1004 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
1005 wp
->w_status_height
= (p_ls
> 0);
1009 /* height and row of new window is same as current window */
1010 wp
->w_winrow
= oldwin
->w_winrow
;
1011 wp
->w_height
= oldwin
->w_height
;
1012 wp
->w_status_height
= oldwin
->w_status_height
;
1014 frp
->fr_height
= curfrp
->fr_height
;
1016 /* "new_size" of the current window goes to the new window, use
1017 * one column for the vertical separator */
1018 wp
->w_width
= new_size
;
1020 wp
->w_vsep_width
= 1;
1023 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1024 oldwin
->w_vsep_width
= 1;
1026 if (flags
& (WSP_TOP
| WSP_BOT
))
1028 if (flags
& WSP_BOT
)
1029 frame_add_vsep(curfrp
);
1030 /* Set width of neighbor frame */
1031 frame_new_width(curfrp
, curfrp
->fr_width
1032 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
1036 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
1037 if (before
) /* new window left of current one */
1039 wp
->w_wincol
= oldwin
->w_wincol
;
1040 oldwin
->w_wincol
+= new_size
+ 1;
1042 else /* new window right of current one */
1043 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
1044 frame_fix_width(oldwin
);
1045 frame_fix_width(wp
);
1050 /* width and column of new window is same as current window */
1051 #ifdef FEAT_VERTSPLIT
1052 if (flags
& (WSP_TOP
| WSP_BOT
))
1055 wp
->w_width
= Columns
;
1056 wp
->w_vsep_width
= 0;
1060 wp
->w_wincol
= oldwin
->w_wincol
;
1061 wp
->w_width
= oldwin
->w_width
;
1062 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1064 frp
->fr_width
= curfrp
->fr_width
;
1067 /* "new_size" of the current window goes to the new window, use
1068 * one row for the status line */
1069 win_new_height(wp
, new_size
);
1070 if (flags
& (WSP_TOP
| WSP_BOT
))
1071 frame_new_height(curfrp
, curfrp
->fr_height
1072 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1074 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1075 if (before
) /* new window above current one */
1077 wp
->w_winrow
= oldwin
->w_winrow
;
1078 wp
->w_status_height
= STATUS_HEIGHT
;
1079 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1081 else /* new window below current one */
1083 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1084 wp
->w_status_height
= oldwin
->w_status_height
;
1085 oldwin
->w_status_height
= STATUS_HEIGHT
;
1087 #ifdef FEAT_VERTSPLIT
1088 if (flags
& WSP_BOT
)
1089 frame_add_statusline(curfrp
);
1091 frame_fix_height(wp
);
1092 frame_fix_height(oldwin
);
1095 if (flags
& (WSP_TOP
| WSP_BOT
))
1096 (void)win_comp_pos();
1099 * Both windows need redrawing
1101 redraw_win_later(wp
, NOT_VALID
);
1102 wp
->w_redr_status
= TRUE
;
1103 redraw_win_later(oldwin
, NOT_VALID
);
1104 oldwin
->w_redr_status
= TRUE
;
1110 msg_clr_eos_force(); /* Old command/ruler may still be there */
1113 msg_col
= 0; /* put position back at start of line */
1117 * make the new window the current window and redraw
1119 if (do_equal
|| dir
!= 0)
1121 #ifdef FEAT_VERTSPLIT
1122 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1123 : dir
== 'h' ? 'b' :
1127 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1128 * size was given. */
1129 #ifdef FEAT_VERTSPLIT
1130 if (flags
& WSP_VERT
)
1137 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1139 gui_init_which_components(NULL
);
1149 win_enter(wp
, FALSE
);
1150 #ifdef FEAT_VERTSPLIT
1151 if (flags
& WSP_VERT
)
1161 * Initialize window "newp" from window "oldp".
1162 * Used when splitting a window and when creating a new tab page.
1163 * The windows will both edit the same buffer.
1166 win_init(newp
, oldp
)
1172 newp
->w_buffer
= oldp
->w_buffer
;
1173 oldp
->w_buffer
->b_nwindows
++;
1174 newp
->w_cursor
= oldp
->w_cursor
;
1176 newp
->w_curswant
= oldp
->w_curswant
;
1177 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1178 newp
->w_topline
= oldp
->w_topline
;
1180 newp
->w_topfill
= oldp
->w_topfill
;
1182 newp
->w_leftcol
= oldp
->w_leftcol
;
1183 newp
->w_pcmark
= oldp
->w_pcmark
;
1184 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1185 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1186 newp
->w_wrow
= oldp
->w_wrow
;
1187 newp
->w_fraction
= oldp
->w_fraction
;
1188 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1189 #ifdef FEAT_JUMPLIST
1190 copy_jumplist(oldp
, newp
);
1192 #ifdef FEAT_QUICKFIX
1193 copy_loclist(oldp
, newp
);
1195 if (oldp
->w_localdir
!= NULL
)
1196 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1198 /* Use the same argument list. */
1199 newp
->w_alist
= oldp
->w_alist
;
1200 ++newp
->w_alist
->al_refcount
;
1201 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1204 * copy tagstack and options from existing window
1206 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1208 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1209 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1210 newp
->w_tagstack
[i
].tagname
=
1211 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1213 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1214 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1215 win_copy_options(oldp
, newp
);
1216 # ifdef FEAT_FOLDING
1217 copyFoldingState(oldp
, newp
);
1221 #endif /* FEAT_WINDOWS */
1223 #if defined(FEAT_WINDOWS) || defined(PROTO)
1225 * Check if "win" is a pointer to an existing window.
1235 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1242 * Return the number of windows.
1250 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1256 * Make "count" windows on the screen.
1257 * Return actual number of windows on the screen.
1258 * Must be called when there is just one window, filling the whole screen
1259 * (excluding the command line).
1263 make_windows(count
, vertical
)
1265 int vertical
; /* split windows vertically if TRUE */
1270 #ifdef FEAT_VERTSPLIT
1273 /* Each windows needs at least 'winminwidth' lines and a separator
1275 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1276 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1281 /* Each window needs at least 'winminheight' lines and a status line. */
1282 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1283 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1288 if (count
> maxcount
)
1292 * add status line now, otherwise first window will be too big
1299 * Don't execute autocommands while creating the windows. Must do that
1300 * when putting the buffers in the windows.
1305 /* todo is number of windows left to create */
1306 for (todo
= count
- 1; todo
> 0; --todo
)
1307 #ifdef FEAT_VERTSPLIT
1310 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1311 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1317 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1318 * STATUS_HEIGHT
) / (todo
+ 1)
1319 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1327 /* return actual number of windows */
1328 return (count
- todo
);
1332 * Exchange current and next window
1335 win_exchange(Prenum
)
1344 if (lastwin
== firstwin
) /* just one window */
1351 need_mouse_correct
= TRUE
;
1355 * find window to exchange with
1359 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1360 while (frp
!= NULL
&& --Prenum
> 0)
1363 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1364 frp
= curwin
->w_frame
->fr_next
;
1365 else /* Swap last window in row/col with previous */
1366 frp
= curwin
->w_frame
->fr_prev
;
1368 /* We can only exchange a window with another window, not with a frame
1369 * containing windows. */
1370 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1375 * 1. remove curwin from the list. Remember after which window it was in wp2
1376 * 2. insert curwin before wp in the list
1378 * 3. remove wp from the list
1379 * 4. insert wp after wp2
1380 * 5. exchange the status line height and vsep width.
1382 wp2
= curwin
->w_prev
;
1383 frp2
= curwin
->w_frame
->fr_prev
;
1384 if (wp
->w_prev
!= curwin
)
1386 win_remove(curwin
, NULL
);
1387 frame_remove(curwin
->w_frame
);
1388 win_append(wp
->w_prev
, curwin
);
1389 frame_insert(frp
, curwin
->w_frame
);
1393 win_remove(wp
, NULL
);
1394 frame_remove(wp
->w_frame
);
1395 win_append(wp2
, wp
);
1397 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1399 frame_append(frp2
, wp
->w_frame
);
1401 temp
= curwin
->w_status_height
;
1402 curwin
->w_status_height
= wp
->w_status_height
;
1403 wp
->w_status_height
= temp
;
1404 #ifdef FEAT_VERTSPLIT
1405 temp
= curwin
->w_vsep_width
;
1406 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1407 wp
->w_vsep_width
= temp
;
1409 /* If the windows are not in the same frame, exchange the sizes to avoid
1410 * messing up the window layout. Otherwise fix the frame sizes. */
1411 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1413 temp
= curwin
->w_height
;
1414 curwin
->w_height
= wp
->w_height
;
1415 wp
->w_height
= temp
;
1416 temp
= curwin
->w_width
;
1417 curwin
->w_width
= wp
->w_width
;
1422 frame_fix_height(curwin
);
1423 frame_fix_height(wp
);
1424 frame_fix_width(curwin
);
1425 frame_fix_width(wp
);
1429 (void)win_comp_pos(); /* recompute window positions */
1431 win_enter(wp
, TRUE
);
1432 redraw_later(CLEAR
);
1436 * rotate windows: if upwards TRUE the second window becomes the first one
1437 * if upwards FALSE the first window becomes the second one
1440 win_rotate(upwards
, count
)
1449 if (firstwin
== lastwin
) /* nothing to do */
1456 need_mouse_correct
= TRUE
;
1459 #ifdef FEAT_VERTSPLIT
1460 /* Check if all frames in this row/col have one window. */
1461 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1463 if (frp
->fr_win
== NULL
)
1465 EMSG(_("E443: Cannot rotate when another window is split"));
1472 if (upwards
) /* first window becomes last window */
1474 /* remove first window/frame from the list */
1475 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1477 win_remove(wp1
, NULL
);
1480 /* find last frame and append removed window/frame after it */
1481 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1483 win_append(frp
->fr_win
, wp1
);
1484 frame_append(frp
, wp1
->w_frame
);
1486 wp2
= frp
->fr_win
; /* previously last window */
1488 else /* last window becomes first window */
1490 /* find last window/frame in the list and remove it */
1491 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1495 wp2
= wp1
->w_prev
; /* will become last window */
1496 win_remove(wp1
, NULL
);
1499 /* append the removed window/frame before the first in the list */
1500 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1501 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1504 /* exchange status height and vsep width of old and new last window */
1505 n
= wp2
->w_status_height
;
1506 wp2
->w_status_height
= wp1
->w_status_height
;
1507 wp1
->w_status_height
= n
;
1508 frame_fix_height(wp1
);
1509 frame_fix_height(wp2
);
1510 #ifdef FEAT_VERTSPLIT
1511 n
= wp2
->w_vsep_width
;
1512 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1513 wp1
->w_vsep_width
= n
;
1514 frame_fix_width(wp1
);
1515 frame_fix_width(wp2
);
1518 /* recompute w_winrow and w_wincol for all windows */
1519 (void)win_comp_pos();
1522 redraw_later(CLEAR
);
1526 * Move the current window to the very top/bottom/left/right of the screen.
1529 win_totop(size
, flags
)
1534 int height
= curwin
->w_height
;
1536 if (lastwin
== firstwin
)
1542 /* Remove the window and frame from the tree of frames. */
1543 (void)winframe_remove(curwin
, &dir
, NULL
);
1544 win_remove(curwin
, NULL
);
1545 last_status(FALSE
); /* may need to remove last status line */
1546 (void)win_comp_pos(); /* recompute window positions */
1548 /* Split a window on the desired side and put the window there. */
1549 (void)win_split_ins(size
, flags
, curwin
, dir
);
1550 if (!(flags
& WSP_VERT
))
1552 win_setheight(height
);
1554 win_equal(curwin
, TRUE
, 'v');
1557 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1558 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1559 * scrollbars. Have to update them anyway. */
1563 gui_init_which_components(NULL
);
1564 gui_update_scrollbars(TRUE
);
1566 need_mouse_correct
= TRUE
;
1572 * Move window "win1" to below/right of "win2" and make "win1" the current
1573 * window. Only works within the same frame!
1576 win_move_after(win1
, win2
)
1581 /* check if the arguments are reasonable */
1585 /* check if there is something to do */
1586 if (win2
->w_next
!= win1
)
1588 /* may need move the status line/vertical separator of the last window
1590 if (win1
== lastwin
)
1592 height
= win1
->w_prev
->w_status_height
;
1593 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1594 win1
->w_status_height
= height
;
1595 #ifdef FEAT_VERTSPLIT
1596 if (win1
->w_prev
->w_vsep_width
== 1)
1598 /* Remove the vertical separator from the last-but-one window,
1599 * add it to the last window. Adjust the frame widths. */
1600 win1
->w_prev
->w_vsep_width
= 0;
1601 win1
->w_prev
->w_frame
->fr_width
-= 1;
1602 win1
->w_vsep_width
= 1;
1603 win1
->w_frame
->fr_width
+= 1;
1607 else if (win2
== lastwin
)
1609 height
= win1
->w_status_height
;
1610 win1
->w_status_height
= win2
->w_status_height
;
1611 win2
->w_status_height
= height
;
1612 #ifdef FEAT_VERTSPLIT
1613 if (win1
->w_vsep_width
== 1)
1615 /* Remove the vertical separator from win1, add it to the last
1616 * window, win2. Adjust the frame widths. */
1617 win2
->w_vsep_width
= 1;
1618 win2
->w_frame
->fr_width
+= 1;
1619 win1
->w_vsep_width
= 0;
1620 win1
->w_frame
->fr_width
-= 1;
1624 win_remove(win1
, NULL
);
1625 frame_remove(win1
->w_frame
);
1626 win_append(win2
, win1
);
1627 frame_append(win2
->w_frame
, win1
->w_frame
);
1629 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1630 redraw_later(NOT_VALID
);
1632 win_enter(win1
, FALSE
);
1636 * Make all windows the same height.
1637 * 'next_curwin' will soon be the current window, make sure it has enough
1641 win_equal(next_curwin
, current
, dir
)
1642 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1643 int current
; /* do only frame with current window */
1644 int dir
; /* 'v' for vertically, 'h' for horizontally,
1645 'b' for both, 0 for using p_ead */
1648 #ifdef FEAT_VERTSPLIT
1653 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1654 topframe
, dir
, 0, tabline_height(),
1655 (int)Columns
, topframe
->fr_height
);
1659 * Set a frame to a new position and height, spreading the available room
1660 * equally over contained frames.
1661 * The window "next_curwin" (if not NULL) should at least get the size from
1662 * 'winheight' and 'winwidth' if possible.
1665 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1666 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1667 int current
; /* do only frame with current window */
1668 frame_T
*topfr
; /* frame to set size off */
1669 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1670 int col
; /* horizontal position for frame */
1671 int row
; /* vertical position for frame */
1672 int width
; /* new width of frame */
1673 int height
; /* new height of frame */
1677 int wincount
, totwincount
= 0;
1679 int next_curwin_size
= 0;
1682 int has_next_curwin
= 0;
1685 if (topfr
->fr_layout
== FR_LEAF
)
1687 /* Set the width/height of this frame.
1688 * Redraw when size or position changes */
1689 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1690 #ifdef FEAT_VERTSPLIT
1691 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1695 topfr
->fr_win
->w_winrow
= row
;
1696 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1697 #ifdef FEAT_VERTSPLIT
1698 topfr
->fr_win
->w_wincol
= col
;
1699 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1701 redraw_all_later(CLEAR
);
1704 #ifdef FEAT_VERTSPLIT
1705 else if (topfr
->fr_layout
== FR_ROW
)
1707 topfr
->fr_width
= width
;
1708 topfr
->fr_height
= height
;
1710 if (dir
!= 'v') /* equalize frame widths */
1712 /* Compute the maximum number of windows horizontally in this
1714 n
= frame_minwidth(topfr
, NOWIN
);
1715 /* add one for the rightmost window, it doesn't have a separator */
1716 if (col
+ width
== Columns
)
1720 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1721 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1724 * Compute width for "next_curwin" window and room available for
1726 * "m" is the minimal width when counting p_wiw for "next_curwin".
1728 m
= frame_minwidth(topfr
, next_curwin
);
1732 next_curwin_size
= p_wiw
+ room
;
1737 next_curwin_size
= -1;
1738 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1740 /* If 'winfixwidth' set keep the window width if
1742 * Watch out for this window being the next_curwin. */
1743 if (frame_fixed_width(fr
))
1745 n
= frame_minwidth(fr
, NOWIN
);
1746 new_size
= fr
->fr_width
;
1747 if (frame_has_win(fr
, next_curwin
))
1749 room
+= p_wiw
- p_wmw
;
1750 next_curwin_size
= 0;
1751 if (new_size
< p_wiw
)
1755 /* These windows don't use up room. */
1756 totwincount
-= (n
+ (fr
->fr_next
== NULL
1757 ? extra_sep
: 0)) / (p_wmw
+ 1);
1758 room
-= new_size
- n
;
1764 fr
->fr_newwidth
= new_size
;
1767 if (next_curwin_size
== -1)
1769 if (!has_next_curwin
)
1770 next_curwin_size
= 0;
1771 else if (totwincount
> 1
1772 && (room
+ (totwincount
- 2))
1773 / (totwincount
- 1) > p_wiw
)
1775 /* Can make all windows wider than 'winwidth', spread
1776 * the room equally. */
1777 next_curwin_size
= (room
+ p_wiw
1778 + (totwincount
- 1) * p_wmw
1779 + (totwincount
- 1)) / totwincount
;
1780 room
-= next_curwin_size
- p_wiw
;
1783 next_curwin_size
= p_wiw
;
1787 if (has_next_curwin
)
1788 --totwincount
; /* don't count curwin */
1791 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1795 if (fr
->fr_next
== NULL
)
1796 /* last frame gets all that remains (avoid roundoff error) */
1798 else if (dir
== 'v')
1799 new_size
= fr
->fr_width
;
1800 else if (frame_fixed_width(fr
))
1802 new_size
= fr
->fr_newwidth
;
1803 wincount
= 0; /* doesn't count as a sizeable window */
1807 /* Compute the maximum number of windows horiz. in "fr". */
1808 n
= frame_minwidth(fr
, NOWIN
);
1809 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1811 m
= frame_minwidth(fr
, next_curwin
);
1812 if (has_next_curwin
)
1813 hnc
= frame_has_win(fr
, next_curwin
);
1816 if (hnc
) /* don't count next_curwin */
1818 if (totwincount
== 0)
1821 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1823 if (hnc
) /* add next_curwin size */
1825 next_curwin_size
-= p_wiw
- (m
- n
);
1826 new_size
+= next_curwin_size
;
1827 room
-= new_size
- next_curwin_size
;
1834 /* Skip frame that is full width when splitting or closing a
1835 * window, unless equalizing all frames. */
1836 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1837 || (new_size
!= fr
->fr_width
)
1838 || frame_has_win(fr
, next_curwin
))
1839 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1843 totwincount
-= wincount
;
1847 else /* topfr->fr_layout == FR_COL */
1849 #ifdef FEAT_VERTSPLIT
1850 topfr
->fr_width
= width
;
1852 topfr
->fr_height
= height
;
1854 if (dir
!= 'h') /* equalize frame heights */
1856 /* Compute maximum number of windows vertically in this frame. */
1857 n
= frame_minheight(topfr
, NOWIN
);
1858 /* add one for the bottom window if it doesn't have a statusline */
1859 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1863 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1864 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1867 * Compute height for "next_curwin" window and room available for
1869 * "m" is the minimal height when counting p_wh for "next_curwin".
1871 m
= frame_minheight(topfr
, next_curwin
);
1875 /* The room is less then 'winheight', use all space for the
1876 * current window. */
1877 next_curwin_size
= p_wh
+ room
;
1882 next_curwin_size
= -1;
1883 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1885 /* If 'winfixheight' set keep the window height if
1887 * Watch out for this window being the next_curwin. */
1888 if (frame_fixed_height(fr
))
1890 n
= frame_minheight(fr
, NOWIN
);
1891 new_size
= fr
->fr_height
;
1892 if (frame_has_win(fr
, next_curwin
))
1894 room
+= p_wh
- p_wmh
;
1895 next_curwin_size
= 0;
1896 if (new_size
< p_wh
)
1900 /* These windows don't use up room. */
1901 totwincount
-= (n
+ (fr
->fr_next
== NULL
1902 ? extra_sep
: 0)) / (p_wmh
+ 1);
1903 room
-= new_size
- n
;
1909 fr
->fr_newheight
= new_size
;
1912 if (next_curwin_size
== -1)
1914 if (!has_next_curwin
)
1915 next_curwin_size
= 0;
1916 else if (totwincount
> 1
1917 && (room
+ (totwincount
- 2))
1918 / (totwincount
- 1) > p_wh
)
1920 /* can make all windows higher than 'winheight',
1921 * spread the room equally. */
1922 next_curwin_size
= (room
+ p_wh
1923 + (totwincount
- 1) * p_wmh
1924 + (totwincount
- 1)) / totwincount
;
1925 room
-= next_curwin_size
- p_wh
;
1928 next_curwin_size
= p_wh
;
1932 if (has_next_curwin
)
1933 --totwincount
; /* don't count curwin */
1936 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1940 if (fr
->fr_next
== NULL
)
1941 /* last frame gets all that remains (avoid roundoff error) */
1943 else if (dir
== 'h')
1944 new_size
= fr
->fr_height
;
1945 else if (frame_fixed_height(fr
))
1947 new_size
= fr
->fr_newheight
;
1948 wincount
= 0; /* doesn't count as a sizeable window */
1952 /* Compute the maximum number of windows vert. in "fr". */
1953 n
= frame_minheight(fr
, NOWIN
);
1954 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1956 m
= frame_minheight(fr
, next_curwin
);
1957 if (has_next_curwin
)
1958 hnc
= frame_has_win(fr
, next_curwin
);
1961 if (hnc
) /* don't count next_curwin */
1963 if (totwincount
== 0)
1966 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1968 if (hnc
) /* add next_curwin size */
1970 next_curwin_size
-= p_wh
- (m
- n
);
1971 new_size
+= next_curwin_size
;
1972 room
-= new_size
- next_curwin_size
;
1978 /* Skip frame that is full width when splitting or closing a
1979 * window, unless equalizing all frames. */
1980 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1981 || (new_size
!= fr
->fr_height
)
1982 || frame_has_win(fr
, next_curwin
))
1983 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1987 totwincount
-= wincount
;
1993 * close all windows for buffer 'buf'
1996 close_windows(buf
, keep_curwin
)
1998 int keep_curwin
; /* don't close "curwin" */
2001 tabpage_T
*tp
, *nexttp
;
2002 int h
= tabline_height();
2004 ++RedrawingDisabled
;
2006 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2008 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2010 win_close(wp
, FALSE
);
2012 /* Start all over, autocommands may change the window layout. */
2019 /* Also check windows in other tab pages. */
2020 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2022 nexttp
= tp
->tp_next
;
2024 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2025 if (wp
->w_buffer
== buf
)
2027 win_close_othertab(wp
, FALSE
, tp
);
2029 /* Start all over, the tab page may be closed and
2030 * autocommands may change the window layout. */
2031 nexttp
= first_tabpage
;
2036 --RedrawingDisabled
;
2038 if (h
!= tabline_height())
2043 * Return TRUE if the current window is the only window that exists.
2044 * Returns FALSE if there is a window, possibly in another tab page.
2049 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2053 * Close window "win". Only works for the current tab page.
2054 * If "free_buf" is TRUE related buffer may be unloaded.
2056 * called by :quit, :close, :xit, :wq and findtag()
2059 win_close(win
, free_buf
)
2065 int other_buffer
= FALSE
;
2067 int close_curwin
= FALSE
;
2069 int help_window
= FALSE
;
2070 tabpage_T
*prev_curtab
= curtab
;
2074 EMSG(_("E444: Cannot close last window"));
2079 * When closing the last window in a tab page first go to another tab
2080 * page and then close the window and the tab page. This avoids that
2081 * curwin and curtab are not invalid while we are freeing memory, they may
2082 * be used in GUI events.
2084 if (firstwin
== lastwin
)
2086 goto_tabpage_tp(alt_tabpage());
2087 redraw_tabline
= TRUE
;
2089 /* Safety check: Autocommands may have closed the window when jumping
2090 * to the other tab page. */
2091 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2093 int h
= tabline_height();
2095 win_close_othertab(win
, free_buf
, prev_curtab
);
2096 if (h
!= tabline_height())
2102 /* When closing the help window, try restoring a snapshot after closing
2103 * the window. Otherwise clear the snapshot, it's now invalid. */
2104 if (win
->w_buffer
->b_help
)
2107 clear_snapshot(curtab
);
2113 * Guess which window is going to be the new current window.
2114 * This may change because of the autocommands (sigh).
2116 wp
= frame2win(win_altframe(win
, NULL
));
2119 * Be careful: If autocommands delete the window, return now.
2121 if (wp
->w_buffer
!= curbuf
)
2123 other_buffer
= TRUE
;
2124 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2125 if (!win_valid(win
) || last_window())
2128 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2129 if (!win_valid(win
) || last_window())
2132 /* autocmds may abort script processing */
2140 /* Avoid trouble with scrollbars that are going to be deleted in
2147 * Close the link to the buffer.
2149 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2151 /* Autocommands may have closed the window already, or closed the only
2152 * other window or moved to another tab page. */
2153 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2156 /* Free the memory used for the window. */
2157 wp
= win_free_mem(win
, &dir
, NULL
);
2159 /* Make sure curwin isn't invalid. It can cause severe trouble when
2160 * printing an error message. For win_equal() curbuf needs to be valid
2165 #ifdef FEAT_QUICKFIX
2166 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2169 * If the cursor goes to the preview or the quickfix window, try
2170 * finding another window to go to.
2174 if (wp
->w_next
== NULL
)
2180 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2188 curbuf
= curwin
->w_buffer
;
2189 close_curwin
= TRUE
;
2192 #ifdef FEAT_VERTSPLIT
2193 && (*p_ead
== 'b' || *p_ead
== dir
)
2196 win_equal(curwin
, TRUE
,
2197 #ifdef FEAT_VERTSPLIT
2207 win_enter_ext(wp
, FALSE
, TRUE
);
2210 /* careful: after this wp and win may be invalid! */
2211 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2216 * If last window has a status line now and we don't want one,
2217 * remove the status line.
2221 /* After closing the help window, try restoring the window layout from
2222 * before it was opened. */
2224 restore_snapshot(close_curwin
);
2226 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2227 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2228 if (gui
.in_use
&& !win_hasvertsplit())
2229 gui_init_which_components(NULL
);
2232 redraw_all_later(NOT_VALID
);
2236 * Close window "win" in tab page "tp", which is not the current tab page.
2237 * This may be the last window ih that tab page and result in closing the tab,
2238 * thus "tp" may become invalid!
2239 * Caller must check if buffer is hidden and whether the tabline needs to be
2243 win_close_othertab(win
, free_buf
, tp
)
2250 tabpage_T
*ptp
= NULL
;
2252 /* Close the link to the buffer. */
2253 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2255 /* Careful: Autocommands may have closed the tab page or made it the
2256 * current tab page. */
2257 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2259 if (ptp
== NULL
|| tp
== curtab
)
2262 /* Autocommands may have closed the window already. */
2263 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2268 /* Free the memory used for the window. */
2269 wp
= win_free_mem(win
, &dir
, tp
);
2271 /* When closing the last window in a tab page remove the tab page. */
2274 if (tp
== first_tabpage
)
2275 first_tabpage
= tp
->tp_next
;
2278 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2283 EMSG2(_(e_intern2
), "win_close_othertab()");
2286 ptp
->tp_next
= tp
->tp_next
;
2293 * Free the memory used for a window.
2294 * Returns a pointer to the window that got the freed up space.
2297 win_free_mem(win
, dirp
, tp
)
2299 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2300 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2309 /* reduce the reference count to the argument list. */
2310 alist_unlink(win
->w_alist
);
2312 /* Remove the window and its frame from the tree of frames. */
2314 wp
= winframe_remove(win
, dirp
, tp
);
2318 /* When deleting the current window of another tab page select a new
2319 * current window. */
2320 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2326 #if defined(EXITFREE) || defined(PROTO)
2332 # ifdef FEAT_WINDOWS
2333 while (first_tabpage
->tp_next
!= NULL
)
2334 tabpage_close(TRUE
);
2337 while (firstwin
!= NULL
)
2338 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2343 * Remove a window and its frame from the tree of frames.
2344 * Returns a pointer to the window that got the freed up space.
2348 winframe_remove(win
, dirp
, tp
)
2350 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2351 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2353 frame_T
*frp
, *frp2
, *frp3
;
2354 frame_T
*frp_close
= win
->w_frame
;
2358 * If there is only one window there is nothing to remove.
2360 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2364 * Remove the window from its frame.
2366 frp2
= win_altframe(win
, tp
);
2367 wp
= frame2win(frp2
);
2369 /* Remove this frame from the list of frames. */
2370 frame_remove(frp_close
);
2372 #ifdef FEAT_VERTSPLIT
2373 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2376 /* When 'winfixheight' is set, try to find another frame in the column
2377 * (as close to the closed frame as possible) to distribute the height
2379 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2381 frp
= frp_close
->fr_prev
;
2382 frp3
= frp_close
->fr_next
;
2383 while (frp
!= NULL
|| frp3
!= NULL
)
2387 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2397 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2403 frp3
= frp3
->fr_next
;
2407 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2408 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2409 #ifdef FEAT_VERTSPLIT
2414 /* When 'winfixwidth' is set, try to find another frame in the column
2415 * (as close to the closed frame as possible) to distribute the width
2417 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2419 frp
= frp_close
->fr_prev
;
2420 frp3
= frp_close
->fr_next
;
2421 while (frp
!= NULL
|| frp3
!= NULL
)
2425 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2435 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2441 frp3
= frp3
->fr_next
;
2445 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2446 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2451 /* If rows/columns go to a window below/right its positions need to be
2452 * updated. Can only be done after the sizes have been updated. */
2453 if (frp2
== frp_close
->fr_next
)
2455 int row
= win
->w_winrow
;
2456 int col
= W_WINCOL(win
);
2458 frame_comp_pos(frp2
, &row
, &col
);
2461 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2463 /* There is no other frame in this list, move its info to the parent
2465 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2466 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2467 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2468 frp
->fr_parent
= frp2
->fr_parent
;
2469 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2470 if (frp2
->fr_win
!= NULL
)
2471 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2472 frp
= frp2
->fr_parent
;
2475 frp2
= frp
->fr_parent
;
2476 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2478 /* The frame above the parent has the same layout, have to merge
2479 * the frames into this list. */
2480 if (frp2
->fr_child
== frp
)
2481 frp2
->fr_child
= frp
->fr_child
;
2482 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2483 if (frp
->fr_prev
!= NULL
)
2484 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2485 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2487 frp3
->fr_parent
= frp2
;
2488 if (frp3
->fr_next
== NULL
)
2490 frp3
->fr_next
= frp
->fr_next
;
2491 if (frp
->fr_next
!= NULL
)
2492 frp
->fr_next
->fr_prev
= frp3
;
2504 * Find out which frame is going to get the freed up space when "win" is
2506 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2507 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2508 * This makes opening a window and closing it immediately keep the same window
2512 win_altframe(win
, tp
)
2514 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2519 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2520 /* Last window in this tab page, will go to next tab page. */
2521 return alt_tabpage()->tp_curwin
->w_frame
;
2524 #ifdef FEAT_VERTSPLIT
2525 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2530 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2531 return frp
->fr_next
;
2532 return frp
->fr_prev
;
2536 * Return the tabpage that will be used if the current one is closed.
2543 /* Use the next tab page if possible. */
2544 if (curtab
->tp_next
!= NULL
)
2545 return curtab
->tp_next
;
2547 /* Find the last but one tab page. */
2548 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2554 * Find the left-upper window in frame "frp".
2560 while (frp
->fr_win
== NULL
)
2561 frp
= frp
->fr_child
;
2566 * Return TRUE if frame "frp" contains window "wp".
2569 frame_has_win(frp
, wp
)
2575 if (frp
->fr_layout
== FR_LEAF
)
2576 return frp
->fr_win
== wp
;
2578 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2579 if (frame_has_win(p
, wp
))
2585 * Set a new height for a frame. Recursively sets the height for contained
2586 * frames and windows. Caller must take care of positions.
2589 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2592 int topfirst
; /* resize topmost contained frame first */
2593 int wfh
; /* obey 'winfixheight' when there is a choice;
2594 may cause the height not to be set */
2600 if (topfrp
->fr_win
!= NULL
)
2602 /* Simple case: just one window. */
2603 win_new_height(topfrp
->fr_win
,
2604 height
- topfrp
->fr_win
->w_status_height
);
2606 #ifdef FEAT_VERTSPLIT
2607 else if (topfrp
->fr_layout
== FR_ROW
)
2611 /* All frames in this row get the same new height. */
2612 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2614 frame_new_height(frp
, height
, topfirst
, wfh
);
2615 if (frp
->fr_height
> height
)
2617 /* Could not fit the windows, make the whole row higher. */
2618 height
= frp
->fr_height
;
2623 while (frp
!= NULL
);
2626 else /* fr_layout == FR_COL */
2628 /* Complicated case: Resize a column of frames. Resize the bottom
2629 * frame first, frames above that when needed. */
2631 frp
= topfrp
->fr_child
;
2633 /* Advance past frames with one window with 'wfh' set. */
2634 while (frame_fixed_height(frp
))
2638 return; /* no frame without 'wfh', give up */
2642 /* Find the bottom frame of this column */
2643 while (frp
->fr_next
!= NULL
)
2646 /* Advance back for frames with one window with 'wfh' set. */
2647 while (frame_fixed_height(frp
))
2651 extra_lines
= height
- topfrp
->fr_height
;
2652 if (extra_lines
< 0)
2654 /* reduce height of contained frames, bottom or top frame first */
2657 h
= frame_minheight(frp
, NULL
);
2658 if (frp
->fr_height
+ extra_lines
< h
)
2660 extra_lines
+= frp
->fr_height
- h
;
2661 frame_new_height(frp
, h
, topfirst
, wfh
);
2665 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2673 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2679 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2681 /* Increase "height" if we could not reduce enough frames. */
2683 height
-= extra_lines
;
2686 else if (extra_lines
> 0)
2688 /* increase height of bottom or top frame */
2689 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2692 topfrp
->fr_height
= height
;
2696 * Return TRUE if height of frame "frp" should not be changed because of
2697 * the 'winfixheight' option.
2700 frame_fixed_height(frp
)
2703 /* frame with one window: fixed height if 'winfixheight' set. */
2704 if (frp
->fr_win
!= NULL
)
2705 return frp
->fr_win
->w_p_wfh
;
2707 if (frp
->fr_layout
== FR_ROW
)
2709 /* The frame is fixed height if one of the frames in the row is fixed
2711 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2712 if (frame_fixed_height(frp
))
2717 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2718 * frames in the row are fixed height. */
2719 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2720 if (!frame_fixed_height(frp
))
2725 #ifdef FEAT_VERTSPLIT
2727 * Return TRUE if width of frame "frp" should not be changed because of
2728 * the 'winfixwidth' option.
2731 frame_fixed_width(frp
)
2734 /* frame with one window: fixed width if 'winfixwidth' set. */
2735 if (frp
->fr_win
!= NULL
)
2736 return frp
->fr_win
->w_p_wfw
;
2738 if (frp
->fr_layout
== FR_COL
)
2740 /* The frame is fixed width if one of the frames in the row is fixed
2742 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2743 if (frame_fixed_width(frp
))
2748 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2749 * frames in the row are fixed width. */
2750 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2751 if (!frame_fixed_width(frp
))
2757 * Add a status line to windows at the bottom of "frp".
2758 * Note: Does not check if there is room!
2761 frame_add_statusline(frp
)
2766 if (frp
->fr_layout
== FR_LEAF
)
2769 if (wp
->w_status_height
== 0)
2771 if (wp
->w_height
> 0) /* don't make it negative */
2773 wp
->w_status_height
= STATUS_HEIGHT
;
2776 else if (frp
->fr_layout
== FR_ROW
)
2778 /* Handle all the frames in the row. */
2779 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2780 frame_add_statusline(frp
);
2782 else /* frp->fr_layout == FR_COL */
2784 /* Only need to handle the last frame in the column. */
2785 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2787 frame_add_statusline(frp
);
2792 * Set width of a frame. Handles recursively going through contained frames.
2793 * May remove separator line for windows at the right side (for win_close()).
2796 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2799 int leftfirst
; /* resize leftmost contained frame first */
2800 int wfw
; /* obey 'winfixwidth' when there is a choice;
2801 may cause the width not to be set */
2808 if (topfrp
->fr_layout
== FR_LEAF
)
2810 /* Simple case: just one window. */
2811 wp
= topfrp
->fr_win
;
2812 /* Find out if there are any windows right of this one. */
2813 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2814 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2816 if (frp
->fr_parent
== NULL
)
2817 wp
->w_vsep_width
= 0;
2818 win_new_width(wp
, width
- wp
->w_vsep_width
);
2820 else if (topfrp
->fr_layout
== FR_COL
)
2824 /* All frames in this column get the same new width. */
2825 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2827 frame_new_width(frp
, width
, leftfirst
, wfw
);
2828 if (frp
->fr_width
> width
)
2830 /* Could not fit the windows, make whole column wider. */
2831 width
= frp
->fr_width
;
2835 } while (frp
!= NULL
);
2837 else /* fr_layout == FR_ROW */
2839 /* Complicated case: Resize a row of frames. Resize the rightmost
2840 * frame first, frames left of it when needed. */
2842 frp
= topfrp
->fr_child
;
2844 /* Advance past frames with one window with 'wfw' set. */
2845 while (frame_fixed_width(frp
))
2849 return; /* no frame without 'wfw', give up */
2853 /* Find the rightmost frame of this row */
2854 while (frp
->fr_next
!= NULL
)
2857 /* Advance back for frames with one window with 'wfw' set. */
2858 while (frame_fixed_width(frp
))
2862 extra_cols
= width
- topfrp
->fr_width
;
2865 /* reduce frame width, rightmost frame first */
2868 w
= frame_minwidth(frp
, NULL
);
2869 if (frp
->fr_width
+ extra_cols
< w
)
2871 extra_cols
+= frp
->fr_width
- w
;
2872 frame_new_width(frp
, w
, leftfirst
, wfw
);
2876 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2884 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2890 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2892 /* Increase "width" if we could not reduce enough frames. */
2894 width
-= extra_cols
;
2897 else if (extra_cols
> 0)
2899 /* increase width of rightmost frame */
2900 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2903 topfrp
->fr_width
= width
;
2907 * Add the vertical separator to windows at the right side of "frp".
2908 * Note: Does not check if there is room!
2916 if (frp
->fr_layout
== FR_LEAF
)
2919 if (wp
->w_vsep_width
== 0)
2921 if (wp
->w_width
> 0) /* don't make it negative */
2923 wp
->w_vsep_width
= 1;
2926 else if (frp
->fr_layout
== FR_COL
)
2928 /* Handle all the frames in the column. */
2929 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2930 frame_add_vsep(frp
);
2932 else /* frp->fr_layout == FR_ROW */
2934 /* Only need to handle the last frame in the row. */
2935 frp
= frp
->fr_child
;
2936 while (frp
->fr_next
!= NULL
)
2938 frame_add_vsep(frp
);
2943 * Set frame width from the window it contains.
2949 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2954 * Set frame height from the window it contains.
2957 frame_fix_height(wp
)
2960 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2964 * Compute the minimal height for frame "topfrp".
2965 * Uses the 'winminheight' option.
2966 * When "next_curwin" isn't NULL, use p_wh for this window.
2967 * When "next_curwin" is NOWIN, don't use at least one line for the current
2971 frame_minheight(topfrp
, next_curwin
)
2977 #ifdef FEAT_VERTSPLIT
2981 if (topfrp
->fr_win
!= NULL
)
2983 if (topfrp
->fr_win
== next_curwin
)
2984 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2987 /* window: minimal height of the window plus status line */
2988 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2989 /* Current window is minimal one line high */
2990 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2994 #ifdef FEAT_VERTSPLIT
2995 else if (topfrp
->fr_layout
== FR_ROW
)
2997 /* get the minimal height from each frame in this row */
2999 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3001 n
= frame_minheight(frp
, next_curwin
);
3009 /* Add up the minimal heights for all frames in this column. */
3011 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3012 m
+= frame_minheight(frp
, next_curwin
);
3018 #ifdef FEAT_VERTSPLIT
3020 * Compute the minimal width for frame "topfrp".
3021 * When "next_curwin" isn't NULL, use p_wiw for this window.
3022 * When "next_curwin" is NOWIN, don't use at least one column for the current
3026 frame_minwidth(topfrp
, next_curwin
)
3028 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3033 if (topfrp
->fr_win
!= NULL
)
3035 if (topfrp
->fr_win
== next_curwin
)
3036 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3039 /* window: minimal width of the window plus separator column */
3040 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3041 /* Current window is minimal one column wide */
3042 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3046 else if (topfrp
->fr_layout
== FR_COL
)
3048 /* get the minimal width from each frame in this column */
3050 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3052 n
= frame_minwidth(frp
, next_curwin
);
3059 /* Add up the minimal widths for all frames in this row. */
3061 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3062 m
+= frame_minwidth(frp
, next_curwin
);
3071 * Try to close all windows except current one.
3072 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3073 * used and the buffer was modified.
3075 * Used by ":bdel" and ":only".
3078 close_others(message
, forceit
)
3080 int forceit
; /* always hide all other windows */
3086 if (lastwin
== firstwin
)
3097 /* Be very careful here: autocommands may change the window layout. */
3098 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3100 nextwp
= wp
->w_next
;
3101 if (wp
!= curwin
) /* don't close current window */
3104 /* Check if it's allowed to abandon this window */
3105 r
= can_abandon(wp
->w_buffer
, forceit
);
3107 if (!win_valid(wp
)) /* autocommands messed wp up */
3115 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3116 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3118 dialog_changed(wp
->w_buffer
, FALSE
);
3119 # ifdef FEAT_AUTOCMD
3120 if (!win_valid(wp
)) /* autocommands messed wp up */
3127 if (bufIsChanged(wp
->w_buffer
))
3131 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3135 if (message
&& lastwin
!= firstwin
)
3136 EMSG(_("E445: Other window contains changes"));
3139 #endif /* FEAT_WINDOWS */
3142 * Init the current window "curwin".
3143 * Called when a new file is being edited.
3148 redraw_win_later(curwin
, NOT_VALID
);
3149 curwin
->w_lines_valid
= 0;
3150 curwin
->w_cursor
.lnum
= 1;
3151 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3152 #ifdef FEAT_VIRTUALEDIT
3153 curwin
->w_cursor
.coladd
= 0;
3155 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3156 curwin
->w_pcmark
.col
= 0;
3157 curwin
->w_prev_pcmark
.lnum
= 0;
3158 curwin
->w_prev_pcmark
.col
= 0;
3159 curwin
->w_topline
= 1;
3161 curwin
->w_topfill
= 0;
3163 curwin
->w_botline
= 2;
3166 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3168 curwin
->w_farsi
= W_CONV
;
3173 * Allocate the first window and put an empty buffer in it.
3174 * Called from main().
3175 * Return FAIL when something goes wrong (out of memory).
3180 if (win_alloc_firstwin(NULL
) == FAIL
)
3184 first_tabpage
= alloc_tabpage();
3185 if (first_tabpage
== NULL
)
3187 first_tabpage
->tp_topframe
= topframe
;
3188 curtab
= first_tabpage
;
3194 * Allocate the first window or the first window in a new tab page.
3195 * When "oldwin" is NULL create an empty buffer for it.
3196 * When "oldwin" is not NULL copy info from it to the new window (only with
3198 * Return FAIL when something goes wrong (out of memory).
3201 win_alloc_firstwin(oldwin
)
3204 curwin
= win_alloc(NULL
);
3207 /* Very first window, need to create an empty buffer for it and
3208 * initialize from scratch. */
3209 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3210 if (curwin
== NULL
|| curbuf
== NULL
)
3212 curwin
->w_buffer
= curbuf
;
3213 curbuf
->b_nwindows
= 1; /* there is one window */
3215 curwin
->w_alist
= &global_alist
;
3217 curwin_init(); /* init current window */
3222 /* First window in new tab page, initialize it from "oldwin". */
3223 win_init(curwin
, oldwin
);
3225 # ifdef FEAT_SCROLLBIND
3226 /* We don't want scroll-binding in the first window. */
3227 curwin
->w_p_scb
= FALSE
;
3232 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3233 if (topframe
== NULL
)
3235 topframe
->fr_layout
= FR_LEAF
;
3236 #ifdef FEAT_VERTSPLIT
3237 topframe
->fr_width
= Columns
;
3239 topframe
->fr_height
= Rows
- p_ch
;
3240 topframe
->fr_win
= curwin
;
3241 curwin
->w_frame
= topframe
;
3247 * Initialize the window and frame size to the maximum.
3252 firstwin
->w_height
= ROWS_AVAIL
;
3253 topframe
->fr_height
= ROWS_AVAIL
;
3254 #ifdef FEAT_VERTSPLIT
3255 firstwin
->w_width
= Columns
;
3256 topframe
->fr_width
= Columns
;
3260 #if defined(FEAT_WINDOWS) || defined(PROTO)
3263 * Allocate a new tabpage_T and init the values.
3264 * Returns NULL when out of memory.
3271 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3277 for (i
= 0; i
< 3; i
++)
3278 tp
->tp_prev_which_scrollbars
[i
] = -1;
3281 tp
->tp_diff_invalid
= TRUE
;
3284 /* init t: variables */
3285 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3287 tp
->tp_ch_used
= p_ch
;
3301 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3307 * Create a new Tab page with one window.
3308 * It will edit the current buffer, like after ":split".
3309 * When "after" is 0 put it just after the current Tab page.
3310 * Otherwise put it just before tab page "after".
3311 * Return FAIL or OK.
3314 win_new_tabpage(after
)
3317 tabpage_T
*tp
= curtab
;
3321 newtp
= alloc_tabpage();
3325 /* Remember the current windows in this Tab page. */
3326 if (leave_tabpage(curbuf
) == FAIL
)
3333 /* Create a new empty window. */
3334 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3336 /* Make the new Tab page the new topframe. */
3339 /* New tab page becomes the first one. */
3340 newtp
->tp_next
= first_tabpage
;
3341 first_tabpage
= newtp
;
3347 /* Put new tab page before tab page "after". */
3349 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3350 && n
< after
; tp
= tp
->tp_next
)
3353 newtp
->tp_next
= tp
->tp_next
;
3354 tp
->tp_next
= newtp
;
3357 firstwin
->w_winrow
= tabline_height();
3358 win_comp_scroll(curwin
);
3360 newtp
->tp_topframe
= topframe
;
3363 #if defined(FEAT_GUI)
3364 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3365 * scrollbars. Have to update them anyway. */
3366 if (gui
.in_use
&& starting
== 0)
3368 gui_init_which_components(NULL
);
3369 gui_update_scrollbars(TRUE
);
3371 need_mouse_correct
= TRUE
;
3374 redraw_all_later(CLEAR
);
3376 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3377 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3382 /* Failed, get back the previous Tab page */
3383 enter_tabpage(curtab
, curbuf
);
3388 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3389 * like with ":split".
3390 * Returns OK if a new tab page was created, FAIL otherwise.
3395 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3399 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3400 postponed_split_tab
= 0;
3401 return win_new_tabpage(n
);
3407 * Create up to "maxcount" tabpages with empty windows.
3408 * Returns the number of resulting tab pages.
3411 make_tabpages(maxcount
)
3414 int count
= maxcount
;
3417 /* Limit to 'tabpagemax' tabs. */
3423 * Don't execute autocommands while creating the tab pages. Must do that
3424 * when putting the buffers in the windows.
3429 for (todo
= count
- 1; todo
> 0; --todo
)
3430 if (win_new_tabpage(0) == FAIL
)
3437 /* return actual number of tab pages */
3438 return (count
- todo
);
3442 * Return TRUE when "tpc" points to a valid tab page.
3450 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3457 * Find tab page "n" (first one is 1). Returns NULL when not found.
3466 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3472 * Get index of tab page "tp". First one has index 1.
3473 * When not found returns number of tab pages plus one.
3482 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3488 * Prepare for leaving the current tab page.
3489 * When autocomands change "curtab" we don't leave the tab page and return
3491 * Careful: When OK is returned need to get a new tab page very very soon!
3495 leave_tabpage(new_curbuf
)
3496 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3499 tabpage_T
*tp
= curtab
;
3502 reset_VIsual_and_resel(); /* stop Visual mode */
3505 if (new_curbuf
!= curbuf
)
3507 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3511 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3514 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3518 #if defined(FEAT_GUI)
3519 /* Remove the scrollbars. They may be added back later. */
3521 gui_remove_scrollbars();
3523 tp
->tp_curwin
= curwin
;
3524 tp
->tp_prevwin
= prevwin
;
3525 tp
->tp_firstwin
= firstwin
;
3526 tp
->tp_lastwin
= lastwin
;
3527 tp
->tp_old_Rows
= Rows
;
3528 tp
->tp_old_Columns
= Columns
;
3535 * Start using tab page "tp".
3536 * Only to be used after leave_tabpage() or freeing the current tab page.
3540 enter_tabpage(tp
, old_curbuf
)
3544 int old_off
= tp
->tp_firstwin
->w_winrow
;
3545 win_T
*next_prevwin
= tp
->tp_prevwin
;
3548 firstwin
= tp
->tp_firstwin
;
3549 lastwin
= tp
->tp_lastwin
;
3550 topframe
= tp
->tp_topframe
;
3552 /* We would like doing the TabEnter event first, but we don't have a
3553 * valid current window yet, which may break some commands.
3554 * This triggers autocommands, thus may make "tp" invalid. */
3555 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3556 prevwin
= next_prevwin
;
3559 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3561 if (old_curbuf
!= curbuf
)
3562 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3565 last_status(FALSE
); /* status line may appear or disappear */
3566 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3567 must_redraw
= CLEAR
; /* need to redraw everything */
3569 diff_need_scrollbind
= TRUE
;
3572 /* The tabpage line may have appeared or disappeared, may need to resize
3573 * the frames for that. When the Vim window was resized need to update
3574 * frame sizes too. Use the stored value of p_ch, so that it can be
3575 * different for each tab page. */
3576 p_ch
= curtab
->tp_ch_used
;
3577 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3578 #ifdef FEAT_GUI_TABLINE
3579 && !gui_use_tabline()
3583 #ifdef FEAT_VERTSPLIT
3584 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3585 shell_new_columns(); /* update window widths */
3588 #if defined(FEAT_GUI)
3589 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3590 * scrollbars. Have to update them anyway. */
3591 if (gui
.in_use
&& starting
== 0)
3593 gui_init_which_components(NULL
);
3594 gui_update_scrollbars(TRUE
);
3596 need_mouse_correct
= TRUE
;
3599 redraw_all_later(CLEAR
);
3603 * Go to tab page "n". For ":tab N" and "Ngt".
3604 * When "n" is 9999 go to the last tab page.
3616 /* Not allowed when editing the command line. */
3618 if (cmdwin_type
!= 0)
3626 /* If there is only one it can't work. */
3627 if (first_tabpage
->tp_next
== NULL
)
3636 /* No count, go to next tab page, wrap around end. */
3637 if (curtab
->tp_next
== NULL
)
3640 tp
= curtab
->tp_next
;
3644 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3647 for (i
= n
; i
< 0; ++i
)
3649 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3657 /* Go to last tab page. */
3658 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3663 /* Go to tab page "n". */
3664 tp
= find_tabpage(n
);
3672 goto_tabpage_tp(tp
);
3674 #ifdef FEAT_GUI_TABLINE
3675 if (gui_use_tabline())
3676 gui_mch_set_curtab(tabpage_index(curtab
));
3681 * Go to tabpage "tp".
3682 * Note: doesn't update the GUI tab.
3688 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3690 if (valid_tabpage(tp
))
3691 enter_tabpage(tp
, curbuf
);
3693 enter_tabpage(curtab
, curbuf
);
3698 * Enter window "wp" in tab page "tp".
3699 * Also updates the GUI tab.
3702 goto_tabpage_win(tp
, wp
)
3706 goto_tabpage_tp(tp
);
3707 if (curtab
== tp
&& win_valid(wp
))
3709 win_enter(wp
, TRUE
);
3710 # ifdef FEAT_GUI_TABLINE
3711 if (gui_use_tabline())
3712 gui_mch_set_curtab(tabpage_index(curtab
));
3718 * Move the current tab page to before tab page "nr".
3727 if (first_tabpage
->tp_next
== NULL
)
3730 /* Remove the current tab page from the list of tab pages. */
3731 if (curtab
== first_tabpage
)
3732 first_tabpage
= curtab
->tp_next
;
3735 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3736 if (tp
->tp_next
== curtab
)
3738 if (tp
== NULL
) /* "cannot happen" */
3740 tp
->tp_next
= curtab
->tp_next
;
3743 /* Re-insert it at the specified position. */
3746 curtab
->tp_next
= first_tabpage
;
3747 first_tabpage
= curtab
;
3751 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3753 curtab
->tp_next
= tp
->tp_next
;
3754 tp
->tp_next
= curtab
;
3757 /* Need to redraw the tabline. Tab page contents doesn't change. */
3758 redraw_tabline
= TRUE
;
3763 * Go to another window.
3764 * When jumping to another buffer, stop Visual mode. Do this before
3765 * changing windows so we can yank the selection into the '*' register.
3766 * When jumping to another window on the same buffer, adjust its cursor
3767 * position to keep the same Visual area.
3780 if (curbuf_locked())
3785 if (wp
->w_buffer
!= curbuf
)
3786 reset_VIsual_and_resel();
3787 else if (VIsual_active
)
3788 wp
->w_cursor
= curwin
->w_cursor
;
3792 need_mouse_correct
= TRUE
;
3794 win_enter(wp
, TRUE
);
3797 #if defined(FEAT_PERL) || defined(PROTO)
3799 * Find window number "winnr" (counting top to bottom).
3807 # ifdef FEAT_WINDOWS
3808 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3818 #ifdef FEAT_VERTSPLIT
3820 * Move to window above or below "count" times.
3823 win_goto_ver(up
, count
)
3824 int up
; /* TRUE to go to win above */
3831 foundfr
= curwin
->w_frame
;
3835 * First go upwards in the tree of frames until we find a upwards or
3836 * downwards neighbor.
3847 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3853 * Now go downwards to find the bottom or top frame in it.
3857 if (nfr
->fr_layout
== FR_LEAF
)
3863 if (nfr
->fr_layout
== FR_ROW
)
3865 /* Find the frame at the cursor row. */
3866 while (fr
->fr_next
!= NULL
3867 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3868 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3871 if (nfr
->fr_layout
== FR_COL
&& up
)
3872 while (fr
->fr_next
!= NULL
)
3878 if (foundfr
!= NULL
)
3879 win_goto(foundfr
->fr_win
);
3883 * Move to left or right window.
3886 win_goto_hor(left
, count
)
3887 int left
; /* TRUE to go to left win */
3894 foundfr
= curwin
->w_frame
;
3898 * First go upwards in the tree of frames until we find a left or
3910 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3916 * Now go downwards to find the leftmost or rightmost frame in it.
3920 if (nfr
->fr_layout
== FR_LEAF
)
3926 if (nfr
->fr_layout
== FR_COL
)
3928 /* Find the frame at the cursor row. */
3929 while (fr
->fr_next
!= NULL
3930 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3931 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3934 if (nfr
->fr_layout
== FR_ROW
&& left
)
3935 while (fr
->fr_next
!= NULL
)
3941 if (foundfr
!= NULL
)
3942 win_goto(foundfr
->fr_win
);
3947 * Make window "wp" the current window.
3950 win_enter(wp
, undo_sync
)
3954 win_enter_ext(wp
, undo_sync
, FALSE
);
3958 * Make window wp the current window.
3959 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3960 * been closed and isn't valid.
3963 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3969 int other_buffer
= FALSE
;
3972 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3976 if (!curwin_invalid
)
3979 * Be careful: If autocommands delete the window, return now.
3981 if (wp
->w_buffer
!= curbuf
)
3983 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3984 other_buffer
= TRUE
;
3988 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3992 /* autocmds may abort script processing */
3999 /* sync undo before leaving the current buffer */
4000 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4002 /* may have to copy the buffer options when 'cpo' contains 'S' */
4003 if (wp
->w_buffer
!= curbuf
)
4004 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4005 if (!curwin_invalid
)
4007 prevwin
= curwin
; /* remember for CTRL-W p */
4008 curwin
->w_redr_status
= TRUE
;
4011 curbuf
= wp
->w_buffer
;
4013 #ifdef FEAT_VIRTUALEDIT
4014 if (!virtual_active())
4015 curwin
->w_cursor
.coladd
= 0;
4017 changed_line_abv_curs(); /* assume cursor position needs updating */
4019 if (curwin
->w_localdir
!= NULL
)
4021 /* Window has a local directory: Save current directory as global
4022 * directory (unless that was done already) and change to the local
4024 if (globaldir
== NULL
)
4026 char_u cwd
[MAXPATHL
];
4028 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4029 globaldir
= vim_strsave(cwd
);
4031 mch_chdir((char *)curwin
->w_localdir
);
4032 shorten_fnames(TRUE
);
4034 else if (globaldir
!= NULL
)
4036 /* Window doesn't have a local directory and we are not in the global
4037 * directory: Change to the global directory. */
4038 mch_chdir((char *)globaldir
);
4039 vim_free(globaldir
);
4041 shorten_fnames(TRUE
);
4045 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4047 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4053 curwin
->w_redr_status
= TRUE
;
4054 redraw_tabline
= TRUE
;
4056 redraw_later(VALID
); /* causes status line redraw */
4058 /* set window height to desired minimal value */
4059 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4060 win_setheight((int)p_wh
);
4061 else if (curwin
->w_height
== 0)
4064 #ifdef FEAT_VERTSPLIT
4065 /* set window width to desired minimal value */
4066 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4067 win_setwidth((int)p_wiw
);
4071 setmouse(); /* in case jumped to/from help buffer */
4074 /* Change directories when the 'acd' option is set. */
4078 #endif /* FEAT_WINDOWS */
4080 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4082 * Jump to the first open window that contains buffer "buf", if one exists.
4083 * Returns a pointer to the window found, otherwise NULL.
4086 buf_jump_open_win(buf
)
4089 # ifdef FEAT_WINDOWS
4092 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4093 if (wp
->w_buffer
== buf
)
4096 win_enter(wp
, FALSE
);
4099 if (curwin
->w_buffer
== buf
)
4106 * Jump to the first open window in any tab page that contains buffer "buf",
4108 * Returns a pointer to the window found, otherwise NULL.
4111 buf_jump_open_tab(buf
)
4114 # ifdef FEAT_WINDOWS
4118 /* First try the current tab page. */
4119 wp
= buf_jump_open_win(buf
);
4123 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4126 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4127 if (wp
->w_buffer
== buf
)
4131 goto_tabpage_win(tp
, wp
);
4133 wp
= NULL
; /* something went wrong */
4140 if (curwin
->w_buffer
== buf
)
4148 * allocate a window structure and link it in the window list
4158 * allocate window structure and linesizes arrays
4160 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4161 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4170 /* Don't execute autocommands while the window is not properly
4171 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4176 * link the window in the window list
4179 win_append(after
, newwin
);
4181 #ifdef FEAT_VERTSPLIT
4182 newwin
->w_wincol
= 0;
4183 newwin
->w_width
= Columns
;
4186 /* position the display and the cursor at the top of the file. */
4187 newwin
->w_topline
= 1;
4189 newwin
->w_topfill
= 0;
4191 newwin
->w_botline
= 2;
4192 newwin
->w_cursor
.lnum
= 1;
4193 #ifdef FEAT_SCROLLBIND
4194 newwin
->w_scbind_pos
= 1;
4197 /* We won't calculate w_fraction until resizing the window */
4198 newwin
->w_fraction
= 0;
4199 newwin
->w_prev_fraction_row
= -1;
4204 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4206 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4207 SBAR_RIGHT
, newwin
);
4211 /* init w: variables */
4212 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4215 foldInitWin(newwin
);
4220 #ifdef FEAT_SEARCH_EXTRA
4221 newwin
->w_match_head
= NULL
;
4222 newwin
->w_next_match_id
= 4;
4228 #if defined(FEAT_WINDOWS) || defined(PROTO)
4231 * remove window 'wp' from the window list and free the structure
4236 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4241 /* Don't execute autocommands while the window is halfway being deleted.
4242 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4246 #ifdef FEAT_MZSCHEME
4247 mzscheme_window_free(wp
);
4255 python_window_free(wp
);
4259 tcl_window_free(wp
);
4263 ruby_window_free(wp
);
4266 clear_winopt(&wp
->w_onebuf_opt
);
4267 clear_winopt(&wp
->w_allbuf_opt
);
4270 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4277 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4278 vim_free(wp
->w_tagstack
[i
].tagname
);
4280 vim_free(wp
->w_localdir
);
4282 #ifdef FEAT_SEARCH_EXTRA
4286 #ifdef FEAT_JUMPLIST
4290 #ifdef FEAT_QUICKFIX
4297 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4298 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4300 #endif /* FEAT_GUI */
4311 * Append window "wp" in the window list after window "after".
4314 win_append(after
, wp
)
4319 if (after
== NULL
) /* after NULL is in front of the first */
4322 before
= after
->w_next
;
4324 wp
->w_next
= before
;
4333 before
->w_prev
= wp
;
4337 * Remove a window from the window list.
4342 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4344 if (wp
->w_prev
!= NULL
)
4345 wp
->w_prev
->w_next
= wp
->w_next
;
4346 else if (tp
== NULL
)
4347 firstwin
= wp
->w_next
;
4349 tp
->tp_firstwin
= wp
->w_next
;
4350 if (wp
->w_next
!= NULL
)
4351 wp
->w_next
->w_prev
= wp
->w_prev
;
4352 else if (tp
== NULL
)
4353 lastwin
= wp
->w_prev
;
4355 tp
->tp_lastwin
= wp
->w_prev
;
4359 * Append frame "frp" in a frame list after frame "after".
4362 frame_append(after
, frp
)
4363 frame_T
*after
, *frp
;
4365 frp
->fr_next
= after
->fr_next
;
4366 after
->fr_next
= frp
;
4367 if (frp
->fr_next
!= NULL
)
4368 frp
->fr_next
->fr_prev
= frp
;
4369 frp
->fr_prev
= after
;
4373 * Insert frame "frp" in a frame list before frame "before".
4376 frame_insert(before
, frp
)
4377 frame_T
*before
, *frp
;
4379 frp
->fr_next
= before
;
4380 frp
->fr_prev
= before
->fr_prev
;
4381 before
->fr_prev
= frp
;
4382 if (frp
->fr_prev
!= NULL
)
4383 frp
->fr_prev
->fr_next
= frp
;
4385 frp
->fr_parent
->fr_child
= frp
;
4389 * Remove a frame from a frame list.
4395 if (frp
->fr_prev
!= NULL
)
4396 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4398 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4399 if (frp
->fr_next
!= NULL
)
4400 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4403 #endif /* FEAT_WINDOWS */
4406 * Allocate w_lines[] for window "wp".
4407 * Return FAIL for failure, OK for success.
4413 wp
->w_lines_valid
= 0;
4414 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4415 if (wp
->w_lines
== NULL
)
4421 * free lsize arrays for a window
4427 vim_free(wp
->w_lines
);
4432 * Called from win_new_shellsize() after Rows changed.
4433 * This only does the current tab page, others must be done when made active.
4438 int h
= (int)ROWS_AVAIL
;
4440 if (firstwin
== NULL
) /* not initialized yet */
4443 if (h
< frame_minheight(topframe
, NULL
))
4444 h
= frame_minheight(topframe
, NULL
);
4446 /* First try setting the heights of windows with 'winfixheight'. If
4447 * that doesn't result in the right height, forget about that option. */
4448 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4449 if (topframe
->fr_height
!= h
)
4450 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4452 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4456 win_new_height(firstwin
, h
);
4460 curtab
->tp_ch_used
= p_ch
;
4464 /* Disabled: don't want making the screen smaller make a window larger. */
4466 win_equal(curwin
, FALSE
, 'v');
4470 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4472 * Called from win_new_shellsize() after Columns changed.
4477 if (firstwin
== NULL
) /* not initialized yet */
4480 /* First try setting the widths of windows with 'winfixwidth'. If that
4481 * doesn't result in the right width, forget about that option. */
4482 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4483 if (topframe
->fr_width
!= Columns
)
4484 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4486 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4488 /* Disabled: don't want making the screen smaller make a window larger. */
4490 win_equal(curwin
, FALSE
, 'h');
4495 #if defined(FEAT_CMDWIN) || defined(PROTO)
4497 * Save the size of all windows in "gap".
4506 ga_init2(gap
, (int)sizeof(int), 1);
4507 if (ga_grow(gap
, win_count() * 2) == OK
)
4508 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4510 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4511 wp
->w_width
+ wp
->w_vsep_width
;
4512 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4517 * Restore window sizes, but only if the number of windows is still the same.
4518 * Does not free the growarray.
4521 win_size_restore(gap
)
4527 if (win_count() * 2 == gap
->ga_len
)
4530 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4532 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4533 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4535 /* recompute the window positions */
4536 (void)win_comp_pos();
4539 #endif /* FEAT_CMDWIN */
4541 #if defined(FEAT_WINDOWS) || defined(PROTO)
4543 * Update the position for all windows, using the width and height of the
4545 * Returns the row just after the last window.
4550 int row
= tabline_height();
4553 frame_comp_pos(topframe
, &row
, &col
);
4558 * Update the position of the windows in frame "topfrp", using the width and
4559 * height of the frames.
4560 * "*row" and "*col" are the top-left position of the frame. They are updated
4561 * to the bottom-right position plus one.
4564 frame_comp_pos(topfrp
, row
, col
)
4571 #ifdef FEAT_VERTSPLIT
4576 wp
= topfrp
->fr_win
;
4579 if (wp
->w_winrow
!= *row
4580 #ifdef FEAT_VERTSPLIT
4581 || wp
->w_wincol
!= *col
4585 /* position changed, redraw */
4586 wp
->w_winrow
= *row
;
4587 #ifdef FEAT_VERTSPLIT
4588 wp
->w_wincol
= *col
;
4590 redraw_win_later(wp
, NOT_VALID
);
4591 wp
->w_redr_status
= TRUE
;
4593 *row
+= wp
->w_height
+ wp
->w_status_height
;
4594 #ifdef FEAT_VERTSPLIT
4595 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4600 #ifdef FEAT_VERTSPLIT
4604 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4606 #ifdef FEAT_VERTSPLIT
4607 if (topfrp
->fr_layout
== FR_ROW
)
4608 *row
= startrow
; /* all frames are at the same row */
4610 *col
= startcol
; /* all frames are at the same col */
4612 frame_comp_pos(frp
, row
, col
);
4617 #endif /* FEAT_WINDOWS */
4620 * Set current window height and take care of repositioning other windows to
4624 win_setheight(height
)
4627 win_setheight_win(height
, curwin
);
4631 * Set the window height of window "win" and take care of repositioning other
4632 * windows to fit around it.
4635 win_setheight_win(height
, win
)
4643 /* Always keep current window at least one line high, even when
4644 * 'winminheight' is zero. */
4654 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4656 /* recompute the window positions */
4657 row
= win_comp_pos();
4659 if (height
> topframe
->fr_height
)
4660 height
= topframe
->fr_height
;
4661 win
->w_height
= height
;
4666 * If there is extra space created between the last window and the command
4669 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4670 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4675 redraw_all_later(NOT_VALID
);
4678 #if defined(FEAT_WINDOWS) || defined(PROTO)
4681 * Set the height of a frame to "height" and take care that all frames and
4682 * windows inside it are resized. Also resize frames on the left and right if
4683 * the are in the same FR_ROW frame.
4686 * If the frame is part of a FR_COL frame, try fitting the frame in that
4687 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4688 * go to containing frames to resize them and make room.
4689 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4690 * Check for the minimal height of the FR_ROW frame.
4691 * At the top level we can also use change the command line height.
4694 frame_setheight(curfrp
, height
)
4698 int room
; /* total number of lines available */
4699 int take
; /* number of lines taken from other windows */
4700 int room_cmdline
; /* lines available from cmdline */
4706 /* If the height already is the desired value, nothing to do. */
4707 if (curfrp
->fr_height
== height
)
4710 if (curfrp
->fr_parent
== NULL
)
4712 /* topframe: can only change the command line */
4713 if (height
> ROWS_AVAIL
)
4714 height
= ROWS_AVAIL
;
4716 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4718 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4720 /* Row of frames: Also need to resize frames left and right of this
4721 * one. First check for the minimal height of these. */
4722 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4725 frame_setheight(curfrp
->fr_parent
, height
);
4730 * Column of frames: try to change only frames in this column.
4732 #ifdef FEAT_VERTSPLIT
4735 * 1: compute room available, if it's not enough try resizing the
4737 * 2: compute the room available and adjust the height to it.
4738 * Try not to reduce the height of a window with 'winfixheight' set.
4740 for (run
= 1; run
<= 2; ++run
)
4747 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4751 && frp
->fr_win
!= NULL
4752 && frp
->fr_win
->w_p_wfh
)
4753 room_reserved
+= frp
->fr_height
;
4754 room
+= frp
->fr_height
;
4756 room
-= frame_minheight(frp
, NULL
);
4758 #ifdef FEAT_VERTSPLIT
4759 if (curfrp
->fr_width
!= Columns
)
4764 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4765 + lastwin
->w_height
+ lastwin
->w_status_height
);
4766 if (room_cmdline
< 0)
4770 if (height
<= room
+ room_cmdline
)
4772 #ifdef FEAT_VERTSPLIT
4773 if (run
== 2 || curfrp
->fr_width
== Columns
)
4776 if (height
> room
+ room_cmdline
)
4777 height
= room
+ room_cmdline
;
4780 #ifdef FEAT_VERTSPLIT
4781 frame_setheight(curfrp
->fr_parent
, height
4782 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4788 * Compute the number of lines we will take from others frames (can be
4791 take
= height
- curfrp
->fr_height
;
4793 /* If there is not enough room, also reduce the height of a window
4794 * with 'winfixheight' set. */
4795 if (height
> room
+ room_cmdline
- room_reserved
)
4796 room_reserved
= room
+ room_cmdline
- height
;
4797 /* If there is only a 'winfixheight' window and making the
4798 * window smaller, need to make the other window taller. */
4799 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4802 if (take
> 0 && room_cmdline
> 0)
4804 /* use lines from cmdline first */
4805 if (take
< room_cmdline
)
4806 room_cmdline
= take
;
4807 take
-= room_cmdline
;
4808 topframe
->fr_height
+= room_cmdline
;
4812 * set the current frame to the new height
4814 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4817 * First take lines from the frames after the current frame. If
4818 * that is not enough, takes lines from frames above the current
4821 for (run
= 0; run
< 2; ++run
)
4824 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4826 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4827 while (frp
!= NULL
&& take
!= 0)
4829 h
= frame_minheight(frp
, NULL
);
4830 if (room_reserved
> 0
4831 && frp
->fr_win
!= NULL
4832 && frp
->fr_win
->w_p_wfh
)
4834 if (room_reserved
>= frp
->fr_height
)
4835 room_reserved
-= frp
->fr_height
;
4838 if (frp
->fr_height
- room_reserved
> take
)
4839 room_reserved
= frp
->fr_height
- take
;
4840 take
-= frp
->fr_height
- room_reserved
;
4841 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4847 if (frp
->fr_height
- take
< h
)
4849 take
-= frp
->fr_height
- h
;
4850 frame_new_height(frp
, h
, FALSE
, FALSE
);
4854 frame_new_height(frp
, frp
->fr_height
- take
,
4868 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4870 * Set current window width and take care of repositioning other windows to
4877 win_setwidth_win(width
, curwin
);
4881 win_setwidth_win(width
, wp
)
4885 /* Always keep current window at least one column wide, even when
4886 * 'winminwidth' is zero. */
4895 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4897 /* recompute the window positions */
4898 (void)win_comp_pos();
4900 redraw_all_later(NOT_VALID
);
4904 * Set the width of a frame to "width" and take care that all frames and
4905 * windows inside it are resized. Also resize frames above and below if the
4906 * are in the same FR_ROW frame.
4908 * Strategy is similar to frame_setheight().
4911 frame_setwidth(curfrp
, width
)
4915 int room
; /* total number of lines available */
4916 int take
; /* number of lines taken from other windows */
4922 /* If the width already is the desired value, nothing to do. */
4923 if (curfrp
->fr_width
== width
)
4926 if (curfrp
->fr_parent
== NULL
)
4927 /* topframe: can't change width */
4930 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4932 /* Column of frames: Also need to resize frames above and below of
4933 * this one. First check for the minimal width of these. */
4934 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4937 frame_setwidth(curfrp
->fr_parent
, width
);
4942 * Row of frames: try to change only frames in this row.
4945 * 1: compute room available, if it's not enough try resizing the
4947 * 2: compute the room available and adjust the width to it.
4949 for (run
= 1; run
<= 2; ++run
)
4953 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4957 && frp
->fr_win
!= NULL
4958 && frp
->fr_win
->w_p_wfw
)
4959 room_reserved
+= frp
->fr_width
;
4960 room
+= frp
->fr_width
;
4962 room
-= frame_minwidth(frp
, NULL
);
4967 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4973 frame_setwidth(curfrp
->fr_parent
, width
4974 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4978 * Compute the number of lines we will take from others frames (can be
4981 take
= width
- curfrp
->fr_width
;
4983 /* If there is not enough room, also reduce the width of a window
4984 * with 'winfixwidth' set. */
4985 if (width
> room
- room_reserved
)
4986 room_reserved
= room
- width
;
4987 /* If there is only a 'winfixwidth' window and making the
4988 * window smaller, need to make the other window narrower. */
4989 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4993 * set the current frame to the new width
4995 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
4998 * First take lines from the frames right of the current frame. If
4999 * that is not enough, takes lines from frames left of the current
5002 for (run
= 0; run
< 2; ++run
)
5005 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5007 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5008 while (frp
!= NULL
&& take
!= 0)
5010 w
= frame_minwidth(frp
, NULL
);
5011 if (room_reserved
> 0
5012 && frp
->fr_win
!= NULL
5013 && frp
->fr_win
->w_p_wfw
)
5015 if (room_reserved
>= frp
->fr_width
)
5016 room_reserved
-= frp
->fr_width
;
5019 if (frp
->fr_width
- room_reserved
> take
)
5020 room_reserved
= frp
->fr_width
- take
;
5021 take
-= frp
->fr_width
- room_reserved
;
5022 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5028 if (frp
->fr_width
- take
< w
)
5030 take
-= frp
->fr_width
- w
;
5031 frame_new_width(frp
, w
, FALSE
, FALSE
);
5035 frame_new_width(frp
, frp
->fr_width
- take
,
5048 #endif /* FEAT_VERTSPLIT */
5051 * Check 'winminheight' for a valid value.
5060 /* loop until there is a 'winminheight' that is possible */
5063 /* TODO: handle vertical splits */
5065 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5066 room
+= wp
->w_height
- p_wmh
;
5081 * Status line of dragwin is dragged "offset" lines down (negative is up).
5084 win_drag_status_line(dragwin
, offset
)
5092 int up
; /* if TRUE, drag status line up, otherwise down */
5095 fr
= dragwin
->w_frame
;
5097 if (fr
!= topframe
) /* more than one window */
5100 /* When the parent frame is not a column of frames, its parent should
5102 if (fr
->fr_layout
!= FR_COL
)
5105 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5110 /* If this is the last frame in a column, may want to resize the parent
5111 * frame instead (go two up to skip a row of frames). */
5112 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5121 if (offset
< 0) /* drag up */
5125 /* sum up the room of the current frame and above it */
5128 /* only one window */
5129 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5134 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5136 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5141 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5143 else /* drag down */
5147 * Only dragging the last status line can reduce p_ch.
5149 room
= Rows
- cmdline_row
;
5150 if (curfr
->fr_next
== NULL
)
5156 /* sum up the room of frames below of the current one */
5157 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5158 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5159 fr
= curfr
; /* put fr at window that grows */
5162 if (room
< offset
) /* Not enough room */
5163 offset
= room
; /* Move as far as we can */
5168 * Grow frame fr by "offset" lines.
5169 * Doesn't happen when dragging the last status line up.
5172 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5175 fr
= curfr
; /* current frame gets smaller */
5177 fr
= curfr
->fr_next
; /* next frame gets smaller */
5180 * Now make the other frames smaller.
5182 while (fr
!= NULL
&& offset
> 0)
5184 n
= frame_minheight(fr
, NULL
);
5185 if (fr
->fr_height
- offset
<= n
)
5187 offset
-= fr
->fr_height
- n
;
5188 frame_new_height(fr
, n
, !up
, FALSE
);
5192 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5200 row
= win_comp_pos();
5201 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5203 p_ch
= Rows
- cmdline_row
;
5206 curtab
->tp_ch_used
= p_ch
;
5207 redraw_all_later(SOME_VALID
);
5211 #ifdef FEAT_VERTSPLIT
5213 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5216 win_drag_vsep_line(dragwin
, offset
)
5223 int left
; /* if TRUE, drag separator line left, otherwise right */
5226 fr
= dragwin
->w_frame
;
5227 if (fr
== topframe
) /* only one window (cannot happen?) */
5231 /* When the parent frame is not a row of frames, its parent should be. */
5232 if (fr
->fr_layout
!= FR_ROW
)
5234 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5240 /* If this is the last frame in a row, may want to resize a parent
5242 while (curfr
->fr_next
== NULL
)
5255 if (offset
< 0) /* drag left */
5259 /* sum up the room of the current frame and left of it */
5261 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5263 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5267 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5269 else /* drag right */
5272 /* sum up the room of frames right of the current one */
5274 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5275 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5276 fr
= curfr
; /* put fr at window that grows */
5279 if (room
< offset
) /* Not enough room */
5280 offset
= room
; /* Move as far as we can */
5281 if (offset
<= 0) /* No room at all, quit. */
5284 /* grow frame fr by offset lines */
5285 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5287 /* shrink other frames: current and at the left or at the right */
5289 fr
= curfr
; /* current frame gets smaller */
5291 fr
= curfr
->fr_next
; /* next frame gets smaller */
5293 while (fr
!= NULL
&& offset
> 0)
5295 n
= frame_minwidth(fr
, NULL
);
5296 if (fr
->fr_width
- offset
<= n
)
5298 offset
-= fr
->fr_width
- n
;
5299 frame_new_width(fr
, n
, !left
, FALSE
);
5303 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5311 (void)win_comp_pos();
5312 redraw_all_later(NOT_VALID
);
5314 #endif /* FEAT_VERTSPLIT */
5315 #endif /* FEAT_MOUSE */
5317 #endif /* FEAT_WINDOWS */
5320 * Set the height of a window.
5321 * This takes care of the things inside the window, not what happens to the
5322 * window position, the frame or to other windows.
5325 win_new_height(wp
, height
)
5330 int sline
, line_size
;
5331 #define FRACTION_MULT 16384L
5333 /* Don't want a negative height. Happens when splitting a tiny window.
5334 * Will equalize heights soon to fix it. */
5337 if (wp
->w_height
== height
)
5338 return; /* nothing to do */
5340 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5341 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5342 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5344 wp
->w_height
= height
;
5347 /* Don't change w_topline when height is zero. Don't set w_topline when
5348 * 'scrollbind' is set and this isn't the current window. */
5350 #ifdef FEAT_SCROLLBIND
5351 && (!wp
->w_p_scb
|| wp
== curwin
)
5356 * Find a value for w_topline that shows the cursor at the same
5357 * relative position in the window as before (more or less).
5359 lnum
= wp
->w_cursor
.lnum
;
5360 if (lnum
< 1) /* can happen when starting up */
5362 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5363 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5364 sline
= wp
->w_wrow
- line_size
;
5368 /* Make sure the whole cursor line is visible, if possible. */
5369 int rows
= plines_win(wp
, lnum
, FALSE
);
5371 if (sline
> wp
->w_height
- rows
)
5373 sline
= wp
->w_height
- rows
;
5374 wp
->w_wrow
-= rows
- line_size
;
5381 * Cursor line would go off top of screen if w_wrow was this high.
5382 * Make cursor line the first line in the window. If not enough
5383 * room use w_skipcol;
5385 wp
->w_wrow
= line_size
;
5386 if (wp
->w_wrow
>= wp
->w_height
5387 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5389 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5391 while (wp
->w_wrow
>= wp
->w_height
)
5393 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5401 while (sline
> 0 && lnum
> 1)
5404 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5407 /* first line in buffer is folded */
5415 if (lnum
== wp
->w_topline
)
5416 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5420 line_size
= plines_win(wp
, lnum
, TRUE
);
5427 * Line we want at top would go off top of screen. Use next
5431 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5434 wp
->w_wrow
-= line_size
+ sline
;
5438 /* First line of file reached, use that as topline. */
5440 wp
->w_wrow
-= sline
;
5443 set_topline(wp
, lnum
);
5450 curs_columns(FALSE
); /* validate w_wrow */
5452 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5454 win_comp_scroll(wp
);
5455 redraw_win_later(wp
, SOME_VALID
);
5457 wp
->w_redr_status
= TRUE
;
5459 invalidate_botline_win(wp
);
5462 #ifdef FEAT_VERTSPLIT
5464 * Set the width of a window.
5467 win_new_width(wp
, width
)
5471 wp
->w_width
= width
;
5472 wp
->w_lines_valid
= 0;
5473 changed_line_abv_curs_win(wp
);
5474 invalidate_botline_win(wp
);
5478 curs_columns(TRUE
); /* validate w_wrow */
5480 redraw_win_later(wp
, NOT_VALID
);
5481 wp
->w_redr_status
= TRUE
;
5489 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5490 if (wp
->w_p_scr
== 0)
5495 * command_height: called whenever p_ch has been changed
5503 int old_p_ch
= curtab
->tp_ch_used
;
5505 /* Use the value of p_ch that we remembered. This is needed for when the
5506 * GUI starts up, we can't be sure in what order things happen. And when
5507 * p_ch was changed in another tab page. */
5508 curtab
->tp_ch_used
= p_ch
;
5510 /* Find bottom frame with width of screen. */
5511 frp
= lastwin
->w_frame
;
5512 # ifdef FEAT_VERTSPLIT
5513 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5514 frp
= frp
->fr_parent
;
5517 /* Avoid changing the height of a window with 'winfixheight' set. */
5518 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5519 && frp
->fr_win
->w_p_wfh
)
5522 if (starting
!= NO_SCREEN
)
5524 cmdline_row
= Rows
- p_ch
;
5526 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5528 while (p_ch
> old_p_ch
)
5534 curtab
->tp_ch_used
= p_ch
;
5535 cmdline_row
= Rows
- p_ch
;
5538 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5539 if (h
> p_ch
- old_p_ch
)
5540 h
= p_ch
- old_p_ch
;
5542 frame_add_height(frp
, -h
);
5546 /* Recompute window positions. */
5547 (void)win_comp_pos();
5549 /* clear the lines added to cmdline */
5551 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5552 (int)Columns
, ' ', ' ', 0);
5553 msg_row
= cmdline_row
;
5554 redraw_cmdline
= TRUE
;
5558 if (msg_row
< cmdline_row
)
5559 msg_row
= cmdline_row
;
5560 redraw_cmdline
= TRUE
;
5562 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5564 /* Recompute window positions. */
5565 if (frp
!= lastwin
->w_frame
)
5566 (void)win_comp_pos();
5568 cmdline_row
= Rows
- p_ch
;
5569 win_setheight(cmdline_row
);
5573 #if defined(FEAT_WINDOWS) || defined(PROTO)
5575 * Resize frame "frp" to be "n" lines higher (negative for less high).
5576 * Also resize the frames it is contained in.
5579 frame_add_height(frp
, n
)
5583 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5586 frp
= frp
->fr_parent
;
5589 frp
->fr_height
+= n
;
5594 * Add or remove a status line for the bottom window(s), according to the
5595 * value of 'laststatus'.
5598 last_status(morewin
)
5599 int morewin
; /* pretend there are two or more windows */
5601 /* Don't make a difference between horizontal or vertical split. */
5602 last_status_rec(topframe
, (p_ls
== 2
5603 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5607 last_status_rec(fr
, statusline
)
5614 if (fr
->fr_layout
== FR_LEAF
)
5617 if (wp
->w_status_height
!= 0 && !statusline
)
5619 /* remove status line */
5620 win_new_height(wp
, wp
->w_height
+ 1);
5621 wp
->w_status_height
= 0;
5624 else if (wp
->w_status_height
== 0 && statusline
)
5626 /* Find a frame to take a line from. */
5628 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5635 /* In a column of frames: go to frame above. If already at
5636 * the top or in a row of frames: go to parent. */
5637 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5642 wp
->w_status_height
= 1;
5645 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5646 frame_fix_height(wp
);
5647 (void)win_comp_pos();
5650 win_new_height(wp
, wp
->w_height
- 1);
5652 redraw_all_later(SOME_VALID
);
5655 #ifdef FEAT_VERTSPLIT
5656 else if (fr
->fr_layout
== FR_ROW
)
5658 /* vertically split windows, set status line for each one */
5659 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5660 last_status_rec(fp
, statusline
);
5665 /* horizontally split window, set status line for last one */
5666 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5668 last_status_rec(fp
, statusline
);
5673 * Return the number of lines used by the tab page line.
5678 #ifdef FEAT_GUI_TABLINE
5679 /* When the GUI has the tabline then this always returns zero. */
5680 if (gui_use_tabline())
5686 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5691 #endif /* FEAT_WINDOWS */
5693 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5695 * Get the file name at the cursor.
5696 * If Visual mode is active, use the selected text if it's in one line.
5697 * Returns the name in allocated memory, NULL for failure.
5700 grab_file_name(count
, file_lnum
)
5702 linenr_T
*file_lnum
;
5710 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5712 return find_file_name_in_path(ptr
, len
,
5713 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5716 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5722 * Return the file name under or after the cursor.
5724 * The 'path' option is searched if the file name is not absolute.
5725 * The string returned has been alloc'ed and should be freed by the caller.
5726 * NULL is returned if the file name or file is not found.
5729 * FNAME_MESS give error messages
5730 * FNAME_EXP expand to path
5731 * FNAME_HYP check for hypertext link
5732 * FNAME_INCL apply "includeexpr"
5735 file_name_at_cursor(options
, count
, file_lnum
)
5738 linenr_T
*file_lnum
;
5740 return file_name_in_line(ml_get_curline(),
5741 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5746 * Return the name of the file under or after ptr[col].
5747 * Otherwise like file_name_at_cursor().
5750 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5755 char_u
*rel_fname
; /* file we are searching relative to */
5756 linenr_T
*file_lnum
; /* line number after the file name */
5762 * search forward for what could be the start of a file name
5765 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5767 if (*ptr
== NUL
) /* nothing found */
5769 if (options
& FNAME_MESS
)
5770 EMSG(_("E446: No file name under cursor"));
5775 * Search backward for first char of the file name.
5776 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5781 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5785 if (vim_isfilec(ptr
[-1])
5786 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5793 * Search forward for the last char of the file name.
5794 * Also allow "://" when ':' is not in 'isfname'.
5797 while (vim_isfilec(ptr
[len
])
5798 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5801 len
+= (*mb_ptr2len
)(ptr
+ len
);
5807 * If there is trailing punctuation, remove it.
5808 * But don't remove "..", could be a directory name.
5810 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5811 && ptr
[len
- 2] != '.')
5814 if (file_lnum
!= NULL
)
5818 /* Get the number after the file name and a separator character */
5824 ++p
; /* skip the separator */
5827 *file_lnum
= (int)getdigits(&p
);
5831 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5834 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5835 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5838 eval_includeexpr(ptr
, len
)
5844 set_vim_var_string(VV_FNAME
, ptr
, len
);
5845 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5846 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5847 set_vim_var_string(VV_FNAME
, NULL
, 0);
5853 * Return the name of the file ptr[len] in 'path'.
5854 * Otherwise like file_name_at_cursor().
5857 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5862 char_u
*rel_fname
; /* file we are searching relative to */
5866 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5867 char_u
*tofree
= NULL
;
5869 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5871 tofree
= eval_includeexpr(ptr
, len
);
5875 len
= (int)STRLEN(ptr
);
5880 if (options
& FNAME_EXP
)
5882 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5885 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5887 * If the file could not be found in a normal way, try applying
5888 * 'includeexpr' (unless done already).
5890 if (file_name
== NULL
5891 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5893 tofree
= eval_includeexpr(ptr
, len
);
5897 len
= (int)STRLEN(ptr
);
5898 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5903 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5907 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5911 /* Repeat finding the file "count" times. This matters when it
5912 * appears several times in the path. */
5913 while (file_name
!= NULL
&& --count
> 0)
5915 vim_free(file_name
);
5916 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5920 file_name
= vim_strnsave(ptr
, len
);
5922 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5928 #endif /* FEAT_SEARCHPATH */
5931 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5932 * Also check for ":\\", which MS Internet Explorer accepts, return
5939 if (STRNCMP(p
, "://", (size_t)3) == 0)
5941 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5942 return URL_BACKSLASH
;
5947 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5948 * Return URL_BACKSLASH for "name:\\".
5949 * Return zero otherwise.
5952 path_with_url(fname
)
5957 for (p
= fname
; isalpha(*p
); ++p
)
5959 return path_is_url(p
);
5963 * Return TRUE if "name" is a full (absolute) path name or URL.
5969 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5973 * Get absolute file name into buffer "buf[len]".
5975 * return FAIL for failure, OK otherwise
5978 vim_FullName(fname
, buf
, len
, force
)
5979 char_u
*fname
, *buf
;
5981 int force
; /* force expansion even when already absolute */
5990 url
= path_with_url(fname
);
5992 retval
= mch_FullName(fname
, buf
, len
, force
);
5993 if (url
|| retval
== FAIL
)
5995 /* something failed; use the file name (truncate when too long) */
5996 vim_strncpy(buf
, fname
, len
- 1);
5998 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6005 * Return the minimal number of rows that is needed on the screen to display
6006 * the current number of windows.
6017 if (firstwin
== NULL
) /* not initialized yet */
6022 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6024 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6028 total
+= tabline_height();
6030 total
= 1; /* at least one window should have a line! */
6032 total
+= 1; /* count the room for the command line */
6037 * Return TRUE if there is only one window (in the current tab page), not
6038 * counting a help or preview window, unless it is the current window.
6047 /* If there is another tab page there always is another window. */
6048 if (first_tabpage
->tp_next
!= NULL
)
6051 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6052 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6053 # ifdef FEAT_QUICKFIX
6058 return (count
<= 1);
6064 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6066 * Correct the cursor line number in other windows. Used after changing the
6067 * current buffer, and before applying autocommands.
6068 * When "do_curwin" is TRUE, also check current window.
6071 check_lnums(do_curwin
)
6079 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6080 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6086 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6087 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6088 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6089 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6094 #if defined(FEAT_WINDOWS) || defined(PROTO)
6097 * A snapshot of the window sizes, to restore them after closing the help
6099 * Only these fields are used:
6105 * fr_win (only valid for the old curwin, NULL otherwise)
6109 * Create a snapshot of the current frame sizes.
6114 clear_snapshot(curtab
);
6115 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6119 make_snapshot_rec(fr
, frp
)
6123 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6126 (*frp
)->fr_layout
= fr
->fr_layout
;
6127 # ifdef FEAT_VERTSPLIT
6128 (*frp
)->fr_width
= fr
->fr_width
;
6130 (*frp
)->fr_height
= fr
->fr_height
;
6131 if (fr
->fr_next
!= NULL
)
6132 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6133 if (fr
->fr_child
!= NULL
)
6134 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6135 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6136 (*frp
)->fr_win
= curwin
;
6140 * Remove any existing snapshot.
6146 clear_snapshot_rec(tp
->tp_snapshot
);
6147 tp
->tp_snapshot
= NULL
;
6151 clear_snapshot_rec(fr
)
6156 clear_snapshot_rec(fr
->fr_next
);
6157 clear_snapshot_rec(fr
->fr_child
);
6163 * Restore a previously created snapshot, if there is any.
6164 * This is only done if the screen size didn't change and the window layout is
6168 restore_snapshot(close_curwin
)
6169 int close_curwin
; /* closing current window */
6173 if (curtab
->tp_snapshot
!= NULL
6174 # ifdef FEAT_VERTSPLIT
6175 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6177 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6178 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6180 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6182 if (wp
!= NULL
&& close_curwin
)
6184 redraw_all_later(CLEAR
);
6186 clear_snapshot(curtab
);
6190 * Check if frames "sn" and "fr" have the same layout, same following frames
6191 * and same children.
6194 check_snapshot_rec(sn
, fr
)
6198 if (sn
->fr_layout
!= fr
->fr_layout
6199 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6200 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6201 || (sn
->fr_next
!= NULL
6202 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6203 || (sn
->fr_child
!= NULL
6204 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6210 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6211 * following frames and children.
6212 * Returns a pointer to the old current window, or NULL.
6215 restore_snapshot_rec(sn
, fr
)
6222 fr
->fr_height
= sn
->fr_height
;
6223 # ifdef FEAT_VERTSPLIT
6224 fr
->fr_width
= sn
->fr_width
;
6226 if (fr
->fr_layout
== FR_LEAF
)
6228 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6229 # ifdef FEAT_VERTSPLIT
6230 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6234 if (sn
->fr_next
!= NULL
)
6236 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6240 if (sn
->fr_child
!= NULL
)
6242 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6251 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6253 * Return TRUE if there is any vertically split window.
6260 if (topframe
->fr_layout
== FR_ROW
)
6263 if (topframe
->fr_layout
== FR_COL
)
6264 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6265 if (fr
->fr_layout
== FR_ROW
)
6272 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6274 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6275 * highlighted with the group 'grp' with priority 'prio'.
6276 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6277 * If no particular ID is desired, -1 must be specified for 'id'.
6278 * Return ID of added match, -1 on failure.
6281 match_add(wp
, grp
, pat
, prio
, id
)
6294 if (*grp
== NUL
|| *pat
== NUL
)
6296 if (id
< -1 || id
== 0)
6298 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6303 cur
= wp
->w_match_head
;
6308 EMSGN("E801: ID already taken: %ld", id
);
6314 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6316 EMSG2(_(e_nogroup
), grp
);
6319 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6321 EMSG2(_(e_invarg2
), pat
);
6325 /* Find available match ID. */
6328 cur
= wp
->w_match_head
;
6329 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6332 id
= wp
->w_next_match_id
;
6333 wp
->w_next_match_id
++;
6336 /* Build new match. */
6337 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6340 m
->pattern
= vim_strsave(pat
);
6342 m
->match
.regprog
= regprog
;
6343 m
->match
.rmm_ic
= FALSE
;
6344 m
->match
.rmm_maxcol
= 0;
6346 /* Insert new match. The match list is in ascending order with regard to
6347 * the match priorities. */
6348 cur
= wp
->w_match_head
;
6350 while (cur
!= NULL
&& prio
>= cur
->priority
)
6356 wp
->w_match_head
= m
;
6361 redraw_later(SOME_VALID
);
6366 * Delete match with ID 'id' in the match list of window 'wp'.
6367 * Print error messages if 'perr' is TRUE.
6370 match_delete(wp
, id
, perr
)
6375 matchitem_T
*cur
= wp
->w_match_head
;
6376 matchitem_T
*prev
= cur
;
6381 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6385 while (cur
!= NULL
&& cur
->id
!= id
)
6393 EMSGN("E803: ID not found: %ld", id
);
6397 wp
->w_match_head
= cur
->next
;
6399 prev
->next
= cur
->next
;
6400 vim_free(cur
->match
.regprog
);
6401 vim_free(cur
->pattern
);
6403 redraw_later(SOME_VALID
);
6408 * Delete all matches in the match list of window 'wp'.
6416 while (wp
->w_match_head
!= NULL
)
6418 m
= wp
->w_match_head
->next
;
6419 vim_free(wp
->w_match_head
->match
.regprog
);
6420 vim_free(wp
->w_match_head
->pattern
);
6421 vim_free(wp
->w_match_head
);
6422 wp
->w_match_head
= m
;
6424 redraw_later(SOME_VALID
);
6428 * Get match from ID 'id' in window 'wp'.
6429 * Return NULL if match not found.
6436 matchitem_T
*cur
= wp
->w_match_head
;
6438 while (cur
!= NULL
&& cur
->id
!= id
)