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.
13 # include <fcntl.h> /* for chdir() */
16 static int path_is_url
__ARGS((char_u
*p
));
17 #if defined(FEAT_WINDOWS) || defined(PROTO)
18 static int win_split_ins
__ARGS((int size
, int flags
, win_T
*newwin
, int dir
));
19 static void win_init
__ARGS((win_T
*newp
, win_T
*oldp
));
20 static void frame_comp_pos
__ARGS((frame_T
*topfrp
, int *row
, int *col
));
21 static void frame_setheight
__ARGS((frame_T
*curfrp
, int height
));
23 static void frame_setwidth
__ARGS((frame_T
*curfrp
, int width
));
25 static void win_exchange
__ARGS((long));
26 static void win_rotate
__ARGS((int, int));
27 static void win_totop
__ARGS((int size
, int flags
));
28 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
));
29 static int last_window
__ARGS((void));
30 static win_T
*win_free_mem
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
31 static win_T
*winframe_remove
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
32 static frame_T
*win_altframe
__ARGS((win_T
*win
, tabpage_T
*tp
));
33 static tabpage_T
*alt_tabpage
__ARGS((void));
34 static win_T
*frame2win
__ARGS((frame_T
*frp
));
35 static int frame_has_win
__ARGS((frame_T
*frp
, win_T
*wp
));
36 static void frame_new_height
__ARGS((frame_T
*topfrp
, int height
, int topfirst
, int wfh
));
37 static int frame_fixed_height
__ARGS((frame_T
*frp
));
39 static int frame_fixed_width
__ARGS((frame_T
*frp
));
40 static void frame_add_statusline
__ARGS((frame_T
*frp
));
41 static void frame_new_width
__ARGS((frame_T
*topfrp
, int width
, int leftfirst
, int wfw
));
42 static void frame_add_vsep
__ARGS((frame_T
*frp
));
43 static int frame_minwidth
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
44 static void frame_fix_width
__ARGS((win_T
*wp
));
47 static int win_alloc_firstwin
__ARGS((win_T
*oldwin
));
48 #if defined(FEAT_WINDOWS) || defined(PROTO)
49 static tabpage_T
*alloc_tabpage
__ARGS((void));
50 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
51 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
52 static void frame_fix_height
__ARGS((win_T
*wp
));
53 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
54 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
55 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
56 static void win_append
__ARGS((win_T
*, win_T
*));
57 static void win_remove
__ARGS((win_T
*, tabpage_T
*tp
));
58 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
59 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
60 static void frame_remove
__ARGS((frame_T
*frp
));
62 static void win_new_width
__ARGS((win_T
*wp
, int width
));
63 static void win_goto_ver
__ARGS((int up
, long count
));
64 static void win_goto_hor
__ARGS((int left
, long count
));
66 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
67 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
69 static void make_snapshot
__ARGS((void));
70 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
71 static void clear_snapshot
__ARGS((tabpage_T
*tp
));
72 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
73 static void restore_snapshot
__ARGS((int close_curwin
));
74 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
75 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
77 #endif /* FEAT_WINDOWS */
79 static win_T
*win_alloc
__ARGS((win_T
*after
));
80 static void win_new_height
__ARGS((win_T
*, int));
82 #define URL_SLASH 1 /* path_is_url() has found "://" */
83 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
85 #define NOWIN (win_T *)-1 /* non-existing window */
88 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
90 # define ROWS_AVAIL (Rows - p_ch)
93 #if defined(FEAT_WINDOWS) || defined(PROTO)
95 static char *m_onlyone
= N_("Already only one window");
98 * all CTRL-W window commands are handled here, called from normal_cmd().
101 do_window(nchar
, Prenum
, xchar
)
104 int xchar
; /* extra char from ":wincmd gx" or NUL */
108 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
113 int type
= FIND_DEFINE
;
124 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
126 # define CHECK_CMDWIN
131 /* split current window in two parts, horizontally */
137 reset_VIsual_and_resel(); /* stop Visual mode */
140 /* When splitting the quickfix window open a new buffer in it,
141 * don't replicate the quickfix buffer. */
142 if (bt_quickfix(curbuf
))
146 need_mouse_correct
= TRUE
;
148 win_split((int)Prenum
, 0);
151 #ifdef FEAT_VERTSPLIT
152 /* split current window in two parts, vertically */
157 reset_VIsual_and_resel(); /* stop Visual mode */
160 need_mouse_correct
= TRUE
;
162 win_split((int)Prenum
, WSP_VERT
);
166 /* split current window and edit alternate file */
171 reset_VIsual_and_resel(); /* stop Visual mode */
173 STRCPY(cbuf
, "split #");
175 sprintf((char *)cbuf
+ 7, "%ld", Prenum
);
176 do_cmdline_cmd(cbuf
);
179 /* open new window */
184 reset_VIsual_and_resel(); /* stop Visual mode */
190 sprintf((char *)cbuf
, "%ld", Prenum
); /* window height */
194 do_cmdline_cmd(cbuf
);
197 /* quit current window */
201 reset_VIsual_and_resel(); /* stop Visual mode */
203 do_cmdline_cmd((char_u
*)"quit");
206 /* close current window */
210 reset_VIsual_and_resel(); /* stop Visual mode */
212 do_cmdline_cmd((char_u
*)"close");
215 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
216 /* close preview window */
221 reset_VIsual_and_resel(); /* stop Visual mode */
223 do_cmdline_cmd((char_u
*)"pclose");
226 /* cursor to preview window */
228 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
232 EMSG(_("E441: There is no preview window"));
238 /* close all but current window */
243 reset_VIsual_and_resel(); /* stop Visual mode */
245 do_cmdline_cmd((char_u
*)"only");
248 /* cursor to next window with wrap around */
251 /* cursor to previous window with wrap around */
254 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
258 if (Prenum
) /* go to specified window */
260 for (wp
= firstwin
; --Prenum
> 0; )
262 if (wp
->w_next
== NULL
)
270 if (nchar
== 'W') /* go to previous window */
274 wp
= lastwin
; /* wrap around */
276 else /* go to next window */
280 wp
= firstwin
; /* wrap around */
287 /* cursor to window below */
292 #ifdef FEAT_VERTSPLIT
293 win_goto_ver(FALSE
, Prenum1
);
295 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
302 /* cursor to window above */
307 #ifdef FEAT_VERTSPLIT
308 win_goto_ver(TRUE
, Prenum1
);
310 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
317 #ifdef FEAT_VERTSPLIT
318 /* cursor to left window */
324 win_goto_hor(TRUE
, Prenum1
);
327 /* cursor to right window */
332 win_goto_hor(FALSE
, Prenum1
);
336 /* move window to new tab page */
338 if (firstwin
== lastwin
)
342 tabpage_T
*oldtab
= curtab
;
345 /* First create a new tab with the window, then go back to
346 * the old tab and close the window there. */
348 if (win_new_tabpage((int)Prenum
) == OK
349 && valid_tabpage(oldtab
))
352 goto_tabpage_tp(oldtab
);
354 win_close(curwin
, FALSE
);
355 if (valid_tabpage(newtab
))
356 goto_tabpage_tp(newtab
);
361 /* cursor to top-left window */
367 /* cursor to bottom-right window */
373 /* cursor to last accessed (previous) window */
382 /* exchange current and next window */
386 win_exchange(Prenum
);
389 /* rotate windows downwards */
394 reset_VIsual_and_resel(); /* stop Visual mode */
396 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
399 /* rotate windows upwards */
403 reset_VIsual_and_resel(); /* stop Visual mode */
405 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
408 /* move window to the very top/bottom/left/right */
411 #ifdef FEAT_VERTSPLIT
416 win_totop((int)Prenum
,
417 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
418 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
421 /* make all windows the same height */
424 need_mouse_correct
= TRUE
;
426 win_equal(NULL
, FALSE
, 'b');
429 /* increase current window height */
432 need_mouse_correct
= TRUE
;
434 win_setheight(curwin
->w_height
+ (int)Prenum1
);
437 /* decrease current window height */
440 need_mouse_correct
= TRUE
;
442 win_setheight(curwin
->w_height
- (int)Prenum1
);
445 /* set current window height */
449 need_mouse_correct
= TRUE
;
451 win_setheight(Prenum
? (int)Prenum
: 9999);
454 #ifdef FEAT_VERTSPLIT
455 /* increase current window width */
458 need_mouse_correct
= TRUE
;
460 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
463 /* decrease current window width */
466 need_mouse_correct
= TRUE
;
468 win_setwidth(curwin
->w_width
- (int)Prenum1
);
471 /* set current window width */
474 need_mouse_correct
= TRUE
;
476 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
480 /* jump to tag and split window if tag exists (in preview window) */
481 #if defined(FEAT_QUICKFIX)
485 g_do_tagpreview
= Prenum
;
487 g_do_tagpreview
= p_pvh
;
494 reset_VIsual_and_resel(); /* stop Visual mode */
497 postponed_split
= Prenum
;
499 postponed_split
= -1;
501 /* Execute the command right here, required when
502 * "wincmd ]" was used in a function. */
503 do_nv_ident(Ctrl_RSB
, NUL
);
506 #ifdef FEAT_SEARCHPATH
507 /* edit file name under cursor in a new window */
514 ptr
= grab_file_name(Prenum1
, &lnum
);
518 need_mouse_correct
= TRUE
;
521 if (win_split(0, 0) == OK
)
523 # ifdef FEAT_SCROLLBIND
524 curwin
->w_p_scb
= FALSE
;
526 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
, ECMD_HIDE
);
527 if (nchar
== 'F' && lnum
>= 0)
529 curwin
->w_cursor
.lnum
= lnum
;
531 beginline(BL_SOL
| BL_FIX
);
540 /* Go to the first occurrence of the identifier under cursor along path in a
543 case 'i': /* Go to any match */
547 case 'd': /* Go to definition, using 'define' */
550 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
552 find_pattern_in_path(ptr
, 0, len
, TRUE
,
553 Prenum
== 0 ? TRUE
: FALSE
, type
,
554 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
555 curwin
->w_set_curswant
= TRUE
;
561 #if defined(FEAT_QUICKFIX)
563 * In a quickfix window a <CR> jumps to the error under the
564 * cursor in a new window.
566 if (bt_quickfix(curbuf
))
568 sprintf((char *)cbuf
, "split +%ld%s",
569 (long)curwin
->w_cursor
.lnum
,
570 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
571 do_cmdline_cmd(cbuf
);
577 /* CTRL-W g extended commands */
581 #ifdef USE_ON_FLY_SCROLL
582 dont_scroll
= TRUE
; /* disallow scrolling here */
585 ++allow_keys
; /* no mapping for xchar, but allow key codes */
587 xchar
= safe_vgetc();
589 LANGMAP_ADJUST(xchar
, TRUE
);
593 #ifdef FEAT_CMDL_INFO
594 (void)add_to_showcmd(xchar
);
598 #if defined(FEAT_QUICKFIX)
602 g_do_tagpreview
= Prenum
;
604 g_do_tagpreview
= p_pvh
;
610 reset_VIsual_and_resel(); /* stop Visual mode */
613 postponed_split
= Prenum
;
615 postponed_split
= -1;
617 /* Execute the command right here, required when
618 * "wincmd g}" was used in a function. */
619 do_nv_ident('g', xchar
);
622 #ifdef FEAT_SEARCHPATH
623 case 'f': /* CTRL-W gf: "gf" in a new tab page */
624 case 'F': /* CTRL-W gF: "gF" in a new tab page */
635 default: beep_flush();
641 * split the current window, implements CTRL-W s and :split
643 * "size" is the height or width for the new window, 0 to use half of current
647 * WSP_ROOM: require enough room for new window
648 * WSP_VERT: vertical split.
649 * WSP_TOP: open window at the top-left of the shell (help window).
650 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
651 * WSP_HELP: creating the help window, keep layout snapshot
653 * return FAIL for failure, OK otherwise
656 win_split(size
, flags
)
660 /* When the ":tab" modifier was used open a new tab page instead. */
661 if (may_open_tabpage() == OK
)
664 /* Add flags from ":vertical", ":topleft" and ":botright". */
665 flags
|= cmdmod
.split
;
666 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
668 EMSG(_("E442: Can't split topleft and botright at the same time"));
672 /* When creating the help window make a snapshot of the window layout.
673 * Otherwise clear the snapshot, it's now invalid. */
674 if (flags
& WSP_HELP
)
677 clear_snapshot(curtab
);
679 return win_split_ins(size
, flags
, NULL
, 0);
683 * When "newwin" is NULL: split the current window in two.
684 * When "newwin" is not NULL: insert this window at the far
685 * top/left/right/bottom.
686 * return FAIL for failure, OK otherwise
689 win_split_ins(size
, flags
, newwin
, dir
)
700 int do_equal
= FALSE
;
703 int oldwin_height
= 0;
705 frame_T
*frp
, *curfrp
;
710 else if (flags
& WSP_BOT
)
715 /* add a status line when p_ls == 1 and splitting the first window */
716 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
718 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
723 need_status
= STATUS_HEIGHT
;
727 /* May be needed for the scrollbars that are going to change. */
732 #ifdef FEAT_VERTSPLIT
733 if (flags
& WSP_VERT
)
736 do_equal
= (p_ea
&& new_size
== 0 && *p_ead
!= 'v');
739 * Check if we are able to split the current window and compute its
743 if (flags
& WSP_ROOM
)
744 needed
+= p_wiw
- p_wmw
;
745 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
747 available
= topframe
->fr_width
;
748 needed
+= frame_minwidth(topframe
, NULL
);
751 available
= oldwin
->w_width
;
752 if (available
< needed
&& newwin
== NULL
)
758 new_size
= oldwin
->w_width
/ 2;
759 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
760 new_size
= oldwin
->w_width
- p_wmw
- 1;
761 if (new_size
< p_wmw
)
764 /* if it doesn't fit in the current window, need win_equal() */
765 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
768 /* We don't like to take lines for the new window from a
769 * 'winfixwidth' window. Take them from a window to the left or right
770 * instead, if possible. */
772 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
778 do_equal
= (p_ea
&& new_size
== 0
779 #ifdef FEAT_VERTSPLIT
785 * Check if we are able to split the current window and compute its
788 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
789 if (flags
& WSP_ROOM
)
790 needed
+= p_wh
- p_wmh
;
791 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
793 available
= topframe
->fr_height
;
794 needed
+= frame_minheight(topframe
, NULL
);
798 available
= oldwin
->w_height
;
801 if (available
< needed
&& newwin
== NULL
)
806 oldwin_height
= oldwin
->w_height
;
809 oldwin
->w_status_height
= STATUS_HEIGHT
;
810 oldwin_height
-= STATUS_HEIGHT
;
813 new_size
= oldwin_height
/ 2;
815 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
816 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
817 if (new_size
< p_wmh
)
820 /* if it doesn't fit in the current window, need win_equal() */
821 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
824 /* We don't like to take lines for the new window from a
825 * 'winfixheight' window. Take them from a window above or below
826 * instead, if possible. */
829 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
831 oldwin_height
= oldwin
->w_height
;
833 oldwin_height
-= STATUS_HEIGHT
;
838 * allocate new window structure and link it in the window list
840 if ((flags
& WSP_TOP
) == 0
841 && ((flags
& WSP_BOT
)
842 || (flags
& WSP_BELOW
)
843 || (!(flags
& WSP_ABOVE
)
845 #ifdef FEAT_VERTSPLIT
846 (flags
& WSP_VERT
) ? p_spr
:
850 /* new window below/right of current one */
852 wp
= win_alloc(oldwin
);
854 win_append(oldwin
, wp
);
859 wp
= win_alloc(oldwin
->w_prev
);
861 win_append(oldwin
->w_prev
, wp
);
869 /* make the contents of the new window the same as the current one */
870 win_init(wp
, curwin
);
874 * Reorganise the tree of frames to insert the new window.
876 if (flags
& (WSP_TOP
| WSP_BOT
))
878 #ifdef FEAT_VERTSPLIT
879 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
880 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
882 if (topframe
->fr_layout
== FR_COL
)
885 curfrp
= topframe
->fr_child
;
887 while (curfrp
->fr_next
!= NULL
)
888 curfrp
= curfrp
->fr_next
;
892 before
= (flags
& WSP_TOP
);
896 curfrp
= oldwin
->w_frame
;
897 if (flags
& WSP_BELOW
)
899 else if (flags
& WSP_ABOVE
)
902 #ifdef FEAT_VERTSPLIT
903 if (flags
& WSP_VERT
)
909 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
911 /* Need to create a new frame in the tree to make a branch. */
912 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
914 curfrp
->fr_layout
= layout
;
915 frp
->fr_parent
= curfrp
;
918 curfrp
->fr_child
= frp
;
919 curfrp
->fr_win
= NULL
;
921 if (frp
->fr_win
!= NULL
)
922 oldwin
->w_frame
= frp
;
924 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
925 frp
->fr_parent
= curfrp
;
930 /* Create a frame for the new window. */
931 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
932 frp
->fr_layout
= FR_LEAF
;
937 frp
= newwin
->w_frame
;
938 frp
->fr_parent
= curfrp
->fr_parent
;
940 /* Insert the new frame at the right place in the frame list. */
942 frame_insert(curfrp
, frp
);
944 frame_append(curfrp
, frp
);
946 #ifdef FEAT_VERTSPLIT
947 if (flags
& WSP_VERT
)
949 wp
->w_p_scr
= curwin
->w_p_scr
;
953 oldwin
->w_status_height
= need_status
;
955 if (flags
& (WSP_TOP
| WSP_BOT
))
957 /* set height and row of new window to full height */
958 wp
->w_winrow
= tabline_height();
959 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
960 wp
->w_status_height
= (p_ls
> 0);
964 /* height and row of new window is same as current window */
965 wp
->w_winrow
= oldwin
->w_winrow
;
966 wp
->w_height
= oldwin
->w_height
;
967 wp
->w_status_height
= oldwin
->w_status_height
;
969 frp
->fr_height
= curfrp
->fr_height
;
971 /* "new_size" of the current window goes to the new window, use
972 * one column for the vertical separator */
973 wp
->w_width
= new_size
;
975 wp
->w_vsep_width
= 1;
978 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
979 oldwin
->w_vsep_width
= 1;
981 if (flags
& (WSP_TOP
| WSP_BOT
))
984 frame_add_vsep(curfrp
);
985 /* Set width of neighbor frame */
986 frame_new_width(curfrp
, curfrp
->fr_width
987 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
991 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
992 if (before
) /* new window left of current one */
994 wp
->w_wincol
= oldwin
->w_wincol
;
995 oldwin
->w_wincol
+= new_size
+ 1;
997 else /* new window right of current one */
998 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
999 frame_fix_width(oldwin
);
1000 frame_fix_width(wp
);
1005 /* width and column of new window is same as current window */
1006 #ifdef FEAT_VERTSPLIT
1007 if (flags
& (WSP_TOP
| WSP_BOT
))
1010 wp
->w_width
= Columns
;
1011 wp
->w_vsep_width
= 0;
1015 wp
->w_wincol
= oldwin
->w_wincol
;
1016 wp
->w_width
= oldwin
->w_width
;
1017 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1019 frp
->fr_width
= curfrp
->fr_width
;
1022 /* "new_size" of the current window goes to the new window, use
1023 * one row for the status line */
1024 win_new_height(wp
, new_size
);
1025 if (flags
& (WSP_TOP
| WSP_BOT
))
1026 frame_new_height(curfrp
, curfrp
->fr_height
1027 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1029 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1030 if (before
) /* new window above current one */
1032 wp
->w_winrow
= oldwin
->w_winrow
;
1033 wp
->w_status_height
= STATUS_HEIGHT
;
1034 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1036 else /* new window below current one */
1038 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1039 wp
->w_status_height
= oldwin
->w_status_height
;
1040 oldwin
->w_status_height
= STATUS_HEIGHT
;
1042 #ifdef FEAT_VERTSPLIT
1043 if (flags
& WSP_BOT
)
1044 frame_add_statusline(curfrp
);
1046 frame_fix_height(wp
);
1047 frame_fix_height(oldwin
);
1050 if (flags
& (WSP_TOP
| WSP_BOT
))
1051 (void)win_comp_pos();
1054 * Both windows need redrawing
1056 redraw_win_later(wp
, NOT_VALID
);
1057 wp
->w_redr_status
= TRUE
;
1058 redraw_win_later(oldwin
, NOT_VALID
);
1059 oldwin
->w_redr_status
= TRUE
;
1065 msg_clr_eos_force(); /* Old command/ruler may still be there */
1068 msg_col
= 0; /* put position back at start of line */
1072 * make the new window the current window and redraw
1074 if (do_equal
|| dir
!= 0)
1076 #ifdef FEAT_VERTSPLIT
1077 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1078 : dir
== 'h' ? 'b' :
1082 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1083 * size was given. */
1084 #ifdef FEAT_VERTSPLIT
1085 if (flags
& WSP_VERT
)
1092 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1094 gui_init_which_components(NULL
);
1104 win_enter(wp
, FALSE
);
1105 #ifdef FEAT_VERTSPLIT
1106 if (flags
& WSP_VERT
)
1116 * Initialize window "newp" from window "oldp".
1117 * Used when splitting a window and when creating a new tab page.
1118 * The windows will both edit the same buffer.
1121 win_init(newp
, oldp
)
1127 newp
->w_buffer
= oldp
->w_buffer
;
1128 oldp
->w_buffer
->b_nwindows
++;
1129 newp
->w_cursor
= oldp
->w_cursor
;
1131 newp
->w_curswant
= oldp
->w_curswant
;
1132 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1133 newp
->w_topline
= oldp
->w_topline
;
1135 newp
->w_topfill
= oldp
->w_topfill
;
1137 newp
->w_leftcol
= oldp
->w_leftcol
;
1138 newp
->w_pcmark
= oldp
->w_pcmark
;
1139 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1140 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1141 newp
->w_wrow
= oldp
->w_wrow
;
1142 newp
->w_fraction
= oldp
->w_fraction
;
1143 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1144 #ifdef FEAT_JUMPLIST
1145 copy_jumplist(oldp
, newp
);
1147 #ifdef FEAT_QUICKFIX
1148 copy_loclist(oldp
, newp
);
1150 if (oldp
->w_localdir
!= NULL
)
1151 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1153 /* Use the same argument list. */
1154 newp
->w_alist
= oldp
->w_alist
;
1155 ++newp
->w_alist
->al_refcount
;
1156 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1159 * copy tagstack and options from existing window
1161 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1163 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1164 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1165 newp
->w_tagstack
[i
].tagname
=
1166 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1168 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1169 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1170 win_copy_options(oldp
, newp
);
1171 # ifdef FEAT_FOLDING
1172 copyFoldingState(oldp
, newp
);
1176 #endif /* FEAT_WINDOWS */
1178 #if defined(FEAT_WINDOWS) || defined(PROTO)
1180 * Check if "win" is a pointer to an existing window.
1190 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1197 * Return the number of windows.
1205 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1211 * Make "count" windows on the screen.
1212 * Return actual number of windows on the screen.
1213 * Must be called when there is just one window, filling the whole screen
1214 * (excluding the command line).
1218 make_windows(count
, vertical
)
1220 int vertical
; /* split windows vertically if TRUE */
1225 #ifdef FEAT_VERTSPLIT
1228 /* Each windows needs at least 'winminwidth' lines and a separator
1230 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1231 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1236 /* Each window needs at least 'winminheight' lines and a status line. */
1237 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1238 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1243 if (count
> maxcount
)
1247 * add status line now, otherwise first window will be too big
1254 * Don't execute autocommands while creating the windows. Must do that
1255 * when putting the buffers in the windows.
1260 /* todo is number of windows left to create */
1261 for (todo
= count
- 1; todo
> 0; --todo
)
1262 #ifdef FEAT_VERTSPLIT
1265 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1266 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1272 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1273 * STATUS_HEIGHT
) / (todo
+ 1)
1274 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1282 /* return actual number of windows */
1283 return (count
- todo
);
1287 * Exchange current and next window
1290 win_exchange(Prenum
)
1299 if (lastwin
== firstwin
) /* just one window */
1306 need_mouse_correct
= TRUE
;
1310 * find window to exchange with
1314 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1315 while (frp
!= NULL
&& --Prenum
> 0)
1318 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1319 frp
= curwin
->w_frame
->fr_next
;
1320 else /* Swap last window in row/col with previous */
1321 frp
= curwin
->w_frame
->fr_prev
;
1323 /* We can only exchange a window with another window, not with a frame
1324 * containing windows. */
1325 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1330 * 1. remove curwin from the list. Remember after which window it was in wp2
1331 * 2. insert curwin before wp in the list
1333 * 3. remove wp from the list
1334 * 4. insert wp after wp2
1335 * 5. exchange the status line height and vsep width.
1337 wp2
= curwin
->w_prev
;
1338 frp2
= curwin
->w_frame
->fr_prev
;
1339 if (wp
->w_prev
!= curwin
)
1341 win_remove(curwin
, NULL
);
1342 frame_remove(curwin
->w_frame
);
1343 win_append(wp
->w_prev
, curwin
);
1344 frame_insert(frp
, curwin
->w_frame
);
1348 win_remove(wp
, NULL
);
1349 frame_remove(wp
->w_frame
);
1350 win_append(wp2
, wp
);
1352 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1354 frame_append(frp2
, wp
->w_frame
);
1356 temp
= curwin
->w_status_height
;
1357 curwin
->w_status_height
= wp
->w_status_height
;
1358 wp
->w_status_height
= temp
;
1359 #ifdef FEAT_VERTSPLIT
1360 temp
= curwin
->w_vsep_width
;
1361 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1362 wp
->w_vsep_width
= temp
;
1364 /* If the windows are not in the same frame, exchange the sizes to avoid
1365 * messing up the window layout. Otherwise fix the frame sizes. */
1366 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1368 temp
= curwin
->w_height
;
1369 curwin
->w_height
= wp
->w_height
;
1370 wp
->w_height
= temp
;
1371 temp
= curwin
->w_width
;
1372 curwin
->w_width
= wp
->w_width
;
1377 frame_fix_height(curwin
);
1378 frame_fix_height(wp
);
1379 frame_fix_width(curwin
);
1380 frame_fix_width(wp
);
1384 (void)win_comp_pos(); /* recompute window positions */
1386 win_enter(wp
, TRUE
);
1387 redraw_later(CLEAR
);
1391 * rotate windows: if upwards TRUE the second window becomes the first one
1392 * if upwards FALSE the first window becomes the second one
1395 win_rotate(upwards
, count
)
1404 if (firstwin
== lastwin
) /* nothing to do */
1411 need_mouse_correct
= TRUE
;
1414 #ifdef FEAT_VERTSPLIT
1415 /* Check if all frames in this row/col have one window. */
1416 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1418 if (frp
->fr_win
== NULL
)
1420 EMSG(_("E443: Cannot rotate when another window is split"));
1427 if (upwards
) /* first window becomes last window */
1429 /* remove first window/frame from the list */
1430 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1432 win_remove(wp1
, NULL
);
1435 /* find last frame and append removed window/frame after it */
1436 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1438 win_append(frp
->fr_win
, wp1
);
1439 frame_append(frp
, wp1
->w_frame
);
1441 wp2
= frp
->fr_win
; /* previously last window */
1443 else /* last window becomes first window */
1445 /* find last window/frame in the list and remove it */
1446 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1450 wp2
= wp1
->w_prev
; /* will become last window */
1451 win_remove(wp1
, NULL
);
1454 /* append the removed window/frame before the first in the list */
1455 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1456 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1459 /* exchange status height and vsep width of old and new last window */
1460 n
= wp2
->w_status_height
;
1461 wp2
->w_status_height
= wp1
->w_status_height
;
1462 wp1
->w_status_height
= n
;
1463 frame_fix_height(wp1
);
1464 frame_fix_height(wp2
);
1465 #ifdef FEAT_VERTSPLIT
1466 n
= wp2
->w_vsep_width
;
1467 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1468 wp1
->w_vsep_width
= n
;
1469 frame_fix_width(wp1
);
1470 frame_fix_width(wp2
);
1473 /* recompute w_winrow and w_wincol for all windows */
1474 (void)win_comp_pos();
1477 redraw_later(CLEAR
);
1481 * Move the current window to the very top/bottom/left/right of the screen.
1484 win_totop(size
, flags
)
1489 int height
= curwin
->w_height
;
1491 if (lastwin
== firstwin
)
1497 /* Remove the window and frame from the tree of frames. */
1498 (void)winframe_remove(curwin
, &dir
, NULL
);
1499 win_remove(curwin
, NULL
);
1500 last_status(FALSE
); /* may need to remove last status line */
1501 (void)win_comp_pos(); /* recompute window positions */
1503 /* Split a window on the desired side and put the window there. */
1504 (void)win_split_ins(size
, flags
, curwin
, dir
);
1505 if (!(flags
& WSP_VERT
))
1507 win_setheight(height
);
1509 win_equal(curwin
, TRUE
, 'v');
1512 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1513 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1514 * scrollbars. Have to update them anyway. */
1518 gui_init_which_components(NULL
);
1519 gui_update_scrollbars(TRUE
);
1521 need_mouse_correct
= TRUE
;
1527 * Move window "win1" to below/right of "win2" and make "win1" the current
1528 * window. Only works within the same frame!
1531 win_move_after(win1
, win2
)
1536 /* check if the arguments are reasonable */
1540 /* check if there is something to do */
1541 if (win2
->w_next
!= win1
)
1543 /* may need move the status line/vertical separator of the last window
1545 if (win1
== lastwin
)
1547 height
= win1
->w_prev
->w_status_height
;
1548 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1549 win1
->w_status_height
= height
;
1550 #ifdef FEAT_VERTSPLIT
1551 if (win1
->w_prev
->w_vsep_width
== 1)
1553 /* Remove the vertical separator from the last-but-one window,
1554 * add it to the last window. Adjust the frame widths. */
1555 win1
->w_prev
->w_vsep_width
= 0;
1556 win1
->w_prev
->w_frame
->fr_width
-= 1;
1557 win1
->w_vsep_width
= 1;
1558 win1
->w_frame
->fr_width
+= 1;
1562 else if (win2
== lastwin
)
1564 height
= win1
->w_status_height
;
1565 win1
->w_status_height
= win2
->w_status_height
;
1566 win2
->w_status_height
= height
;
1567 #ifdef FEAT_VERTSPLIT
1568 if (win1
->w_vsep_width
== 1)
1570 /* Remove the vertical separator from win1, add it to the last
1571 * window, win2. Adjust the frame widths. */
1572 win2
->w_vsep_width
= 1;
1573 win2
->w_frame
->fr_width
+= 1;
1574 win1
->w_vsep_width
= 0;
1575 win1
->w_frame
->fr_width
-= 1;
1579 win_remove(win1
, NULL
);
1580 frame_remove(win1
->w_frame
);
1581 win_append(win2
, win1
);
1582 frame_append(win2
->w_frame
, win1
->w_frame
);
1584 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1585 redraw_later(NOT_VALID
);
1587 win_enter(win1
, FALSE
);
1591 * Make all windows the same height.
1592 * 'next_curwin' will soon be the current window, make sure it has enough
1596 win_equal(next_curwin
, current
, dir
)
1597 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1598 int current
; /* do only frame with current window */
1599 int dir
; /* 'v' for vertically, 'h' for horizontally,
1600 'b' for both, 0 for using p_ead */
1603 #ifdef FEAT_VERTSPLIT
1608 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1609 topframe
, dir
, 0, tabline_height(),
1610 (int)Columns
, topframe
->fr_height
);
1614 * Set a frame to a new position and height, spreading the available room
1615 * equally over contained frames.
1616 * The window "next_curwin" (if not NULL) should at least get the size from
1617 * 'winheight' and 'winwidth' if possible.
1620 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1621 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1622 int current
; /* do only frame with current window */
1623 frame_T
*topfr
; /* frame to set size off */
1624 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1625 int col
; /* horizontal position for frame */
1626 int row
; /* vertical position for frame */
1627 int width
; /* new width of frame */
1628 int height
; /* new height of frame */
1632 int wincount
, totwincount
= 0;
1634 int next_curwin_size
= 0;
1637 int has_next_curwin
= 0;
1640 if (topfr
->fr_layout
== FR_LEAF
)
1642 /* Set the width/height of this frame.
1643 * Redraw when size or position changes */
1644 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1645 #ifdef FEAT_VERTSPLIT
1646 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1650 topfr
->fr_win
->w_winrow
= row
;
1651 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1652 #ifdef FEAT_VERTSPLIT
1653 topfr
->fr_win
->w_wincol
= col
;
1654 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1656 redraw_all_later(CLEAR
);
1659 #ifdef FEAT_VERTSPLIT
1660 else if (topfr
->fr_layout
== FR_ROW
)
1662 topfr
->fr_width
= width
;
1663 topfr
->fr_height
= height
;
1665 if (dir
!= 'v') /* equalize frame widths */
1667 /* Compute the maximum number of windows horizontally in this
1669 n
= frame_minwidth(topfr
, NOWIN
);
1670 /* add one for the rightmost window, it doesn't have a separator */
1671 if (col
+ width
== Columns
)
1675 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1676 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1679 * Compute width for "next_curwin" window and room available for
1681 * "m" is the minimal width when counting p_wiw for "next_curwin".
1683 m
= frame_minwidth(topfr
, next_curwin
);
1687 next_curwin_size
= p_wiw
+ room
;
1692 next_curwin_size
= -1;
1693 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1695 /* If 'winfixwidth' set keep the window width if
1697 * Watch out for this window being the next_curwin. */
1698 if (frame_fixed_width(fr
))
1700 n
= frame_minwidth(fr
, NOWIN
);
1701 new_size
= fr
->fr_width
;
1702 if (frame_has_win(fr
, next_curwin
))
1704 room
+= p_wiw
- p_wmw
;
1705 next_curwin_size
= 0;
1706 if (new_size
< p_wiw
)
1710 /* These windows don't use up room. */
1711 totwincount
-= (n
+ (fr
->fr_next
== NULL
1712 ? extra_sep
: 0)) / (p_wmw
+ 1);
1713 room
-= new_size
- n
;
1719 fr
->fr_newwidth
= new_size
;
1722 if (next_curwin_size
== -1)
1724 if (!has_next_curwin
)
1725 next_curwin_size
= 0;
1726 else if (totwincount
> 1
1727 && (room
+ (totwincount
- 2))
1728 / (totwincount
- 1) > p_wiw
)
1730 /* Can make all windows wider than 'winwidth', spread
1731 * the room equally. */
1732 next_curwin_size
= (room
+ p_wiw
1733 + (totwincount
- 1) * p_wmw
1734 + (totwincount
- 1)) / totwincount
;
1735 room
-= next_curwin_size
- p_wiw
;
1738 next_curwin_size
= p_wiw
;
1742 if (has_next_curwin
)
1743 --totwincount
; /* don't count curwin */
1746 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1750 if (fr
->fr_next
== NULL
)
1751 /* last frame gets all that remains (avoid roundoff error) */
1753 else if (dir
== 'v')
1754 new_size
= fr
->fr_width
;
1755 else if (frame_fixed_width(fr
))
1757 new_size
= fr
->fr_newwidth
;
1758 wincount
= 0; /* doesn't count as a sizeable window */
1762 /* Compute the maximum number of windows horiz. in "fr". */
1763 n
= frame_minwidth(fr
, NOWIN
);
1764 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1766 m
= frame_minwidth(fr
, next_curwin
);
1767 if (has_next_curwin
)
1768 hnc
= frame_has_win(fr
, next_curwin
);
1771 if (hnc
) /* don't count next_curwin */
1773 if (totwincount
== 0)
1776 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1778 if (hnc
) /* add next_curwin size */
1780 next_curwin_size
-= p_wiw
- (m
- n
);
1781 new_size
+= next_curwin_size
;
1782 room
-= new_size
- next_curwin_size
;
1789 /* Skip frame that is full width when splitting or closing a
1790 * window, unless equalizing all frames. */
1791 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1792 || (new_size
!= fr
->fr_width
)
1793 || frame_has_win(fr
, next_curwin
))
1794 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1798 totwincount
-= wincount
;
1802 else /* topfr->fr_layout == FR_COL */
1804 #ifdef FEAT_VERTSPLIT
1805 topfr
->fr_width
= width
;
1807 topfr
->fr_height
= height
;
1809 if (dir
!= 'h') /* equalize frame heights */
1811 /* Compute maximum number of windows vertically in this frame. */
1812 n
= frame_minheight(topfr
, NOWIN
);
1813 /* add one for the bottom window if it doesn't have a statusline */
1814 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1818 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1819 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1822 * Compute height for "next_curwin" window and room available for
1824 * "m" is the minimal height when counting p_wh for "next_curwin".
1826 m
= frame_minheight(topfr
, next_curwin
);
1830 /* The room is less then 'winheight', use all space for the
1831 * current window. */
1832 next_curwin_size
= p_wh
+ room
;
1837 next_curwin_size
= -1;
1838 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1840 /* If 'winfixheight' set keep the window height if
1842 * Watch out for this window being the next_curwin. */
1843 if (frame_fixed_height(fr
))
1845 n
= frame_minheight(fr
, NOWIN
);
1846 new_size
= fr
->fr_height
;
1847 if (frame_has_win(fr
, next_curwin
))
1849 room
+= p_wh
- p_wmh
;
1850 next_curwin_size
= 0;
1851 if (new_size
< p_wh
)
1855 /* These windows don't use up room. */
1856 totwincount
-= (n
+ (fr
->fr_next
== NULL
1857 ? extra_sep
: 0)) / (p_wmh
+ 1);
1858 room
-= new_size
- n
;
1864 fr
->fr_newheight
= new_size
;
1867 if (next_curwin_size
== -1)
1869 if (!has_next_curwin
)
1870 next_curwin_size
= 0;
1871 else if (totwincount
> 1
1872 && (room
+ (totwincount
- 2))
1873 / (totwincount
- 1) > p_wh
)
1875 /* can make all windows higher than 'winheight',
1876 * spread the room equally. */
1877 next_curwin_size
= (room
+ p_wh
1878 + (totwincount
- 1) * p_wmh
1879 + (totwincount
- 1)) / totwincount
;
1880 room
-= next_curwin_size
- p_wh
;
1883 next_curwin_size
= p_wh
;
1887 if (has_next_curwin
)
1888 --totwincount
; /* don't count curwin */
1891 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1895 if (fr
->fr_next
== NULL
)
1896 /* last frame gets all that remains (avoid roundoff error) */
1898 else if (dir
== 'h')
1899 new_size
= fr
->fr_height
;
1900 else if (frame_fixed_height(fr
))
1902 new_size
= fr
->fr_newheight
;
1903 wincount
= 0; /* doesn't count as a sizeable window */
1907 /* Compute the maximum number of windows vert. in "fr". */
1908 n
= frame_minheight(fr
, NOWIN
);
1909 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1911 m
= frame_minheight(fr
, next_curwin
);
1912 if (has_next_curwin
)
1913 hnc
= frame_has_win(fr
, next_curwin
);
1916 if (hnc
) /* don't count next_curwin */
1918 if (totwincount
== 0)
1921 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1923 if (hnc
) /* add next_curwin size */
1925 next_curwin_size
-= p_wh
- (m
- n
);
1926 new_size
+= next_curwin_size
;
1927 room
-= new_size
- next_curwin_size
;
1933 /* Skip frame that is full width when splitting or closing a
1934 * window, unless equalizing all frames. */
1935 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1936 || (new_size
!= fr
->fr_height
)
1937 || frame_has_win(fr
, next_curwin
))
1938 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1942 totwincount
-= wincount
;
1948 * close all windows for buffer 'buf'
1951 close_windows(buf
, keep_curwin
)
1953 int keep_curwin
; /* don't close "curwin" */
1956 tabpage_T
*tp
, *nexttp
;
1957 int h
= tabline_height();
1959 ++RedrawingDisabled
;
1961 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
1963 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
1965 win_close(wp
, FALSE
);
1967 /* Start all over, autocommands may change the window layout. */
1974 /* Also check windows in other tab pages. */
1975 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
1977 nexttp
= tp
->tp_next
;
1979 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1980 if (wp
->w_buffer
== buf
)
1982 win_close_othertab(wp
, FALSE
, tp
);
1984 /* Start all over, the tab page may be closed and
1985 * autocommands may change the window layout. */
1986 nexttp
= first_tabpage
;
1991 --RedrawingDisabled
;
1993 if (h
!= tabline_height())
1998 * Return TRUE if the current window is the only window that exists.
1999 * Returns FALSE if there is a window, possibly in another tab page.
2004 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2008 * Close window "win". Only works for the current tab page.
2009 * If "free_buf" is TRUE related buffer may be unloaded.
2011 * called by :quit, :close, :xit, :wq and findtag()
2014 win_close(win
, free_buf
)
2020 int other_buffer
= FALSE
;
2022 int close_curwin
= FALSE
;
2024 int help_window
= FALSE
;
2025 tabpage_T
*prev_curtab
= curtab
;
2029 EMSG(_("E444: Cannot close last window"));
2034 * When closing the last window in a tab page first go to another tab
2035 * page and then close the window and the tab page. This avoids that
2036 * curwin and curtab are not invalid while we are freeing memory, they may
2037 * be used in GUI events.
2039 if (firstwin
== lastwin
)
2041 goto_tabpage_tp(alt_tabpage());
2042 redraw_tabline
= TRUE
;
2044 /* Safety check: Autocommands may have closed the window when jumping
2045 * to the other tab page. */
2046 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2048 int h
= tabline_height();
2050 win_close_othertab(win
, free_buf
, prev_curtab
);
2051 if (h
!= tabline_height())
2057 /* When closing the help window, try restoring a snapshot after closing
2058 * the window. Otherwise clear the snapshot, it's now invalid. */
2059 if (win
->w_buffer
->b_help
)
2062 clear_snapshot(curtab
);
2068 * Guess which window is going to be the new current window.
2069 * This may change because of the autocommands (sigh).
2071 wp
= frame2win(win_altframe(win
, NULL
));
2074 * Be careful: If autocommands delete the window, return now.
2076 if (wp
->w_buffer
!= curbuf
)
2078 other_buffer
= TRUE
;
2079 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2080 if (!win_valid(win
) || last_window())
2083 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2084 if (!win_valid(win
) || last_window())
2087 /* autocmds may abort script processing */
2095 /* Avoid trouble with scrollbars that are going to be deleted in
2102 * Close the link to the buffer.
2104 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2106 /* Autocommands may have closed the window already, or closed the only
2107 * other window or moved to another tab page. */
2108 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2111 /* Free the memory used for the window. */
2112 wp
= win_free_mem(win
, &dir
, NULL
);
2114 /* Make sure curwin isn't invalid. It can cause severe trouble when
2115 * printing an error message. For win_equal() curbuf needs to be valid
2120 #ifdef FEAT_QUICKFIX
2121 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2124 * If the cursor goes to the preview or the quickfix window, try
2125 * finding another window to go to.
2129 if (wp
->w_next
== NULL
)
2135 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2143 curbuf
= curwin
->w_buffer
;
2144 close_curwin
= TRUE
;
2147 #ifdef FEAT_VERTSPLIT
2148 && (*p_ead
== 'b' || *p_ead
== dir
)
2151 win_equal(curwin
, TRUE
,
2152 #ifdef FEAT_VERTSPLIT
2162 win_enter_ext(wp
, FALSE
, TRUE
);
2165 /* careful: after this wp and win may be invalid! */
2166 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2171 * If last window has a status line now and we don't want one,
2172 * remove the status line.
2176 /* After closing the help window, try restoring the window layout from
2177 * before it was opened. */
2179 restore_snapshot(close_curwin
);
2181 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2182 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2183 if (gui
.in_use
&& !win_hasvertsplit())
2184 gui_init_which_components(NULL
);
2187 redraw_all_later(NOT_VALID
);
2191 * Close window "win" in tab page "tp", which is not the current tab page.
2192 * This may be the last window ih that tab page and result in closing the tab,
2193 * thus "tp" may become invalid!
2194 * Caller must check if buffer is hidden and whether the tabline needs to be
2198 win_close_othertab(win
, free_buf
, tp
)
2205 tabpage_T
*ptp
= NULL
;
2207 /* Close the link to the buffer. */
2208 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2210 /* Careful: Autocommands may have closed the tab page or made it the
2211 * current tab page. */
2212 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2214 if (ptp
== NULL
|| tp
== curtab
)
2217 /* Autocommands may have closed the window already. */
2218 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2223 /* Free the memory used for the window. */
2224 wp
= win_free_mem(win
, &dir
, tp
);
2226 /* When closing the last window in a tab page remove the tab page. */
2229 if (tp
== first_tabpage
)
2230 first_tabpage
= tp
->tp_next
;
2233 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2238 EMSG2(_(e_intern2
), "win_close_othertab()");
2241 ptp
->tp_next
= tp
->tp_next
;
2248 * Free the memory used for a window.
2249 * Returns a pointer to the window that got the freed up space.
2252 win_free_mem(win
, dirp
, tp
)
2254 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2255 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2264 /* reduce the reference count to the argument list. */
2265 alist_unlink(win
->w_alist
);
2267 /* Remove the window and its frame from the tree of frames. */
2269 wp
= winframe_remove(win
, dirp
, tp
);
2273 /* When deleting the current window of another tab page select a new
2274 * current window. */
2275 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2281 #if defined(EXITFREE) || defined(PROTO)
2287 # ifdef FEAT_WINDOWS
2288 while (first_tabpage
->tp_next
!= NULL
)
2289 tabpage_close(TRUE
);
2292 while (firstwin
!= NULL
)
2293 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2298 * Remove a window and its frame from the tree of frames.
2299 * Returns a pointer to the window that got the freed up space.
2303 winframe_remove(win
, dirp
, tp
)
2305 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2306 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2308 frame_T
*frp
, *frp2
, *frp3
;
2309 frame_T
*frp_close
= win
->w_frame
;
2313 * If there is only one window there is nothing to remove.
2315 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2319 * Remove the window from its frame.
2321 frp2
= win_altframe(win
, tp
);
2322 wp
= frame2win(frp2
);
2324 /* Remove this frame from the list of frames. */
2325 frame_remove(frp_close
);
2327 #ifdef FEAT_VERTSPLIT
2328 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2331 /* When 'winfixheight' is set, try to find another frame in the column
2332 * (as close to the closed frame as possible) to distribute the height
2334 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2336 frp
= frp_close
->fr_prev
;
2337 frp3
= frp_close
->fr_next
;
2338 while (frp
!= NULL
|| frp3
!= NULL
)
2342 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2352 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2358 frp3
= frp3
->fr_next
;
2362 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2363 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2364 #ifdef FEAT_VERTSPLIT
2369 /* When 'winfixwidth' is set, try to find another frame in the column
2370 * (as close to the closed frame as possible) to distribute the width
2372 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2374 frp
= frp_close
->fr_prev
;
2375 frp3
= frp_close
->fr_next
;
2376 while (frp
!= NULL
|| frp3
!= NULL
)
2380 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2390 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2396 frp3
= frp3
->fr_next
;
2400 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2401 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2406 /* If rows/columns go to a window below/right its positions need to be
2407 * updated. Can only be done after the sizes have been updated. */
2408 if (frp2
== frp_close
->fr_next
)
2410 int row
= win
->w_winrow
;
2411 int col
= W_WINCOL(win
);
2413 frame_comp_pos(frp2
, &row
, &col
);
2416 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2418 /* There is no other frame in this list, move its info to the parent
2420 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2421 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2422 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2423 frp
->fr_parent
= frp2
->fr_parent
;
2424 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2425 if (frp2
->fr_win
!= NULL
)
2426 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2427 frp
= frp2
->fr_parent
;
2430 frp2
= frp
->fr_parent
;
2431 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2433 /* The frame above the parent has the same layout, have to merge
2434 * the frames into this list. */
2435 if (frp2
->fr_child
== frp
)
2436 frp2
->fr_child
= frp
->fr_child
;
2437 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2438 if (frp
->fr_prev
!= NULL
)
2439 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2440 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2442 frp3
->fr_parent
= frp2
;
2443 if (frp3
->fr_next
== NULL
)
2445 frp3
->fr_next
= frp
->fr_next
;
2446 if (frp
->fr_next
!= NULL
)
2447 frp
->fr_next
->fr_prev
= frp3
;
2459 * Find out which frame is going to get the freed up space when "win" is
2461 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2462 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2463 * This makes opening a window and closing it immediately keep the same window
2467 win_altframe(win
, tp
)
2469 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2474 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2475 /* Last window in this tab page, will go to next tab page. */
2476 return alt_tabpage()->tp_curwin
->w_frame
;
2479 #ifdef FEAT_VERTSPLIT
2480 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2485 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2486 return frp
->fr_next
;
2487 return frp
->fr_prev
;
2491 * Return the tabpage that will be used if the current one is closed.
2498 /* Use the next tab page if possible. */
2499 if (curtab
->tp_next
!= NULL
)
2500 return curtab
->tp_next
;
2502 /* Find the last but one tab page. */
2503 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2509 * Find the left-upper window in frame "frp".
2515 while (frp
->fr_win
== NULL
)
2516 frp
= frp
->fr_child
;
2521 * Return TRUE if frame "frp" contains window "wp".
2524 frame_has_win(frp
, wp
)
2530 if (frp
->fr_layout
== FR_LEAF
)
2531 return frp
->fr_win
== wp
;
2533 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2534 if (frame_has_win(p
, wp
))
2540 * Set a new height for a frame. Recursively sets the height for contained
2541 * frames and windows. Caller must take care of positions.
2544 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2547 int topfirst
; /* resize topmost contained frame first */
2548 int wfh
; /* obey 'winfixheight' when there is a choice;
2549 may cause the height not to be set */
2555 if (topfrp
->fr_win
!= NULL
)
2557 /* Simple case: just one window. */
2558 win_new_height(topfrp
->fr_win
,
2559 height
- topfrp
->fr_win
->w_status_height
);
2561 #ifdef FEAT_VERTSPLIT
2562 else if (topfrp
->fr_layout
== FR_ROW
)
2566 /* All frames in this row get the same new height. */
2567 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2569 frame_new_height(frp
, height
, topfirst
, wfh
);
2570 if (frp
->fr_height
> height
)
2572 /* Could not fit the windows, make the whole row higher. */
2573 height
= frp
->fr_height
;
2578 while (frp
!= NULL
);
2581 else /* fr_layout == FR_COL */
2583 /* Complicated case: Resize a column of frames. Resize the bottom
2584 * frame first, frames above that when needed. */
2586 frp
= topfrp
->fr_child
;
2588 /* Advance past frames with one window with 'wfh' set. */
2589 while (frame_fixed_height(frp
))
2593 return; /* no frame without 'wfh', give up */
2597 /* Find the bottom frame of this column */
2598 while (frp
->fr_next
!= NULL
)
2601 /* Advance back for frames with one window with 'wfh' set. */
2602 while (frame_fixed_height(frp
))
2606 extra_lines
= height
- topfrp
->fr_height
;
2607 if (extra_lines
< 0)
2609 /* reduce height of contained frames, bottom or top frame first */
2612 h
= frame_minheight(frp
, NULL
);
2613 if (frp
->fr_height
+ extra_lines
< h
)
2615 extra_lines
+= frp
->fr_height
- h
;
2616 frame_new_height(frp
, h
, topfirst
, wfh
);
2620 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2628 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2634 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2636 /* Increase "height" if we could not reduce enough frames. */
2638 height
-= extra_lines
;
2641 else if (extra_lines
> 0)
2643 /* increase height of bottom or top frame */
2644 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2647 topfrp
->fr_height
= height
;
2651 * Return TRUE if height of frame "frp" should not be changed because of
2652 * the 'winfixheight' option.
2655 frame_fixed_height(frp
)
2658 /* frame with one window: fixed height if 'winfixheight' set. */
2659 if (frp
->fr_win
!= NULL
)
2660 return frp
->fr_win
->w_p_wfh
;
2662 if (frp
->fr_layout
== FR_ROW
)
2664 /* The frame is fixed height if one of the frames in the row is fixed
2666 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2667 if (frame_fixed_height(frp
))
2672 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2673 * frames in the row are fixed height. */
2674 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2675 if (!frame_fixed_height(frp
))
2680 #ifdef FEAT_VERTSPLIT
2682 * Return TRUE if width of frame "frp" should not be changed because of
2683 * the 'winfixwidth' option.
2686 frame_fixed_width(frp
)
2689 /* frame with one window: fixed width if 'winfixwidth' set. */
2690 if (frp
->fr_win
!= NULL
)
2691 return frp
->fr_win
->w_p_wfw
;
2693 if (frp
->fr_layout
== FR_COL
)
2695 /* The frame is fixed width if one of the frames in the row is fixed
2697 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2698 if (frame_fixed_width(frp
))
2703 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2704 * frames in the row are fixed width. */
2705 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2706 if (!frame_fixed_width(frp
))
2712 * Add a status line to windows at the bottom of "frp".
2713 * Note: Does not check if there is room!
2716 frame_add_statusline(frp
)
2721 if (frp
->fr_layout
== FR_LEAF
)
2724 if (wp
->w_status_height
== 0)
2726 if (wp
->w_height
> 0) /* don't make it negative */
2728 wp
->w_status_height
= STATUS_HEIGHT
;
2731 else if (frp
->fr_layout
== FR_ROW
)
2733 /* Handle all the frames in the row. */
2734 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2735 frame_add_statusline(frp
);
2737 else /* frp->fr_layout == FR_COL */
2739 /* Only need to handle the last frame in the column. */
2740 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2742 frame_add_statusline(frp
);
2747 * Set width of a frame. Handles recursively going through contained frames.
2748 * May remove separator line for windows at the right side (for win_close()).
2751 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2754 int leftfirst
; /* resize leftmost contained frame first */
2755 int wfw
; /* obey 'winfixwidth' when there is a choice;
2756 may cause the width not to be set */
2763 if (topfrp
->fr_layout
== FR_LEAF
)
2765 /* Simple case: just one window. */
2766 wp
= topfrp
->fr_win
;
2767 /* Find out if there are any windows right of this one. */
2768 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2769 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2771 if (frp
->fr_parent
== NULL
)
2772 wp
->w_vsep_width
= 0;
2773 win_new_width(wp
, width
- wp
->w_vsep_width
);
2775 else if (topfrp
->fr_layout
== FR_COL
)
2779 /* All frames in this column get the same new width. */
2780 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2782 frame_new_width(frp
, width
, leftfirst
, wfw
);
2783 if (frp
->fr_width
> width
)
2785 /* Could not fit the windows, make whole column wider. */
2786 width
= frp
->fr_width
;
2790 } while (frp
!= NULL
);
2792 else /* fr_layout == FR_ROW */
2794 /* Complicated case: Resize a row of frames. Resize the rightmost
2795 * frame first, frames left of it when needed. */
2797 frp
= topfrp
->fr_child
;
2799 /* Advance past frames with one window with 'wfw' set. */
2800 while (frame_fixed_width(frp
))
2804 return; /* no frame without 'wfw', give up */
2808 /* Find the rightmost frame of this row */
2809 while (frp
->fr_next
!= NULL
)
2812 /* Advance back for frames with one window with 'wfw' set. */
2813 while (frame_fixed_width(frp
))
2817 extra_cols
= width
- topfrp
->fr_width
;
2820 /* reduce frame width, rightmost frame first */
2823 w
= frame_minwidth(frp
, NULL
);
2824 if (frp
->fr_width
+ extra_cols
< w
)
2826 extra_cols
+= frp
->fr_width
- w
;
2827 frame_new_width(frp
, w
, leftfirst
, wfw
);
2831 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2839 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2845 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2847 /* Increase "width" if we could not reduce enough frames. */
2849 width
-= extra_cols
;
2852 else if (extra_cols
> 0)
2854 /* increase width of rightmost frame */
2855 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2858 topfrp
->fr_width
= width
;
2862 * Add the vertical separator to windows at the right side of "frp".
2863 * Note: Does not check if there is room!
2871 if (frp
->fr_layout
== FR_LEAF
)
2874 if (wp
->w_vsep_width
== 0)
2876 if (wp
->w_width
> 0) /* don't make it negative */
2878 wp
->w_vsep_width
= 1;
2881 else if (frp
->fr_layout
== FR_COL
)
2883 /* Handle all the frames in the column. */
2884 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2885 frame_add_vsep(frp
);
2887 else /* frp->fr_layout == FR_ROW */
2889 /* Only need to handle the last frame in the row. */
2890 frp
= frp
->fr_child
;
2891 while (frp
->fr_next
!= NULL
)
2893 frame_add_vsep(frp
);
2898 * Set frame width from the window it contains.
2904 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2909 * Set frame height from the window it contains.
2912 frame_fix_height(wp
)
2915 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2919 * Compute the minimal height for frame "topfrp".
2920 * Uses the 'winminheight' option.
2921 * When "next_curwin" isn't NULL, use p_wh for this window.
2922 * When "next_curwin" is NOWIN, don't use at least one line for the current
2926 frame_minheight(topfrp
, next_curwin
)
2932 #ifdef FEAT_VERTSPLIT
2936 if (topfrp
->fr_win
!= NULL
)
2938 if (topfrp
->fr_win
== next_curwin
)
2939 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2942 /* window: minimal height of the window plus status line */
2943 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2944 /* Current window is minimal one line high */
2945 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2949 #ifdef FEAT_VERTSPLIT
2950 else if (topfrp
->fr_layout
== FR_ROW
)
2952 /* get the minimal height from each frame in this row */
2954 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2956 n
= frame_minheight(frp
, next_curwin
);
2964 /* Add up the minimal heights for all frames in this column. */
2966 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2967 m
+= frame_minheight(frp
, next_curwin
);
2973 #ifdef FEAT_VERTSPLIT
2975 * Compute the minimal width for frame "topfrp".
2976 * When "next_curwin" isn't NULL, use p_wiw for this window.
2977 * When "next_curwin" is NOWIN, don't use at least one column for the current
2981 frame_minwidth(topfrp
, next_curwin
)
2983 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
2988 if (topfrp
->fr_win
!= NULL
)
2990 if (topfrp
->fr_win
== next_curwin
)
2991 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
2994 /* window: minimal width of the window plus separator column */
2995 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
2996 /* Current window is minimal one column wide */
2997 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3001 else if (topfrp
->fr_layout
== FR_COL
)
3003 /* get the minimal width from each frame in this column */
3005 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3007 n
= frame_minwidth(frp
, next_curwin
);
3014 /* Add up the minimal widths for all frames in this row. */
3016 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3017 m
+= frame_minwidth(frp
, next_curwin
);
3026 * Try to close all windows except current one.
3027 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3028 * used and the buffer was modified.
3030 * Used by ":bdel" and ":only".
3033 close_others(message
, forceit
)
3035 int forceit
; /* always hide all other windows */
3041 if (lastwin
== firstwin
)
3052 /* Be very careful here: autocommands may change the window layout. */
3053 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3055 nextwp
= wp
->w_next
;
3056 if (wp
!= curwin
) /* don't close current window */
3059 /* Check if it's allowed to abandon this window */
3060 r
= can_abandon(wp
->w_buffer
, forceit
);
3062 if (!win_valid(wp
)) /* autocommands messed wp up */
3070 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3071 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3073 dialog_changed(wp
->w_buffer
, FALSE
);
3074 # ifdef FEAT_AUTOCMD
3075 if (!win_valid(wp
)) /* autocommands messed wp up */
3082 if (bufIsChanged(wp
->w_buffer
))
3086 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3090 if (message
&& lastwin
!= firstwin
)
3091 EMSG(_("E445: Other window contains changes"));
3094 #endif /* FEAT_WINDOWS */
3097 * Init the current window "curwin".
3098 * Called when a new file is being edited.
3103 redraw_win_later(curwin
, NOT_VALID
);
3104 curwin
->w_lines_valid
= 0;
3105 curwin
->w_cursor
.lnum
= 1;
3106 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3107 #ifdef FEAT_VIRTUALEDIT
3108 curwin
->w_cursor
.coladd
= 0;
3110 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3111 curwin
->w_pcmark
.col
= 0;
3112 curwin
->w_prev_pcmark
.lnum
= 0;
3113 curwin
->w_prev_pcmark
.col
= 0;
3114 curwin
->w_topline
= 1;
3116 curwin
->w_topfill
= 0;
3118 curwin
->w_botline
= 2;
3121 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3123 curwin
->w_farsi
= W_CONV
;
3128 * Allocate the first window and put an empty buffer in it.
3129 * Called from main().
3130 * Return FAIL when something goes wrong (out of memory).
3135 if (win_alloc_firstwin(NULL
) == FAIL
)
3139 first_tabpage
= alloc_tabpage();
3140 if (first_tabpage
== NULL
)
3142 first_tabpage
->tp_topframe
= topframe
;
3143 curtab
= first_tabpage
;
3149 * Allocate the first window or the first window in a new tab page.
3150 * When "oldwin" is NULL create an empty buffer for it.
3151 * When "oldwin" is not NULL copy info from it to the new window (only with
3153 * Return FAIL when something goes wrong (out of memory).
3156 win_alloc_firstwin(oldwin
)
3159 curwin
= win_alloc(NULL
);
3162 /* Very first window, need to create an empty buffer for it and
3163 * initialize from scratch. */
3164 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3165 if (curwin
== NULL
|| curbuf
== NULL
)
3167 curwin
->w_buffer
= curbuf
;
3168 curbuf
->b_nwindows
= 1; /* there is one window */
3170 curwin
->w_alist
= &global_alist
;
3172 curwin_init(); /* init current window */
3177 /* First window in new tab page, initialize it from "oldwin". */
3178 win_init(curwin
, oldwin
);
3180 # ifdef FEAT_SCROLLBIND
3181 /* We don't want scroll-binding in the first window. */
3182 curwin
->w_p_scb
= FALSE
;
3187 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3188 if (topframe
== NULL
)
3190 topframe
->fr_layout
= FR_LEAF
;
3191 #ifdef FEAT_VERTSPLIT
3192 topframe
->fr_width
= Columns
;
3194 topframe
->fr_height
= Rows
- p_ch
;
3195 topframe
->fr_win
= curwin
;
3196 curwin
->w_frame
= topframe
;
3202 * Initialize the window and frame size to the maximum.
3207 firstwin
->w_height
= ROWS_AVAIL
;
3208 topframe
->fr_height
= ROWS_AVAIL
;
3209 #ifdef FEAT_VERTSPLIT
3210 firstwin
->w_width
= Columns
;
3211 topframe
->fr_width
= Columns
;
3215 #if defined(FEAT_WINDOWS) || defined(PROTO)
3218 * Allocate a new tabpage_T and init the values.
3219 * Returns NULL when out of memory.
3226 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3232 for (i
= 0; i
< 3; i
++)
3233 tp
->tp_prev_which_scrollbars
[i
] = -1;
3236 tp
->tp_diff_invalid
= TRUE
;
3239 /* init t: variables */
3240 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3242 tp
->tp_ch_used
= p_ch
;
3256 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3262 * Create a new Tab page with one window.
3263 * It will edit the current buffer, like after ":split".
3264 * When "after" is 0 put it just after the current Tab page.
3265 * Otherwise put it just before tab page "after".
3266 * Return FAIL or OK.
3269 win_new_tabpage(after
)
3272 tabpage_T
*tp
= curtab
;
3276 newtp
= alloc_tabpage();
3280 /* Remember the current windows in this Tab page. */
3281 if (leave_tabpage(curbuf
) == FAIL
)
3288 /* Create a new empty window. */
3289 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3291 /* Make the new Tab page the new topframe. */
3294 /* New tab page becomes the first one. */
3295 newtp
->tp_next
= first_tabpage
;
3296 first_tabpage
= newtp
;
3302 /* Put new tab page before tab page "after". */
3304 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3305 && n
< after
; tp
= tp
->tp_next
)
3308 newtp
->tp_next
= tp
->tp_next
;
3309 tp
->tp_next
= newtp
;
3312 firstwin
->w_winrow
= tabline_height();
3313 win_comp_scroll(curwin
);
3315 newtp
->tp_topframe
= topframe
;
3318 #if defined(FEAT_GUI)
3319 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3320 * scrollbars. Have to update them anyway. */
3321 if (gui
.in_use
&& starting
== 0)
3323 gui_init_which_components(NULL
);
3324 gui_update_scrollbars(TRUE
);
3326 need_mouse_correct
= TRUE
;
3329 redraw_all_later(CLEAR
);
3331 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3332 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3337 /* Failed, get back the previous Tab page */
3338 enter_tabpage(curtab
, curbuf
);
3343 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3344 * like with ":split".
3345 * Returns OK if a new tab page was created, FAIL otherwise.
3350 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3354 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3355 postponed_split_tab
= 0;
3356 return win_new_tabpage(n
);
3362 * Create up to "maxcount" tabpages with empty windows.
3363 * Returns the number of resulting tab pages.
3366 make_tabpages(maxcount
)
3369 int count
= maxcount
;
3372 /* Limit to 'tabpagemax' tabs. */
3378 * Don't execute autocommands while creating the tab pages. Must do that
3379 * when putting the buffers in the windows.
3384 for (todo
= count
- 1; todo
> 0; --todo
)
3385 if (win_new_tabpage(0) == FAIL
)
3392 /* return actual number of tab pages */
3393 return (count
- todo
);
3397 * Return TRUE when "tpc" points to a valid tab page.
3405 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3412 * Find tab page "n" (first one is 1). Returns NULL when not found.
3421 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3427 * Get index of tab page "tp". First one has index 1.
3428 * When not found returns number of tab pages plus one.
3437 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3443 * Prepare for leaving the current tab page.
3444 * When autocomands change "curtab" we don't leave the tab page and return
3446 * Careful: When OK is returned need to get a new tab page very very soon!
3450 leave_tabpage(new_curbuf
)
3451 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3454 tabpage_T
*tp
= curtab
;
3457 reset_VIsual_and_resel(); /* stop Visual mode */
3460 if (new_curbuf
!= curbuf
)
3462 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3466 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3469 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3473 #if defined(FEAT_GUI)
3474 /* Remove the scrollbars. They may be added back later. */
3476 gui_remove_scrollbars();
3478 tp
->tp_curwin
= curwin
;
3479 tp
->tp_prevwin
= prevwin
;
3480 tp
->tp_firstwin
= firstwin
;
3481 tp
->tp_lastwin
= lastwin
;
3482 tp
->tp_old_Rows
= Rows
;
3483 tp
->tp_old_Columns
= Columns
;
3490 * Start using tab page "tp".
3491 * Only to be used after leave_tabpage() or freeing the current tab page.
3495 enter_tabpage(tp
, old_curbuf
)
3499 int old_off
= tp
->tp_firstwin
->w_winrow
;
3500 win_T
*next_prevwin
= tp
->tp_prevwin
;
3503 firstwin
= tp
->tp_firstwin
;
3504 lastwin
= tp
->tp_lastwin
;
3505 topframe
= tp
->tp_topframe
;
3507 /* We would like doing the TabEnter event first, but we don't have a
3508 * valid current window yet, which may break some commands.
3509 * This triggers autocommands, thus may make "tp" invalid. */
3510 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3511 prevwin
= next_prevwin
;
3514 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3516 if (old_curbuf
!= curbuf
)
3517 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3520 last_status(FALSE
); /* status line may appear or disappear */
3521 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3522 must_redraw
= CLEAR
; /* need to redraw everything */
3524 diff_need_scrollbind
= TRUE
;
3527 /* The tabpage line may have appeared or disappeared, may need to resize
3528 * the frames for that. When the Vim window was resized need to update
3529 * frame sizes too. Use the stored value of p_ch, so that it can be
3530 * different for each tab page. */
3531 p_ch
= curtab
->tp_ch_used
;
3532 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3533 #ifdef FEAT_GUI_TABLINE
3534 && !gui_use_tabline()
3538 #ifdef FEAT_VERTSPLIT
3539 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3540 shell_new_columns(); /* update window widths */
3543 #if defined(FEAT_GUI)
3544 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3545 * scrollbars. Have to update them anyway. */
3546 if (gui
.in_use
&& starting
== 0)
3548 gui_init_which_components(NULL
);
3549 gui_update_scrollbars(TRUE
);
3551 need_mouse_correct
= TRUE
;
3554 redraw_all_later(CLEAR
);
3558 * Go to tab page "n". For ":tab N" and "Ngt".
3559 * When "n" is 9999 go to the last tab page.
3571 /* Not allowed when editing the command line. */
3573 if (cmdwin_type
!= 0)
3581 /* If there is only one it can't work. */
3582 if (first_tabpage
->tp_next
== NULL
)
3591 /* No count, go to next tab page, wrap around end. */
3592 if (curtab
->tp_next
== NULL
)
3595 tp
= curtab
->tp_next
;
3599 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3602 for (i
= n
; i
< 0; ++i
)
3604 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3612 /* Go to last tab page. */
3613 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3618 /* Go to tab page "n". */
3619 tp
= find_tabpage(n
);
3627 goto_tabpage_tp(tp
);
3629 #ifdef FEAT_GUI_TABLINE
3630 if (gui_use_tabline())
3631 gui_mch_set_curtab(tabpage_index(curtab
));
3636 * Go to tabpage "tp".
3637 * Note: doesn't update the GUI tab.
3643 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3645 if (valid_tabpage(tp
))
3646 enter_tabpage(tp
, curbuf
);
3648 enter_tabpage(curtab
, curbuf
);
3653 * Enter window "wp" in tab page "tp".
3654 * Also updates the GUI tab.
3657 goto_tabpage_win(tp
, wp
)
3661 goto_tabpage_tp(tp
);
3662 if (curtab
== tp
&& win_valid(wp
))
3664 win_enter(wp
, TRUE
);
3665 # ifdef FEAT_GUI_TABLINE
3666 if (gui_use_tabline())
3667 gui_mch_set_curtab(tabpage_index(curtab
));
3673 * Move the current tab page to before tab page "nr".
3682 if (first_tabpage
->tp_next
== NULL
)
3685 /* Remove the current tab page from the list of tab pages. */
3686 if (curtab
== first_tabpage
)
3687 first_tabpage
= curtab
->tp_next
;
3690 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3691 if (tp
->tp_next
== curtab
)
3693 if (tp
== NULL
) /* "cannot happen" */
3695 tp
->tp_next
= curtab
->tp_next
;
3698 /* Re-insert it at the specified position. */
3701 curtab
->tp_next
= first_tabpage
;
3702 first_tabpage
= curtab
;
3706 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3708 curtab
->tp_next
= tp
->tp_next
;
3709 tp
->tp_next
= curtab
;
3712 /* Need to redraw the tabline. Tab page contents doesn't change. */
3713 redraw_tabline
= TRUE
;
3718 * Go to another window.
3719 * When jumping to another buffer, stop Visual mode. Do this before
3720 * changing windows so we can yank the selection into the '*' register.
3721 * When jumping to another window on the same buffer, adjust its cursor
3722 * position to keep the same Visual area.
3735 if (curbuf_locked())
3740 if (wp
->w_buffer
!= curbuf
)
3741 reset_VIsual_and_resel();
3742 else if (VIsual_active
)
3743 wp
->w_cursor
= curwin
->w_cursor
;
3747 need_mouse_correct
= TRUE
;
3749 win_enter(wp
, TRUE
);
3752 #if defined(FEAT_PERL) || defined(PROTO)
3754 * Find window number "winnr" (counting top to bottom).
3762 # ifdef FEAT_WINDOWS
3763 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3773 #ifdef FEAT_VERTSPLIT
3775 * Move to window above or below "count" times.
3778 win_goto_ver(up
, count
)
3779 int up
; /* TRUE to go to win above */
3786 foundfr
= curwin
->w_frame
;
3790 * First go upwards in the tree of frames until we find a upwards or
3791 * downwards neighbor.
3802 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3808 * Now go downwards to find the bottom or top frame in it.
3812 if (nfr
->fr_layout
== FR_LEAF
)
3818 if (nfr
->fr_layout
== FR_ROW
)
3820 /* Find the frame at the cursor row. */
3821 while (fr
->fr_next
!= NULL
3822 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3823 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3826 if (nfr
->fr_layout
== FR_COL
&& up
)
3827 while (fr
->fr_next
!= NULL
)
3833 if (foundfr
!= NULL
)
3834 win_goto(foundfr
->fr_win
);
3838 * Move to left or right window.
3841 win_goto_hor(left
, count
)
3842 int left
; /* TRUE to go to left win */
3849 foundfr
= curwin
->w_frame
;
3853 * First go upwards in the tree of frames until we find a left or
3865 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3871 * Now go downwards to find the leftmost or rightmost frame in it.
3875 if (nfr
->fr_layout
== FR_LEAF
)
3881 if (nfr
->fr_layout
== FR_COL
)
3883 /* Find the frame at the cursor row. */
3884 while (fr
->fr_next
!= NULL
3885 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3886 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3889 if (nfr
->fr_layout
== FR_ROW
&& left
)
3890 while (fr
->fr_next
!= NULL
)
3896 if (foundfr
!= NULL
)
3897 win_goto(foundfr
->fr_win
);
3902 * Make window "wp" the current window.
3905 win_enter(wp
, undo_sync
)
3909 win_enter_ext(wp
, undo_sync
, FALSE
);
3913 * Make window wp the current window.
3914 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3915 * been closed and isn't valid.
3918 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3924 int other_buffer
= FALSE
;
3927 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3931 if (!curwin_invalid
)
3934 * Be careful: If autocommands delete the window, return now.
3936 if (wp
->w_buffer
!= curbuf
)
3938 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3939 other_buffer
= TRUE
;
3943 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3947 /* autocmds may abort script processing */
3954 /* sync undo before leaving the current buffer */
3955 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
3957 /* may have to copy the buffer options when 'cpo' contains 'S' */
3958 if (wp
->w_buffer
!= curbuf
)
3959 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
3960 if (!curwin_invalid
)
3962 prevwin
= curwin
; /* remember for CTRL-W p */
3963 curwin
->w_redr_status
= TRUE
;
3966 curbuf
= wp
->w_buffer
;
3968 #ifdef FEAT_VIRTUALEDIT
3969 if (!virtual_active())
3970 curwin
->w_cursor
.coladd
= 0;
3972 changed_line_abv_curs(); /* assume cursor position needs updating */
3974 if (curwin
->w_localdir
!= NULL
)
3976 /* Window has a local directory: Save current directory as global
3977 * directory (unless that was done already) and change to the local
3979 if (globaldir
== NULL
)
3981 char_u cwd
[MAXPATHL
];
3983 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
3984 globaldir
= vim_strsave(cwd
);
3986 mch_chdir((char *)curwin
->w_localdir
);
3987 shorten_fnames(TRUE
);
3989 else if (globaldir
!= NULL
)
3991 /* Window doesn't have a local directory and we are not in the global
3992 * directory: Change to the global directory. */
3993 mch_chdir((char *)globaldir
);
3994 vim_free(globaldir
);
3996 shorten_fnames(TRUE
);
4000 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4002 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4008 curwin
->w_redr_status
= TRUE
;
4009 redraw_tabline
= TRUE
;
4011 redraw_later(VALID
); /* causes status line redraw */
4013 /* set window height to desired minimal value */
4014 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4015 win_setheight((int)p_wh
);
4016 else if (curwin
->w_height
== 0)
4019 #ifdef FEAT_VERTSPLIT
4020 /* set window width to desired minimal value */
4021 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4022 win_setwidth((int)p_wiw
);
4026 setmouse(); /* in case jumped to/from help buffer */
4029 /* Change directories when the 'acd' option is set. */
4033 #endif /* FEAT_WINDOWS */
4035 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4037 * Jump to the first open window that contains buffer "buf", if one exists.
4038 * Returns a pointer to the window found, otherwise NULL.
4041 buf_jump_open_win(buf
)
4044 # ifdef FEAT_WINDOWS
4047 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4048 if (wp
->w_buffer
== buf
)
4051 win_enter(wp
, FALSE
);
4054 if (curwin
->w_buffer
== buf
)
4061 * Jump to the first open window in any tab page that contains buffer "buf",
4063 * Returns a pointer to the window found, otherwise NULL.
4066 buf_jump_open_tab(buf
)
4069 # ifdef FEAT_WINDOWS
4073 /* First try the current tab page. */
4074 wp
= buf_jump_open_win(buf
);
4078 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4081 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4082 if (wp
->w_buffer
== buf
)
4086 goto_tabpage_win(tp
, wp
);
4088 wp
= NULL
; /* something went wrong */
4095 if (curwin
->w_buffer
== buf
)
4103 * allocate a window structure and link it in the window list
4113 * allocate window structure and linesizes arrays
4115 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4116 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4125 /* Don't execute autocommands while the window is not properly
4126 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4131 * link the window in the window list
4134 win_append(after
, newwin
);
4136 #ifdef FEAT_VERTSPLIT
4137 newwin
->w_wincol
= 0;
4138 newwin
->w_width
= Columns
;
4141 /* position the display and the cursor at the top of the file. */
4142 newwin
->w_topline
= 1;
4144 newwin
->w_topfill
= 0;
4146 newwin
->w_botline
= 2;
4147 newwin
->w_cursor
.lnum
= 1;
4148 #ifdef FEAT_SCROLLBIND
4149 newwin
->w_scbind_pos
= 1;
4152 /* We won't calculate w_fraction until resizing the window */
4153 newwin
->w_fraction
= 0;
4154 newwin
->w_prev_fraction_row
= -1;
4159 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4161 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4162 SBAR_RIGHT
, newwin
);
4166 /* init w: variables */
4167 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4170 foldInitWin(newwin
);
4175 #ifdef FEAT_SEARCH_EXTRA
4176 newwin
->w_match_head
= NULL
;
4177 newwin
->w_next_match_id
= 4;
4183 #if defined(FEAT_WINDOWS) || defined(PROTO)
4186 * remove window 'wp' from the window list and free the structure
4191 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4196 /* Don't execute autocommands while the window is halfway being deleted.
4197 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4201 #ifdef FEAT_MZSCHEME
4202 mzscheme_window_free(wp
);
4210 python_window_free(wp
);
4214 tcl_window_free(wp
);
4218 ruby_window_free(wp
);
4221 clear_winopt(&wp
->w_onebuf_opt
);
4222 clear_winopt(&wp
->w_allbuf_opt
);
4225 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4232 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4233 vim_free(wp
->w_tagstack
[i
].tagname
);
4235 vim_free(wp
->w_localdir
);
4237 #ifdef FEAT_SEARCH_EXTRA
4241 #ifdef FEAT_JUMPLIST
4245 #ifdef FEAT_QUICKFIX
4252 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4253 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4255 #endif /* FEAT_GUI */
4266 * Append window "wp" in the window list after window "after".
4269 win_append(after
, wp
)
4274 if (after
== NULL
) /* after NULL is in front of the first */
4277 before
= after
->w_next
;
4279 wp
->w_next
= before
;
4288 before
->w_prev
= wp
;
4292 * Remove a window from the window list.
4297 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4299 if (wp
->w_prev
!= NULL
)
4300 wp
->w_prev
->w_next
= wp
->w_next
;
4301 else if (tp
== NULL
)
4302 firstwin
= wp
->w_next
;
4304 tp
->tp_firstwin
= wp
->w_next
;
4305 if (wp
->w_next
!= NULL
)
4306 wp
->w_next
->w_prev
= wp
->w_prev
;
4307 else if (tp
== NULL
)
4308 lastwin
= wp
->w_prev
;
4310 tp
->tp_lastwin
= wp
->w_prev
;
4314 * Append frame "frp" in a frame list after frame "after".
4317 frame_append(after
, frp
)
4318 frame_T
*after
, *frp
;
4320 frp
->fr_next
= after
->fr_next
;
4321 after
->fr_next
= frp
;
4322 if (frp
->fr_next
!= NULL
)
4323 frp
->fr_next
->fr_prev
= frp
;
4324 frp
->fr_prev
= after
;
4328 * Insert frame "frp" in a frame list before frame "before".
4331 frame_insert(before
, frp
)
4332 frame_T
*before
, *frp
;
4334 frp
->fr_next
= before
;
4335 frp
->fr_prev
= before
->fr_prev
;
4336 before
->fr_prev
= frp
;
4337 if (frp
->fr_prev
!= NULL
)
4338 frp
->fr_prev
->fr_next
= frp
;
4340 frp
->fr_parent
->fr_child
= frp
;
4344 * Remove a frame from a frame list.
4350 if (frp
->fr_prev
!= NULL
)
4351 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4353 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4354 if (frp
->fr_next
!= NULL
)
4355 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4358 #endif /* FEAT_WINDOWS */
4361 * Allocate w_lines[] for window "wp".
4362 * Return FAIL for failure, OK for success.
4368 wp
->w_lines_valid
= 0;
4369 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4370 if (wp
->w_lines
== NULL
)
4376 * free lsize arrays for a window
4382 vim_free(wp
->w_lines
);
4387 * Called from win_new_shellsize() after Rows changed.
4388 * This only does the current tab page, others must be done when made active.
4393 int h
= (int)ROWS_AVAIL
;
4395 if (firstwin
== NULL
) /* not initialized yet */
4398 if (h
< frame_minheight(topframe
, NULL
))
4399 h
= frame_minheight(topframe
, NULL
);
4401 /* First try setting the heights of windows with 'winfixheight'. If
4402 * that doesn't result in the right height, forget about that option. */
4403 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4404 if (topframe
->fr_height
!= h
)
4405 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4407 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4411 win_new_height(firstwin
, h
);
4415 curtab
->tp_ch_used
= p_ch
;
4419 /* Disabled: don't want making the screen smaller make a window larger. */
4421 win_equal(curwin
, FALSE
, 'v');
4425 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4427 * Called from win_new_shellsize() after Columns changed.
4432 if (firstwin
== NULL
) /* not initialized yet */
4435 /* First try setting the widths of windows with 'winfixwidth'. If that
4436 * doesn't result in the right width, forget about that option. */
4437 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4438 if (topframe
->fr_width
!= Columns
)
4439 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4441 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4443 /* Disabled: don't want making the screen smaller make a window larger. */
4445 win_equal(curwin
, FALSE
, 'h');
4450 #if defined(FEAT_CMDWIN) || defined(PROTO)
4452 * Save the size of all windows in "gap".
4461 ga_init2(gap
, (int)sizeof(int), 1);
4462 if (ga_grow(gap
, win_count() * 2) == OK
)
4463 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4465 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4466 wp
->w_width
+ wp
->w_vsep_width
;
4467 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4472 * Restore window sizes, but only if the number of windows is still the same.
4473 * Does not free the growarray.
4476 win_size_restore(gap
)
4482 if (win_count() * 2 == gap
->ga_len
)
4485 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4487 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4488 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4490 /* recompute the window positions */
4491 (void)win_comp_pos();
4494 #endif /* FEAT_CMDWIN */
4496 #if defined(FEAT_WINDOWS) || defined(PROTO)
4498 * Update the position for all windows, using the width and height of the
4500 * Returns the row just after the last window.
4505 int row
= tabline_height();
4508 frame_comp_pos(topframe
, &row
, &col
);
4513 * Update the position of the windows in frame "topfrp", using the width and
4514 * height of the frames.
4515 * "*row" and "*col" are the top-left position of the frame. They are updated
4516 * to the bottom-right position plus one.
4519 frame_comp_pos(topfrp
, row
, col
)
4526 #ifdef FEAT_VERTSPLIT
4531 wp
= topfrp
->fr_win
;
4534 if (wp
->w_winrow
!= *row
4535 #ifdef FEAT_VERTSPLIT
4536 || wp
->w_wincol
!= *col
4540 /* position changed, redraw */
4541 wp
->w_winrow
= *row
;
4542 #ifdef FEAT_VERTSPLIT
4543 wp
->w_wincol
= *col
;
4545 redraw_win_later(wp
, NOT_VALID
);
4546 wp
->w_redr_status
= TRUE
;
4548 *row
+= wp
->w_height
+ wp
->w_status_height
;
4549 #ifdef FEAT_VERTSPLIT
4550 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4555 #ifdef FEAT_VERTSPLIT
4559 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4561 #ifdef FEAT_VERTSPLIT
4562 if (topfrp
->fr_layout
== FR_ROW
)
4563 *row
= startrow
; /* all frames are at the same row */
4565 *col
= startcol
; /* all frames are at the same col */
4567 frame_comp_pos(frp
, row
, col
);
4572 #endif /* FEAT_WINDOWS */
4575 * Set current window height and take care of repositioning other windows to
4579 win_setheight(height
)
4582 win_setheight_win(height
, curwin
);
4586 * Set the window height of window "win" and take care of repositioning other
4587 * windows to fit around it.
4590 win_setheight_win(height
, win
)
4598 /* Always keep current window at least one line high, even when
4599 * 'winminheight' is zero. */
4609 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4611 /* recompute the window positions */
4612 row
= win_comp_pos();
4614 if (height
> topframe
->fr_height
)
4615 height
= topframe
->fr_height
;
4616 win
->w_height
= height
;
4621 * If there is extra space created between the last window and the command
4624 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4625 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4630 redraw_all_later(NOT_VALID
);
4633 #if defined(FEAT_WINDOWS) || defined(PROTO)
4636 * Set the height of a frame to "height" and take care that all frames and
4637 * windows inside it are resized. Also resize frames on the left and right if
4638 * the are in the same FR_ROW frame.
4641 * If the frame is part of a FR_COL frame, try fitting the frame in that
4642 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4643 * go to containing frames to resize them and make room.
4644 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4645 * Check for the minimal height of the FR_ROW frame.
4646 * At the top level we can also use change the command line height.
4649 frame_setheight(curfrp
, height
)
4653 int room
; /* total number of lines available */
4654 int take
; /* number of lines taken from other windows */
4655 int room_cmdline
; /* lines available from cmdline */
4661 /* If the height already is the desired value, nothing to do. */
4662 if (curfrp
->fr_height
== height
)
4665 if (curfrp
->fr_parent
== NULL
)
4667 /* topframe: can only change the command line */
4668 if (height
> ROWS_AVAIL
)
4669 height
= ROWS_AVAIL
;
4671 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4673 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4675 /* Row of frames: Also need to resize frames left and right of this
4676 * one. First check for the minimal height of these. */
4677 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4680 frame_setheight(curfrp
->fr_parent
, height
);
4685 * Column of frames: try to change only frames in this column.
4687 #ifdef FEAT_VERTSPLIT
4690 * 1: compute room available, if it's not enough try resizing the
4692 * 2: compute the room available and adjust the height to it.
4693 * Try not to reduce the height of a window with 'winfixheight' set.
4695 for (run
= 1; run
<= 2; ++run
)
4702 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4706 && frp
->fr_win
!= NULL
4707 && frp
->fr_win
->w_p_wfh
)
4708 room_reserved
+= frp
->fr_height
;
4709 room
+= frp
->fr_height
;
4711 room
-= frame_minheight(frp
, NULL
);
4713 #ifdef FEAT_VERTSPLIT
4714 if (curfrp
->fr_width
!= Columns
)
4719 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4720 + lastwin
->w_height
+ lastwin
->w_status_height
);
4721 if (room_cmdline
< 0)
4725 if (height
<= room
+ room_cmdline
)
4727 #ifdef FEAT_VERTSPLIT
4728 if (run
== 2 || curfrp
->fr_width
== Columns
)
4731 if (height
> room
+ room_cmdline
)
4732 height
= room
+ room_cmdline
;
4735 #ifdef FEAT_VERTSPLIT
4736 frame_setheight(curfrp
->fr_parent
, height
4737 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4743 * Compute the number of lines we will take from others frames (can be
4746 take
= height
- curfrp
->fr_height
;
4748 /* If there is not enough room, also reduce the height of a window
4749 * with 'winfixheight' set. */
4750 if (height
> room
+ room_cmdline
- room_reserved
)
4751 room_reserved
= room
+ room_cmdline
- height
;
4752 /* If there is only a 'winfixheight' window and making the
4753 * window smaller, need to make the other window taller. */
4754 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4757 if (take
> 0 && room_cmdline
> 0)
4759 /* use lines from cmdline first */
4760 if (take
< room_cmdline
)
4761 room_cmdline
= take
;
4762 take
-= room_cmdline
;
4763 topframe
->fr_height
+= room_cmdline
;
4767 * set the current frame to the new height
4769 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4772 * First take lines from the frames after the current frame. If
4773 * that is not enough, takes lines from frames above the current
4776 for (run
= 0; run
< 2; ++run
)
4779 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4781 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4782 while (frp
!= NULL
&& take
!= 0)
4784 h
= frame_minheight(frp
, NULL
);
4785 if (room_reserved
> 0
4786 && frp
->fr_win
!= NULL
4787 && frp
->fr_win
->w_p_wfh
)
4789 if (room_reserved
>= frp
->fr_height
)
4790 room_reserved
-= frp
->fr_height
;
4793 if (frp
->fr_height
- room_reserved
> take
)
4794 room_reserved
= frp
->fr_height
- take
;
4795 take
-= frp
->fr_height
- room_reserved
;
4796 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4802 if (frp
->fr_height
- take
< h
)
4804 take
-= frp
->fr_height
- h
;
4805 frame_new_height(frp
, h
, FALSE
, FALSE
);
4809 frame_new_height(frp
, frp
->fr_height
- take
,
4823 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4825 * Set current window width and take care of repositioning other windows to
4832 win_setwidth_win(width
, curwin
);
4836 win_setwidth_win(width
, wp
)
4840 /* Always keep current window at least one column wide, even when
4841 * 'winminwidth' is zero. */
4850 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4852 /* recompute the window positions */
4853 (void)win_comp_pos();
4855 redraw_all_later(NOT_VALID
);
4859 * Set the width of a frame to "width" and take care that all frames and
4860 * windows inside it are resized. Also resize frames above and below if the
4861 * are in the same FR_ROW frame.
4863 * Strategy is similar to frame_setheight().
4866 frame_setwidth(curfrp
, width
)
4870 int room
; /* total number of lines available */
4871 int take
; /* number of lines taken from other windows */
4877 /* If the width already is the desired value, nothing to do. */
4878 if (curfrp
->fr_width
== width
)
4881 if (curfrp
->fr_parent
== NULL
)
4882 /* topframe: can't change width */
4885 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4887 /* Column of frames: Also need to resize frames above and below of
4888 * this one. First check for the minimal width of these. */
4889 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4892 frame_setwidth(curfrp
->fr_parent
, width
);
4897 * Row of frames: try to change only frames in this row.
4900 * 1: compute room available, if it's not enough try resizing the
4902 * 2: compute the room available and adjust the width to it.
4904 for (run
= 1; run
<= 2; ++run
)
4908 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4912 && frp
->fr_win
!= NULL
4913 && frp
->fr_win
->w_p_wfw
)
4914 room_reserved
+= frp
->fr_width
;
4915 room
+= frp
->fr_width
;
4917 room
-= frame_minwidth(frp
, NULL
);
4922 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4928 frame_setwidth(curfrp
->fr_parent
, width
4929 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4933 * Compute the number of lines we will take from others frames (can be
4936 take
= width
- curfrp
->fr_width
;
4938 /* If there is not enough room, also reduce the width of a window
4939 * with 'winfixwidth' set. */
4940 if (width
> room
- room_reserved
)
4941 room_reserved
= room
- width
;
4942 /* If there is only a 'winfixwidth' window and making the
4943 * window smaller, need to make the other window narrower. */
4944 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4948 * set the current frame to the new width
4950 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
4953 * First take lines from the frames right of the current frame. If
4954 * that is not enough, takes lines from frames left of the current
4957 for (run
= 0; run
< 2; ++run
)
4960 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4962 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4963 while (frp
!= NULL
&& take
!= 0)
4965 w
= frame_minwidth(frp
, NULL
);
4966 if (room_reserved
> 0
4967 && frp
->fr_win
!= NULL
4968 && frp
->fr_win
->w_p_wfw
)
4970 if (room_reserved
>= frp
->fr_width
)
4971 room_reserved
-= frp
->fr_width
;
4974 if (frp
->fr_width
- room_reserved
> take
)
4975 room_reserved
= frp
->fr_width
- take
;
4976 take
-= frp
->fr_width
- room_reserved
;
4977 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
4983 if (frp
->fr_width
- take
< w
)
4985 take
-= frp
->fr_width
- w
;
4986 frame_new_width(frp
, w
, FALSE
, FALSE
);
4990 frame_new_width(frp
, frp
->fr_width
- take
,
5003 #endif /* FEAT_VERTSPLIT */
5006 * Check 'winminheight' for a valid value.
5015 /* loop until there is a 'winminheight' that is possible */
5018 /* TODO: handle vertical splits */
5020 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5021 room
+= wp
->w_height
- p_wmh
;
5036 * Status line of dragwin is dragged "offset" lines down (negative is up).
5039 win_drag_status_line(dragwin
, offset
)
5047 int up
; /* if TRUE, drag status line up, otherwise down */
5050 fr
= dragwin
->w_frame
;
5052 if (fr
!= topframe
) /* more than one window */
5055 /* When the parent frame is not a column of frames, its parent should
5057 if (fr
->fr_layout
!= FR_COL
)
5060 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5065 /* If this is the last frame in a column, may want to resize the parent
5066 * frame instead (go two up to skip a row of frames). */
5067 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5076 if (offset
< 0) /* drag up */
5080 /* sum up the room of the current frame and above it */
5083 /* only one window */
5084 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5089 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5091 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5096 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5098 else /* drag down */
5102 * Only dragging the last status line can reduce p_ch.
5104 room
= Rows
- cmdline_row
;
5105 if (curfr
->fr_next
== NULL
)
5111 /* sum up the room of frames below of the current one */
5112 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5113 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5114 fr
= curfr
; /* put fr at window that grows */
5117 if (room
< offset
) /* Not enough room */
5118 offset
= room
; /* Move as far as we can */
5123 * Grow frame fr by "offset" lines.
5124 * Doesn't happen when dragging the last status line up.
5127 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5130 fr
= curfr
; /* current frame gets smaller */
5132 fr
= curfr
->fr_next
; /* next frame gets smaller */
5135 * Now make the other frames smaller.
5137 while (fr
!= NULL
&& offset
> 0)
5139 n
= frame_minheight(fr
, NULL
);
5140 if (fr
->fr_height
- offset
<= n
)
5142 offset
-= fr
->fr_height
- n
;
5143 frame_new_height(fr
, n
, !up
, FALSE
);
5147 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5155 row
= win_comp_pos();
5156 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5158 p_ch
= Rows
- cmdline_row
;
5161 curtab
->tp_ch_used
= p_ch
;
5162 redraw_all_later(SOME_VALID
);
5166 #ifdef FEAT_VERTSPLIT
5168 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5171 win_drag_vsep_line(dragwin
, offset
)
5178 int left
; /* if TRUE, drag separator line left, otherwise right */
5181 fr
= dragwin
->w_frame
;
5182 if (fr
== topframe
) /* only one window (cannot happen?) */
5186 /* When the parent frame is not a row of frames, its parent should be. */
5187 if (fr
->fr_layout
!= FR_ROW
)
5189 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5195 /* If this is the last frame in a row, may want to resize a parent
5197 while (curfr
->fr_next
== NULL
)
5210 if (offset
< 0) /* drag left */
5214 /* sum up the room of the current frame and left of it */
5216 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5218 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5222 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5224 else /* drag right */
5227 /* sum up the room of frames right of the current one */
5229 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5230 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5231 fr
= curfr
; /* put fr at window that grows */
5234 if (room
< offset
) /* Not enough room */
5235 offset
= room
; /* Move as far as we can */
5236 if (offset
<= 0) /* No room at all, quit. */
5239 /* grow frame fr by offset lines */
5240 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5242 /* shrink other frames: current and at the left or at the right */
5244 fr
= curfr
; /* current frame gets smaller */
5246 fr
= curfr
->fr_next
; /* next frame gets smaller */
5248 while (fr
!= NULL
&& offset
> 0)
5250 n
= frame_minwidth(fr
, NULL
);
5251 if (fr
->fr_width
- offset
<= n
)
5253 offset
-= fr
->fr_width
- n
;
5254 frame_new_width(fr
, n
, !left
, FALSE
);
5258 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5266 (void)win_comp_pos();
5267 redraw_all_later(NOT_VALID
);
5269 #endif /* FEAT_VERTSPLIT */
5270 #endif /* FEAT_MOUSE */
5272 #endif /* FEAT_WINDOWS */
5275 * Set the height of a window.
5276 * This takes care of the things inside the window, not what happens to the
5277 * window position, the frame or to other windows.
5280 win_new_height(wp
, height
)
5285 int sline
, line_size
;
5286 #define FRACTION_MULT 16384L
5288 /* Don't want a negative height. Happens when splitting a tiny window.
5289 * Will equalize heights soon to fix it. */
5292 if (wp
->w_height
== height
)
5293 return; /* nothing to do */
5295 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5296 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5297 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5299 wp
->w_height
= height
;
5302 /* Don't change w_topline when height is zero. Don't set w_topline when
5303 * 'scrollbind' is set and this isn't the current window. */
5305 #ifdef FEAT_SCROLLBIND
5306 && (!wp
->w_p_scb
|| wp
== curwin
)
5311 * Find a value for w_topline that shows the cursor at the same
5312 * relative position in the window as before (more or less).
5314 lnum
= wp
->w_cursor
.lnum
;
5315 if (lnum
< 1) /* can happen when starting up */
5317 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5318 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5319 sline
= wp
->w_wrow
- line_size
;
5323 /* Make sure the whole cursor line is visible, if possible. */
5324 int rows
= plines_win(wp
, lnum
, FALSE
);
5326 if (sline
> wp
->w_height
- rows
)
5328 sline
= wp
->w_height
- rows
;
5329 wp
->w_wrow
-= rows
- line_size
;
5336 * Cursor line would go off top of screen if w_wrow was this high.
5337 * Make cursor line the first line in the window. If not enough
5338 * room use w_skipcol;
5340 wp
->w_wrow
= line_size
;
5341 if (wp
->w_wrow
>= wp
->w_height
5342 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5344 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5346 while (wp
->w_wrow
>= wp
->w_height
)
5348 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5356 while (sline
> 0 && lnum
> 1)
5359 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5362 /* first line in buffer is folded */
5370 if (lnum
== wp
->w_topline
)
5371 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5375 line_size
= plines_win(wp
, lnum
, TRUE
);
5382 * Line we want at top would go off top of screen. Use next
5386 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5389 wp
->w_wrow
-= line_size
+ sline
;
5393 /* First line of file reached, use that as topline. */
5395 wp
->w_wrow
-= sline
;
5398 set_topline(wp
, lnum
);
5405 curs_columns(FALSE
); /* validate w_wrow */
5407 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5409 win_comp_scroll(wp
);
5410 redraw_win_later(wp
, SOME_VALID
);
5412 wp
->w_redr_status
= TRUE
;
5414 invalidate_botline_win(wp
);
5417 #ifdef FEAT_VERTSPLIT
5419 * Set the width of a window.
5422 win_new_width(wp
, width
)
5426 wp
->w_width
= width
;
5427 wp
->w_lines_valid
= 0;
5428 changed_line_abv_curs_win(wp
);
5429 invalidate_botline_win(wp
);
5433 curs_columns(TRUE
); /* validate w_wrow */
5435 redraw_win_later(wp
, NOT_VALID
);
5436 wp
->w_redr_status
= TRUE
;
5444 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5445 if (wp
->w_p_scr
== 0)
5450 * command_height: called whenever p_ch has been changed
5458 int old_p_ch
= curtab
->tp_ch_used
;
5460 /* Use the value of p_ch that we remembered. This is needed for when the
5461 * GUI starts up, we can't be sure in what order things happen. And when
5462 * p_ch was changed in another tab page. */
5463 curtab
->tp_ch_used
= p_ch
;
5465 /* Find bottom frame with width of screen. */
5466 frp
= lastwin
->w_frame
;
5467 # ifdef FEAT_VERTSPLIT
5468 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5469 frp
= frp
->fr_parent
;
5472 /* Avoid changing the height of a window with 'winfixheight' set. */
5473 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5474 && frp
->fr_win
->w_p_wfh
)
5477 if (starting
!= NO_SCREEN
)
5479 cmdline_row
= Rows
- p_ch
;
5481 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5483 while (p_ch
> old_p_ch
)
5489 cmdline_row
= Rows
- p_ch
;
5492 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5493 if (h
> p_ch
- old_p_ch
)
5494 h
= p_ch
- old_p_ch
;
5496 frame_add_height(frp
, -h
);
5500 /* Recompute window positions. */
5501 (void)win_comp_pos();
5503 /* clear the lines added to cmdline */
5505 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5506 (int)Columns
, ' ', ' ', 0);
5507 msg_row
= cmdline_row
;
5508 redraw_cmdline
= TRUE
;
5512 if (msg_row
< cmdline_row
)
5513 msg_row
= cmdline_row
;
5514 redraw_cmdline
= TRUE
;
5516 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5518 /* Recompute window positions. */
5519 if (frp
!= lastwin
->w_frame
)
5520 (void)win_comp_pos();
5522 cmdline_row
= Rows
- p_ch
;
5523 win_setheight(cmdline_row
);
5527 #if defined(FEAT_WINDOWS) || defined(PROTO)
5529 * Resize frame "frp" to be "n" lines higher (negative for less high).
5530 * Also resize the frames it is contained in.
5533 frame_add_height(frp
, n
)
5537 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5540 frp
= frp
->fr_parent
;
5543 frp
->fr_height
+= n
;
5548 * Add or remove a status line for the bottom window(s), according to the
5549 * value of 'laststatus'.
5552 last_status(morewin
)
5553 int morewin
; /* pretend there are two or more windows */
5555 /* Don't make a difference between horizontal or vertical split. */
5556 last_status_rec(topframe
, (p_ls
== 2
5557 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5561 last_status_rec(fr
, statusline
)
5568 if (fr
->fr_layout
== FR_LEAF
)
5571 if (wp
->w_status_height
!= 0 && !statusline
)
5573 /* remove status line */
5574 win_new_height(wp
, wp
->w_height
+ 1);
5575 wp
->w_status_height
= 0;
5578 else if (wp
->w_status_height
== 0 && statusline
)
5580 /* Find a frame to take a line from. */
5582 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5589 /* In a column of frames: go to frame above. If already at
5590 * the top or in a row of frames: go to parent. */
5591 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5596 wp
->w_status_height
= 1;
5599 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5600 frame_fix_height(wp
);
5601 (void)win_comp_pos();
5604 win_new_height(wp
, wp
->w_height
- 1);
5606 redraw_all_later(SOME_VALID
);
5609 #ifdef FEAT_VERTSPLIT
5610 else if (fr
->fr_layout
== FR_ROW
)
5612 /* vertically split windows, set status line for each one */
5613 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5614 last_status_rec(fp
, statusline
);
5619 /* horizontally split window, set status line for last one */
5620 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5622 last_status_rec(fp
, statusline
);
5627 * Return the number of lines used by the tab page line.
5632 #ifdef FEAT_GUI_TABLINE
5633 /* When the GUI has the tabline then this always returns zero. */
5634 if (gui_use_tabline())
5640 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5645 #endif /* FEAT_WINDOWS */
5647 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5649 * Get the file name at the cursor.
5650 * If Visual mode is active, use the selected text if it's in one line.
5651 * Returns the name in allocated memory, NULL for failure.
5654 grab_file_name(count
, file_lnum
)
5656 linenr_T
*file_lnum
;
5664 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5666 return find_file_name_in_path(ptr
, len
,
5667 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5670 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5676 * Return the file name under or after the cursor.
5678 * The 'path' option is searched if the file name is not absolute.
5679 * The string returned has been alloc'ed and should be freed by the caller.
5680 * NULL is returned if the file name or file is not found.
5683 * FNAME_MESS give error messages
5684 * FNAME_EXP expand to path
5685 * FNAME_HYP check for hypertext link
5686 * FNAME_INCL apply "includeexpr"
5689 file_name_at_cursor(options
, count
, file_lnum
)
5692 linenr_T
*file_lnum
;
5694 return file_name_in_line(ml_get_curline(),
5695 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5700 * Return the name of the file under or after ptr[col].
5701 * Otherwise like file_name_at_cursor().
5704 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5709 char_u
*rel_fname
; /* file we are searching relative to */
5710 linenr_T
*file_lnum
; /* line number after the file name */
5716 * search forward for what could be the start of a file name
5719 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5721 if (*ptr
== NUL
) /* nothing found */
5723 if (options
& FNAME_MESS
)
5724 EMSG(_("E446: No file name under cursor"));
5729 * Search backward for first char of the file name.
5730 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5735 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5739 if (vim_isfilec(ptr
[-1])
5740 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5747 * Search forward for the last char of the file name.
5748 * Also allow "://" when ':' is not in 'isfname'.
5751 while (vim_isfilec(ptr
[len
])
5752 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5755 len
+= (*mb_ptr2len
)(ptr
+ len
);
5761 * If there is trailing punctuation, remove it.
5762 * But don't remove "..", could be a directory name.
5764 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5765 && ptr
[len
- 2] != '.')
5768 if (file_lnum
!= NULL
)
5772 /* Get the number after the file name and a separator character */
5778 ++p
; /* skip the separator */
5781 *file_lnum
= (int)getdigits(&p
);
5785 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5788 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5789 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5792 eval_includeexpr(ptr
, len
)
5798 set_vim_var_string(VV_FNAME
, ptr
, len
);
5799 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5800 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5801 set_vim_var_string(VV_FNAME
, NULL
, 0);
5807 * Return the name of the file ptr[len] in 'path'.
5808 * Otherwise like file_name_at_cursor().
5811 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5816 char_u
*rel_fname
; /* file we are searching relative to */
5820 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5821 char_u
*tofree
= NULL
;
5823 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5825 tofree
= eval_includeexpr(ptr
, len
);
5829 len
= (int)STRLEN(ptr
);
5834 if (options
& FNAME_EXP
)
5836 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5839 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5841 * If the file could not be found in a normal way, try applying
5842 * 'includeexpr' (unless done already).
5844 if (file_name
== NULL
5845 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5847 tofree
= eval_includeexpr(ptr
, len
);
5851 len
= (int)STRLEN(ptr
);
5852 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5857 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5861 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5865 /* Repeat finding the file "count" times. This matters when it
5866 * appears several times in the path. */
5867 while (file_name
!= NULL
&& --count
> 0)
5869 vim_free(file_name
);
5870 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5874 file_name
= vim_strnsave(ptr
, len
);
5876 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5882 #endif /* FEAT_SEARCHPATH */
5885 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5886 * Also check for ":\\", which MS Internet Explorer accepts, return
5893 if (STRNCMP(p
, "://", (size_t)3) == 0)
5895 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5896 return URL_BACKSLASH
;
5901 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5902 * Return URL_BACKSLASH for "name:\\".
5903 * Return zero otherwise.
5906 path_with_url(fname
)
5911 for (p
= fname
; isalpha(*p
); ++p
)
5913 return path_is_url(p
);
5917 * Return TRUE if "name" is a full (absolute) path name or URL.
5923 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5927 * Get absolute file name into buffer "buf[len]".
5929 * return FAIL for failure, OK otherwise
5932 vim_FullName(fname
, buf
, len
, force
)
5933 char_u
*fname
, *buf
;
5935 int force
; /* force expansion even when already absolute */
5944 url
= path_with_url(fname
);
5946 retval
= mch_FullName(fname
, buf
, len
, force
);
5947 if (url
|| retval
== FAIL
)
5949 /* something failed; use the file name (truncate when too long) */
5950 vim_strncpy(buf
, fname
, len
- 1);
5952 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
5959 * Return the minimal number of rows that is needed on the screen to display
5960 * the current number of windows.
5971 if (firstwin
== NULL
) /* not initialized yet */
5976 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
5978 n
= frame_minheight(tp
->tp_topframe
, NULL
);
5982 total
+= tabline_height();
5984 total
= 1; /* at least one window should have a line! */
5986 total
+= 1; /* count the room for the command line */
5991 * Return TRUE if there is only one window (in the current tab page), not
5992 * counting a help or preview window, unless it is the current window.
6001 /* If there is another tab page there always is another window. */
6002 if (first_tabpage
->tp_next
!= NULL
)
6005 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6006 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6007 # ifdef FEAT_QUICKFIX
6012 return (count
<= 1);
6018 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6020 * Correct the cursor line number in other windows. Used after changing the
6021 * current buffer, and before applying autocommands.
6022 * When "do_curwin" is TRUE, also check current window.
6025 check_lnums(do_curwin
)
6033 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6034 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6040 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6041 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6042 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6043 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6048 #if defined(FEAT_WINDOWS) || defined(PROTO)
6051 * A snapshot of the window sizes, to restore them after closing the help
6053 * Only these fields are used:
6059 * fr_win (only valid for the old curwin, NULL otherwise)
6063 * Create a snapshot of the current frame sizes.
6068 clear_snapshot(curtab
);
6069 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6073 make_snapshot_rec(fr
, frp
)
6077 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6080 (*frp
)->fr_layout
= fr
->fr_layout
;
6081 # ifdef FEAT_VERTSPLIT
6082 (*frp
)->fr_width
= fr
->fr_width
;
6084 (*frp
)->fr_height
= fr
->fr_height
;
6085 if (fr
->fr_next
!= NULL
)
6086 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6087 if (fr
->fr_child
!= NULL
)
6088 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6089 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6090 (*frp
)->fr_win
= curwin
;
6094 * Remove any existing snapshot.
6100 clear_snapshot_rec(tp
->tp_snapshot
);
6101 tp
->tp_snapshot
= NULL
;
6105 clear_snapshot_rec(fr
)
6110 clear_snapshot_rec(fr
->fr_next
);
6111 clear_snapshot_rec(fr
->fr_child
);
6117 * Restore a previously created snapshot, if there is any.
6118 * This is only done if the screen size didn't change and the window layout is
6122 restore_snapshot(close_curwin
)
6123 int close_curwin
; /* closing current window */
6127 if (curtab
->tp_snapshot
!= NULL
6128 # ifdef FEAT_VERTSPLIT
6129 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6131 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6132 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6134 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6136 if (wp
!= NULL
&& close_curwin
)
6138 redraw_all_later(CLEAR
);
6140 clear_snapshot(curtab
);
6144 * Check if frames "sn" and "fr" have the same layout, same following frames
6145 * and same children.
6148 check_snapshot_rec(sn
, fr
)
6152 if (sn
->fr_layout
!= fr
->fr_layout
6153 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6154 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6155 || (sn
->fr_next
!= NULL
6156 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6157 || (sn
->fr_child
!= NULL
6158 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6164 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6165 * following frames and children.
6166 * Returns a pointer to the old current window, or NULL.
6169 restore_snapshot_rec(sn
, fr
)
6176 fr
->fr_height
= sn
->fr_height
;
6177 # ifdef FEAT_VERTSPLIT
6178 fr
->fr_width
= sn
->fr_width
;
6180 if (fr
->fr_layout
== FR_LEAF
)
6182 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6183 # ifdef FEAT_VERTSPLIT
6184 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6188 if (sn
->fr_next
!= NULL
)
6190 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6194 if (sn
->fr_child
!= NULL
)
6196 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6205 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6207 * Return TRUE if there is any vertically split window.
6214 if (topframe
->fr_layout
== FR_ROW
)
6217 if (topframe
->fr_layout
== FR_COL
)
6218 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6219 if (fr
->fr_layout
== FR_ROW
)
6226 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6228 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6229 * highligted with the group 'grp' with priority 'prio'.
6230 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6231 * If no particular ID is desired, -1 must be specified for 'id'.
6232 * Return ID of added match, -1 on failure.
6235 match_add(wp
, grp
, pat
, prio
, id
)
6248 if (*grp
== NUL
|| *pat
== NUL
)
6250 if (id
< -1 || id
== 0)
6252 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6257 cur
= wp
->w_match_head
;
6262 EMSGN("E801: ID already taken: %ld", id
);
6268 if ((hlg_id
= syn_namen2id(grp
, STRLEN(grp
))) == 0)
6270 EMSG2(_(e_nogroup
), grp
);
6273 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6275 EMSG2(_(e_invarg2
), pat
);
6279 /* Find available match ID. */
6282 cur
= wp
->w_match_head
;
6283 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6286 id
= wp
->w_next_match_id
;
6287 wp
->w_next_match_id
++;
6290 /* Build new match. */
6291 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6294 m
->pattern
= vim_strsave(pat
);
6296 m
->match
.regprog
= regprog
;
6297 m
->match
.rmm_ic
= FALSE
;
6298 m
->match
.rmm_maxcol
= 0;
6300 /* Insert new match. The match list is in ascending order with regard to
6301 * the match priorities. */
6302 cur
= wp
->w_match_head
;
6304 while (cur
!= NULL
&& prio
>= cur
->priority
)
6310 wp
->w_match_head
= m
;
6315 redraw_later(SOME_VALID
);
6320 * Delete match with ID 'id' in the match list of window 'wp'.
6321 * Print error messages if 'perr' is TRUE.
6324 match_delete(wp
, id
, perr
)
6329 matchitem_T
*cur
= wp
->w_match_head
;
6330 matchitem_T
*prev
= cur
;
6335 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6339 while (cur
!= NULL
&& cur
->id
!= id
)
6347 EMSGN("E803: ID not found: %ld", id
);
6351 wp
->w_match_head
= cur
->next
;
6353 prev
->next
= cur
->next
;
6354 vim_free(cur
->match
.regprog
);
6355 vim_free(cur
->pattern
);
6357 redraw_later(SOME_VALID
);
6362 * Delete all matches in the match list of window 'wp'.
6370 while (wp
->w_match_head
!= NULL
)
6372 m
= wp
->w_match_head
->next
;
6373 vim_free(wp
->w_match_head
->match
.regprog
);
6374 vim_free(wp
->w_match_head
->pattern
);
6375 vim_free(wp
->w_match_head
);
6376 wp
->w_match_head
= m
;
6378 redraw_later(SOME_VALID
);
6382 * Get match from ID 'id' in window 'wp'.
6383 * Return NULL if match not found.
6390 matchitem_T
*cur
= wp
->w_match_head
;
6392 while (cur
!= NULL
&& cur
->id
!= id
)