1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read a list of people who contributed.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
12 static int path_is_url
__ARGS((char_u
*p
));
13 #if defined(FEAT_WINDOWS) || defined(PROTO)
14 static int win_split_ins
__ARGS((int size
, int flags
, win_T
*newwin
, int dir
));
15 static void win_init
__ARGS((win_T
*newp
, win_T
*oldp
, int flags
));
16 static void frame_comp_pos
__ARGS((frame_T
*topfrp
, int *row
, int *col
));
17 static void frame_setheight
__ARGS((frame_T
*curfrp
, int height
));
19 static void frame_setwidth
__ARGS((frame_T
*curfrp
, int width
));
21 static void win_exchange
__ARGS((long));
22 static void win_rotate
__ARGS((int, int));
23 static void win_totop
__ARGS((int size
, int flags
));
24 static void win_equal_rec
__ARGS((win_T
*next_curwin
, int current
, frame_T
*topfr
, int dir
, int col
, int row
, int width
, int height
));
25 static int last_window
__ARGS((void));
26 static win_T
*win_free_mem
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
27 static win_T
*winframe_remove
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
28 static frame_T
*win_altframe
__ARGS((win_T
*win
, tabpage_T
*tp
));
29 static tabpage_T
*alt_tabpage
__ARGS((void));
30 static win_T
*frame2win
__ARGS((frame_T
*frp
));
31 static int frame_has_win
__ARGS((frame_T
*frp
, win_T
*wp
));
32 static void frame_new_height
__ARGS((frame_T
*topfrp
, int height
, int topfirst
, int wfh
));
33 static int frame_fixed_height
__ARGS((frame_T
*frp
));
35 static int frame_fixed_width
__ARGS((frame_T
*frp
));
36 static void frame_add_statusline
__ARGS((frame_T
*frp
));
37 static void frame_new_width
__ARGS((frame_T
*topfrp
, int width
, int leftfirst
, int wfw
));
38 static void frame_add_vsep
__ARGS((frame_T
*frp
));
39 static int frame_minwidth
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
40 static void frame_fix_width
__ARGS((win_T
*wp
));
43 static int win_alloc_firstwin
__ARGS((win_T
*oldwin
));
44 #if defined(FEAT_WINDOWS) || defined(PROTO)
45 static tabpage_T
*alloc_tabpage
__ARGS((void));
46 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
47 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
48 static void frame_fix_height
__ARGS((win_T
*wp
));
49 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
50 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
51 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
52 static void win_append
__ARGS((win_T
*, win_T
*));
53 static void win_remove
__ARGS((win_T
*, tabpage_T
*tp
));
54 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
55 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
56 static void frame_remove
__ARGS((frame_T
*frp
));
58 static void win_new_width
__ARGS((win_T
*wp
, int width
));
59 static void win_goto_ver
__ARGS((int up
, long count
));
60 static void win_goto_hor
__ARGS((int left
, long count
));
62 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
63 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
65 static void make_snapshot
__ARGS((void));
66 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
67 static void clear_snapshot
__ARGS((tabpage_T
*tp
));
68 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
69 static void restore_snapshot
__ARGS((int close_curwin
));
70 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
71 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
73 #endif /* FEAT_WINDOWS */
75 static win_T
*win_alloc
__ARGS((win_T
*after
));
76 static void win_new_height
__ARGS((win_T
*, int));
78 #define URL_SLASH 1 /* path_is_url() has found "://" */
79 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
81 #define NOWIN (win_T *)-1 /* non-existing window */
84 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
86 # define ROWS_AVAIL (Rows - p_ch)
89 #if defined(FEAT_WINDOWS) || defined(PROTO)
91 static char *m_onlyone
= N_("Already only one window");
94 * all CTRL-W window commands are handled here, called from normal_cmd().
97 do_window(nchar
, Prenum
, xchar
)
100 int xchar
; /* extra char from ":wincmd gx" or NUL */
104 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
109 int type
= FIND_DEFINE
;
120 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
122 # define CHECK_CMDWIN
127 /* split current window in two parts, horizontally */
133 reset_VIsual_and_resel(); /* stop Visual mode */
136 /* When splitting the quickfix window open a new buffer in it,
137 * don't replicate the quickfix buffer. */
138 if (bt_quickfix(curbuf
))
142 need_mouse_correct
= TRUE
;
144 win_split((int)Prenum
, 0);
147 #ifdef FEAT_VERTSPLIT
148 /* split current window in two parts, vertically */
153 reset_VIsual_and_resel(); /* stop Visual mode */
155 # ifdef FEAT_QUICKFIX
156 /* When splitting the quickfix window open a new buffer in it,
157 * don't replicate the quickfix buffer. */
158 if (bt_quickfix(curbuf
))
162 need_mouse_correct
= TRUE
;
164 win_split((int)Prenum
, WSP_VERT
);
168 /* split current window and edit alternate file */
173 reset_VIsual_and_resel(); /* stop Visual mode */
175 STRCPY(cbuf
, "split #");
177 vim_snprintf((char *)cbuf
+ 7, sizeof(cbuf
) - 7,
179 do_cmdline_cmd(cbuf
);
182 /* open new window */
187 reset_VIsual_and_resel(); /* stop Visual mode */
194 vim_snprintf((char *)cbuf
, sizeof(cbuf
) - 5, "%ld", Prenum
);
197 #if defined(FEAT_VERTSPLIT) && defined(FEAT_QUICKFIX)
198 if (nchar
== 'v' || nchar
== Ctrl_V
)
202 do_cmdline_cmd(cbuf
);
205 /* quit current window */
209 reset_VIsual_and_resel(); /* stop Visual mode */
211 do_cmdline_cmd((char_u
*)"quit");
214 /* close current window */
218 reset_VIsual_and_resel(); /* stop Visual mode */
220 do_cmdline_cmd((char_u
*)"close");
223 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
224 /* close preview window */
229 reset_VIsual_and_resel(); /* stop Visual mode */
231 do_cmdline_cmd((char_u
*)"pclose");
234 /* cursor to preview window */
236 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
240 EMSG(_("E441: There is no preview window"));
246 /* close all but current window */
251 reset_VIsual_and_resel(); /* stop Visual mode */
253 do_cmdline_cmd((char_u
*)"only");
256 /* cursor to next window with wrap around */
259 /* cursor to previous window with wrap around */
262 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
266 if (Prenum
) /* go to specified window */
268 for (wp
= firstwin
; --Prenum
> 0; )
270 if (wp
->w_next
== NULL
)
278 if (nchar
== 'W') /* go to previous window */
282 wp
= lastwin
; /* wrap around */
284 else /* go to next window */
288 wp
= firstwin
; /* wrap around */
295 /* cursor to window below */
300 #ifdef FEAT_VERTSPLIT
301 win_goto_ver(FALSE
, Prenum1
);
303 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
310 /* cursor to window above */
315 #ifdef FEAT_VERTSPLIT
316 win_goto_ver(TRUE
, Prenum1
);
318 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
325 #ifdef FEAT_VERTSPLIT
326 /* cursor to left window */
332 win_goto_hor(TRUE
, Prenum1
);
335 /* cursor to right window */
340 win_goto_hor(FALSE
, Prenum1
);
344 /* move window to new tab page */
346 if (firstwin
== lastwin
)
350 tabpage_T
*oldtab
= curtab
;
353 /* First create a new tab with the window, then go back to
354 * the old tab and close the window there. */
356 if (win_new_tabpage((int)Prenum
) == OK
357 && valid_tabpage(oldtab
))
360 goto_tabpage_tp(oldtab
);
362 win_close(curwin
, FALSE
);
363 if (valid_tabpage(newtab
))
364 goto_tabpage_tp(newtab
);
369 /* cursor to top-left window */
375 /* cursor to bottom-right window */
381 /* cursor to last accessed (previous) window */
390 /* exchange current and next window */
394 win_exchange(Prenum
);
397 /* rotate windows downwards */
402 reset_VIsual_and_resel(); /* stop Visual mode */
404 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
407 /* rotate windows upwards */
411 reset_VIsual_and_resel(); /* stop Visual mode */
413 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
416 /* move window to the very top/bottom/left/right */
419 #ifdef FEAT_VERTSPLIT
424 win_totop((int)Prenum
,
425 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
426 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
429 /* make all windows the same height */
432 need_mouse_correct
= TRUE
;
434 win_equal(NULL
, FALSE
, 'b');
437 /* increase current window height */
440 need_mouse_correct
= TRUE
;
442 win_setheight(curwin
->w_height
+ (int)Prenum1
);
445 /* decrease current window height */
448 need_mouse_correct
= TRUE
;
450 win_setheight(curwin
->w_height
- (int)Prenum1
);
453 /* set current window height */
457 need_mouse_correct
= TRUE
;
459 win_setheight(Prenum
? (int)Prenum
: 9999);
462 #ifdef FEAT_VERTSPLIT
463 /* increase current window width */
466 need_mouse_correct
= TRUE
;
468 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
471 /* decrease current window width */
474 need_mouse_correct
= TRUE
;
476 win_setwidth(curwin
->w_width
- (int)Prenum1
);
479 /* set current window width */
482 need_mouse_correct
= TRUE
;
484 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
488 /* jump to tag and split window if tag exists (in preview window) */
489 #if defined(FEAT_QUICKFIX)
493 g_do_tagpreview
= Prenum
;
495 g_do_tagpreview
= p_pvh
;
502 reset_VIsual_and_resel(); /* stop Visual mode */
505 postponed_split
= Prenum
;
507 postponed_split
= -1;
509 /* Execute the command right here, required when
510 * "wincmd ]" was used in a function. */
511 do_nv_ident(Ctrl_RSB
, NUL
);
514 #ifdef FEAT_SEARCHPATH
515 /* edit file name under cursor in a new window */
522 ptr
= grab_file_name(Prenum1
, &lnum
);
526 need_mouse_correct
= TRUE
;
529 if (win_split(0, 0) == OK
)
531 # ifdef FEAT_SCROLLBIND
532 curwin
->w_p_scb
= FALSE
;
534 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
,
536 if (nchar
== 'F' && lnum
>= 0)
538 curwin
->w_cursor
.lnum
= lnum
;
540 beginline(BL_SOL
| BL_FIX
);
549 /* Go to the first occurrence of the identifier under cursor along path in a
552 case 'i': /* Go to any match */
556 case 'd': /* Go to definition, using 'define' */
559 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
561 find_pattern_in_path(ptr
, 0, len
, TRUE
,
562 Prenum
== 0 ? TRUE
: FALSE
, type
,
563 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
564 curwin
->w_set_curswant
= TRUE
;
570 #if defined(FEAT_QUICKFIX)
572 * In a quickfix window a <CR> jumps to the error under the
573 * cursor in a new window.
575 if (bt_quickfix(curbuf
))
577 sprintf((char *)cbuf
, "split +%ld%s",
578 (long)curwin
->w_cursor
.lnum
,
579 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
580 do_cmdline_cmd(cbuf
);
586 /* CTRL-W g extended commands */
590 #ifdef USE_ON_FLY_SCROLL
591 dont_scroll
= TRUE
; /* disallow scrolling here */
594 ++allow_keys
; /* no mapping for xchar, but allow key codes */
596 xchar
= plain_vgetc();
597 LANGMAP_ADJUST(xchar
, TRUE
);
600 #ifdef FEAT_CMDL_INFO
601 (void)add_to_showcmd(xchar
);
605 #if defined(FEAT_QUICKFIX)
609 g_do_tagpreview
= Prenum
;
611 g_do_tagpreview
= p_pvh
;
617 reset_VIsual_and_resel(); /* stop Visual mode */
620 postponed_split
= Prenum
;
622 postponed_split
= -1;
624 /* Execute the command right here, required when
625 * "wincmd g}" was used in a function. */
626 do_nv_ident('g', xchar
);
629 #ifdef FEAT_SEARCHPATH
630 case 'f': /* CTRL-W gf: "gf" in a new tab page */
631 case 'F': /* CTRL-W gF: "gF" in a new tab page */
642 default: beep_flush();
648 * split the current window, implements CTRL-W s and :split
650 * "size" is the height or width for the new window, 0 to use half of current
654 * WSP_ROOM: require enough room for new window
655 * WSP_VERT: vertical split.
656 * WSP_TOP: open window at the top-left of the shell (help window).
657 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
658 * WSP_HELP: creating the help window, keep layout snapshot
660 * return FAIL for failure, OK otherwise
663 win_split(size
, flags
)
667 /* When the ":tab" modifier was used open a new tab page instead. */
668 if (may_open_tabpage() == OK
)
671 /* Add flags from ":vertical", ":topleft" and ":botright". */
672 flags
|= cmdmod
.split
;
673 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
675 EMSG(_("E442: Can't split topleft and botright at the same time"));
679 /* When creating the help window make a snapshot of the window layout.
680 * Otherwise clear the snapshot, it's now invalid. */
681 if (flags
& WSP_HELP
)
684 clear_snapshot(curtab
);
686 return win_split_ins(size
, flags
, NULL
, 0);
690 * When "newwin" is NULL: split the current window in two.
691 * When "newwin" is not NULL: insert this window at the far
692 * top/left/right/bottom.
693 * return FAIL for failure, OK otherwise
696 win_split_ins(size
, flags
, newwin
, dir
)
707 int do_equal
= FALSE
;
710 int oldwin_height
= 0;
712 frame_T
*frp
, *curfrp
;
717 else if (flags
& WSP_BOT
)
722 /* add a status line when p_ls == 1 and splitting the first window */
723 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
725 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
730 need_status
= STATUS_HEIGHT
;
734 /* May be needed for the scrollbars that are going to change. */
739 #ifdef FEAT_VERTSPLIT
740 if (flags
& WSP_VERT
)
745 * Check if we are able to split the current window and compute its
749 if (flags
& WSP_ROOM
)
750 needed
+= p_wiw
- p_wmw
;
751 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
753 available
= topframe
->fr_width
;
754 needed
+= frame_minwidth(topframe
, NULL
);
757 available
= oldwin
->w_width
;
758 if (available
< needed
&& newwin
== NULL
)
764 new_size
= oldwin
->w_width
/ 2;
765 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
766 new_size
= oldwin
->w_width
- p_wmw
- 1;
767 if (new_size
< p_wmw
)
770 /* if it doesn't fit in the current window, need win_equal() */
771 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
774 /* We don't like to take lines for the new window from a
775 * 'winfixwidth' window. Take them from a window to the left or right
776 * instead, if possible. */
778 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
780 /* Only make all windows the same width if one of them (except oldwin)
781 * is wider than one of the split windows. */
782 if (!do_equal
&& p_ea
&& size
== 0 && *p_ead
!= 'v'
783 && oldwin
->w_frame
->fr_parent
!= NULL
)
785 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
788 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
789 && (frp
->fr_win
->w_width
> new_size
790 || frp
->fr_win
->w_width
> oldwin
->w_width
791 - new_size
- STATUS_HEIGHT
))
806 * Check if we are able to split the current window and compute its
809 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
810 if (flags
& WSP_ROOM
)
811 needed
+= p_wh
- p_wmh
;
812 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
814 available
= topframe
->fr_height
;
815 needed
+= frame_minheight(topframe
, NULL
);
819 available
= oldwin
->w_height
;
822 if (available
< needed
&& newwin
== NULL
)
827 oldwin_height
= oldwin
->w_height
;
830 oldwin
->w_status_height
= STATUS_HEIGHT
;
831 oldwin_height
-= STATUS_HEIGHT
;
834 new_size
= oldwin_height
/ 2;
836 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
837 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
838 if (new_size
< p_wmh
)
841 /* if it doesn't fit in the current window, need win_equal() */
842 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
845 /* We don't like to take lines for the new window from a
846 * 'winfixheight' window. Take them from a window above or below
847 * instead, if possible. */
850 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
852 oldwin_height
= oldwin
->w_height
;
854 oldwin_height
-= STATUS_HEIGHT
;
857 /* Only make all windows the same height if one of them (except oldwin)
858 * is higher than one of the split windows. */
859 if (!do_equal
&& p_ea
&& size
== 0
860 #ifdef FEAT_VERTSPLIT
863 && oldwin
->w_frame
->fr_parent
!= NULL
)
865 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
868 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
869 && (frp
->fr_win
->w_height
> new_size
870 || frp
->fr_win
->w_height
> oldwin_height
- new_size
882 * allocate new window structure and link it in the window list
884 if ((flags
& WSP_TOP
) == 0
885 && ((flags
& WSP_BOT
)
886 || (flags
& WSP_BELOW
)
887 || (!(flags
& WSP_ABOVE
)
889 #ifdef FEAT_VERTSPLIT
890 (flags
& WSP_VERT
) ? p_spr
:
894 /* new window below/right of current one */
896 wp
= win_alloc(oldwin
);
898 win_append(oldwin
, wp
);
903 wp
= win_alloc(oldwin
->w_prev
);
905 win_append(oldwin
->w_prev
, wp
);
913 /* make the contents of the new window the same as the current one */
914 win_init(wp
, curwin
, flags
);
918 * Reorganise the tree of frames to insert the new window.
920 if (flags
& (WSP_TOP
| WSP_BOT
))
922 #ifdef FEAT_VERTSPLIT
923 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
924 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
926 if (topframe
->fr_layout
== FR_COL
)
929 curfrp
= topframe
->fr_child
;
931 while (curfrp
->fr_next
!= NULL
)
932 curfrp
= curfrp
->fr_next
;
936 before
= (flags
& WSP_TOP
);
940 curfrp
= oldwin
->w_frame
;
941 if (flags
& WSP_BELOW
)
943 else if (flags
& WSP_ABOVE
)
946 #ifdef FEAT_VERTSPLIT
947 if (flags
& WSP_VERT
)
953 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
955 /* Need to create a new frame in the tree to make a branch. */
956 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
958 curfrp
->fr_layout
= layout
;
959 frp
->fr_parent
= curfrp
;
962 curfrp
->fr_child
= frp
;
963 curfrp
->fr_win
= NULL
;
965 if (frp
->fr_win
!= NULL
)
966 oldwin
->w_frame
= frp
;
968 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
969 frp
->fr_parent
= curfrp
;
974 /* Create a frame for the new window. */
975 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
976 frp
->fr_layout
= FR_LEAF
;
981 frp
= newwin
->w_frame
;
982 frp
->fr_parent
= curfrp
->fr_parent
;
984 /* Insert the new frame at the right place in the frame list. */
986 frame_insert(curfrp
, frp
);
988 frame_append(curfrp
, frp
);
990 #ifdef FEAT_VERTSPLIT
991 if (flags
& WSP_VERT
)
993 wp
->w_p_scr
= curwin
->w_p_scr
;
997 oldwin
->w_status_height
= need_status
;
999 if (flags
& (WSP_TOP
| WSP_BOT
))
1001 /* set height and row of new window to full height */
1002 wp
->w_winrow
= tabline_height();
1003 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
1004 wp
->w_status_height
= (p_ls
> 0);
1008 /* height and row of new window is same as current window */
1009 wp
->w_winrow
= oldwin
->w_winrow
;
1010 wp
->w_height
= oldwin
->w_height
;
1011 wp
->w_status_height
= oldwin
->w_status_height
;
1013 frp
->fr_height
= curfrp
->fr_height
;
1015 /* "new_size" of the current window goes to the new window, use
1016 * one column for the vertical separator */
1017 wp
->w_width
= new_size
;
1019 wp
->w_vsep_width
= 1;
1022 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1023 oldwin
->w_vsep_width
= 1;
1025 if (flags
& (WSP_TOP
| WSP_BOT
))
1027 if (flags
& WSP_BOT
)
1028 frame_add_vsep(curfrp
);
1029 /* Set width of neighbor frame */
1030 frame_new_width(curfrp
, curfrp
->fr_width
1031 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
1035 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
1036 if (before
) /* new window left of current one */
1038 wp
->w_wincol
= oldwin
->w_wincol
;
1039 oldwin
->w_wincol
+= new_size
+ 1;
1041 else /* new window right of current one */
1042 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
1043 frame_fix_width(oldwin
);
1044 frame_fix_width(wp
);
1049 /* width and column of new window is same as current window */
1050 #ifdef FEAT_VERTSPLIT
1051 if (flags
& (WSP_TOP
| WSP_BOT
))
1054 wp
->w_width
= Columns
;
1055 wp
->w_vsep_width
= 0;
1059 wp
->w_wincol
= oldwin
->w_wincol
;
1060 wp
->w_width
= oldwin
->w_width
;
1061 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1063 frp
->fr_width
= curfrp
->fr_width
;
1066 /* "new_size" of the current window goes to the new window, use
1067 * one row for the status line */
1068 win_new_height(wp
, new_size
);
1069 if (flags
& (WSP_TOP
| WSP_BOT
))
1070 frame_new_height(curfrp
, curfrp
->fr_height
1071 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1073 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1074 if (before
) /* new window above current one */
1076 wp
->w_winrow
= oldwin
->w_winrow
;
1077 wp
->w_status_height
= STATUS_HEIGHT
;
1078 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1080 else /* new window below current one */
1082 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1083 wp
->w_status_height
= oldwin
->w_status_height
;
1084 oldwin
->w_status_height
= STATUS_HEIGHT
;
1086 #ifdef FEAT_VERTSPLIT
1087 if (flags
& WSP_BOT
)
1088 frame_add_statusline(curfrp
);
1090 frame_fix_height(wp
);
1091 frame_fix_height(oldwin
);
1094 if (flags
& (WSP_TOP
| WSP_BOT
))
1095 (void)win_comp_pos();
1098 * Both windows need redrawing
1100 redraw_win_later(wp
, NOT_VALID
);
1101 wp
->w_redr_status
= TRUE
;
1102 redraw_win_later(oldwin
, NOT_VALID
);
1103 oldwin
->w_redr_status
= TRUE
;
1109 msg_clr_eos_force(); /* Old command/ruler may still be there */
1112 msg_col
= 0; /* put position back at start of line */
1116 * make the new window the current window and redraw
1118 if (do_equal
|| dir
!= 0)
1120 #ifdef FEAT_VERTSPLIT
1121 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1122 : dir
== 'h' ? 'b' :
1126 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1127 * size was given. */
1128 #ifdef FEAT_VERTSPLIT
1129 if (flags
& WSP_VERT
)
1136 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1138 gui_init_which_components(NULL
);
1148 win_enter(wp
, FALSE
);
1149 #ifdef FEAT_VERTSPLIT
1150 if (flags
& WSP_VERT
)
1160 * Initialize window "newp" from window "oldp".
1161 * Used when splitting a window and when creating a new tab page.
1162 * The windows will both edit the same buffer.
1163 * WSP_NEWLOC may be specified in flags to prevent the location list from
1167 win_init(newp
, oldp
, flags
)
1174 newp
->w_buffer
= oldp
->w_buffer
;
1175 oldp
->w_buffer
->b_nwindows
++;
1176 newp
->w_cursor
= oldp
->w_cursor
;
1178 newp
->w_curswant
= oldp
->w_curswant
;
1179 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1180 newp
->w_topline
= oldp
->w_topline
;
1182 newp
->w_topfill
= oldp
->w_topfill
;
1184 newp
->w_leftcol
= oldp
->w_leftcol
;
1185 newp
->w_pcmark
= oldp
->w_pcmark
;
1186 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1187 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1188 newp
->w_wrow
= oldp
->w_wrow
;
1189 newp
->w_fraction
= oldp
->w_fraction
;
1190 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1191 #ifdef FEAT_JUMPLIST
1192 copy_jumplist(oldp
, newp
);
1194 #ifdef FEAT_QUICKFIX
1195 if (flags
& WSP_NEWLOC
)
1197 /* Don't copy the location list. */
1198 newp
->w_llist
= NULL
;
1199 newp
->w_llist_ref
= NULL
;
1202 copy_loclist(oldp
, newp
);
1204 if (oldp
->w_localdir
!= NULL
)
1205 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1207 /* Use the same argument list. */
1208 newp
->w_alist
= oldp
->w_alist
;
1209 ++newp
->w_alist
->al_refcount
;
1210 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1213 * copy tagstack and options from existing window
1215 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1217 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1218 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1219 newp
->w_tagstack
[i
].tagname
=
1220 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1222 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1223 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1224 win_copy_options(oldp
, newp
);
1225 # ifdef FEAT_FOLDING
1226 copyFoldingState(oldp
, newp
);
1230 #endif /* FEAT_WINDOWS */
1232 #if defined(FEAT_WINDOWS) || defined(PROTO)
1234 * Check if "win" is a pointer to an existing window.
1244 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1251 * Return the number of windows.
1259 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1265 * Make "count" windows on the screen.
1266 * Return actual number of windows on the screen.
1267 * Must be called when there is just one window, filling the whole screen
1268 * (excluding the command line).
1271 make_windows(count
, vertical
)
1273 int vertical UNUSED
; /* split windows vertically if TRUE */
1278 #ifdef FEAT_VERTSPLIT
1281 /* Each windows needs at least 'winminwidth' lines and a separator
1283 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1284 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1289 /* Each window needs at least 'winminheight' lines and a status line. */
1290 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1291 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1296 if (count
> maxcount
)
1300 * add status line now, otherwise first window will be too big
1307 * Don't execute autocommands while creating the windows. Must do that
1308 * when putting the buffers in the windows.
1313 /* todo is number of windows left to create */
1314 for (todo
= count
- 1; todo
> 0; --todo
)
1315 #ifdef FEAT_VERTSPLIT
1318 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1319 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1325 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1326 * STATUS_HEIGHT
) / (todo
+ 1)
1327 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1335 /* return actual number of windows */
1336 return (count
- todo
);
1340 * Exchange current and next window
1343 win_exchange(Prenum
)
1352 if (lastwin
== firstwin
) /* just one window */
1359 need_mouse_correct
= TRUE
;
1363 * find window to exchange with
1367 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1368 while (frp
!= NULL
&& --Prenum
> 0)
1371 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1372 frp
= curwin
->w_frame
->fr_next
;
1373 else /* Swap last window in row/col with previous */
1374 frp
= curwin
->w_frame
->fr_prev
;
1376 /* We can only exchange a window with another window, not with a frame
1377 * containing windows. */
1378 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1383 * 1. remove curwin from the list. Remember after which window it was in wp2
1384 * 2. insert curwin before wp in the list
1386 * 3. remove wp from the list
1387 * 4. insert wp after wp2
1388 * 5. exchange the status line height and vsep width.
1390 wp2
= curwin
->w_prev
;
1391 frp2
= curwin
->w_frame
->fr_prev
;
1392 if (wp
->w_prev
!= curwin
)
1394 win_remove(curwin
, NULL
);
1395 frame_remove(curwin
->w_frame
);
1396 win_append(wp
->w_prev
, curwin
);
1397 frame_insert(frp
, curwin
->w_frame
);
1401 win_remove(wp
, NULL
);
1402 frame_remove(wp
->w_frame
);
1403 win_append(wp2
, wp
);
1405 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1407 frame_append(frp2
, wp
->w_frame
);
1409 temp
= curwin
->w_status_height
;
1410 curwin
->w_status_height
= wp
->w_status_height
;
1411 wp
->w_status_height
= temp
;
1412 #ifdef FEAT_VERTSPLIT
1413 temp
= curwin
->w_vsep_width
;
1414 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1415 wp
->w_vsep_width
= temp
;
1417 /* If the windows are not in the same frame, exchange the sizes to avoid
1418 * messing up the window layout. Otherwise fix the frame sizes. */
1419 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1421 temp
= curwin
->w_height
;
1422 curwin
->w_height
= wp
->w_height
;
1423 wp
->w_height
= temp
;
1424 temp
= curwin
->w_width
;
1425 curwin
->w_width
= wp
->w_width
;
1430 frame_fix_height(curwin
);
1431 frame_fix_height(wp
);
1432 frame_fix_width(curwin
);
1433 frame_fix_width(wp
);
1437 (void)win_comp_pos(); /* recompute window positions */
1439 win_enter(wp
, TRUE
);
1440 redraw_later(CLEAR
);
1444 * rotate windows: if upwards TRUE the second window becomes the first one
1445 * if upwards FALSE the first window becomes the second one
1448 win_rotate(upwards
, count
)
1457 if (firstwin
== lastwin
) /* nothing to do */
1464 need_mouse_correct
= TRUE
;
1467 #ifdef FEAT_VERTSPLIT
1468 /* Check if all frames in this row/col have one window. */
1469 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1471 if (frp
->fr_win
== NULL
)
1473 EMSG(_("E443: Cannot rotate when another window is split"));
1480 if (upwards
) /* first window becomes last window */
1482 /* remove first window/frame from the list */
1483 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1485 win_remove(wp1
, NULL
);
1488 /* find last frame and append removed window/frame after it */
1489 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1491 win_append(frp
->fr_win
, wp1
);
1492 frame_append(frp
, wp1
->w_frame
);
1494 wp2
= frp
->fr_win
; /* previously last window */
1496 else /* last window becomes first window */
1498 /* find last window/frame in the list and remove it */
1499 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1503 wp2
= wp1
->w_prev
; /* will become last window */
1504 win_remove(wp1
, NULL
);
1507 /* append the removed window/frame before the first in the list */
1508 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1509 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1512 /* exchange status height and vsep width of old and new last window */
1513 n
= wp2
->w_status_height
;
1514 wp2
->w_status_height
= wp1
->w_status_height
;
1515 wp1
->w_status_height
= n
;
1516 frame_fix_height(wp1
);
1517 frame_fix_height(wp2
);
1518 #ifdef FEAT_VERTSPLIT
1519 n
= wp2
->w_vsep_width
;
1520 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1521 wp1
->w_vsep_width
= n
;
1522 frame_fix_width(wp1
);
1523 frame_fix_width(wp2
);
1526 /* recompute w_winrow and w_wincol for all windows */
1527 (void)win_comp_pos();
1530 redraw_later(CLEAR
);
1534 * Move the current window to the very top/bottom/left/right of the screen.
1537 win_totop(size
, flags
)
1542 int height
= curwin
->w_height
;
1544 if (lastwin
== firstwin
)
1550 /* Remove the window and frame from the tree of frames. */
1551 (void)winframe_remove(curwin
, &dir
, NULL
);
1552 win_remove(curwin
, NULL
);
1553 last_status(FALSE
); /* may need to remove last status line */
1554 (void)win_comp_pos(); /* recompute window positions */
1556 /* Split a window on the desired side and put the window there. */
1557 (void)win_split_ins(size
, flags
, curwin
, dir
);
1558 if (!(flags
& WSP_VERT
))
1560 win_setheight(height
);
1562 win_equal(curwin
, TRUE
, 'v');
1565 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1566 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1567 * scrollbars. Have to update them anyway. */
1571 gui_init_which_components(NULL
);
1572 gui_update_scrollbars(TRUE
);
1574 need_mouse_correct
= TRUE
;
1580 * Move window "win1" to below/right of "win2" and make "win1" the current
1581 * window. Only works within the same frame!
1584 win_move_after(win1
, win2
)
1589 /* check if the arguments are reasonable */
1593 /* check if there is something to do */
1594 if (win2
->w_next
!= win1
)
1596 /* may need move the status line/vertical separator of the last window
1598 if (win1
== lastwin
)
1600 height
= win1
->w_prev
->w_status_height
;
1601 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1602 win1
->w_status_height
= height
;
1603 #ifdef FEAT_VERTSPLIT
1604 if (win1
->w_prev
->w_vsep_width
== 1)
1606 /* Remove the vertical separator from the last-but-one window,
1607 * add it to the last window. Adjust the frame widths. */
1608 win1
->w_prev
->w_vsep_width
= 0;
1609 win1
->w_prev
->w_frame
->fr_width
-= 1;
1610 win1
->w_vsep_width
= 1;
1611 win1
->w_frame
->fr_width
+= 1;
1615 else if (win2
== lastwin
)
1617 height
= win1
->w_status_height
;
1618 win1
->w_status_height
= win2
->w_status_height
;
1619 win2
->w_status_height
= height
;
1620 #ifdef FEAT_VERTSPLIT
1621 if (win1
->w_vsep_width
== 1)
1623 /* Remove the vertical separator from win1, add it to the last
1624 * window, win2. Adjust the frame widths. */
1625 win2
->w_vsep_width
= 1;
1626 win2
->w_frame
->fr_width
+= 1;
1627 win1
->w_vsep_width
= 0;
1628 win1
->w_frame
->fr_width
-= 1;
1632 win_remove(win1
, NULL
);
1633 frame_remove(win1
->w_frame
);
1634 win_append(win2
, win1
);
1635 frame_append(win2
->w_frame
, win1
->w_frame
);
1637 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1638 redraw_later(NOT_VALID
);
1640 win_enter(win1
, FALSE
);
1644 * Make all windows the same height.
1645 * 'next_curwin' will soon be the current window, make sure it has enough
1649 win_equal(next_curwin
, current
, dir
)
1650 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1651 int current
; /* do only frame with current window */
1652 int dir
; /* 'v' for vertically, 'h' for horizontally,
1653 'b' for both, 0 for using p_ead */
1656 #ifdef FEAT_VERTSPLIT
1661 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1662 topframe
, dir
, 0, tabline_height(),
1663 (int)Columns
, topframe
->fr_height
);
1667 * Set a frame to a new position and height, spreading the available room
1668 * equally over contained frames.
1669 * The window "next_curwin" (if not NULL) should at least get the size from
1670 * 'winheight' and 'winwidth' if possible.
1673 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1674 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1675 int current
; /* do only frame with current window */
1676 frame_T
*topfr
; /* frame to set size off */
1677 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1678 int col
; /* horizontal position for frame */
1679 int row
; /* vertical position for frame */
1680 int width
; /* new width of frame */
1681 int height
; /* new height of frame */
1685 int wincount
, totwincount
= 0;
1687 int next_curwin_size
= 0;
1690 int has_next_curwin
= 0;
1693 if (topfr
->fr_layout
== FR_LEAF
)
1695 /* Set the width/height of this frame.
1696 * Redraw when size or position changes */
1697 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1698 #ifdef FEAT_VERTSPLIT
1699 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1703 topfr
->fr_win
->w_winrow
= row
;
1704 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1705 #ifdef FEAT_VERTSPLIT
1706 topfr
->fr_win
->w_wincol
= col
;
1707 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1709 redraw_all_later(CLEAR
);
1712 #ifdef FEAT_VERTSPLIT
1713 else if (topfr
->fr_layout
== FR_ROW
)
1715 topfr
->fr_width
= width
;
1716 topfr
->fr_height
= height
;
1718 if (dir
!= 'v') /* equalize frame widths */
1720 /* Compute the maximum number of windows horizontally in this
1722 n
= frame_minwidth(topfr
, NOWIN
);
1723 /* add one for the rightmost window, it doesn't have a separator */
1724 if (col
+ width
== Columns
)
1728 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1729 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1732 * Compute width for "next_curwin" window and room available for
1734 * "m" is the minimal width when counting p_wiw for "next_curwin".
1736 m
= frame_minwidth(topfr
, next_curwin
);
1740 next_curwin_size
= p_wiw
+ room
;
1745 next_curwin_size
= -1;
1746 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1748 /* If 'winfixwidth' set keep the window width if
1750 * Watch out for this window being the next_curwin. */
1751 if (frame_fixed_width(fr
))
1753 n
= frame_minwidth(fr
, NOWIN
);
1754 new_size
= fr
->fr_width
;
1755 if (frame_has_win(fr
, next_curwin
))
1757 room
+= p_wiw
- p_wmw
;
1758 next_curwin_size
= 0;
1759 if (new_size
< p_wiw
)
1763 /* These windows don't use up room. */
1764 totwincount
-= (n
+ (fr
->fr_next
== NULL
1765 ? extra_sep
: 0)) / (p_wmw
+ 1);
1766 room
-= new_size
- n
;
1772 fr
->fr_newwidth
= new_size
;
1775 if (next_curwin_size
== -1)
1777 if (!has_next_curwin
)
1778 next_curwin_size
= 0;
1779 else if (totwincount
> 1
1780 && (room
+ (totwincount
- 2))
1781 / (totwincount
- 1) > p_wiw
)
1783 /* Can make all windows wider than 'winwidth', spread
1784 * the room equally. */
1785 next_curwin_size
= (room
+ p_wiw
1786 + (totwincount
- 1) * p_wmw
1787 + (totwincount
- 1)) / totwincount
;
1788 room
-= next_curwin_size
- p_wiw
;
1791 next_curwin_size
= p_wiw
;
1795 if (has_next_curwin
)
1796 --totwincount
; /* don't count curwin */
1799 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1803 if (fr
->fr_next
== NULL
)
1804 /* last frame gets all that remains (avoid roundoff error) */
1806 else if (dir
== 'v')
1807 new_size
= fr
->fr_width
;
1808 else if (frame_fixed_width(fr
))
1810 new_size
= fr
->fr_newwidth
;
1811 wincount
= 0; /* doesn't count as a sizeable window */
1815 /* Compute the maximum number of windows horiz. in "fr". */
1816 n
= frame_minwidth(fr
, NOWIN
);
1817 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1819 m
= frame_minwidth(fr
, next_curwin
);
1820 if (has_next_curwin
)
1821 hnc
= frame_has_win(fr
, next_curwin
);
1824 if (hnc
) /* don't count next_curwin */
1826 if (totwincount
== 0)
1829 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1831 if (hnc
) /* add next_curwin size */
1833 next_curwin_size
-= p_wiw
- (m
- n
);
1834 new_size
+= next_curwin_size
;
1835 room
-= new_size
- next_curwin_size
;
1842 /* Skip frame that is full width when splitting or closing a
1843 * window, unless equalizing all frames. */
1844 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1845 || (new_size
!= fr
->fr_width
)
1846 || frame_has_win(fr
, next_curwin
))
1847 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1851 totwincount
-= wincount
;
1855 else /* topfr->fr_layout == FR_COL */
1857 #ifdef FEAT_VERTSPLIT
1858 topfr
->fr_width
= width
;
1860 topfr
->fr_height
= height
;
1862 if (dir
!= 'h') /* equalize frame heights */
1864 /* Compute maximum number of windows vertically in this frame. */
1865 n
= frame_minheight(topfr
, NOWIN
);
1866 /* add one for the bottom window if it doesn't have a statusline */
1867 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1871 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1872 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1875 * Compute height for "next_curwin" window and room available for
1877 * "m" is the minimal height when counting p_wh for "next_curwin".
1879 m
= frame_minheight(topfr
, next_curwin
);
1883 /* The room is less then 'winheight', use all space for the
1884 * current window. */
1885 next_curwin_size
= p_wh
+ room
;
1890 next_curwin_size
= -1;
1891 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1893 /* If 'winfixheight' set keep the window height if
1895 * Watch out for this window being the next_curwin. */
1896 if (frame_fixed_height(fr
))
1898 n
= frame_minheight(fr
, NOWIN
);
1899 new_size
= fr
->fr_height
;
1900 if (frame_has_win(fr
, next_curwin
))
1902 room
+= p_wh
- p_wmh
;
1903 next_curwin_size
= 0;
1904 if (new_size
< p_wh
)
1908 /* These windows don't use up room. */
1909 totwincount
-= (n
+ (fr
->fr_next
== NULL
1910 ? extra_sep
: 0)) / (p_wmh
+ 1);
1911 room
-= new_size
- n
;
1917 fr
->fr_newheight
= new_size
;
1920 if (next_curwin_size
== -1)
1922 if (!has_next_curwin
)
1923 next_curwin_size
= 0;
1924 else if (totwincount
> 1
1925 && (room
+ (totwincount
- 2))
1926 / (totwincount
- 1) > p_wh
)
1928 /* can make all windows higher than 'winheight',
1929 * spread the room equally. */
1930 next_curwin_size
= (room
+ p_wh
1931 + (totwincount
- 1) * p_wmh
1932 + (totwincount
- 1)) / totwincount
;
1933 room
-= next_curwin_size
- p_wh
;
1936 next_curwin_size
= p_wh
;
1940 if (has_next_curwin
)
1941 --totwincount
; /* don't count curwin */
1944 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1948 if (fr
->fr_next
== NULL
)
1949 /* last frame gets all that remains (avoid roundoff error) */
1951 else if (dir
== 'h')
1952 new_size
= fr
->fr_height
;
1953 else if (frame_fixed_height(fr
))
1955 new_size
= fr
->fr_newheight
;
1956 wincount
= 0; /* doesn't count as a sizeable window */
1960 /* Compute the maximum number of windows vert. in "fr". */
1961 n
= frame_minheight(fr
, NOWIN
);
1962 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1964 m
= frame_minheight(fr
, next_curwin
);
1965 if (has_next_curwin
)
1966 hnc
= frame_has_win(fr
, next_curwin
);
1969 if (hnc
) /* don't count next_curwin */
1971 if (totwincount
== 0)
1974 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1976 if (hnc
) /* add next_curwin size */
1978 next_curwin_size
-= p_wh
- (m
- n
);
1979 new_size
+= next_curwin_size
;
1980 room
-= new_size
- next_curwin_size
;
1986 /* Skip frame that is full width when splitting or closing a
1987 * window, unless equalizing all frames. */
1988 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1989 || (new_size
!= fr
->fr_height
)
1990 || frame_has_win(fr
, next_curwin
))
1991 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1995 totwincount
-= wincount
;
2001 * close all windows for buffer 'buf'
2004 close_windows(buf
, keep_curwin
)
2006 int keep_curwin
; /* don't close "curwin" */
2009 tabpage_T
*tp
, *nexttp
;
2010 int h
= tabline_height();
2012 ++RedrawingDisabled
;
2014 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2016 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2018 win_close(wp
, FALSE
);
2020 /* Start all over, autocommands may change the window layout. */
2027 /* Also check windows in other tab pages. */
2028 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2030 nexttp
= tp
->tp_next
;
2032 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2033 if (wp
->w_buffer
== buf
)
2035 win_close_othertab(wp
, FALSE
, tp
);
2037 /* Start all over, the tab page may be closed and
2038 * autocommands may change the window layout. */
2039 nexttp
= first_tabpage
;
2044 --RedrawingDisabled
;
2046 if (h
!= tabline_height())
2051 * Return TRUE if the current window is the only window that exists.
2052 * Returns FALSE if there is a window, possibly in another tab page.
2057 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2061 * Close window "win". Only works for the current tab page.
2062 * If "free_buf" is TRUE related buffer may be unloaded.
2064 * called by :quit, :close, :xit, :wq and findtag()
2067 win_close(win
, free_buf
)
2073 int other_buffer
= FALSE
;
2075 int close_curwin
= FALSE
;
2077 int help_window
= FALSE
;
2078 tabpage_T
*prev_curtab
= curtab
;
2082 EMSG(_("E444: Cannot close last window"));
2087 * When closing the last window in a tab page first go to another tab
2088 * page and then close the window and the tab page. This avoids that
2089 * curwin and curtab are not invalid while we are freeing memory, they may
2090 * be used in GUI events.
2092 if (firstwin
== lastwin
)
2094 goto_tabpage_tp(alt_tabpage());
2095 redraw_tabline
= TRUE
;
2097 /* Safety check: Autocommands may have closed the window when jumping
2098 * to the other tab page. */
2099 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2101 int h
= tabline_height();
2103 win_close_othertab(win
, free_buf
, prev_curtab
);
2104 if (h
!= tabline_height())
2110 /* When closing the help window, try restoring a snapshot after closing
2111 * the window. Otherwise clear the snapshot, it's now invalid. */
2112 if (win
->w_buffer
->b_help
)
2115 clear_snapshot(curtab
);
2121 * Guess which window is going to be the new current window.
2122 * This may change because of the autocommands (sigh).
2124 wp
= frame2win(win_altframe(win
, NULL
));
2127 * Be careful: If autocommands delete the window, return now.
2129 if (wp
->w_buffer
!= curbuf
)
2131 other_buffer
= TRUE
;
2132 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2133 if (!win_valid(win
) || last_window())
2136 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2137 if (!win_valid(win
) || last_window())
2140 /* autocmds may abort script processing */
2148 /* Avoid trouble with scrollbars that are going to be deleted in
2155 * Close the link to the buffer.
2157 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2159 /* Autocommands may have closed the window already, or closed the only
2160 * other window or moved to another tab page. */
2161 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2164 /* Free the memory used for the window. */
2165 wp
= win_free_mem(win
, &dir
, NULL
);
2167 /* Make sure curwin isn't invalid. It can cause severe trouble when
2168 * printing an error message. For win_equal() curbuf needs to be valid
2173 #ifdef FEAT_QUICKFIX
2174 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2177 * If the cursor goes to the preview or the quickfix window, try
2178 * finding another window to go to.
2182 if (wp
->w_next
== NULL
)
2188 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2196 curbuf
= curwin
->w_buffer
;
2197 close_curwin
= TRUE
;
2200 #ifdef FEAT_VERTSPLIT
2201 && (*p_ead
== 'b' || *p_ead
== dir
)
2204 win_equal(curwin
, TRUE
,
2205 #ifdef FEAT_VERTSPLIT
2215 win_enter_ext(wp
, FALSE
, TRUE
);
2218 /* careful: after this wp and win may be invalid! */
2219 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2224 * If last window has a status line now and we don't want one,
2225 * remove the status line.
2229 /* After closing the help window, try restoring the window layout from
2230 * before it was opened. */
2232 restore_snapshot(close_curwin
);
2234 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2235 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2236 if (gui
.in_use
&& !win_hasvertsplit())
2237 gui_init_which_components(NULL
);
2240 redraw_all_later(NOT_VALID
);
2244 * Close window "win" in tab page "tp", which is not the current tab page.
2245 * This may be the last window ih that tab page and result in closing the tab,
2246 * thus "tp" may become invalid!
2247 * Caller must check if buffer is hidden and whether the tabline needs to be
2251 win_close_othertab(win
, free_buf
, tp
)
2258 tabpage_T
*ptp
= NULL
;
2260 /* Close the link to the buffer. */
2261 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2263 /* Careful: Autocommands may have closed the tab page or made it the
2264 * current tab page. */
2265 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2267 if (ptp
== NULL
|| tp
== curtab
)
2270 /* Autocommands may have closed the window already. */
2271 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2276 /* Free the memory used for the window. */
2277 wp
= win_free_mem(win
, &dir
, tp
);
2279 /* When closing the last window in a tab page remove the tab page. */
2282 if (tp
== first_tabpage
)
2283 first_tabpage
= tp
->tp_next
;
2286 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2291 EMSG2(_(e_intern2
), "win_close_othertab()");
2294 ptp
->tp_next
= tp
->tp_next
;
2301 * Free the memory used for a window.
2302 * Returns a pointer to the window that got the freed up space.
2305 win_free_mem(win
, dirp
, tp
)
2307 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2308 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2317 /* reduce the reference count to the argument list. */
2318 alist_unlink(win
->w_alist
);
2320 /* Remove the window and its frame from the tree of frames. */
2322 wp
= winframe_remove(win
, dirp
, tp
);
2326 /* When deleting the current window of another tab page select a new
2327 * current window. */
2328 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2334 #if defined(EXITFREE) || defined(PROTO)
2340 # ifdef FEAT_WINDOWS
2341 while (first_tabpage
->tp_next
!= NULL
)
2342 tabpage_close(TRUE
);
2345 while (firstwin
!= NULL
)
2346 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2351 * Remove a window and its frame from the tree of frames.
2352 * Returns a pointer to the window that got the freed up space.
2355 winframe_remove(win
, dirp
, tp
)
2357 int *dirp UNUSED
; /* set to 'v' or 'h' for direction if 'ea' */
2358 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2360 frame_T
*frp
, *frp2
, *frp3
;
2361 frame_T
*frp_close
= win
->w_frame
;
2365 * If there is only one window there is nothing to remove.
2367 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2371 * Remove the window from its frame.
2373 frp2
= win_altframe(win
, tp
);
2374 wp
= frame2win(frp2
);
2376 /* Remove this frame from the list of frames. */
2377 frame_remove(frp_close
);
2379 #ifdef FEAT_VERTSPLIT
2380 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2383 /* When 'winfixheight' is set, try to find another frame in the column
2384 * (as close to the closed frame as possible) to distribute the height
2386 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2388 frp
= frp_close
->fr_prev
;
2389 frp3
= frp_close
->fr_next
;
2390 while (frp
!= NULL
|| frp3
!= NULL
)
2394 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2404 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2410 frp3
= frp3
->fr_next
;
2414 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2415 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2416 #ifdef FEAT_VERTSPLIT
2421 /* When 'winfixwidth' is set, try to find another frame in the column
2422 * (as close to the closed frame as possible) to distribute the width
2424 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2426 frp
= frp_close
->fr_prev
;
2427 frp3
= frp_close
->fr_next
;
2428 while (frp
!= NULL
|| frp3
!= NULL
)
2432 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2442 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2448 frp3
= frp3
->fr_next
;
2452 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2453 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2458 /* If rows/columns go to a window below/right its positions need to be
2459 * updated. Can only be done after the sizes have been updated. */
2460 if (frp2
== frp_close
->fr_next
)
2462 int row
= win
->w_winrow
;
2463 int col
= W_WINCOL(win
);
2465 frame_comp_pos(frp2
, &row
, &col
);
2468 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2470 /* There is no other frame in this list, move its info to the parent
2472 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2473 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2474 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2475 frp
->fr_parent
= frp2
->fr_parent
;
2476 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2477 if (frp2
->fr_win
!= NULL
)
2478 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2479 frp
= frp2
->fr_parent
;
2482 frp2
= frp
->fr_parent
;
2483 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2485 /* The frame above the parent has the same layout, have to merge
2486 * the frames into this list. */
2487 if (frp2
->fr_child
== frp
)
2488 frp2
->fr_child
= frp
->fr_child
;
2489 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2490 if (frp
->fr_prev
!= NULL
)
2491 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2492 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2494 frp3
->fr_parent
= frp2
;
2495 if (frp3
->fr_next
== NULL
)
2497 frp3
->fr_next
= frp
->fr_next
;
2498 if (frp
->fr_next
!= NULL
)
2499 frp
->fr_next
->fr_prev
= frp3
;
2511 * Find out which frame is going to get the freed up space when "win" is
2513 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2514 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2515 * This makes opening a window and closing it immediately keep the same window
2519 win_altframe(win
, tp
)
2521 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2526 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2527 /* Last window in this tab page, will go to next tab page. */
2528 return alt_tabpage()->tp_curwin
->w_frame
;
2531 #ifdef FEAT_VERTSPLIT
2532 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2537 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2538 return frp
->fr_next
;
2539 return frp
->fr_prev
;
2543 * Return the tabpage that will be used if the current one is closed.
2550 /* Use the next tab page if possible. */
2551 if (curtab
->tp_next
!= NULL
)
2552 return curtab
->tp_next
;
2554 /* Find the last but one tab page. */
2555 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2561 * Find the left-upper window in frame "frp".
2567 while (frp
->fr_win
== NULL
)
2568 frp
= frp
->fr_child
;
2573 * Return TRUE if frame "frp" contains window "wp".
2576 frame_has_win(frp
, wp
)
2582 if (frp
->fr_layout
== FR_LEAF
)
2583 return frp
->fr_win
== wp
;
2585 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2586 if (frame_has_win(p
, wp
))
2592 * Set a new height for a frame. Recursively sets the height for contained
2593 * frames and windows. Caller must take care of positions.
2596 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2599 int topfirst
; /* resize topmost contained frame first */
2600 int wfh
; /* obey 'winfixheight' when there is a choice;
2601 may cause the height not to be set */
2607 if (topfrp
->fr_win
!= NULL
)
2609 /* Simple case: just one window. */
2610 win_new_height(topfrp
->fr_win
,
2611 height
- topfrp
->fr_win
->w_status_height
);
2613 #ifdef FEAT_VERTSPLIT
2614 else if (topfrp
->fr_layout
== FR_ROW
)
2618 /* All frames in this row get the same new height. */
2619 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2621 frame_new_height(frp
, height
, topfirst
, wfh
);
2622 if (frp
->fr_height
> height
)
2624 /* Could not fit the windows, make the whole row higher. */
2625 height
= frp
->fr_height
;
2630 while (frp
!= NULL
);
2633 else /* fr_layout == FR_COL */
2635 /* Complicated case: Resize a column of frames. Resize the bottom
2636 * frame first, frames above that when needed. */
2638 frp
= topfrp
->fr_child
;
2640 /* Advance past frames with one window with 'wfh' set. */
2641 while (frame_fixed_height(frp
))
2645 return; /* no frame without 'wfh', give up */
2649 /* Find the bottom frame of this column */
2650 while (frp
->fr_next
!= NULL
)
2653 /* Advance back for frames with one window with 'wfh' set. */
2654 while (frame_fixed_height(frp
))
2658 extra_lines
= height
- topfrp
->fr_height
;
2659 if (extra_lines
< 0)
2661 /* reduce height of contained frames, bottom or top frame first */
2664 h
= frame_minheight(frp
, NULL
);
2665 if (frp
->fr_height
+ extra_lines
< h
)
2667 extra_lines
+= frp
->fr_height
- h
;
2668 frame_new_height(frp
, h
, topfirst
, wfh
);
2672 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2680 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2686 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2688 /* Increase "height" if we could not reduce enough frames. */
2690 height
-= extra_lines
;
2693 else if (extra_lines
> 0)
2695 /* increase height of bottom or top frame */
2696 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2699 topfrp
->fr_height
= height
;
2703 * Return TRUE if height of frame "frp" should not be changed because of
2704 * the 'winfixheight' option.
2707 frame_fixed_height(frp
)
2710 /* frame with one window: fixed height if 'winfixheight' set. */
2711 if (frp
->fr_win
!= NULL
)
2712 return frp
->fr_win
->w_p_wfh
;
2714 if (frp
->fr_layout
== FR_ROW
)
2716 /* The frame is fixed height if one of the frames in the row is fixed
2718 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2719 if (frame_fixed_height(frp
))
2724 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2725 * frames in the row are fixed height. */
2726 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2727 if (!frame_fixed_height(frp
))
2732 #ifdef FEAT_VERTSPLIT
2734 * Return TRUE if width of frame "frp" should not be changed because of
2735 * the 'winfixwidth' option.
2738 frame_fixed_width(frp
)
2741 /* frame with one window: fixed width if 'winfixwidth' set. */
2742 if (frp
->fr_win
!= NULL
)
2743 return frp
->fr_win
->w_p_wfw
;
2745 if (frp
->fr_layout
== FR_COL
)
2747 /* The frame is fixed width if one of the frames in the row is fixed
2749 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2750 if (frame_fixed_width(frp
))
2755 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2756 * frames in the row are fixed width. */
2757 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2758 if (!frame_fixed_width(frp
))
2764 * Add a status line to windows at the bottom of "frp".
2765 * Note: Does not check if there is room!
2768 frame_add_statusline(frp
)
2773 if (frp
->fr_layout
== FR_LEAF
)
2776 if (wp
->w_status_height
== 0)
2778 if (wp
->w_height
> 0) /* don't make it negative */
2780 wp
->w_status_height
= STATUS_HEIGHT
;
2783 else if (frp
->fr_layout
== FR_ROW
)
2785 /* Handle all the frames in the row. */
2786 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2787 frame_add_statusline(frp
);
2789 else /* frp->fr_layout == FR_COL */
2791 /* Only need to handle the last frame in the column. */
2792 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2794 frame_add_statusline(frp
);
2799 * Set width of a frame. Handles recursively going through contained frames.
2800 * May remove separator line for windows at the right side (for win_close()).
2803 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2806 int leftfirst
; /* resize leftmost contained frame first */
2807 int wfw
; /* obey 'winfixwidth' when there is a choice;
2808 may cause the width not to be set */
2815 if (topfrp
->fr_layout
== FR_LEAF
)
2817 /* Simple case: just one window. */
2818 wp
= topfrp
->fr_win
;
2819 /* Find out if there are any windows right of this one. */
2820 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2821 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2823 if (frp
->fr_parent
== NULL
)
2824 wp
->w_vsep_width
= 0;
2825 win_new_width(wp
, width
- wp
->w_vsep_width
);
2827 else if (topfrp
->fr_layout
== FR_COL
)
2831 /* All frames in this column get the same new width. */
2832 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2834 frame_new_width(frp
, width
, leftfirst
, wfw
);
2835 if (frp
->fr_width
> width
)
2837 /* Could not fit the windows, make whole column wider. */
2838 width
= frp
->fr_width
;
2842 } while (frp
!= NULL
);
2844 else /* fr_layout == FR_ROW */
2846 /* Complicated case: Resize a row of frames. Resize the rightmost
2847 * frame first, frames left of it when needed. */
2849 frp
= topfrp
->fr_child
;
2851 /* Advance past frames with one window with 'wfw' set. */
2852 while (frame_fixed_width(frp
))
2856 return; /* no frame without 'wfw', give up */
2860 /* Find the rightmost frame of this row */
2861 while (frp
->fr_next
!= NULL
)
2864 /* Advance back for frames with one window with 'wfw' set. */
2865 while (frame_fixed_width(frp
))
2869 extra_cols
= width
- topfrp
->fr_width
;
2872 /* reduce frame width, rightmost frame first */
2875 w
= frame_minwidth(frp
, NULL
);
2876 if (frp
->fr_width
+ extra_cols
< w
)
2878 extra_cols
+= frp
->fr_width
- w
;
2879 frame_new_width(frp
, w
, leftfirst
, wfw
);
2883 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2891 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2897 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2899 /* Increase "width" if we could not reduce enough frames. */
2901 width
-= extra_cols
;
2904 else if (extra_cols
> 0)
2906 /* increase width of rightmost frame */
2907 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2910 topfrp
->fr_width
= width
;
2914 * Add the vertical separator to windows at the right side of "frp".
2915 * Note: Does not check if there is room!
2923 if (frp
->fr_layout
== FR_LEAF
)
2926 if (wp
->w_vsep_width
== 0)
2928 if (wp
->w_width
> 0) /* don't make it negative */
2930 wp
->w_vsep_width
= 1;
2933 else if (frp
->fr_layout
== FR_COL
)
2935 /* Handle all the frames in the column. */
2936 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2937 frame_add_vsep(frp
);
2939 else /* frp->fr_layout == FR_ROW */
2941 /* Only need to handle the last frame in the row. */
2942 frp
= frp
->fr_child
;
2943 while (frp
->fr_next
!= NULL
)
2945 frame_add_vsep(frp
);
2950 * Set frame width from the window it contains.
2956 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2961 * Set frame height from the window it contains.
2964 frame_fix_height(wp
)
2967 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2971 * Compute the minimal height for frame "topfrp".
2972 * Uses the 'winminheight' option.
2973 * When "next_curwin" isn't NULL, use p_wh for this window.
2974 * When "next_curwin" is NOWIN, don't use at least one line for the current
2978 frame_minheight(topfrp
, next_curwin
)
2984 #ifdef FEAT_VERTSPLIT
2988 if (topfrp
->fr_win
!= NULL
)
2990 if (topfrp
->fr_win
== next_curwin
)
2991 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2994 /* window: minimal height of the window plus status line */
2995 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2996 /* Current window is minimal one line high */
2997 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3001 #ifdef FEAT_VERTSPLIT
3002 else if (topfrp
->fr_layout
== FR_ROW
)
3004 /* get the minimal height from each frame in this row */
3006 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3008 n
= frame_minheight(frp
, next_curwin
);
3016 /* Add up the minimal heights for all frames in this column. */
3018 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3019 m
+= frame_minheight(frp
, next_curwin
);
3025 #ifdef FEAT_VERTSPLIT
3027 * Compute the minimal width for frame "topfrp".
3028 * When "next_curwin" isn't NULL, use p_wiw for this window.
3029 * When "next_curwin" is NOWIN, don't use at least one column for the current
3033 frame_minwidth(topfrp
, next_curwin
)
3035 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3040 if (topfrp
->fr_win
!= NULL
)
3042 if (topfrp
->fr_win
== next_curwin
)
3043 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3046 /* window: minimal width of the window plus separator column */
3047 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3048 /* Current window is minimal one column wide */
3049 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3053 else if (topfrp
->fr_layout
== FR_COL
)
3055 /* get the minimal width from each frame in this column */
3057 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3059 n
= frame_minwidth(frp
, next_curwin
);
3066 /* Add up the minimal widths for all frames in this row. */
3068 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3069 m
+= frame_minwidth(frp
, next_curwin
);
3078 * Try to close all windows except current one.
3079 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3080 * used and the buffer was modified.
3082 * Used by ":bdel" and ":only".
3085 close_others(message
, forceit
)
3087 int forceit
; /* always hide all other windows */
3093 if (lastwin
== firstwin
)
3104 /* Be very careful here: autocommands may change the window layout. */
3105 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3107 nextwp
= wp
->w_next
;
3108 if (wp
!= curwin
) /* don't close current window */
3111 /* Check if it's allowed to abandon this window */
3112 r
= can_abandon(wp
->w_buffer
, forceit
);
3114 if (!win_valid(wp
)) /* autocommands messed wp up */
3122 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3123 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3125 dialog_changed(wp
->w_buffer
, FALSE
);
3126 # ifdef FEAT_AUTOCMD
3127 if (!win_valid(wp
)) /* autocommands messed wp up */
3134 if (bufIsChanged(wp
->w_buffer
))
3138 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3142 if (message
&& lastwin
!= firstwin
)
3143 EMSG(_("E445: Other window contains changes"));
3146 #endif /* FEAT_WINDOWS */
3149 * Init the current window "curwin".
3150 * Called when a new file is being edited.
3155 redraw_win_later(curwin
, NOT_VALID
);
3156 curwin
->w_lines_valid
= 0;
3157 curwin
->w_cursor
.lnum
= 1;
3158 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3159 #ifdef FEAT_VIRTUALEDIT
3160 curwin
->w_cursor
.coladd
= 0;
3162 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3163 curwin
->w_pcmark
.col
= 0;
3164 curwin
->w_prev_pcmark
.lnum
= 0;
3165 curwin
->w_prev_pcmark
.col
= 0;
3166 curwin
->w_topline
= 1;
3168 curwin
->w_topfill
= 0;
3170 curwin
->w_botline
= 2;
3173 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3175 curwin
->w_farsi
= W_CONV
;
3180 * Allocate the first window and put an empty buffer in it.
3181 * Called from main().
3182 * Return FAIL when something goes wrong (out of memory).
3187 if (win_alloc_firstwin(NULL
) == FAIL
)
3191 first_tabpage
= alloc_tabpage();
3192 if (first_tabpage
== NULL
)
3194 first_tabpage
->tp_topframe
= topframe
;
3195 curtab
= first_tabpage
;
3201 * Allocate the first window or the first window in a new tab page.
3202 * When "oldwin" is NULL create an empty buffer for it.
3203 * When "oldwin" is not NULL copy info from it to the new window (only with
3205 * Return FAIL when something goes wrong (out of memory).
3208 win_alloc_firstwin(oldwin
)
3211 curwin
= win_alloc(NULL
);
3214 /* Very first window, need to create an empty buffer for it and
3215 * initialize from scratch. */
3216 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3217 if (curwin
== NULL
|| curbuf
== NULL
)
3219 curwin
->w_buffer
= curbuf
;
3220 curbuf
->b_nwindows
= 1; /* there is one window */
3222 curwin
->w_alist
= &global_alist
;
3224 curwin_init(); /* init current window */
3229 /* First window in new tab page, initialize it from "oldwin". */
3230 win_init(curwin
, oldwin
, 0);
3232 # ifdef FEAT_SCROLLBIND
3233 /* We don't want scroll-binding in the first window. */
3234 curwin
->w_p_scb
= FALSE
;
3239 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3240 if (topframe
== NULL
)
3242 topframe
->fr_layout
= FR_LEAF
;
3243 #ifdef FEAT_VERTSPLIT
3244 topframe
->fr_width
= Columns
;
3246 topframe
->fr_height
= Rows
- p_ch
;
3247 topframe
->fr_win
= curwin
;
3248 curwin
->w_frame
= topframe
;
3254 * Initialize the window and frame size to the maximum.
3259 firstwin
->w_height
= ROWS_AVAIL
;
3260 topframe
->fr_height
= ROWS_AVAIL
;
3261 #ifdef FEAT_VERTSPLIT
3262 firstwin
->w_width
= Columns
;
3263 topframe
->fr_width
= Columns
;
3267 #if defined(FEAT_WINDOWS) || defined(PROTO)
3270 * Allocate a new tabpage_T and init the values.
3271 * Returns NULL when out of memory.
3278 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3284 for (i
= 0; i
< 3; i
++)
3285 tp
->tp_prev_which_scrollbars
[i
] = -1;
3288 tp
->tp_diff_invalid
= TRUE
;
3291 /* init t: variables */
3292 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3294 tp
->tp_ch_used
= p_ch
;
3308 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3314 * Create a new Tab page with one window.
3315 * It will edit the current buffer, like after ":split".
3316 * When "after" is 0 put it just after the current Tab page.
3317 * Otherwise put it just before tab page "after".
3318 * Return FAIL or OK.
3321 win_new_tabpage(after
)
3324 tabpage_T
*tp
= curtab
;
3328 newtp
= alloc_tabpage();
3332 /* Remember the current windows in this Tab page. */
3333 if (leave_tabpage(curbuf
) == FAIL
)
3340 /* Create a new empty window. */
3341 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3343 /* Make the new Tab page the new topframe. */
3346 /* New tab page becomes the first one. */
3347 newtp
->tp_next
= first_tabpage
;
3348 first_tabpage
= newtp
;
3354 /* Put new tab page before tab page "after". */
3356 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3357 && n
< after
; tp
= tp
->tp_next
)
3360 newtp
->tp_next
= tp
->tp_next
;
3361 tp
->tp_next
= newtp
;
3364 firstwin
->w_winrow
= tabline_height();
3365 win_comp_scroll(curwin
);
3367 newtp
->tp_topframe
= topframe
;
3370 #if defined(FEAT_GUI)
3371 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3372 * scrollbars. Have to update them anyway. */
3373 if (gui
.in_use
&& starting
== 0)
3375 gui_init_which_components(NULL
);
3376 gui_update_scrollbars(TRUE
);
3378 need_mouse_correct
= TRUE
;
3381 redraw_all_later(CLEAR
);
3383 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3384 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3389 /* Failed, get back the previous Tab page */
3390 enter_tabpage(curtab
, curbuf
);
3395 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3396 * like with ":split".
3397 * Returns OK if a new tab page was created, FAIL otherwise.
3402 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3406 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3407 postponed_split_tab
= 0;
3408 return win_new_tabpage(n
);
3414 * Create up to "maxcount" tabpages with empty windows.
3415 * Returns the number of resulting tab pages.
3418 make_tabpages(maxcount
)
3421 int count
= maxcount
;
3424 /* Limit to 'tabpagemax' tabs. */
3430 * Don't execute autocommands while creating the tab pages. Must do that
3431 * when putting the buffers in the windows.
3436 for (todo
= count
- 1; todo
> 0; --todo
)
3437 if (win_new_tabpage(0) == FAIL
)
3444 /* return actual number of tab pages */
3445 return (count
- todo
);
3449 * Return TRUE when "tpc" points to a valid tab page.
3457 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3464 * Find tab page "n" (first one is 1). Returns NULL when not found.
3473 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3479 * Get index of tab page "tp". First one has index 1.
3480 * When not found returns number of tab pages plus one.
3489 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3495 * Prepare for leaving the current tab page.
3496 * When autocomands change "curtab" we don't leave the tab page and return
3498 * Careful: When OK is returned need to get a new tab page very very soon!
3501 leave_tabpage(new_curbuf
)
3502 buf_T
*new_curbuf UNUSED
; /* what is going to be the new curbuf,
3505 tabpage_T
*tp
= curtab
;
3508 reset_VIsual_and_resel(); /* stop Visual mode */
3511 if (new_curbuf
!= curbuf
)
3513 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3517 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3520 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3524 #if defined(FEAT_GUI)
3525 /* Remove the scrollbars. They may be added back later. */
3527 gui_remove_scrollbars();
3529 tp
->tp_curwin
= curwin
;
3530 tp
->tp_prevwin
= prevwin
;
3531 tp
->tp_firstwin
= firstwin
;
3532 tp
->tp_lastwin
= lastwin
;
3533 tp
->tp_old_Rows
= Rows
;
3534 tp
->tp_old_Columns
= Columns
;
3541 * Start using tab page "tp".
3542 * Only to be used after leave_tabpage() or freeing the current tab page.
3545 enter_tabpage(tp
, old_curbuf
)
3547 buf_T
*old_curbuf UNUSED
;
3549 int old_off
= tp
->tp_firstwin
->w_winrow
;
3550 win_T
*next_prevwin
= tp
->tp_prevwin
;
3553 firstwin
= tp
->tp_firstwin
;
3554 lastwin
= tp
->tp_lastwin
;
3555 topframe
= tp
->tp_topframe
;
3557 /* We would like doing the TabEnter event first, but we don't have a
3558 * valid current window yet, which may break some commands.
3559 * This triggers autocommands, thus may make "tp" invalid. */
3560 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3561 prevwin
= next_prevwin
;
3564 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3566 if (old_curbuf
!= curbuf
)
3567 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3570 last_status(FALSE
); /* status line may appear or disappear */
3571 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3572 must_redraw
= CLEAR
; /* need to redraw everything */
3574 diff_need_scrollbind
= TRUE
;
3577 /* The tabpage line may have appeared or disappeared, may need to resize
3578 * the frames for that. When the Vim window was resized need to update
3579 * frame sizes too. Use the stored value of p_ch, so that it can be
3580 * different for each tab page. */
3581 p_ch
= curtab
->tp_ch_used
;
3582 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3583 #ifdef FEAT_GUI_TABLINE
3584 && !gui_use_tabline()
3588 #ifdef FEAT_VERTSPLIT
3589 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3590 shell_new_columns(); /* update window widths */
3593 #if defined(FEAT_GUI)
3594 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3595 * scrollbars. Have to update them anyway. */
3596 if (gui
.in_use
&& starting
== 0)
3598 gui_init_which_components(NULL
);
3599 gui_update_scrollbars(TRUE
);
3601 need_mouse_correct
= TRUE
;
3604 redraw_all_later(CLEAR
);
3608 * Go to tab page "n". For ":tab N" and "Ngt".
3609 * When "n" is 9999 go to the last tab page.
3621 /* Not allowed when editing the command line. */
3623 if (cmdwin_type
!= 0)
3631 /* If there is only one it can't work. */
3632 if (first_tabpage
->tp_next
== NULL
)
3641 /* No count, go to next tab page, wrap around end. */
3642 if (curtab
->tp_next
== NULL
)
3645 tp
= curtab
->tp_next
;
3649 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3652 for (i
= n
; i
< 0; ++i
)
3654 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3662 /* Go to last tab page. */
3663 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3668 /* Go to tab page "n". */
3669 tp
= find_tabpage(n
);
3677 goto_tabpage_tp(tp
);
3679 #ifdef FEAT_GUI_TABLINE
3680 if (gui_use_tabline())
3681 gui_mch_set_curtab(tabpage_index(curtab
));
3686 * Go to tabpage "tp".
3687 * Note: doesn't update the GUI tab.
3693 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3695 if (valid_tabpage(tp
))
3696 enter_tabpage(tp
, curbuf
);
3698 enter_tabpage(curtab
, curbuf
);
3703 * Enter window "wp" in tab page "tp".
3704 * Also updates the GUI tab.
3707 goto_tabpage_win(tp
, wp
)
3711 goto_tabpage_tp(tp
);
3712 if (curtab
== tp
&& win_valid(wp
))
3714 win_enter(wp
, TRUE
);
3715 # ifdef FEAT_GUI_TABLINE
3716 if (gui_use_tabline())
3717 gui_mch_set_curtab(tabpage_index(curtab
));
3723 * Move the current tab page to before tab page "nr".
3732 if (first_tabpage
->tp_next
== NULL
)
3735 /* Remove the current tab page from the list of tab pages. */
3736 if (curtab
== first_tabpage
)
3737 first_tabpage
= curtab
->tp_next
;
3740 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3741 if (tp
->tp_next
== curtab
)
3743 if (tp
== NULL
) /* "cannot happen" */
3745 tp
->tp_next
= curtab
->tp_next
;
3748 /* Re-insert it at the specified position. */
3751 curtab
->tp_next
= first_tabpage
;
3752 first_tabpage
= curtab
;
3756 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3758 curtab
->tp_next
= tp
->tp_next
;
3759 tp
->tp_next
= curtab
;
3762 /* Need to redraw the tabline. Tab page contents doesn't change. */
3763 redraw_tabline
= TRUE
;
3768 * Go to another window.
3769 * When jumping to another buffer, stop Visual mode. Do this before
3770 * changing windows so we can yank the selection into the '*' register.
3771 * When jumping to another window on the same buffer, adjust its cursor
3772 * position to keep the same Visual area.
3785 if (curbuf_locked())
3790 if (wp
->w_buffer
!= curbuf
)
3791 reset_VIsual_and_resel();
3792 else if (VIsual_active
)
3793 wp
->w_cursor
= curwin
->w_cursor
;
3797 need_mouse_correct
= TRUE
;
3799 win_enter(wp
, TRUE
);
3802 #if defined(FEAT_PERL) || defined(PROTO)
3804 * Find window number "winnr" (counting top to bottom).
3812 # ifdef FEAT_WINDOWS
3813 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3823 #ifdef FEAT_VERTSPLIT
3825 * Move to window above or below "count" times.
3828 win_goto_ver(up
, count
)
3829 int up
; /* TRUE to go to win above */
3836 foundfr
= curwin
->w_frame
;
3840 * First go upwards in the tree of frames until we find a upwards or
3841 * downwards neighbor.
3852 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3858 * Now go downwards to find the bottom or top frame in it.
3862 if (nfr
->fr_layout
== FR_LEAF
)
3868 if (nfr
->fr_layout
== FR_ROW
)
3870 /* Find the frame at the cursor row. */
3871 while (fr
->fr_next
!= NULL
3872 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3873 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3876 if (nfr
->fr_layout
== FR_COL
&& up
)
3877 while (fr
->fr_next
!= NULL
)
3883 if (foundfr
!= NULL
)
3884 win_goto(foundfr
->fr_win
);
3888 * Move to left or right window.
3891 win_goto_hor(left
, count
)
3892 int left
; /* TRUE to go to left win */
3899 foundfr
= curwin
->w_frame
;
3903 * First go upwards in the tree of frames until we find a left or
3915 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3921 * Now go downwards to find the leftmost or rightmost frame in it.
3925 if (nfr
->fr_layout
== FR_LEAF
)
3931 if (nfr
->fr_layout
== FR_COL
)
3933 /* Find the frame at the cursor row. */
3934 while (fr
->fr_next
!= NULL
3935 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3936 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3939 if (nfr
->fr_layout
== FR_ROW
&& left
)
3940 while (fr
->fr_next
!= NULL
)
3946 if (foundfr
!= NULL
)
3947 win_goto(foundfr
->fr_win
);
3952 * Make window "wp" the current window.
3955 win_enter(wp
, undo_sync
)
3959 win_enter_ext(wp
, undo_sync
, FALSE
);
3963 * Make window wp the current window.
3964 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3965 * been closed and isn't valid.
3968 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3974 int other_buffer
= FALSE
;
3977 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3981 if (!curwin_invalid
)
3984 * Be careful: If autocommands delete the window, return now.
3986 if (wp
->w_buffer
!= curbuf
)
3988 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3989 other_buffer
= TRUE
;
3993 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3997 /* autocmds may abort script processing */
4004 /* sync undo before leaving the current buffer */
4005 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4007 /* may have to copy the buffer options when 'cpo' contains 'S' */
4008 if (wp
->w_buffer
!= curbuf
)
4009 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4010 if (!curwin_invalid
)
4012 prevwin
= curwin
; /* remember for CTRL-W p */
4013 curwin
->w_redr_status
= TRUE
;
4016 curbuf
= wp
->w_buffer
;
4018 #ifdef FEAT_VIRTUALEDIT
4019 if (!virtual_active())
4020 curwin
->w_cursor
.coladd
= 0;
4022 changed_line_abv_curs(); /* assume cursor position needs updating */
4024 if (curwin
->w_localdir
!= NULL
)
4026 /* Window has a local directory: Save current directory as global
4027 * directory (unless that was done already) and change to the local
4029 if (globaldir
== NULL
)
4031 char_u cwd
[MAXPATHL
];
4033 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4034 globaldir
= vim_strsave(cwd
);
4036 if (mch_chdir((char *)curwin
->w_localdir
) == 0)
4037 shorten_fnames(TRUE
);
4039 else if (globaldir
!= NULL
)
4041 /* Window doesn't have a local directory and we are not in the global
4042 * directory: Change to the global directory. */
4043 ignored
= mch_chdir((char *)globaldir
);
4044 vim_free(globaldir
);
4046 shorten_fnames(TRUE
);
4050 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4052 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4058 curwin
->w_redr_status
= TRUE
;
4059 redraw_tabline
= TRUE
;
4061 redraw_later(VALID
); /* causes status line redraw */
4063 /* set window height to desired minimal value */
4064 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4065 win_setheight((int)p_wh
);
4066 else if (curwin
->w_height
== 0)
4069 #ifdef FEAT_VERTSPLIT
4070 /* set window width to desired minimal value */
4071 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4072 win_setwidth((int)p_wiw
);
4076 setmouse(); /* in case jumped to/from help buffer */
4079 /* Change directories when the 'acd' option is set. */
4083 #endif /* FEAT_WINDOWS */
4085 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4087 * Jump to the first open window that contains buffer "buf", if one exists.
4088 * Returns a pointer to the window found, otherwise NULL.
4091 buf_jump_open_win(buf
)
4094 # ifdef FEAT_WINDOWS
4097 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4098 if (wp
->w_buffer
== buf
)
4101 win_enter(wp
, FALSE
);
4104 if (curwin
->w_buffer
== buf
)
4111 * Jump to the first open window in any tab page that contains buffer "buf",
4113 * Returns a pointer to the window found, otherwise NULL.
4116 buf_jump_open_tab(buf
)
4119 # ifdef FEAT_WINDOWS
4123 /* First try the current tab page. */
4124 wp
= buf_jump_open_win(buf
);
4128 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4131 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4132 if (wp
->w_buffer
== buf
)
4136 goto_tabpage_win(tp
, wp
);
4138 wp
= NULL
; /* something went wrong */
4145 if (curwin
->w_buffer
== buf
)
4153 * allocate a window structure and link it in the window list
4157 win_T
*after UNUSED
;
4162 * allocate window structure and linesizes arrays
4164 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4165 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4174 /* Don't execute autocommands while the window is not properly
4175 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4180 * link the window in the window list
4183 win_append(after
, newwin
);
4185 #ifdef FEAT_VERTSPLIT
4186 newwin
->w_wincol
= 0;
4187 newwin
->w_width
= Columns
;
4190 /* position the display and the cursor at the top of the file. */
4191 newwin
->w_topline
= 1;
4193 newwin
->w_topfill
= 0;
4195 newwin
->w_botline
= 2;
4196 newwin
->w_cursor
.lnum
= 1;
4197 #ifdef FEAT_SCROLLBIND
4198 newwin
->w_scbind_pos
= 1;
4201 /* We won't calculate w_fraction until resizing the window */
4202 newwin
->w_fraction
= 0;
4203 newwin
->w_prev_fraction_row
= -1;
4208 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4210 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4211 SBAR_RIGHT
, newwin
);
4215 /* init w: variables */
4216 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4219 foldInitWin(newwin
);
4224 #ifdef FEAT_SEARCH_EXTRA
4225 newwin
->w_match_head
= NULL
;
4226 newwin
->w_next_match_id
= 4;
4232 #if defined(FEAT_WINDOWS) || defined(PROTO)
4235 * remove window 'wp' from the window list and free the structure
4240 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4245 /* Don't execute autocommands while the window is halfway being deleted.
4246 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4250 #ifdef FEAT_MZSCHEME
4251 mzscheme_window_free(wp
);
4259 python_window_free(wp
);
4263 tcl_window_free(wp
);
4267 ruby_window_free(wp
);
4270 clear_winopt(&wp
->w_onebuf_opt
);
4271 clear_winopt(&wp
->w_allbuf_opt
);
4274 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4281 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4282 vim_free(wp
->w_tagstack
[i
].tagname
);
4284 vim_free(wp
->w_localdir
);
4286 #ifdef FEAT_SEARCH_EXTRA
4290 #ifdef FEAT_JUMPLIST
4294 #ifdef FEAT_QUICKFIX
4301 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4302 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4304 #endif /* FEAT_GUI */
4315 * Append window "wp" in the window list after window "after".
4318 win_append(after
, wp
)
4323 if (after
== NULL
) /* after NULL is in front of the first */
4326 before
= after
->w_next
;
4328 wp
->w_next
= before
;
4337 before
->w_prev
= wp
;
4341 * Remove a window from the window list.
4346 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4348 if (wp
->w_prev
!= NULL
)
4349 wp
->w_prev
->w_next
= wp
->w_next
;
4350 else if (tp
== NULL
)
4351 firstwin
= wp
->w_next
;
4353 tp
->tp_firstwin
= wp
->w_next
;
4354 if (wp
->w_next
!= NULL
)
4355 wp
->w_next
->w_prev
= wp
->w_prev
;
4356 else if (tp
== NULL
)
4357 lastwin
= wp
->w_prev
;
4359 tp
->tp_lastwin
= wp
->w_prev
;
4363 * Append frame "frp" in a frame list after frame "after".
4366 frame_append(after
, frp
)
4367 frame_T
*after
, *frp
;
4369 frp
->fr_next
= after
->fr_next
;
4370 after
->fr_next
= frp
;
4371 if (frp
->fr_next
!= NULL
)
4372 frp
->fr_next
->fr_prev
= frp
;
4373 frp
->fr_prev
= after
;
4377 * Insert frame "frp" in a frame list before frame "before".
4380 frame_insert(before
, frp
)
4381 frame_T
*before
, *frp
;
4383 frp
->fr_next
= before
;
4384 frp
->fr_prev
= before
->fr_prev
;
4385 before
->fr_prev
= frp
;
4386 if (frp
->fr_prev
!= NULL
)
4387 frp
->fr_prev
->fr_next
= frp
;
4389 frp
->fr_parent
->fr_child
= frp
;
4393 * Remove a frame from a frame list.
4399 if (frp
->fr_prev
!= NULL
)
4400 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4402 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4403 if (frp
->fr_next
!= NULL
)
4404 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4407 #endif /* FEAT_WINDOWS */
4410 * Allocate w_lines[] for window "wp".
4411 * Return FAIL for failure, OK for success.
4417 wp
->w_lines_valid
= 0;
4418 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4419 if (wp
->w_lines
== NULL
)
4425 * free lsize arrays for a window
4431 vim_free(wp
->w_lines
);
4436 * Called from win_new_shellsize() after Rows changed.
4437 * This only does the current tab page, others must be done when made active.
4442 int h
= (int)ROWS_AVAIL
;
4444 if (firstwin
== NULL
) /* not initialized yet */
4447 if (h
< frame_minheight(topframe
, NULL
))
4448 h
= frame_minheight(topframe
, NULL
);
4450 /* First try setting the heights of windows with 'winfixheight'. If
4451 * that doesn't result in the right height, forget about that option. */
4452 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4453 if (topframe
->fr_height
!= h
)
4454 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4456 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4460 win_new_height(firstwin
, h
);
4464 curtab
->tp_ch_used
= p_ch
;
4468 /* Disabled: don't want making the screen smaller make a window larger. */
4470 win_equal(curwin
, FALSE
, 'v');
4474 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4476 * Called from win_new_shellsize() after Columns changed.
4481 if (firstwin
== NULL
) /* not initialized yet */
4484 /* First try setting the widths of windows with 'winfixwidth'. If that
4485 * doesn't result in the right width, forget about that option. */
4486 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4487 if (topframe
->fr_width
!= Columns
)
4488 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4490 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4492 /* Disabled: don't want making the screen smaller make a window larger. */
4494 win_equal(curwin
, FALSE
, 'h');
4499 #if defined(FEAT_CMDWIN) || defined(PROTO)
4501 * Save the size of all windows in "gap".
4510 ga_init2(gap
, (int)sizeof(int), 1);
4511 if (ga_grow(gap
, win_count() * 2) == OK
)
4512 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4514 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4515 wp
->w_width
+ wp
->w_vsep_width
;
4516 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4521 * Restore window sizes, but only if the number of windows is still the same.
4522 * Does not free the growarray.
4525 win_size_restore(gap
)
4531 if (win_count() * 2 == gap
->ga_len
)
4534 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4536 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4537 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4539 /* recompute the window positions */
4540 (void)win_comp_pos();
4543 #endif /* FEAT_CMDWIN */
4545 #if defined(FEAT_WINDOWS) || defined(PROTO)
4547 * Update the position for all windows, using the width and height of the
4549 * Returns the row just after the last window.
4554 int row
= tabline_height();
4557 frame_comp_pos(topframe
, &row
, &col
);
4562 * Update the position of the windows in frame "topfrp", using the width and
4563 * height of the frames.
4564 * "*row" and "*col" are the top-left position of the frame. They are updated
4565 * to the bottom-right position plus one.
4568 frame_comp_pos(topfrp
, row
, col
)
4575 #ifdef FEAT_VERTSPLIT
4580 wp
= topfrp
->fr_win
;
4583 if (wp
->w_winrow
!= *row
4584 #ifdef FEAT_VERTSPLIT
4585 || wp
->w_wincol
!= *col
4589 /* position changed, redraw */
4590 wp
->w_winrow
= *row
;
4591 #ifdef FEAT_VERTSPLIT
4592 wp
->w_wincol
= *col
;
4594 redraw_win_later(wp
, NOT_VALID
);
4595 wp
->w_redr_status
= TRUE
;
4597 *row
+= wp
->w_height
+ wp
->w_status_height
;
4598 #ifdef FEAT_VERTSPLIT
4599 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4604 #ifdef FEAT_VERTSPLIT
4608 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4610 #ifdef FEAT_VERTSPLIT
4611 if (topfrp
->fr_layout
== FR_ROW
)
4612 *row
= startrow
; /* all frames are at the same row */
4614 *col
= startcol
; /* all frames are at the same col */
4616 frame_comp_pos(frp
, row
, col
);
4621 #endif /* FEAT_WINDOWS */
4624 * Set current window height and take care of repositioning other windows to
4628 win_setheight(height
)
4631 win_setheight_win(height
, curwin
);
4635 * Set the window height of window "win" and take care of repositioning other
4636 * windows to fit around it.
4639 win_setheight_win(height
, win
)
4647 /* Always keep current window at least one line high, even when
4648 * 'winminheight' is zero. */
4658 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4660 /* recompute the window positions */
4661 row
= win_comp_pos();
4663 if (height
> topframe
->fr_height
)
4664 height
= topframe
->fr_height
;
4665 win
->w_height
= height
;
4670 * If there is extra space created between the last window and the command
4673 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4674 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4679 redraw_all_later(NOT_VALID
);
4682 #if defined(FEAT_WINDOWS) || defined(PROTO)
4685 * Set the height of a frame to "height" and take care that all frames and
4686 * windows inside it are resized. Also resize frames on the left and right if
4687 * the are in the same FR_ROW frame.
4690 * If the frame is part of a FR_COL frame, try fitting the frame in that
4691 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4692 * go to containing frames to resize them and make room.
4693 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4694 * Check for the minimal height of the FR_ROW frame.
4695 * At the top level we can also use change the command line height.
4698 frame_setheight(curfrp
, height
)
4702 int room
; /* total number of lines available */
4703 int take
; /* number of lines taken from other windows */
4704 int room_cmdline
; /* lines available from cmdline */
4710 /* If the height already is the desired value, nothing to do. */
4711 if (curfrp
->fr_height
== height
)
4714 if (curfrp
->fr_parent
== NULL
)
4716 /* topframe: can only change the command line */
4717 if (height
> ROWS_AVAIL
)
4718 height
= ROWS_AVAIL
;
4720 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4722 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4724 /* Row of frames: Also need to resize frames left and right of this
4725 * one. First check for the minimal height of these. */
4726 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4729 frame_setheight(curfrp
->fr_parent
, height
);
4734 * Column of frames: try to change only frames in this column.
4736 #ifdef FEAT_VERTSPLIT
4739 * 1: compute room available, if it's not enough try resizing the
4741 * 2: compute the room available and adjust the height to it.
4742 * Try not to reduce the height of a window with 'winfixheight' set.
4744 for (run
= 1; run
<= 2; ++run
)
4751 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4755 && frp
->fr_win
!= NULL
4756 && frp
->fr_win
->w_p_wfh
)
4757 room_reserved
+= frp
->fr_height
;
4758 room
+= frp
->fr_height
;
4760 room
-= frame_minheight(frp
, NULL
);
4762 #ifdef FEAT_VERTSPLIT
4763 if (curfrp
->fr_width
!= Columns
)
4768 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4769 + lastwin
->w_height
+ lastwin
->w_status_height
);
4770 if (room_cmdline
< 0)
4774 if (height
<= room
+ room_cmdline
)
4776 #ifdef FEAT_VERTSPLIT
4777 if (run
== 2 || curfrp
->fr_width
== Columns
)
4780 if (height
> room
+ room_cmdline
)
4781 height
= room
+ room_cmdline
;
4784 #ifdef FEAT_VERTSPLIT
4785 frame_setheight(curfrp
->fr_parent
, height
4786 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4792 * Compute the number of lines we will take from others frames (can be
4795 take
= height
- curfrp
->fr_height
;
4797 /* If there is not enough room, also reduce the height of a window
4798 * with 'winfixheight' set. */
4799 if (height
> room
+ room_cmdline
- room_reserved
)
4800 room_reserved
= room
+ room_cmdline
- height
;
4801 /* If there is only a 'winfixheight' window and making the
4802 * window smaller, need to make the other window taller. */
4803 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4806 if (take
> 0 && room_cmdline
> 0)
4808 /* use lines from cmdline first */
4809 if (take
< room_cmdline
)
4810 room_cmdline
= take
;
4811 take
-= room_cmdline
;
4812 topframe
->fr_height
+= room_cmdline
;
4816 * set the current frame to the new height
4818 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4821 * First take lines from the frames after the current frame. If
4822 * that is not enough, takes lines from frames above the current
4825 for (run
= 0; run
< 2; ++run
)
4828 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4830 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4831 while (frp
!= NULL
&& take
!= 0)
4833 h
= frame_minheight(frp
, NULL
);
4834 if (room_reserved
> 0
4835 && frp
->fr_win
!= NULL
4836 && frp
->fr_win
->w_p_wfh
)
4838 if (room_reserved
>= frp
->fr_height
)
4839 room_reserved
-= frp
->fr_height
;
4842 if (frp
->fr_height
- room_reserved
> take
)
4843 room_reserved
= frp
->fr_height
- take
;
4844 take
-= frp
->fr_height
- room_reserved
;
4845 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4851 if (frp
->fr_height
- take
< h
)
4853 take
-= frp
->fr_height
- h
;
4854 frame_new_height(frp
, h
, FALSE
, FALSE
);
4858 frame_new_height(frp
, frp
->fr_height
- take
,
4872 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4874 * Set current window width and take care of repositioning other windows to
4881 win_setwidth_win(width
, curwin
);
4885 win_setwidth_win(width
, wp
)
4889 /* Always keep current window at least one column wide, even when
4890 * 'winminwidth' is zero. */
4899 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4901 /* recompute the window positions */
4902 (void)win_comp_pos();
4904 redraw_all_later(NOT_VALID
);
4908 * Set the width of a frame to "width" and take care that all frames and
4909 * windows inside it are resized. Also resize frames above and below if the
4910 * are in the same FR_ROW frame.
4912 * Strategy is similar to frame_setheight().
4915 frame_setwidth(curfrp
, width
)
4919 int room
; /* total number of lines available */
4920 int take
; /* number of lines taken from other windows */
4926 /* If the width already is the desired value, nothing to do. */
4927 if (curfrp
->fr_width
== width
)
4930 if (curfrp
->fr_parent
== NULL
)
4931 /* topframe: can't change width */
4934 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4936 /* Column of frames: Also need to resize frames above and below of
4937 * this one. First check for the minimal width of these. */
4938 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4941 frame_setwidth(curfrp
->fr_parent
, width
);
4946 * Row of frames: try to change only frames in this row.
4949 * 1: compute room available, if it's not enough try resizing the
4951 * 2: compute the room available and adjust the width to it.
4953 for (run
= 1; run
<= 2; ++run
)
4957 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4961 && frp
->fr_win
!= NULL
4962 && frp
->fr_win
->w_p_wfw
)
4963 room_reserved
+= frp
->fr_width
;
4964 room
+= frp
->fr_width
;
4966 room
-= frame_minwidth(frp
, NULL
);
4971 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4977 frame_setwidth(curfrp
->fr_parent
, width
4978 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4982 * Compute the number of lines we will take from others frames (can be
4985 take
= width
- curfrp
->fr_width
;
4987 /* If there is not enough room, also reduce the width of a window
4988 * with 'winfixwidth' set. */
4989 if (width
> room
- room_reserved
)
4990 room_reserved
= room
- width
;
4991 /* If there is only a 'winfixwidth' window and making the
4992 * window smaller, need to make the other window narrower. */
4993 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4997 * set the current frame to the new width
4999 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
5002 * First take lines from the frames right of the current frame. If
5003 * that is not enough, takes lines from frames left of the current
5006 for (run
= 0; run
< 2; ++run
)
5009 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5011 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5012 while (frp
!= NULL
&& take
!= 0)
5014 w
= frame_minwidth(frp
, NULL
);
5015 if (room_reserved
> 0
5016 && frp
->fr_win
!= NULL
5017 && frp
->fr_win
->w_p_wfw
)
5019 if (room_reserved
>= frp
->fr_width
)
5020 room_reserved
-= frp
->fr_width
;
5023 if (frp
->fr_width
- room_reserved
> take
)
5024 room_reserved
= frp
->fr_width
- take
;
5025 take
-= frp
->fr_width
- room_reserved
;
5026 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5032 if (frp
->fr_width
- take
< w
)
5034 take
-= frp
->fr_width
- w
;
5035 frame_new_width(frp
, w
, FALSE
, FALSE
);
5039 frame_new_width(frp
, frp
->fr_width
- take
,
5052 #endif /* FEAT_VERTSPLIT */
5055 * Check 'winminheight' for a valid value.
5064 /* loop until there is a 'winminheight' that is possible */
5067 /* TODO: handle vertical splits */
5069 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5070 room
+= wp
->w_height
- p_wmh
;
5085 * Status line of dragwin is dragged "offset" lines down (negative is up).
5088 win_drag_status_line(dragwin
, offset
)
5096 int up
; /* if TRUE, drag status line up, otherwise down */
5099 fr
= dragwin
->w_frame
;
5101 if (fr
!= topframe
) /* more than one window */
5104 /* When the parent frame is not a column of frames, its parent should
5106 if (fr
->fr_layout
!= FR_COL
)
5109 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5114 /* If this is the last frame in a column, may want to resize the parent
5115 * frame instead (go two up to skip a row of frames). */
5116 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5125 if (offset
< 0) /* drag up */
5129 /* sum up the room of the current frame and above it */
5132 /* only one window */
5133 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5138 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5140 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5145 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5147 else /* drag down */
5151 * Only dragging the last status line can reduce p_ch.
5153 room
= Rows
- cmdline_row
;
5154 if (curfr
->fr_next
== NULL
)
5160 /* sum up the room of frames below of the current one */
5161 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5162 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5163 fr
= curfr
; /* put fr at window that grows */
5166 if (room
< offset
) /* Not enough room */
5167 offset
= room
; /* Move as far as we can */
5172 * Grow frame fr by "offset" lines.
5173 * Doesn't happen when dragging the last status line up.
5176 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5179 fr
= curfr
; /* current frame gets smaller */
5181 fr
= curfr
->fr_next
; /* next frame gets smaller */
5184 * Now make the other frames smaller.
5186 while (fr
!= NULL
&& offset
> 0)
5188 n
= frame_minheight(fr
, NULL
);
5189 if (fr
->fr_height
- offset
<= n
)
5191 offset
-= fr
->fr_height
- n
;
5192 frame_new_height(fr
, n
, !up
, FALSE
);
5196 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5204 row
= win_comp_pos();
5205 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5207 p_ch
= Rows
- cmdline_row
;
5210 curtab
->tp_ch_used
= p_ch
;
5211 redraw_all_later(SOME_VALID
);
5215 #ifdef FEAT_VERTSPLIT
5217 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5220 win_drag_vsep_line(dragwin
, offset
)
5227 int left
; /* if TRUE, drag separator line left, otherwise right */
5230 fr
= dragwin
->w_frame
;
5231 if (fr
== topframe
) /* only one window (cannot happen?) */
5235 /* When the parent frame is not a row of frames, its parent should be. */
5236 if (fr
->fr_layout
!= FR_ROW
)
5238 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5244 /* If this is the last frame in a row, may want to resize a parent
5246 while (curfr
->fr_next
== NULL
)
5259 if (offset
< 0) /* drag left */
5263 /* sum up the room of the current frame and left of it */
5265 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5267 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5271 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5273 else /* drag right */
5276 /* sum up the room of frames right of the current one */
5278 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5279 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5280 fr
= curfr
; /* put fr at window that grows */
5283 if (room
< offset
) /* Not enough room */
5284 offset
= room
; /* Move as far as we can */
5285 if (offset
<= 0) /* No room at all, quit. */
5288 /* grow frame fr by offset lines */
5289 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5291 /* shrink other frames: current and at the left or at the right */
5293 fr
= curfr
; /* current frame gets smaller */
5295 fr
= curfr
->fr_next
; /* next frame gets smaller */
5297 while (fr
!= NULL
&& offset
> 0)
5299 n
= frame_minwidth(fr
, NULL
);
5300 if (fr
->fr_width
- offset
<= n
)
5302 offset
-= fr
->fr_width
- n
;
5303 frame_new_width(fr
, n
, !left
, FALSE
);
5307 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5315 (void)win_comp_pos();
5316 redraw_all_later(NOT_VALID
);
5318 #endif /* FEAT_VERTSPLIT */
5319 #endif /* FEAT_MOUSE */
5321 #endif /* FEAT_WINDOWS */
5324 * Set the height of a window.
5325 * This takes care of the things inside the window, not what happens to the
5326 * window position, the frame or to other windows.
5329 win_new_height(wp
, height
)
5334 int sline
, line_size
;
5335 #define FRACTION_MULT 16384L
5337 /* Don't want a negative height. Happens when splitting a tiny window.
5338 * Will equalize heights soon to fix it. */
5341 if (wp
->w_height
== height
)
5342 return; /* nothing to do */
5344 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5345 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5346 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5348 wp
->w_height
= height
;
5351 /* Don't change w_topline when height is zero. Don't set w_topline when
5352 * 'scrollbind' is set and this isn't the current window. */
5354 #ifdef FEAT_SCROLLBIND
5355 && (!wp
->w_p_scb
|| wp
== curwin
)
5360 * Find a value for w_topline that shows the cursor at the same
5361 * relative position in the window as before (more or less).
5363 lnum
= wp
->w_cursor
.lnum
;
5364 if (lnum
< 1) /* can happen when starting up */
5366 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5367 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5368 sline
= wp
->w_wrow
- line_size
;
5372 /* Make sure the whole cursor line is visible, if possible. */
5373 int rows
= plines_win(wp
, lnum
, FALSE
);
5375 if (sline
> wp
->w_height
- rows
)
5377 sline
= wp
->w_height
- rows
;
5378 wp
->w_wrow
-= rows
- line_size
;
5385 * Cursor line would go off top of screen if w_wrow was this high.
5386 * Make cursor line the first line in the window. If not enough
5387 * room use w_skipcol;
5389 wp
->w_wrow
= line_size
;
5390 if (wp
->w_wrow
>= wp
->w_height
5391 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5393 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5395 while (wp
->w_wrow
>= wp
->w_height
)
5397 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5405 while (sline
> 0 && lnum
> 1)
5408 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5411 /* first line in buffer is folded */
5419 if (lnum
== wp
->w_topline
)
5420 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5424 line_size
= plines_win(wp
, lnum
, TRUE
);
5431 * Line we want at top would go off top of screen. Use next
5435 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5438 wp
->w_wrow
-= line_size
+ sline
;
5442 /* First line of file reached, use that as topline. */
5444 wp
->w_wrow
-= sline
;
5447 set_topline(wp
, lnum
);
5454 curs_columns(FALSE
); /* validate w_wrow */
5456 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5458 win_comp_scroll(wp
);
5459 redraw_win_later(wp
, SOME_VALID
);
5461 wp
->w_redr_status
= TRUE
;
5463 invalidate_botline_win(wp
);
5466 #ifdef FEAT_VERTSPLIT
5468 * Set the width of a window.
5471 win_new_width(wp
, width
)
5475 wp
->w_width
= width
;
5476 wp
->w_lines_valid
= 0;
5477 changed_line_abv_curs_win(wp
);
5478 invalidate_botline_win(wp
);
5482 curs_columns(TRUE
); /* validate w_wrow */
5484 redraw_win_later(wp
, NOT_VALID
);
5485 wp
->w_redr_status
= TRUE
;
5493 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5494 if (wp
->w_p_scr
== 0)
5499 * command_height: called whenever p_ch has been changed
5507 int old_p_ch
= curtab
->tp_ch_used
;
5509 /* Use the value of p_ch that we remembered. This is needed for when the
5510 * GUI starts up, we can't be sure in what order things happen. And when
5511 * p_ch was changed in another tab page. */
5512 curtab
->tp_ch_used
= p_ch
;
5514 /* Find bottom frame with width of screen. */
5515 frp
= lastwin
->w_frame
;
5516 # ifdef FEAT_VERTSPLIT
5517 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5518 frp
= frp
->fr_parent
;
5521 /* Avoid changing the height of a window with 'winfixheight' set. */
5522 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5523 && frp
->fr_win
->w_p_wfh
)
5526 if (starting
!= NO_SCREEN
)
5528 cmdline_row
= Rows
- p_ch
;
5530 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5532 while (p_ch
> old_p_ch
)
5538 curtab
->tp_ch_used
= p_ch
;
5539 cmdline_row
= Rows
- p_ch
;
5542 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5543 if (h
> p_ch
- old_p_ch
)
5544 h
= p_ch
- old_p_ch
;
5546 frame_add_height(frp
, -h
);
5550 /* Recompute window positions. */
5551 (void)win_comp_pos();
5553 /* clear the lines added to cmdline */
5555 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5556 (int)Columns
, ' ', ' ', 0);
5557 msg_row
= cmdline_row
;
5558 redraw_cmdline
= TRUE
;
5562 if (msg_row
< cmdline_row
)
5563 msg_row
= cmdline_row
;
5564 redraw_cmdline
= TRUE
;
5566 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5568 /* Recompute window positions. */
5569 if (frp
!= lastwin
->w_frame
)
5570 (void)win_comp_pos();
5572 cmdline_row
= Rows
- p_ch
;
5573 win_setheight(cmdline_row
);
5577 #if defined(FEAT_WINDOWS) || defined(PROTO)
5579 * Resize frame "frp" to be "n" lines higher (negative for less high).
5580 * Also resize the frames it is contained in.
5583 frame_add_height(frp
, n
)
5587 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5590 frp
= frp
->fr_parent
;
5593 frp
->fr_height
+= n
;
5598 * Add or remove a status line for the bottom window(s), according to the
5599 * value of 'laststatus'.
5602 last_status(morewin
)
5603 int morewin
; /* pretend there are two or more windows */
5605 /* Don't make a difference between horizontal or vertical split. */
5606 last_status_rec(topframe
, (p_ls
== 2
5607 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5611 last_status_rec(fr
, statusline
)
5618 if (fr
->fr_layout
== FR_LEAF
)
5621 if (wp
->w_status_height
!= 0 && !statusline
)
5623 /* remove status line */
5624 win_new_height(wp
, wp
->w_height
+ 1);
5625 wp
->w_status_height
= 0;
5628 else if (wp
->w_status_height
== 0 && statusline
)
5630 /* Find a frame to take a line from. */
5632 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5639 /* In a column of frames: go to frame above. If already at
5640 * the top or in a row of frames: go to parent. */
5641 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5646 wp
->w_status_height
= 1;
5649 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5650 frame_fix_height(wp
);
5651 (void)win_comp_pos();
5654 win_new_height(wp
, wp
->w_height
- 1);
5656 redraw_all_later(SOME_VALID
);
5659 #ifdef FEAT_VERTSPLIT
5660 else if (fr
->fr_layout
== FR_ROW
)
5662 /* vertically split windows, set status line for each one */
5663 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5664 last_status_rec(fp
, statusline
);
5669 /* horizontally split window, set status line for last one */
5670 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5672 last_status_rec(fp
, statusline
);
5677 * Return the number of lines used by the tab page line.
5682 #ifdef FEAT_GUI_TABLINE
5683 /* When the GUI has the tabline then this always returns zero. */
5684 if (gui_use_tabline())
5690 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5695 #endif /* FEAT_WINDOWS */
5697 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5699 * Get the file name at the cursor.
5700 * If Visual mode is active, use the selected text if it's in one line.
5701 * Returns the name in allocated memory, NULL for failure.
5704 grab_file_name(count
, file_lnum
)
5706 linenr_T
*file_lnum
;
5714 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5716 return find_file_name_in_path(ptr
, len
,
5717 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5720 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5726 * Return the file name under or after the cursor.
5728 * The 'path' option is searched if the file name is not absolute.
5729 * The string returned has been alloc'ed and should be freed by the caller.
5730 * NULL is returned if the file name or file is not found.
5733 * FNAME_MESS give error messages
5734 * FNAME_EXP expand to path
5735 * FNAME_HYP check for hypertext link
5736 * FNAME_INCL apply "includeexpr"
5739 file_name_at_cursor(options
, count
, file_lnum
)
5742 linenr_T
*file_lnum
;
5744 return file_name_in_line(ml_get_curline(),
5745 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5750 * Return the name of the file under or after ptr[col].
5751 * Otherwise like file_name_at_cursor().
5754 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5759 char_u
*rel_fname
; /* file we are searching relative to */
5760 linenr_T
*file_lnum
; /* line number after the file name */
5766 * search forward for what could be the start of a file name
5769 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5771 if (*ptr
== NUL
) /* nothing found */
5773 if (options
& FNAME_MESS
)
5774 EMSG(_("E446: No file name under cursor"));
5779 * Search backward for first char of the file name.
5780 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5785 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5789 if (vim_isfilec(ptr
[-1])
5790 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5797 * Search forward for the last char of the file name.
5798 * Also allow "://" when ':' is not in 'isfname'.
5801 while (vim_isfilec(ptr
[len
])
5802 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5805 len
+= (*mb_ptr2len
)(ptr
+ len
);
5811 * If there is trailing punctuation, remove it.
5812 * But don't remove "..", could be a directory name.
5814 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5815 && ptr
[len
- 2] != '.')
5818 if (file_lnum
!= NULL
)
5822 /* Get the number after the file name and a separator character */
5828 ++p
; /* skip the separator */
5831 *file_lnum
= (int)getdigits(&p
);
5835 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5838 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5839 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5842 eval_includeexpr(ptr
, len
)
5848 set_vim_var_string(VV_FNAME
, ptr
, len
);
5849 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5850 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5851 set_vim_var_string(VV_FNAME
, NULL
, 0);
5857 * Return the name of the file ptr[len] in 'path'.
5858 * Otherwise like file_name_at_cursor().
5861 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5866 char_u
*rel_fname
; /* file we are searching relative to */
5870 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5871 char_u
*tofree
= NULL
;
5873 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5875 tofree
= eval_includeexpr(ptr
, len
);
5879 len
= (int)STRLEN(ptr
);
5884 if (options
& FNAME_EXP
)
5886 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5889 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5891 * If the file could not be found in a normal way, try applying
5892 * 'includeexpr' (unless done already).
5894 if (file_name
== NULL
5895 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5897 tofree
= eval_includeexpr(ptr
, len
);
5901 len
= (int)STRLEN(ptr
);
5902 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5907 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5911 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5915 /* Repeat finding the file "count" times. This matters when it
5916 * appears several times in the path. */
5917 while (file_name
!= NULL
&& --count
> 0)
5919 vim_free(file_name
);
5920 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5924 file_name
= vim_strnsave(ptr
, len
);
5926 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5932 #endif /* FEAT_SEARCHPATH */
5935 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5936 * Also check for ":\\", which MS Internet Explorer accepts, return
5943 if (STRNCMP(p
, "://", (size_t)3) == 0)
5945 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5946 return URL_BACKSLASH
;
5951 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5952 * Return URL_BACKSLASH for "name:\\".
5953 * Return zero otherwise.
5956 path_with_url(fname
)
5961 for (p
= fname
; isalpha(*p
); ++p
)
5963 return path_is_url(p
);
5967 * Return TRUE if "name" is a full (absolute) path name or URL.
5973 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5977 * Get absolute file name into buffer "buf[len]".
5979 * return FAIL for failure, OK otherwise
5982 vim_FullName(fname
, buf
, len
, force
)
5983 char_u
*fname
, *buf
;
5985 int force
; /* force expansion even when already absolute */
5994 url
= path_with_url(fname
);
5996 retval
= mch_FullName(fname
, buf
, len
, force
);
5997 if (url
|| retval
== FAIL
)
5999 /* something failed; use the file name (truncate when too long) */
6000 vim_strncpy(buf
, fname
, len
- 1);
6002 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6009 * Return the minimal number of rows that is needed on the screen to display
6010 * the current number of windows.
6021 if (firstwin
== NULL
) /* not initialized yet */
6026 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6028 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6032 total
+= tabline_height();
6034 total
= 1; /* at least one window should have a line! */
6036 total
+= 1; /* count the room for the command line */
6041 * Return TRUE if there is only one window (in the current tab page), not
6042 * counting a help or preview window, unless it is the current window.
6051 /* If there is another tab page there always is another window. */
6052 if (first_tabpage
->tp_next
!= NULL
)
6055 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6056 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6057 # ifdef FEAT_QUICKFIX
6062 return (count
<= 1);
6068 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6070 * Correct the cursor line number in other windows. Used after changing the
6071 * current buffer, and before applying autocommands.
6072 * When "do_curwin" is TRUE, also check current window.
6075 check_lnums(do_curwin
)
6083 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6084 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6090 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6091 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6092 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6093 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6098 #if defined(FEAT_WINDOWS) || defined(PROTO)
6101 * A snapshot of the window sizes, to restore them after closing the help
6103 * Only these fields are used:
6109 * fr_win (only valid for the old curwin, NULL otherwise)
6113 * Create a snapshot of the current frame sizes.
6118 clear_snapshot(curtab
);
6119 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6123 make_snapshot_rec(fr
, frp
)
6127 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6130 (*frp
)->fr_layout
= fr
->fr_layout
;
6131 # ifdef FEAT_VERTSPLIT
6132 (*frp
)->fr_width
= fr
->fr_width
;
6134 (*frp
)->fr_height
= fr
->fr_height
;
6135 if (fr
->fr_next
!= NULL
)
6136 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6137 if (fr
->fr_child
!= NULL
)
6138 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6139 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6140 (*frp
)->fr_win
= curwin
;
6144 * Remove any existing snapshot.
6150 clear_snapshot_rec(tp
->tp_snapshot
);
6151 tp
->tp_snapshot
= NULL
;
6155 clear_snapshot_rec(fr
)
6160 clear_snapshot_rec(fr
->fr_next
);
6161 clear_snapshot_rec(fr
->fr_child
);
6167 * Restore a previously created snapshot, if there is any.
6168 * This is only done if the screen size didn't change and the window layout is
6172 restore_snapshot(close_curwin
)
6173 int close_curwin
; /* closing current window */
6177 if (curtab
->tp_snapshot
!= NULL
6178 # ifdef FEAT_VERTSPLIT
6179 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6181 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6182 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6184 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6186 if (wp
!= NULL
&& close_curwin
)
6188 redraw_all_later(CLEAR
);
6190 clear_snapshot(curtab
);
6194 * Check if frames "sn" and "fr" have the same layout, same following frames
6195 * and same children.
6198 check_snapshot_rec(sn
, fr
)
6202 if (sn
->fr_layout
!= fr
->fr_layout
6203 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6204 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6205 || (sn
->fr_next
!= NULL
6206 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6207 || (sn
->fr_child
!= NULL
6208 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6214 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6215 * following frames and children.
6216 * Returns a pointer to the old current window, or NULL.
6219 restore_snapshot_rec(sn
, fr
)
6226 fr
->fr_height
= sn
->fr_height
;
6227 # ifdef FEAT_VERTSPLIT
6228 fr
->fr_width
= sn
->fr_width
;
6230 if (fr
->fr_layout
== FR_LEAF
)
6232 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6233 # ifdef FEAT_VERTSPLIT
6234 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6238 if (sn
->fr_next
!= NULL
)
6240 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6244 if (sn
->fr_child
!= NULL
)
6246 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6255 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6257 * Return TRUE if there is any vertically split window.
6264 if (topframe
->fr_layout
== FR_ROW
)
6267 if (topframe
->fr_layout
== FR_COL
)
6268 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6269 if (fr
->fr_layout
== FR_ROW
)
6276 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6278 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6279 * highlighted with the group 'grp' with priority 'prio'.
6280 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6281 * If no particular ID is desired, -1 must be specified for 'id'.
6282 * Return ID of added match, -1 on failure.
6285 match_add(wp
, grp
, pat
, prio
, id
)
6298 if (*grp
== NUL
|| *pat
== NUL
)
6300 if (id
< -1 || id
== 0)
6302 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6307 cur
= wp
->w_match_head
;
6312 EMSGN("E801: ID already taken: %ld", id
);
6318 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6320 EMSG2(_(e_nogroup
), grp
);
6323 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6325 EMSG2(_(e_invarg2
), pat
);
6329 /* Find available match ID. */
6332 cur
= wp
->w_match_head
;
6333 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6336 id
= wp
->w_next_match_id
;
6337 wp
->w_next_match_id
++;
6340 /* Build new match. */
6341 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6344 m
->pattern
= vim_strsave(pat
);
6346 m
->match
.regprog
= regprog
;
6347 m
->match
.rmm_ic
= FALSE
;
6348 m
->match
.rmm_maxcol
= 0;
6350 /* Insert new match. The match list is in ascending order with regard to
6351 * the match priorities. */
6352 cur
= wp
->w_match_head
;
6354 while (cur
!= NULL
&& prio
>= cur
->priority
)
6360 wp
->w_match_head
= m
;
6365 redraw_later(SOME_VALID
);
6370 * Delete match with ID 'id' in the match list of window 'wp'.
6371 * Print error messages if 'perr' is TRUE.
6374 match_delete(wp
, id
, perr
)
6379 matchitem_T
*cur
= wp
->w_match_head
;
6380 matchitem_T
*prev
= cur
;
6385 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6389 while (cur
!= NULL
&& cur
->id
!= id
)
6397 EMSGN("E803: ID not found: %ld", id
);
6401 wp
->w_match_head
= cur
->next
;
6403 prev
->next
= cur
->next
;
6404 vim_free(cur
->match
.regprog
);
6405 vim_free(cur
->pattern
);
6407 redraw_later(SOME_VALID
);
6412 * Delete all matches in the match list of window 'wp'.
6420 while (wp
->w_match_head
!= NULL
)
6422 m
= wp
->w_match_head
->next
;
6423 vim_free(wp
->w_match_head
->match
.regprog
);
6424 vim_free(wp
->w_match_head
->pattern
);
6425 vim_free(wp
->w_match_head
);
6426 wp
->w_match_head
= m
;
6428 redraw_later(SOME_VALID
);
6432 * Get match from ID 'id' in window 'wp'.
6433 * Return NULL if match not found.
6440 matchitem_T
*cur
= wp
->w_match_head
;
6442 while (cur
!= NULL
&& cur
->id
!= id
)