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
1168 win_init(newp
, oldp
, flags
)
1175 newp
->w_buffer
= oldp
->w_buffer
;
1176 oldp
->w_buffer
->b_nwindows
++;
1177 newp
->w_cursor
= oldp
->w_cursor
;
1179 newp
->w_curswant
= oldp
->w_curswant
;
1180 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1181 newp
->w_topline
= oldp
->w_topline
;
1183 newp
->w_topfill
= oldp
->w_topfill
;
1185 newp
->w_leftcol
= oldp
->w_leftcol
;
1186 newp
->w_pcmark
= oldp
->w_pcmark
;
1187 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1188 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1189 newp
->w_wrow
= oldp
->w_wrow
;
1190 newp
->w_fraction
= oldp
->w_fraction
;
1191 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1192 #ifdef FEAT_JUMPLIST
1193 copy_jumplist(oldp
, newp
);
1195 #ifdef FEAT_QUICKFIX
1196 if (flags
& WSP_NEWLOC
)
1198 /* Don't copy the location list. */
1199 newp
->w_llist
= NULL
;
1200 newp
->w_llist_ref
= NULL
;
1203 copy_loclist(oldp
, newp
);
1205 if (oldp
->w_localdir
!= NULL
)
1206 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1208 /* Use the same argument list. */
1209 newp
->w_alist
= oldp
->w_alist
;
1210 ++newp
->w_alist
->al_refcount
;
1211 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1214 * copy tagstack and options from existing window
1216 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1218 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1219 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1220 newp
->w_tagstack
[i
].tagname
=
1221 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1223 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1224 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1225 win_copy_options(oldp
, newp
);
1226 # ifdef FEAT_FOLDING
1227 copyFoldingState(oldp
, newp
);
1231 #endif /* FEAT_WINDOWS */
1233 #if defined(FEAT_WINDOWS) || defined(PROTO)
1235 * Check if "win" is a pointer to an existing window.
1245 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1252 * Return the number of windows.
1260 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1266 * Make "count" windows on the screen.
1267 * Return actual number of windows on the screen.
1268 * Must be called when there is just one window, filling the whole screen
1269 * (excluding the command line).
1273 make_windows(count
, vertical
)
1275 int vertical
; /* split windows vertically if TRUE */
1280 #ifdef FEAT_VERTSPLIT
1283 /* Each windows needs at least 'winminwidth' lines and a separator
1285 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1286 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1291 /* Each window needs at least 'winminheight' lines and a status line. */
1292 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1293 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1298 if (count
> maxcount
)
1302 * add status line now, otherwise first window will be too big
1309 * Don't execute autocommands while creating the windows. Must do that
1310 * when putting the buffers in the windows.
1315 /* todo is number of windows left to create */
1316 for (todo
= count
- 1; todo
> 0; --todo
)
1317 #ifdef FEAT_VERTSPLIT
1320 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1321 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1327 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1328 * STATUS_HEIGHT
) / (todo
+ 1)
1329 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1337 /* return actual number of windows */
1338 return (count
- todo
);
1342 * Exchange current and next window
1345 win_exchange(Prenum
)
1354 if (lastwin
== firstwin
) /* just one window */
1361 need_mouse_correct
= TRUE
;
1365 * find window to exchange with
1369 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1370 while (frp
!= NULL
&& --Prenum
> 0)
1373 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1374 frp
= curwin
->w_frame
->fr_next
;
1375 else /* Swap last window in row/col with previous */
1376 frp
= curwin
->w_frame
->fr_prev
;
1378 /* We can only exchange a window with another window, not with a frame
1379 * containing windows. */
1380 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1385 * 1. remove curwin from the list. Remember after which window it was in wp2
1386 * 2. insert curwin before wp in the list
1388 * 3. remove wp from the list
1389 * 4. insert wp after wp2
1390 * 5. exchange the status line height and vsep width.
1392 wp2
= curwin
->w_prev
;
1393 frp2
= curwin
->w_frame
->fr_prev
;
1394 if (wp
->w_prev
!= curwin
)
1396 win_remove(curwin
, NULL
);
1397 frame_remove(curwin
->w_frame
);
1398 win_append(wp
->w_prev
, curwin
);
1399 frame_insert(frp
, curwin
->w_frame
);
1403 win_remove(wp
, NULL
);
1404 frame_remove(wp
->w_frame
);
1405 win_append(wp2
, wp
);
1407 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1409 frame_append(frp2
, wp
->w_frame
);
1411 temp
= curwin
->w_status_height
;
1412 curwin
->w_status_height
= wp
->w_status_height
;
1413 wp
->w_status_height
= temp
;
1414 #ifdef FEAT_VERTSPLIT
1415 temp
= curwin
->w_vsep_width
;
1416 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1417 wp
->w_vsep_width
= temp
;
1419 /* If the windows are not in the same frame, exchange the sizes to avoid
1420 * messing up the window layout. Otherwise fix the frame sizes. */
1421 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1423 temp
= curwin
->w_height
;
1424 curwin
->w_height
= wp
->w_height
;
1425 wp
->w_height
= temp
;
1426 temp
= curwin
->w_width
;
1427 curwin
->w_width
= wp
->w_width
;
1432 frame_fix_height(curwin
);
1433 frame_fix_height(wp
);
1434 frame_fix_width(curwin
);
1435 frame_fix_width(wp
);
1439 (void)win_comp_pos(); /* recompute window positions */
1441 win_enter(wp
, TRUE
);
1442 redraw_later(CLEAR
);
1446 * rotate windows: if upwards TRUE the second window becomes the first one
1447 * if upwards FALSE the first window becomes the second one
1450 win_rotate(upwards
, count
)
1459 if (firstwin
== lastwin
) /* nothing to do */
1466 need_mouse_correct
= TRUE
;
1469 #ifdef FEAT_VERTSPLIT
1470 /* Check if all frames in this row/col have one window. */
1471 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1473 if (frp
->fr_win
== NULL
)
1475 EMSG(_("E443: Cannot rotate when another window is split"));
1482 if (upwards
) /* first window becomes last window */
1484 /* remove first window/frame from the list */
1485 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1487 win_remove(wp1
, NULL
);
1490 /* find last frame and append removed window/frame after it */
1491 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1493 win_append(frp
->fr_win
, wp1
);
1494 frame_append(frp
, wp1
->w_frame
);
1496 wp2
= frp
->fr_win
; /* previously last window */
1498 else /* last window becomes first window */
1500 /* find last window/frame in the list and remove it */
1501 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1505 wp2
= wp1
->w_prev
; /* will become last window */
1506 win_remove(wp1
, NULL
);
1509 /* append the removed window/frame before the first in the list */
1510 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1511 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1514 /* exchange status height and vsep width of old and new last window */
1515 n
= wp2
->w_status_height
;
1516 wp2
->w_status_height
= wp1
->w_status_height
;
1517 wp1
->w_status_height
= n
;
1518 frame_fix_height(wp1
);
1519 frame_fix_height(wp2
);
1520 #ifdef FEAT_VERTSPLIT
1521 n
= wp2
->w_vsep_width
;
1522 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1523 wp1
->w_vsep_width
= n
;
1524 frame_fix_width(wp1
);
1525 frame_fix_width(wp2
);
1528 /* recompute w_winrow and w_wincol for all windows */
1529 (void)win_comp_pos();
1532 redraw_later(CLEAR
);
1536 * Move the current window to the very top/bottom/left/right of the screen.
1539 win_totop(size
, flags
)
1544 int height
= curwin
->w_height
;
1546 if (lastwin
== firstwin
)
1552 /* Remove the window and frame from the tree of frames. */
1553 (void)winframe_remove(curwin
, &dir
, NULL
);
1554 win_remove(curwin
, NULL
);
1555 last_status(FALSE
); /* may need to remove last status line */
1556 (void)win_comp_pos(); /* recompute window positions */
1558 /* Split a window on the desired side and put the window there. */
1559 (void)win_split_ins(size
, flags
, curwin
, dir
);
1560 if (!(flags
& WSP_VERT
))
1562 win_setheight(height
);
1564 win_equal(curwin
, TRUE
, 'v');
1567 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1568 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1569 * scrollbars. Have to update them anyway. */
1573 gui_init_which_components(NULL
);
1574 gui_update_scrollbars(TRUE
);
1576 need_mouse_correct
= TRUE
;
1582 * Move window "win1" to below/right of "win2" and make "win1" the current
1583 * window. Only works within the same frame!
1586 win_move_after(win1
, win2
)
1591 /* check if the arguments are reasonable */
1595 /* check if there is something to do */
1596 if (win2
->w_next
!= win1
)
1598 /* may need move the status line/vertical separator of the last window
1600 if (win1
== lastwin
)
1602 height
= win1
->w_prev
->w_status_height
;
1603 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1604 win1
->w_status_height
= height
;
1605 #ifdef FEAT_VERTSPLIT
1606 if (win1
->w_prev
->w_vsep_width
== 1)
1608 /* Remove the vertical separator from the last-but-one window,
1609 * add it to the last window. Adjust the frame widths. */
1610 win1
->w_prev
->w_vsep_width
= 0;
1611 win1
->w_prev
->w_frame
->fr_width
-= 1;
1612 win1
->w_vsep_width
= 1;
1613 win1
->w_frame
->fr_width
+= 1;
1617 else if (win2
== lastwin
)
1619 height
= win1
->w_status_height
;
1620 win1
->w_status_height
= win2
->w_status_height
;
1621 win2
->w_status_height
= height
;
1622 #ifdef FEAT_VERTSPLIT
1623 if (win1
->w_vsep_width
== 1)
1625 /* Remove the vertical separator from win1, add it to the last
1626 * window, win2. Adjust the frame widths. */
1627 win2
->w_vsep_width
= 1;
1628 win2
->w_frame
->fr_width
+= 1;
1629 win1
->w_vsep_width
= 0;
1630 win1
->w_frame
->fr_width
-= 1;
1634 win_remove(win1
, NULL
);
1635 frame_remove(win1
->w_frame
);
1636 win_append(win2
, win1
);
1637 frame_append(win2
->w_frame
, win1
->w_frame
);
1639 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1640 redraw_later(NOT_VALID
);
1642 win_enter(win1
, FALSE
);
1646 * Make all windows the same height.
1647 * 'next_curwin' will soon be the current window, make sure it has enough
1651 win_equal(next_curwin
, current
, dir
)
1652 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1653 int current
; /* do only frame with current window */
1654 int dir
; /* 'v' for vertically, 'h' for horizontally,
1655 'b' for both, 0 for using p_ead */
1658 #ifdef FEAT_VERTSPLIT
1663 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1664 topframe
, dir
, 0, tabline_height(),
1665 (int)Columns
, topframe
->fr_height
);
1669 * Set a frame to a new position and height, spreading the available room
1670 * equally over contained frames.
1671 * The window "next_curwin" (if not NULL) should at least get the size from
1672 * 'winheight' and 'winwidth' if possible.
1675 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1676 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1677 int current
; /* do only frame with current window */
1678 frame_T
*topfr
; /* frame to set size off */
1679 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1680 int col
; /* horizontal position for frame */
1681 int row
; /* vertical position for frame */
1682 int width
; /* new width of frame */
1683 int height
; /* new height of frame */
1687 int wincount
, totwincount
= 0;
1689 int next_curwin_size
= 0;
1692 int has_next_curwin
= 0;
1695 if (topfr
->fr_layout
== FR_LEAF
)
1697 /* Set the width/height of this frame.
1698 * Redraw when size or position changes */
1699 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1700 #ifdef FEAT_VERTSPLIT
1701 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1705 topfr
->fr_win
->w_winrow
= row
;
1706 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1707 #ifdef FEAT_VERTSPLIT
1708 topfr
->fr_win
->w_wincol
= col
;
1709 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1711 redraw_all_later(CLEAR
);
1714 #ifdef FEAT_VERTSPLIT
1715 else if (topfr
->fr_layout
== FR_ROW
)
1717 topfr
->fr_width
= width
;
1718 topfr
->fr_height
= height
;
1720 if (dir
!= 'v') /* equalize frame widths */
1722 /* Compute the maximum number of windows horizontally in this
1724 n
= frame_minwidth(topfr
, NOWIN
);
1725 /* add one for the rightmost window, it doesn't have a separator */
1726 if (col
+ width
== Columns
)
1730 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1731 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1734 * Compute width for "next_curwin" window and room available for
1736 * "m" is the minimal width when counting p_wiw for "next_curwin".
1738 m
= frame_minwidth(topfr
, next_curwin
);
1742 next_curwin_size
= p_wiw
+ room
;
1747 next_curwin_size
= -1;
1748 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1750 /* If 'winfixwidth' set keep the window width if
1752 * Watch out for this window being the next_curwin. */
1753 if (frame_fixed_width(fr
))
1755 n
= frame_minwidth(fr
, NOWIN
);
1756 new_size
= fr
->fr_width
;
1757 if (frame_has_win(fr
, next_curwin
))
1759 room
+= p_wiw
- p_wmw
;
1760 next_curwin_size
= 0;
1761 if (new_size
< p_wiw
)
1765 /* These windows don't use up room. */
1766 totwincount
-= (n
+ (fr
->fr_next
== NULL
1767 ? extra_sep
: 0)) / (p_wmw
+ 1);
1768 room
-= new_size
- n
;
1774 fr
->fr_newwidth
= new_size
;
1777 if (next_curwin_size
== -1)
1779 if (!has_next_curwin
)
1780 next_curwin_size
= 0;
1781 else if (totwincount
> 1
1782 && (room
+ (totwincount
- 2))
1783 / (totwincount
- 1) > p_wiw
)
1785 /* Can make all windows wider than 'winwidth', spread
1786 * the room equally. */
1787 next_curwin_size
= (room
+ p_wiw
1788 + (totwincount
- 1) * p_wmw
1789 + (totwincount
- 1)) / totwincount
;
1790 room
-= next_curwin_size
- p_wiw
;
1793 next_curwin_size
= p_wiw
;
1797 if (has_next_curwin
)
1798 --totwincount
; /* don't count curwin */
1801 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1805 if (fr
->fr_next
== NULL
)
1806 /* last frame gets all that remains (avoid roundoff error) */
1808 else if (dir
== 'v')
1809 new_size
= fr
->fr_width
;
1810 else if (frame_fixed_width(fr
))
1812 new_size
= fr
->fr_newwidth
;
1813 wincount
= 0; /* doesn't count as a sizeable window */
1817 /* Compute the maximum number of windows horiz. in "fr". */
1818 n
= frame_minwidth(fr
, NOWIN
);
1819 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1821 m
= frame_minwidth(fr
, next_curwin
);
1822 if (has_next_curwin
)
1823 hnc
= frame_has_win(fr
, next_curwin
);
1826 if (hnc
) /* don't count next_curwin */
1828 if (totwincount
== 0)
1831 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1833 if (hnc
) /* add next_curwin size */
1835 next_curwin_size
-= p_wiw
- (m
- n
);
1836 new_size
+= next_curwin_size
;
1837 room
-= new_size
- next_curwin_size
;
1844 /* Skip frame that is full width when splitting or closing a
1845 * window, unless equalizing all frames. */
1846 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1847 || (new_size
!= fr
->fr_width
)
1848 || frame_has_win(fr
, next_curwin
))
1849 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1853 totwincount
-= wincount
;
1857 else /* topfr->fr_layout == FR_COL */
1859 #ifdef FEAT_VERTSPLIT
1860 topfr
->fr_width
= width
;
1862 topfr
->fr_height
= height
;
1864 if (dir
!= 'h') /* equalize frame heights */
1866 /* Compute maximum number of windows vertically in this frame. */
1867 n
= frame_minheight(topfr
, NOWIN
);
1868 /* add one for the bottom window if it doesn't have a statusline */
1869 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1873 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1874 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1877 * Compute height for "next_curwin" window and room available for
1879 * "m" is the minimal height when counting p_wh for "next_curwin".
1881 m
= frame_minheight(topfr
, next_curwin
);
1885 /* The room is less then 'winheight', use all space for the
1886 * current window. */
1887 next_curwin_size
= p_wh
+ room
;
1892 next_curwin_size
= -1;
1893 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1895 /* If 'winfixheight' set keep the window height if
1897 * Watch out for this window being the next_curwin. */
1898 if (frame_fixed_height(fr
))
1900 n
= frame_minheight(fr
, NOWIN
);
1901 new_size
= fr
->fr_height
;
1902 if (frame_has_win(fr
, next_curwin
))
1904 room
+= p_wh
- p_wmh
;
1905 next_curwin_size
= 0;
1906 if (new_size
< p_wh
)
1910 /* These windows don't use up room. */
1911 totwincount
-= (n
+ (fr
->fr_next
== NULL
1912 ? extra_sep
: 0)) / (p_wmh
+ 1);
1913 room
-= new_size
- n
;
1919 fr
->fr_newheight
= new_size
;
1922 if (next_curwin_size
== -1)
1924 if (!has_next_curwin
)
1925 next_curwin_size
= 0;
1926 else if (totwincount
> 1
1927 && (room
+ (totwincount
- 2))
1928 / (totwincount
- 1) > p_wh
)
1930 /* can make all windows higher than 'winheight',
1931 * spread the room equally. */
1932 next_curwin_size
= (room
+ p_wh
1933 + (totwincount
- 1) * p_wmh
1934 + (totwincount
- 1)) / totwincount
;
1935 room
-= next_curwin_size
- p_wh
;
1938 next_curwin_size
= p_wh
;
1942 if (has_next_curwin
)
1943 --totwincount
; /* don't count curwin */
1946 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1950 if (fr
->fr_next
== NULL
)
1951 /* last frame gets all that remains (avoid roundoff error) */
1953 else if (dir
== 'h')
1954 new_size
= fr
->fr_height
;
1955 else if (frame_fixed_height(fr
))
1957 new_size
= fr
->fr_newheight
;
1958 wincount
= 0; /* doesn't count as a sizeable window */
1962 /* Compute the maximum number of windows vert. in "fr". */
1963 n
= frame_minheight(fr
, NOWIN
);
1964 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1966 m
= frame_minheight(fr
, next_curwin
);
1967 if (has_next_curwin
)
1968 hnc
= frame_has_win(fr
, next_curwin
);
1971 if (hnc
) /* don't count next_curwin */
1973 if (totwincount
== 0)
1976 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1978 if (hnc
) /* add next_curwin size */
1980 next_curwin_size
-= p_wh
- (m
- n
);
1981 new_size
+= next_curwin_size
;
1982 room
-= new_size
- next_curwin_size
;
1988 /* Skip frame that is full width when splitting or closing a
1989 * window, unless equalizing all frames. */
1990 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1991 || (new_size
!= fr
->fr_height
)
1992 || frame_has_win(fr
, next_curwin
))
1993 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1997 totwincount
-= wincount
;
2003 * close all windows for buffer 'buf'
2006 close_windows(buf
, keep_curwin
)
2008 int keep_curwin
; /* don't close "curwin" */
2011 tabpage_T
*tp
, *nexttp
;
2012 int h
= tabline_height();
2014 ++RedrawingDisabled
;
2016 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2018 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2020 win_close(wp
, FALSE
);
2022 /* Start all over, autocommands may change the window layout. */
2029 /* Also check windows in other tab pages. */
2030 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2032 nexttp
= tp
->tp_next
;
2034 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2035 if (wp
->w_buffer
== buf
)
2037 win_close_othertab(wp
, FALSE
, tp
);
2039 /* Start all over, the tab page may be closed and
2040 * autocommands may change the window layout. */
2041 nexttp
= first_tabpage
;
2046 --RedrawingDisabled
;
2048 if (h
!= tabline_height())
2053 * Return TRUE if the current window is the only window that exists.
2054 * Returns FALSE if there is a window, possibly in another tab page.
2059 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2063 * Close window "win". Only works for the current tab page.
2064 * If "free_buf" is TRUE related buffer may be unloaded.
2066 * called by :quit, :close, :xit, :wq and findtag()
2069 win_close(win
, free_buf
)
2075 int other_buffer
= FALSE
;
2077 int close_curwin
= FALSE
;
2079 int help_window
= FALSE
;
2080 tabpage_T
*prev_curtab
= curtab
;
2084 EMSG(_("E444: Cannot close last window"));
2089 * When closing the last window in a tab page first go to another tab
2090 * page and then close the window and the tab page. This avoids that
2091 * curwin and curtab are not invalid while we are freeing memory, they may
2092 * be used in GUI events.
2094 if (firstwin
== lastwin
)
2096 goto_tabpage_tp(alt_tabpage());
2097 redraw_tabline
= TRUE
;
2099 /* Safety check: Autocommands may have closed the window when jumping
2100 * to the other tab page. */
2101 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2103 int h
= tabline_height();
2105 win_close_othertab(win
, free_buf
, prev_curtab
);
2106 if (h
!= tabline_height())
2112 /* When closing the help window, try restoring a snapshot after closing
2113 * the window. Otherwise clear the snapshot, it's now invalid. */
2114 if (win
->w_buffer
->b_help
)
2117 clear_snapshot(curtab
);
2123 * Guess which window is going to be the new current window.
2124 * This may change because of the autocommands (sigh).
2126 wp
= frame2win(win_altframe(win
, NULL
));
2129 * Be careful: If autocommands delete the window, return now.
2131 if (wp
->w_buffer
!= curbuf
)
2133 other_buffer
= TRUE
;
2134 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2135 if (!win_valid(win
) || last_window())
2138 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2139 if (!win_valid(win
) || last_window())
2142 /* autocmds may abort script processing */
2150 /* Avoid trouble with scrollbars that are going to be deleted in
2157 * Close the link to the buffer.
2159 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2161 /* Autocommands may have closed the window already, or closed the only
2162 * other window or moved to another tab page. */
2163 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2166 /* Free the memory used for the window. */
2167 wp
= win_free_mem(win
, &dir
, NULL
);
2169 /* Make sure curwin isn't invalid. It can cause severe trouble when
2170 * printing an error message. For win_equal() curbuf needs to be valid
2175 #ifdef FEAT_QUICKFIX
2176 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2179 * If the cursor goes to the preview or the quickfix window, try
2180 * finding another window to go to.
2184 if (wp
->w_next
== NULL
)
2190 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2198 curbuf
= curwin
->w_buffer
;
2199 close_curwin
= TRUE
;
2202 #ifdef FEAT_VERTSPLIT
2203 && (*p_ead
== 'b' || *p_ead
== dir
)
2206 win_equal(curwin
, TRUE
,
2207 #ifdef FEAT_VERTSPLIT
2217 win_enter_ext(wp
, FALSE
, TRUE
);
2220 /* careful: after this wp and win may be invalid! */
2221 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2226 * If last window has a status line now and we don't want one,
2227 * remove the status line.
2231 /* After closing the help window, try restoring the window layout from
2232 * before it was opened. */
2234 restore_snapshot(close_curwin
);
2236 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2237 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2238 if (gui
.in_use
&& !win_hasvertsplit())
2239 gui_init_which_components(NULL
);
2242 redraw_all_later(NOT_VALID
);
2246 * Close window "win" in tab page "tp", which is not the current tab page.
2247 * This may be the last window ih that tab page and result in closing the tab,
2248 * thus "tp" may become invalid!
2249 * Caller must check if buffer is hidden and whether the tabline needs to be
2253 win_close_othertab(win
, free_buf
, tp
)
2260 tabpage_T
*ptp
= NULL
;
2262 /* Close the link to the buffer. */
2263 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2265 /* Careful: Autocommands may have closed the tab page or made it the
2266 * current tab page. */
2267 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2269 if (ptp
== NULL
|| tp
== curtab
)
2272 /* Autocommands may have closed the window already. */
2273 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2278 /* Free the memory used for the window. */
2279 wp
= win_free_mem(win
, &dir
, tp
);
2281 /* When closing the last window in a tab page remove the tab page. */
2284 if (tp
== first_tabpage
)
2285 first_tabpage
= tp
->tp_next
;
2288 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2293 EMSG2(_(e_intern2
), "win_close_othertab()");
2296 ptp
->tp_next
= tp
->tp_next
;
2303 * Free the memory used for a window.
2304 * Returns a pointer to the window that got the freed up space.
2307 win_free_mem(win
, dirp
, tp
)
2309 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2310 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2319 /* reduce the reference count to the argument list. */
2320 alist_unlink(win
->w_alist
);
2322 /* Remove the window and its frame from the tree of frames. */
2324 wp
= winframe_remove(win
, dirp
, tp
);
2328 /* When deleting the current window of another tab page select a new
2329 * current window. */
2330 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2336 #if defined(EXITFREE) || defined(PROTO)
2342 # ifdef FEAT_WINDOWS
2343 while (first_tabpage
->tp_next
!= NULL
)
2344 tabpage_close(TRUE
);
2347 while (firstwin
!= NULL
)
2348 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2353 * Remove a window and its frame from the tree of frames.
2354 * Returns a pointer to the window that got the freed up space.
2358 winframe_remove(win
, dirp
, tp
)
2360 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2361 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2363 frame_T
*frp
, *frp2
, *frp3
;
2364 frame_T
*frp_close
= win
->w_frame
;
2368 * If there is only one window there is nothing to remove.
2370 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2374 * Remove the window from its frame.
2376 frp2
= win_altframe(win
, tp
);
2377 wp
= frame2win(frp2
);
2379 /* Remove this frame from the list of frames. */
2380 frame_remove(frp_close
);
2382 #ifdef FEAT_VERTSPLIT
2383 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2386 /* When 'winfixheight' is set, try to find another frame in the column
2387 * (as close to the closed frame as possible) to distribute the height
2389 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2391 frp
= frp_close
->fr_prev
;
2392 frp3
= frp_close
->fr_next
;
2393 while (frp
!= NULL
|| frp3
!= NULL
)
2397 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2407 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2413 frp3
= frp3
->fr_next
;
2417 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2418 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2419 #ifdef FEAT_VERTSPLIT
2424 /* When 'winfixwidth' is set, try to find another frame in the column
2425 * (as close to the closed frame as possible) to distribute the width
2427 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2429 frp
= frp_close
->fr_prev
;
2430 frp3
= frp_close
->fr_next
;
2431 while (frp
!= NULL
|| frp3
!= NULL
)
2435 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2445 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2451 frp3
= frp3
->fr_next
;
2455 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2456 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2461 /* If rows/columns go to a window below/right its positions need to be
2462 * updated. Can only be done after the sizes have been updated. */
2463 if (frp2
== frp_close
->fr_next
)
2465 int row
= win
->w_winrow
;
2466 int col
= W_WINCOL(win
);
2468 frame_comp_pos(frp2
, &row
, &col
);
2471 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2473 /* There is no other frame in this list, move its info to the parent
2475 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2476 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2477 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2478 frp
->fr_parent
= frp2
->fr_parent
;
2479 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2480 if (frp2
->fr_win
!= NULL
)
2481 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2482 frp
= frp2
->fr_parent
;
2485 frp2
= frp
->fr_parent
;
2486 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2488 /* The frame above the parent has the same layout, have to merge
2489 * the frames into this list. */
2490 if (frp2
->fr_child
== frp
)
2491 frp2
->fr_child
= frp
->fr_child
;
2492 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2493 if (frp
->fr_prev
!= NULL
)
2494 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2495 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2497 frp3
->fr_parent
= frp2
;
2498 if (frp3
->fr_next
== NULL
)
2500 frp3
->fr_next
= frp
->fr_next
;
2501 if (frp
->fr_next
!= NULL
)
2502 frp
->fr_next
->fr_prev
= frp3
;
2514 * Find out which frame is going to get the freed up space when "win" is
2516 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2517 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2518 * This makes opening a window and closing it immediately keep the same window
2522 win_altframe(win
, tp
)
2524 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2529 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2530 /* Last window in this tab page, will go to next tab page. */
2531 return alt_tabpage()->tp_curwin
->w_frame
;
2534 #ifdef FEAT_VERTSPLIT
2535 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2540 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2541 return frp
->fr_next
;
2542 return frp
->fr_prev
;
2546 * Return the tabpage that will be used if the current one is closed.
2553 /* Use the next tab page if possible. */
2554 if (curtab
->tp_next
!= NULL
)
2555 return curtab
->tp_next
;
2557 /* Find the last but one tab page. */
2558 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2564 * Find the left-upper window in frame "frp".
2570 while (frp
->fr_win
== NULL
)
2571 frp
= frp
->fr_child
;
2576 * Return TRUE if frame "frp" contains window "wp".
2579 frame_has_win(frp
, wp
)
2585 if (frp
->fr_layout
== FR_LEAF
)
2586 return frp
->fr_win
== wp
;
2588 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2589 if (frame_has_win(p
, wp
))
2595 * Set a new height for a frame. Recursively sets the height for contained
2596 * frames and windows. Caller must take care of positions.
2599 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2602 int topfirst
; /* resize topmost contained frame first */
2603 int wfh
; /* obey 'winfixheight' when there is a choice;
2604 may cause the height not to be set */
2610 if (topfrp
->fr_win
!= NULL
)
2612 /* Simple case: just one window. */
2613 win_new_height(topfrp
->fr_win
,
2614 height
- topfrp
->fr_win
->w_status_height
);
2616 #ifdef FEAT_VERTSPLIT
2617 else if (topfrp
->fr_layout
== FR_ROW
)
2621 /* All frames in this row get the same new height. */
2622 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2624 frame_new_height(frp
, height
, topfirst
, wfh
);
2625 if (frp
->fr_height
> height
)
2627 /* Could not fit the windows, make the whole row higher. */
2628 height
= frp
->fr_height
;
2633 while (frp
!= NULL
);
2636 else /* fr_layout == FR_COL */
2638 /* Complicated case: Resize a column of frames. Resize the bottom
2639 * frame first, frames above that when needed. */
2641 frp
= topfrp
->fr_child
;
2643 /* Advance past frames with one window with 'wfh' set. */
2644 while (frame_fixed_height(frp
))
2648 return; /* no frame without 'wfh', give up */
2652 /* Find the bottom frame of this column */
2653 while (frp
->fr_next
!= NULL
)
2656 /* Advance back for frames with one window with 'wfh' set. */
2657 while (frame_fixed_height(frp
))
2661 extra_lines
= height
- topfrp
->fr_height
;
2662 if (extra_lines
< 0)
2664 /* reduce height of contained frames, bottom or top frame first */
2667 h
= frame_minheight(frp
, NULL
);
2668 if (frp
->fr_height
+ extra_lines
< h
)
2670 extra_lines
+= frp
->fr_height
- h
;
2671 frame_new_height(frp
, h
, topfirst
, wfh
);
2675 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2683 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2689 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2691 /* Increase "height" if we could not reduce enough frames. */
2693 height
-= extra_lines
;
2696 else if (extra_lines
> 0)
2698 /* increase height of bottom or top frame */
2699 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2702 topfrp
->fr_height
= height
;
2706 * Return TRUE if height of frame "frp" should not be changed because of
2707 * the 'winfixheight' option.
2710 frame_fixed_height(frp
)
2713 /* frame with one window: fixed height if 'winfixheight' set. */
2714 if (frp
->fr_win
!= NULL
)
2715 return frp
->fr_win
->w_p_wfh
;
2717 if (frp
->fr_layout
== FR_ROW
)
2719 /* The frame is fixed height if one of the frames in the row is fixed
2721 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2722 if (frame_fixed_height(frp
))
2727 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2728 * frames in the row are fixed height. */
2729 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2730 if (!frame_fixed_height(frp
))
2735 #ifdef FEAT_VERTSPLIT
2737 * Return TRUE if width of frame "frp" should not be changed because of
2738 * the 'winfixwidth' option.
2741 frame_fixed_width(frp
)
2744 /* frame with one window: fixed width if 'winfixwidth' set. */
2745 if (frp
->fr_win
!= NULL
)
2746 return frp
->fr_win
->w_p_wfw
;
2748 if (frp
->fr_layout
== FR_COL
)
2750 /* The frame is fixed width if one of the frames in the row is fixed
2752 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2753 if (frame_fixed_width(frp
))
2758 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2759 * frames in the row are fixed width. */
2760 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2761 if (!frame_fixed_width(frp
))
2767 * Add a status line to windows at the bottom of "frp".
2768 * Note: Does not check if there is room!
2771 frame_add_statusline(frp
)
2776 if (frp
->fr_layout
== FR_LEAF
)
2779 if (wp
->w_status_height
== 0)
2781 if (wp
->w_height
> 0) /* don't make it negative */
2783 wp
->w_status_height
= STATUS_HEIGHT
;
2786 else if (frp
->fr_layout
== FR_ROW
)
2788 /* Handle all the frames in the row. */
2789 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2790 frame_add_statusline(frp
);
2792 else /* frp->fr_layout == FR_COL */
2794 /* Only need to handle the last frame in the column. */
2795 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2797 frame_add_statusline(frp
);
2802 * Set width of a frame. Handles recursively going through contained frames.
2803 * May remove separator line for windows at the right side (for win_close()).
2806 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2809 int leftfirst
; /* resize leftmost contained frame first */
2810 int wfw
; /* obey 'winfixwidth' when there is a choice;
2811 may cause the width not to be set */
2818 if (topfrp
->fr_layout
== FR_LEAF
)
2820 /* Simple case: just one window. */
2821 wp
= topfrp
->fr_win
;
2822 /* Find out if there are any windows right of this one. */
2823 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2824 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2826 if (frp
->fr_parent
== NULL
)
2827 wp
->w_vsep_width
= 0;
2828 win_new_width(wp
, width
- wp
->w_vsep_width
);
2830 else if (topfrp
->fr_layout
== FR_COL
)
2834 /* All frames in this column get the same new width. */
2835 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2837 frame_new_width(frp
, width
, leftfirst
, wfw
);
2838 if (frp
->fr_width
> width
)
2840 /* Could not fit the windows, make whole column wider. */
2841 width
= frp
->fr_width
;
2845 } while (frp
!= NULL
);
2847 else /* fr_layout == FR_ROW */
2849 /* Complicated case: Resize a row of frames. Resize the rightmost
2850 * frame first, frames left of it when needed. */
2852 frp
= topfrp
->fr_child
;
2854 /* Advance past frames with one window with 'wfw' set. */
2855 while (frame_fixed_width(frp
))
2859 return; /* no frame without 'wfw', give up */
2863 /* Find the rightmost frame of this row */
2864 while (frp
->fr_next
!= NULL
)
2867 /* Advance back for frames with one window with 'wfw' set. */
2868 while (frame_fixed_width(frp
))
2872 extra_cols
= width
- topfrp
->fr_width
;
2875 /* reduce frame width, rightmost frame first */
2878 w
= frame_minwidth(frp
, NULL
);
2879 if (frp
->fr_width
+ extra_cols
< w
)
2881 extra_cols
+= frp
->fr_width
- w
;
2882 frame_new_width(frp
, w
, leftfirst
, wfw
);
2886 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2894 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2900 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2902 /* Increase "width" if we could not reduce enough frames. */
2904 width
-= extra_cols
;
2907 else if (extra_cols
> 0)
2909 /* increase width of rightmost frame */
2910 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2913 topfrp
->fr_width
= width
;
2917 * Add the vertical separator to windows at the right side of "frp".
2918 * Note: Does not check if there is room!
2926 if (frp
->fr_layout
== FR_LEAF
)
2929 if (wp
->w_vsep_width
== 0)
2931 if (wp
->w_width
> 0) /* don't make it negative */
2933 wp
->w_vsep_width
= 1;
2936 else if (frp
->fr_layout
== FR_COL
)
2938 /* Handle all the frames in the column. */
2939 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2940 frame_add_vsep(frp
);
2942 else /* frp->fr_layout == FR_ROW */
2944 /* Only need to handle the last frame in the row. */
2945 frp
= frp
->fr_child
;
2946 while (frp
->fr_next
!= NULL
)
2948 frame_add_vsep(frp
);
2953 * Set frame width from the window it contains.
2959 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2964 * Set frame height from the window it contains.
2967 frame_fix_height(wp
)
2970 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2974 * Compute the minimal height for frame "topfrp".
2975 * Uses the 'winminheight' option.
2976 * When "next_curwin" isn't NULL, use p_wh for this window.
2977 * When "next_curwin" is NOWIN, don't use at least one line for the current
2981 frame_minheight(topfrp
, next_curwin
)
2987 #ifdef FEAT_VERTSPLIT
2991 if (topfrp
->fr_win
!= NULL
)
2993 if (topfrp
->fr_win
== next_curwin
)
2994 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2997 /* window: minimal height of the window plus status line */
2998 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2999 /* Current window is minimal one line high */
3000 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3004 #ifdef FEAT_VERTSPLIT
3005 else if (topfrp
->fr_layout
== FR_ROW
)
3007 /* get the minimal height from each frame in this row */
3009 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3011 n
= frame_minheight(frp
, next_curwin
);
3019 /* Add up the minimal heights for all frames in this column. */
3021 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3022 m
+= frame_minheight(frp
, next_curwin
);
3028 #ifdef FEAT_VERTSPLIT
3030 * Compute the minimal width for frame "topfrp".
3031 * When "next_curwin" isn't NULL, use p_wiw for this window.
3032 * When "next_curwin" is NOWIN, don't use at least one column for the current
3036 frame_minwidth(topfrp
, next_curwin
)
3038 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3043 if (topfrp
->fr_win
!= NULL
)
3045 if (topfrp
->fr_win
== next_curwin
)
3046 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3049 /* window: minimal width of the window plus separator column */
3050 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3051 /* Current window is minimal one column wide */
3052 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3056 else if (topfrp
->fr_layout
== FR_COL
)
3058 /* get the minimal width from each frame in this column */
3060 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3062 n
= frame_minwidth(frp
, next_curwin
);
3069 /* Add up the minimal widths for all frames in this row. */
3071 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3072 m
+= frame_minwidth(frp
, next_curwin
);
3081 * Try to close all windows except current one.
3082 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3083 * used and the buffer was modified.
3085 * Used by ":bdel" and ":only".
3088 close_others(message
, forceit
)
3090 int forceit
; /* always hide all other windows */
3096 if (lastwin
== firstwin
)
3107 /* Be very careful here: autocommands may change the window layout. */
3108 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3110 nextwp
= wp
->w_next
;
3111 if (wp
!= curwin
) /* don't close current window */
3114 /* Check if it's allowed to abandon this window */
3115 r
= can_abandon(wp
->w_buffer
, forceit
);
3117 if (!win_valid(wp
)) /* autocommands messed wp up */
3125 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3126 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3128 dialog_changed(wp
->w_buffer
, FALSE
);
3129 # ifdef FEAT_AUTOCMD
3130 if (!win_valid(wp
)) /* autocommands messed wp up */
3137 if (bufIsChanged(wp
->w_buffer
))
3141 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3145 if (message
&& lastwin
!= firstwin
)
3146 EMSG(_("E445: Other window contains changes"));
3149 #endif /* FEAT_WINDOWS */
3152 * Init the current window "curwin".
3153 * Called when a new file is being edited.
3158 redraw_win_later(curwin
, NOT_VALID
);
3159 curwin
->w_lines_valid
= 0;
3160 curwin
->w_cursor
.lnum
= 1;
3161 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3162 #ifdef FEAT_VIRTUALEDIT
3163 curwin
->w_cursor
.coladd
= 0;
3165 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3166 curwin
->w_pcmark
.col
= 0;
3167 curwin
->w_prev_pcmark
.lnum
= 0;
3168 curwin
->w_prev_pcmark
.col
= 0;
3169 curwin
->w_topline
= 1;
3171 curwin
->w_topfill
= 0;
3173 curwin
->w_botline
= 2;
3176 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3178 curwin
->w_farsi
= W_CONV
;
3183 * Allocate the first window and put an empty buffer in it.
3184 * Called from main().
3185 * Return FAIL when something goes wrong (out of memory).
3190 if (win_alloc_firstwin(NULL
) == FAIL
)
3194 first_tabpage
= alloc_tabpage();
3195 if (first_tabpage
== NULL
)
3197 first_tabpage
->tp_topframe
= topframe
;
3198 curtab
= first_tabpage
;
3204 * Allocate the first window or the first window in a new tab page.
3205 * When "oldwin" is NULL create an empty buffer for it.
3206 * When "oldwin" is not NULL copy info from it to the new window (only with
3208 * Return FAIL when something goes wrong (out of memory).
3211 win_alloc_firstwin(oldwin
)
3214 curwin
= win_alloc(NULL
);
3217 /* Very first window, need to create an empty buffer for it and
3218 * initialize from scratch. */
3219 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3220 if (curwin
== NULL
|| curbuf
== NULL
)
3222 curwin
->w_buffer
= curbuf
;
3223 curbuf
->b_nwindows
= 1; /* there is one window */
3225 curwin
->w_alist
= &global_alist
;
3227 curwin_init(); /* init current window */
3232 /* First window in new tab page, initialize it from "oldwin". */
3233 win_init(curwin
, oldwin
, 0);
3235 # ifdef FEAT_SCROLLBIND
3236 /* We don't want scroll-binding in the first window. */
3237 curwin
->w_p_scb
= FALSE
;
3242 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3243 if (topframe
== NULL
)
3245 topframe
->fr_layout
= FR_LEAF
;
3246 #ifdef FEAT_VERTSPLIT
3247 topframe
->fr_width
= Columns
;
3249 topframe
->fr_height
= Rows
- p_ch
;
3250 topframe
->fr_win
= curwin
;
3251 curwin
->w_frame
= topframe
;
3257 * Initialize the window and frame size to the maximum.
3262 firstwin
->w_height
= ROWS_AVAIL
;
3263 topframe
->fr_height
= ROWS_AVAIL
;
3264 #ifdef FEAT_VERTSPLIT
3265 firstwin
->w_width
= Columns
;
3266 topframe
->fr_width
= Columns
;
3270 #if defined(FEAT_WINDOWS) || defined(PROTO)
3273 * Allocate a new tabpage_T and init the values.
3274 * Returns NULL when out of memory.
3281 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3287 for (i
= 0; i
< 3; i
++)
3288 tp
->tp_prev_which_scrollbars
[i
] = -1;
3291 tp
->tp_diff_invalid
= TRUE
;
3294 /* init t: variables */
3295 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3297 tp
->tp_ch_used
= p_ch
;
3311 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3317 * Create a new Tab page with one window.
3318 * It will edit the current buffer, like after ":split".
3319 * When "after" is 0 put it just after the current Tab page.
3320 * Otherwise put it just before tab page "after".
3321 * Return FAIL or OK.
3324 win_new_tabpage(after
)
3327 tabpage_T
*tp
= curtab
;
3331 newtp
= alloc_tabpage();
3335 /* Remember the current windows in this Tab page. */
3336 if (leave_tabpage(curbuf
) == FAIL
)
3343 /* Create a new empty window. */
3344 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3346 /* Make the new Tab page the new topframe. */
3349 /* New tab page becomes the first one. */
3350 newtp
->tp_next
= first_tabpage
;
3351 first_tabpage
= newtp
;
3357 /* Put new tab page before tab page "after". */
3359 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3360 && n
< after
; tp
= tp
->tp_next
)
3363 newtp
->tp_next
= tp
->tp_next
;
3364 tp
->tp_next
= newtp
;
3367 firstwin
->w_winrow
= tabline_height();
3368 win_comp_scroll(curwin
);
3370 newtp
->tp_topframe
= topframe
;
3373 #if defined(FEAT_GUI)
3374 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3375 * scrollbars. Have to update them anyway. */
3376 if (gui
.in_use
&& starting
== 0)
3378 gui_init_which_components(NULL
);
3379 gui_update_scrollbars(TRUE
);
3381 need_mouse_correct
= TRUE
;
3384 redraw_all_later(CLEAR
);
3386 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3387 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3392 /* Failed, get back the previous Tab page */
3393 enter_tabpage(curtab
, curbuf
);
3398 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3399 * like with ":split".
3400 * Returns OK if a new tab page was created, FAIL otherwise.
3405 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3409 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3410 postponed_split_tab
= 0;
3411 return win_new_tabpage(n
);
3417 * Create up to "maxcount" tabpages with empty windows.
3418 * Returns the number of resulting tab pages.
3421 make_tabpages(maxcount
)
3424 int count
= maxcount
;
3427 /* Limit to 'tabpagemax' tabs. */
3433 * Don't execute autocommands while creating the tab pages. Must do that
3434 * when putting the buffers in the windows.
3439 for (todo
= count
- 1; todo
> 0; --todo
)
3440 if (win_new_tabpage(0) == FAIL
)
3447 /* return actual number of tab pages */
3448 return (count
- todo
);
3452 * Return TRUE when "tpc" points to a valid tab page.
3460 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3467 * Find tab page "n" (first one is 1). Returns NULL when not found.
3476 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3482 * Get index of tab page "tp". First one has index 1.
3483 * When not found returns number of tab pages plus one.
3492 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3498 * Prepare for leaving the current tab page.
3499 * When autocomands change "curtab" we don't leave the tab page and return
3501 * Careful: When OK is returned need to get a new tab page very very soon!
3505 leave_tabpage(new_curbuf
)
3506 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3509 tabpage_T
*tp
= curtab
;
3512 reset_VIsual_and_resel(); /* stop Visual mode */
3515 if (new_curbuf
!= curbuf
)
3517 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3521 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3524 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3528 #if defined(FEAT_GUI)
3529 /* Remove the scrollbars. They may be added back later. */
3531 gui_remove_scrollbars();
3533 tp
->tp_curwin
= curwin
;
3534 tp
->tp_prevwin
= prevwin
;
3535 tp
->tp_firstwin
= firstwin
;
3536 tp
->tp_lastwin
= lastwin
;
3537 tp
->tp_old_Rows
= Rows
;
3538 tp
->tp_old_Columns
= Columns
;
3545 * Start using tab page "tp".
3546 * Only to be used after leave_tabpage() or freeing the current tab page.
3550 enter_tabpage(tp
, old_curbuf
)
3554 int old_off
= tp
->tp_firstwin
->w_winrow
;
3555 win_T
*next_prevwin
= tp
->tp_prevwin
;
3558 firstwin
= tp
->tp_firstwin
;
3559 lastwin
= tp
->tp_lastwin
;
3560 topframe
= tp
->tp_topframe
;
3562 /* We would like doing the TabEnter event first, but we don't have a
3563 * valid current window yet, which may break some commands.
3564 * This triggers autocommands, thus may make "tp" invalid. */
3565 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3566 prevwin
= next_prevwin
;
3569 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3571 if (old_curbuf
!= curbuf
)
3572 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3575 last_status(FALSE
); /* status line may appear or disappear */
3576 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3577 must_redraw
= CLEAR
; /* need to redraw everything */
3579 diff_need_scrollbind
= TRUE
;
3582 /* The tabpage line may have appeared or disappeared, may need to resize
3583 * the frames for that. When the Vim window was resized need to update
3584 * frame sizes too. Use the stored value of p_ch, so that it can be
3585 * different for each tab page. */
3586 p_ch
= curtab
->tp_ch_used
;
3587 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3588 #ifdef FEAT_GUI_TABLINE
3589 && !gui_use_tabline()
3593 #ifdef FEAT_VERTSPLIT
3594 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3595 shell_new_columns(); /* update window widths */
3598 #if defined(FEAT_GUI)
3599 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3600 * scrollbars. Have to update them anyway. */
3601 if (gui
.in_use
&& starting
== 0)
3603 gui_init_which_components(NULL
);
3604 gui_update_scrollbars(TRUE
);
3606 need_mouse_correct
= TRUE
;
3609 redraw_all_later(CLEAR
);
3613 * Go to tab page "n". For ":tab N" and "Ngt".
3614 * When "n" is 9999 go to the last tab page.
3626 /* Not allowed when editing the command line. */
3628 if (cmdwin_type
!= 0)
3636 /* If there is only one it can't work. */
3637 if (first_tabpage
->tp_next
== NULL
)
3646 /* No count, go to next tab page, wrap around end. */
3647 if (curtab
->tp_next
== NULL
)
3650 tp
= curtab
->tp_next
;
3654 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3657 for (i
= n
; i
< 0; ++i
)
3659 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3667 /* Go to last tab page. */
3668 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3673 /* Go to tab page "n". */
3674 tp
= find_tabpage(n
);
3682 goto_tabpage_tp(tp
);
3684 #ifdef FEAT_GUI_TABLINE
3685 if (gui_use_tabline())
3686 gui_mch_set_curtab(tabpage_index(curtab
));
3691 * Go to tabpage "tp".
3692 * Note: doesn't update the GUI tab.
3698 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3700 if (valid_tabpage(tp
))
3701 enter_tabpage(tp
, curbuf
);
3703 enter_tabpage(curtab
, curbuf
);
3708 * Enter window "wp" in tab page "tp".
3709 * Also updates the GUI tab.
3712 goto_tabpage_win(tp
, wp
)
3716 goto_tabpage_tp(tp
);
3717 if (curtab
== tp
&& win_valid(wp
))
3719 win_enter(wp
, TRUE
);
3720 # ifdef FEAT_GUI_TABLINE
3721 if (gui_use_tabline())
3722 gui_mch_set_curtab(tabpage_index(curtab
));
3728 * Move the current tab page to before tab page "nr".
3737 if (first_tabpage
->tp_next
== NULL
)
3740 /* Remove the current tab page from the list of tab pages. */
3741 if (curtab
== first_tabpage
)
3742 first_tabpage
= curtab
->tp_next
;
3745 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3746 if (tp
->tp_next
== curtab
)
3748 if (tp
== NULL
) /* "cannot happen" */
3750 tp
->tp_next
= curtab
->tp_next
;
3753 /* Re-insert it at the specified position. */
3756 curtab
->tp_next
= first_tabpage
;
3757 first_tabpage
= curtab
;
3761 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3763 curtab
->tp_next
= tp
->tp_next
;
3764 tp
->tp_next
= curtab
;
3767 /* Need to redraw the tabline. Tab page contents doesn't change. */
3768 redraw_tabline
= TRUE
;
3773 * Go to another window.
3774 * When jumping to another buffer, stop Visual mode. Do this before
3775 * changing windows so we can yank the selection into the '*' register.
3776 * When jumping to another window on the same buffer, adjust its cursor
3777 * position to keep the same Visual area.
3790 if (curbuf_locked())
3795 if (wp
->w_buffer
!= curbuf
)
3796 reset_VIsual_and_resel();
3797 else if (VIsual_active
)
3798 wp
->w_cursor
= curwin
->w_cursor
;
3802 need_mouse_correct
= TRUE
;
3804 win_enter(wp
, TRUE
);
3807 #if defined(FEAT_PERL) || defined(PROTO)
3809 * Find window number "winnr" (counting top to bottom).
3817 # ifdef FEAT_WINDOWS
3818 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3828 #ifdef FEAT_VERTSPLIT
3830 * Move to window above or below "count" times.
3833 win_goto_ver(up
, count
)
3834 int up
; /* TRUE to go to win above */
3841 foundfr
= curwin
->w_frame
;
3845 * First go upwards in the tree of frames until we find a upwards or
3846 * downwards neighbor.
3857 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3863 * Now go downwards to find the bottom or top frame in it.
3867 if (nfr
->fr_layout
== FR_LEAF
)
3873 if (nfr
->fr_layout
== FR_ROW
)
3875 /* Find the frame at the cursor row. */
3876 while (fr
->fr_next
!= NULL
3877 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3878 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3881 if (nfr
->fr_layout
== FR_COL
&& up
)
3882 while (fr
->fr_next
!= NULL
)
3888 if (foundfr
!= NULL
)
3889 win_goto(foundfr
->fr_win
);
3893 * Move to left or right window.
3896 win_goto_hor(left
, count
)
3897 int left
; /* TRUE to go to left win */
3904 foundfr
= curwin
->w_frame
;
3908 * First go upwards in the tree of frames until we find a left or
3920 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3926 * Now go downwards to find the leftmost or rightmost frame in it.
3930 if (nfr
->fr_layout
== FR_LEAF
)
3936 if (nfr
->fr_layout
== FR_COL
)
3938 /* Find the frame at the cursor row. */
3939 while (fr
->fr_next
!= NULL
3940 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3941 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3944 if (nfr
->fr_layout
== FR_ROW
&& left
)
3945 while (fr
->fr_next
!= NULL
)
3951 if (foundfr
!= NULL
)
3952 win_goto(foundfr
->fr_win
);
3957 * Make window "wp" the current window.
3960 win_enter(wp
, undo_sync
)
3964 win_enter_ext(wp
, undo_sync
, FALSE
);
3968 * Make window wp the current window.
3969 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3970 * been closed and isn't valid.
3973 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3979 int other_buffer
= FALSE
;
3982 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3986 if (!curwin_invalid
)
3989 * Be careful: If autocommands delete the window, return now.
3991 if (wp
->w_buffer
!= curbuf
)
3993 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3994 other_buffer
= TRUE
;
3998 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
4002 /* autocmds may abort script processing */
4009 /* sync undo before leaving the current buffer */
4010 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
4012 /* may have to copy the buffer options when 'cpo' contains 'S' */
4013 if (wp
->w_buffer
!= curbuf
)
4014 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
4015 if (!curwin_invalid
)
4017 prevwin
= curwin
; /* remember for CTRL-W p */
4018 curwin
->w_redr_status
= TRUE
;
4021 curbuf
= wp
->w_buffer
;
4023 #ifdef FEAT_VIRTUALEDIT
4024 if (!virtual_active())
4025 curwin
->w_cursor
.coladd
= 0;
4027 changed_line_abv_curs(); /* assume cursor position needs updating */
4029 if (curwin
->w_localdir
!= NULL
)
4031 /* Window has a local directory: Save current directory as global
4032 * directory (unless that was done already) and change to the local
4034 if (globaldir
== NULL
)
4036 char_u cwd
[MAXPATHL
];
4038 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4039 globaldir
= vim_strsave(cwd
);
4041 if (mch_chdir((char *)curwin
->w_localdir
) == 0)
4042 shorten_fnames(TRUE
);
4044 else if (globaldir
!= NULL
)
4046 /* Window doesn't have a local directory and we are not in the global
4047 * directory: Change to the global directory. */
4048 ignored
= mch_chdir((char *)globaldir
);
4049 vim_free(globaldir
);
4051 shorten_fnames(TRUE
);
4055 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4057 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4063 curwin
->w_redr_status
= TRUE
;
4064 redraw_tabline
= TRUE
;
4066 redraw_later(VALID
); /* causes status line redraw */
4068 /* set window height to desired minimal value */
4069 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4070 win_setheight((int)p_wh
);
4071 else if (curwin
->w_height
== 0)
4074 #ifdef FEAT_VERTSPLIT
4075 /* set window width to desired minimal value */
4076 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4077 win_setwidth((int)p_wiw
);
4081 setmouse(); /* in case jumped to/from help buffer */
4084 /* Change directories when the 'acd' option is set. */
4088 #endif /* FEAT_WINDOWS */
4090 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4092 * Jump to the first open window that contains buffer "buf", if one exists.
4093 * Returns a pointer to the window found, otherwise NULL.
4096 buf_jump_open_win(buf
)
4099 # ifdef FEAT_WINDOWS
4102 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4103 if (wp
->w_buffer
== buf
)
4106 win_enter(wp
, FALSE
);
4109 if (curwin
->w_buffer
== buf
)
4116 * Jump to the first open window in any tab page that contains buffer "buf",
4118 * Returns a pointer to the window found, otherwise NULL.
4121 buf_jump_open_tab(buf
)
4124 # ifdef FEAT_WINDOWS
4128 /* First try the current tab page. */
4129 wp
= buf_jump_open_win(buf
);
4133 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4136 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4137 if (wp
->w_buffer
== buf
)
4141 goto_tabpage_win(tp
, wp
);
4143 wp
= NULL
; /* something went wrong */
4150 if (curwin
->w_buffer
== buf
)
4158 * allocate a window structure and link it in the window list
4168 * allocate window structure and linesizes arrays
4170 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4171 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4180 /* Don't execute autocommands while the window is not properly
4181 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4186 * link the window in the window list
4189 win_append(after
, newwin
);
4191 #ifdef FEAT_VERTSPLIT
4192 newwin
->w_wincol
= 0;
4193 newwin
->w_width
= Columns
;
4196 /* position the display and the cursor at the top of the file. */
4197 newwin
->w_topline
= 1;
4199 newwin
->w_topfill
= 0;
4201 newwin
->w_botline
= 2;
4202 newwin
->w_cursor
.lnum
= 1;
4203 #ifdef FEAT_SCROLLBIND
4204 newwin
->w_scbind_pos
= 1;
4207 /* We won't calculate w_fraction until resizing the window */
4208 newwin
->w_fraction
= 0;
4209 newwin
->w_prev_fraction_row
= -1;
4214 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4216 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4217 SBAR_RIGHT
, newwin
);
4221 /* init w: variables */
4222 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4225 foldInitWin(newwin
);
4230 #ifdef FEAT_SEARCH_EXTRA
4231 newwin
->w_match_head
= NULL
;
4232 newwin
->w_next_match_id
= 4;
4238 #if defined(FEAT_WINDOWS) || defined(PROTO)
4241 * remove window 'wp' from the window list and free the structure
4246 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4251 /* Don't execute autocommands while the window is halfway being deleted.
4252 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4256 #ifdef FEAT_MZSCHEME
4257 mzscheme_window_free(wp
);
4265 python_window_free(wp
);
4269 tcl_window_free(wp
);
4273 ruby_window_free(wp
);
4276 clear_winopt(&wp
->w_onebuf_opt
);
4277 clear_winopt(&wp
->w_allbuf_opt
);
4280 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4287 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4288 vim_free(wp
->w_tagstack
[i
].tagname
);
4290 vim_free(wp
->w_localdir
);
4292 #ifdef FEAT_SEARCH_EXTRA
4296 #ifdef FEAT_JUMPLIST
4300 #ifdef FEAT_QUICKFIX
4307 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4308 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4310 #endif /* FEAT_GUI */
4321 * Append window "wp" in the window list after window "after".
4324 win_append(after
, wp
)
4329 if (after
== NULL
) /* after NULL is in front of the first */
4332 before
= after
->w_next
;
4334 wp
->w_next
= before
;
4343 before
->w_prev
= wp
;
4347 * Remove a window from the window list.
4352 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4354 if (wp
->w_prev
!= NULL
)
4355 wp
->w_prev
->w_next
= wp
->w_next
;
4356 else if (tp
== NULL
)
4357 firstwin
= wp
->w_next
;
4359 tp
->tp_firstwin
= wp
->w_next
;
4360 if (wp
->w_next
!= NULL
)
4361 wp
->w_next
->w_prev
= wp
->w_prev
;
4362 else if (tp
== NULL
)
4363 lastwin
= wp
->w_prev
;
4365 tp
->tp_lastwin
= wp
->w_prev
;
4369 * Append frame "frp" in a frame list after frame "after".
4372 frame_append(after
, frp
)
4373 frame_T
*after
, *frp
;
4375 frp
->fr_next
= after
->fr_next
;
4376 after
->fr_next
= frp
;
4377 if (frp
->fr_next
!= NULL
)
4378 frp
->fr_next
->fr_prev
= frp
;
4379 frp
->fr_prev
= after
;
4383 * Insert frame "frp" in a frame list before frame "before".
4386 frame_insert(before
, frp
)
4387 frame_T
*before
, *frp
;
4389 frp
->fr_next
= before
;
4390 frp
->fr_prev
= before
->fr_prev
;
4391 before
->fr_prev
= frp
;
4392 if (frp
->fr_prev
!= NULL
)
4393 frp
->fr_prev
->fr_next
= frp
;
4395 frp
->fr_parent
->fr_child
= frp
;
4399 * Remove a frame from a frame list.
4405 if (frp
->fr_prev
!= NULL
)
4406 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4408 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4409 if (frp
->fr_next
!= NULL
)
4410 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4413 #endif /* FEAT_WINDOWS */
4416 * Allocate w_lines[] for window "wp".
4417 * Return FAIL for failure, OK for success.
4423 wp
->w_lines_valid
= 0;
4424 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4425 if (wp
->w_lines
== NULL
)
4431 * free lsize arrays for a window
4437 vim_free(wp
->w_lines
);
4442 * Called from win_new_shellsize() after Rows changed.
4443 * This only does the current tab page, others must be done when made active.
4448 int h
= (int)ROWS_AVAIL
;
4450 if (firstwin
== NULL
) /* not initialized yet */
4453 if (h
< frame_minheight(topframe
, NULL
))
4454 h
= frame_minheight(topframe
, NULL
);
4456 /* First try setting the heights of windows with 'winfixheight'. If
4457 * that doesn't result in the right height, forget about that option. */
4458 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4459 if (topframe
->fr_height
!= h
)
4460 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4462 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4466 win_new_height(firstwin
, h
);
4470 curtab
->tp_ch_used
= p_ch
;
4474 /* Disabled: don't want making the screen smaller make a window larger. */
4476 win_equal(curwin
, FALSE
, 'v');
4480 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4482 * Called from win_new_shellsize() after Columns changed.
4487 if (firstwin
== NULL
) /* not initialized yet */
4490 /* First try setting the widths of windows with 'winfixwidth'. If that
4491 * doesn't result in the right width, forget about that option. */
4492 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4493 if (topframe
->fr_width
!= Columns
)
4494 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4496 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4498 /* Disabled: don't want making the screen smaller make a window larger. */
4500 win_equal(curwin
, FALSE
, 'h');
4505 #if defined(FEAT_CMDWIN) || defined(PROTO)
4507 * Save the size of all windows in "gap".
4516 ga_init2(gap
, (int)sizeof(int), 1);
4517 if (ga_grow(gap
, win_count() * 2) == OK
)
4518 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4520 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4521 wp
->w_width
+ wp
->w_vsep_width
;
4522 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4527 * Restore window sizes, but only if the number of windows is still the same.
4528 * Does not free the growarray.
4531 win_size_restore(gap
)
4537 if (win_count() * 2 == gap
->ga_len
)
4540 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4542 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4543 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4545 /* recompute the window positions */
4546 (void)win_comp_pos();
4549 #endif /* FEAT_CMDWIN */
4551 #if defined(FEAT_WINDOWS) || defined(PROTO)
4553 * Update the position for all windows, using the width and height of the
4555 * Returns the row just after the last window.
4560 int row
= tabline_height();
4563 frame_comp_pos(topframe
, &row
, &col
);
4568 * Update the position of the windows in frame "topfrp", using the width and
4569 * height of the frames.
4570 * "*row" and "*col" are the top-left position of the frame. They are updated
4571 * to the bottom-right position plus one.
4574 frame_comp_pos(topfrp
, row
, col
)
4581 #ifdef FEAT_VERTSPLIT
4586 wp
= topfrp
->fr_win
;
4589 if (wp
->w_winrow
!= *row
4590 #ifdef FEAT_VERTSPLIT
4591 || wp
->w_wincol
!= *col
4595 /* position changed, redraw */
4596 wp
->w_winrow
= *row
;
4597 #ifdef FEAT_VERTSPLIT
4598 wp
->w_wincol
= *col
;
4600 redraw_win_later(wp
, NOT_VALID
);
4601 wp
->w_redr_status
= TRUE
;
4603 *row
+= wp
->w_height
+ wp
->w_status_height
;
4604 #ifdef FEAT_VERTSPLIT
4605 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4610 #ifdef FEAT_VERTSPLIT
4614 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4616 #ifdef FEAT_VERTSPLIT
4617 if (topfrp
->fr_layout
== FR_ROW
)
4618 *row
= startrow
; /* all frames are at the same row */
4620 *col
= startcol
; /* all frames are at the same col */
4622 frame_comp_pos(frp
, row
, col
);
4627 #endif /* FEAT_WINDOWS */
4630 * Set current window height and take care of repositioning other windows to
4634 win_setheight(height
)
4637 win_setheight_win(height
, curwin
);
4641 * Set the window height of window "win" and take care of repositioning other
4642 * windows to fit around it.
4645 win_setheight_win(height
, win
)
4653 /* Always keep current window at least one line high, even when
4654 * 'winminheight' is zero. */
4664 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4666 /* recompute the window positions */
4667 row
= win_comp_pos();
4669 if (height
> topframe
->fr_height
)
4670 height
= topframe
->fr_height
;
4671 win
->w_height
= height
;
4676 * If there is extra space created between the last window and the command
4679 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4680 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4685 redraw_all_later(NOT_VALID
);
4688 #if defined(FEAT_WINDOWS) || defined(PROTO)
4691 * Set the height of a frame to "height" and take care that all frames and
4692 * windows inside it are resized. Also resize frames on the left and right if
4693 * the are in the same FR_ROW frame.
4696 * If the frame is part of a FR_COL frame, try fitting the frame in that
4697 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4698 * go to containing frames to resize them and make room.
4699 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4700 * Check for the minimal height of the FR_ROW frame.
4701 * At the top level we can also use change the command line height.
4704 frame_setheight(curfrp
, height
)
4708 int room
; /* total number of lines available */
4709 int take
; /* number of lines taken from other windows */
4710 int room_cmdline
; /* lines available from cmdline */
4716 /* If the height already is the desired value, nothing to do. */
4717 if (curfrp
->fr_height
== height
)
4720 if (curfrp
->fr_parent
== NULL
)
4722 /* topframe: can only change the command line */
4723 if (height
> ROWS_AVAIL
)
4724 height
= ROWS_AVAIL
;
4726 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4728 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4730 /* Row of frames: Also need to resize frames left and right of this
4731 * one. First check for the minimal height of these. */
4732 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4735 frame_setheight(curfrp
->fr_parent
, height
);
4740 * Column of frames: try to change only frames in this column.
4742 #ifdef FEAT_VERTSPLIT
4745 * 1: compute room available, if it's not enough try resizing the
4747 * 2: compute the room available and adjust the height to it.
4748 * Try not to reduce the height of a window with 'winfixheight' set.
4750 for (run
= 1; run
<= 2; ++run
)
4757 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4761 && frp
->fr_win
!= NULL
4762 && frp
->fr_win
->w_p_wfh
)
4763 room_reserved
+= frp
->fr_height
;
4764 room
+= frp
->fr_height
;
4766 room
-= frame_minheight(frp
, NULL
);
4768 #ifdef FEAT_VERTSPLIT
4769 if (curfrp
->fr_width
!= Columns
)
4774 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4775 + lastwin
->w_height
+ lastwin
->w_status_height
);
4776 if (room_cmdline
< 0)
4780 if (height
<= room
+ room_cmdline
)
4782 #ifdef FEAT_VERTSPLIT
4783 if (run
== 2 || curfrp
->fr_width
== Columns
)
4786 if (height
> room
+ room_cmdline
)
4787 height
= room
+ room_cmdline
;
4790 #ifdef FEAT_VERTSPLIT
4791 frame_setheight(curfrp
->fr_parent
, height
4792 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4798 * Compute the number of lines we will take from others frames (can be
4801 take
= height
- curfrp
->fr_height
;
4803 /* If there is not enough room, also reduce the height of a window
4804 * with 'winfixheight' set. */
4805 if (height
> room
+ room_cmdline
- room_reserved
)
4806 room_reserved
= room
+ room_cmdline
- height
;
4807 /* If there is only a 'winfixheight' window and making the
4808 * window smaller, need to make the other window taller. */
4809 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4812 if (take
> 0 && room_cmdline
> 0)
4814 /* use lines from cmdline first */
4815 if (take
< room_cmdline
)
4816 room_cmdline
= take
;
4817 take
-= room_cmdline
;
4818 topframe
->fr_height
+= room_cmdline
;
4822 * set the current frame to the new height
4824 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4827 * First take lines from the frames after the current frame. If
4828 * that is not enough, takes lines from frames above the current
4831 for (run
= 0; run
< 2; ++run
)
4834 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4836 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4837 while (frp
!= NULL
&& take
!= 0)
4839 h
= frame_minheight(frp
, NULL
);
4840 if (room_reserved
> 0
4841 && frp
->fr_win
!= NULL
4842 && frp
->fr_win
->w_p_wfh
)
4844 if (room_reserved
>= frp
->fr_height
)
4845 room_reserved
-= frp
->fr_height
;
4848 if (frp
->fr_height
- room_reserved
> take
)
4849 room_reserved
= frp
->fr_height
- take
;
4850 take
-= frp
->fr_height
- room_reserved
;
4851 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4857 if (frp
->fr_height
- take
< h
)
4859 take
-= frp
->fr_height
- h
;
4860 frame_new_height(frp
, h
, FALSE
, FALSE
);
4864 frame_new_height(frp
, frp
->fr_height
- take
,
4878 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4880 * Set current window width and take care of repositioning other windows to
4887 win_setwidth_win(width
, curwin
);
4891 win_setwidth_win(width
, wp
)
4895 /* Always keep current window at least one column wide, even when
4896 * 'winminwidth' is zero. */
4905 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4907 /* recompute the window positions */
4908 (void)win_comp_pos();
4910 redraw_all_later(NOT_VALID
);
4914 * Set the width of a frame to "width" and take care that all frames and
4915 * windows inside it are resized. Also resize frames above and below if the
4916 * are in the same FR_ROW frame.
4918 * Strategy is similar to frame_setheight().
4921 frame_setwidth(curfrp
, width
)
4925 int room
; /* total number of lines available */
4926 int take
; /* number of lines taken from other windows */
4932 /* If the width already is the desired value, nothing to do. */
4933 if (curfrp
->fr_width
== width
)
4936 if (curfrp
->fr_parent
== NULL
)
4937 /* topframe: can't change width */
4940 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4942 /* Column of frames: Also need to resize frames above and below of
4943 * this one. First check for the minimal width of these. */
4944 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4947 frame_setwidth(curfrp
->fr_parent
, width
);
4952 * Row of frames: try to change only frames in this row.
4955 * 1: compute room available, if it's not enough try resizing the
4957 * 2: compute the room available and adjust the width to it.
4959 for (run
= 1; run
<= 2; ++run
)
4963 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4967 && frp
->fr_win
!= NULL
4968 && frp
->fr_win
->w_p_wfw
)
4969 room_reserved
+= frp
->fr_width
;
4970 room
+= frp
->fr_width
;
4972 room
-= frame_minwidth(frp
, NULL
);
4977 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4983 frame_setwidth(curfrp
->fr_parent
, width
4984 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4988 * Compute the number of lines we will take from others frames (can be
4991 take
= width
- curfrp
->fr_width
;
4993 /* If there is not enough room, also reduce the width of a window
4994 * with 'winfixwidth' set. */
4995 if (width
> room
- room_reserved
)
4996 room_reserved
= room
- width
;
4997 /* If there is only a 'winfixwidth' window and making the
4998 * window smaller, need to make the other window narrower. */
4999 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
5003 * set the current frame to the new width
5005 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
5008 * First take lines from the frames right of the current frame. If
5009 * that is not enough, takes lines from frames left of the current
5012 for (run
= 0; run
< 2; ++run
)
5015 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
5017 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5018 while (frp
!= NULL
&& take
!= 0)
5020 w
= frame_minwidth(frp
, NULL
);
5021 if (room_reserved
> 0
5022 && frp
->fr_win
!= NULL
5023 && frp
->fr_win
->w_p_wfw
)
5025 if (room_reserved
>= frp
->fr_width
)
5026 room_reserved
-= frp
->fr_width
;
5029 if (frp
->fr_width
- room_reserved
> take
)
5030 room_reserved
= frp
->fr_width
- take
;
5031 take
-= frp
->fr_width
- room_reserved
;
5032 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5038 if (frp
->fr_width
- take
< w
)
5040 take
-= frp
->fr_width
- w
;
5041 frame_new_width(frp
, w
, FALSE
, FALSE
);
5045 frame_new_width(frp
, frp
->fr_width
- take
,
5058 #endif /* FEAT_VERTSPLIT */
5061 * Check 'winminheight' for a valid value.
5070 /* loop until there is a 'winminheight' that is possible */
5073 /* TODO: handle vertical splits */
5075 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5076 room
+= wp
->w_height
- p_wmh
;
5091 * Status line of dragwin is dragged "offset" lines down (negative is up).
5094 win_drag_status_line(dragwin
, offset
)
5102 int up
; /* if TRUE, drag status line up, otherwise down */
5105 fr
= dragwin
->w_frame
;
5107 if (fr
!= topframe
) /* more than one window */
5110 /* When the parent frame is not a column of frames, its parent should
5112 if (fr
->fr_layout
!= FR_COL
)
5115 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5120 /* If this is the last frame in a column, may want to resize the parent
5121 * frame instead (go two up to skip a row of frames). */
5122 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5131 if (offset
< 0) /* drag up */
5135 /* sum up the room of the current frame and above it */
5138 /* only one window */
5139 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5144 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5146 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5151 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5153 else /* drag down */
5157 * Only dragging the last status line can reduce p_ch.
5159 room
= Rows
- cmdline_row
;
5160 if (curfr
->fr_next
== NULL
)
5166 /* sum up the room of frames below of the current one */
5167 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5168 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5169 fr
= curfr
; /* put fr at window that grows */
5172 if (room
< offset
) /* Not enough room */
5173 offset
= room
; /* Move as far as we can */
5178 * Grow frame fr by "offset" lines.
5179 * Doesn't happen when dragging the last status line up.
5182 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5185 fr
= curfr
; /* current frame gets smaller */
5187 fr
= curfr
->fr_next
; /* next frame gets smaller */
5190 * Now make the other frames smaller.
5192 while (fr
!= NULL
&& offset
> 0)
5194 n
= frame_minheight(fr
, NULL
);
5195 if (fr
->fr_height
- offset
<= n
)
5197 offset
-= fr
->fr_height
- n
;
5198 frame_new_height(fr
, n
, !up
, FALSE
);
5202 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5210 row
= win_comp_pos();
5211 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5213 p_ch
= Rows
- cmdline_row
;
5216 curtab
->tp_ch_used
= p_ch
;
5217 redraw_all_later(SOME_VALID
);
5221 #ifdef FEAT_VERTSPLIT
5223 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5226 win_drag_vsep_line(dragwin
, offset
)
5233 int left
; /* if TRUE, drag separator line left, otherwise right */
5236 fr
= dragwin
->w_frame
;
5237 if (fr
== topframe
) /* only one window (cannot happen?) */
5241 /* When the parent frame is not a row of frames, its parent should be. */
5242 if (fr
->fr_layout
!= FR_ROW
)
5244 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5250 /* If this is the last frame in a row, may want to resize a parent
5252 while (curfr
->fr_next
== NULL
)
5265 if (offset
< 0) /* drag left */
5269 /* sum up the room of the current frame and left of it */
5271 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5273 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5277 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5279 else /* drag right */
5282 /* sum up the room of frames right of the current one */
5284 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5285 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5286 fr
= curfr
; /* put fr at window that grows */
5289 if (room
< offset
) /* Not enough room */
5290 offset
= room
; /* Move as far as we can */
5291 if (offset
<= 0) /* No room at all, quit. */
5294 /* grow frame fr by offset lines */
5295 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5297 /* shrink other frames: current and at the left or at the right */
5299 fr
= curfr
; /* current frame gets smaller */
5301 fr
= curfr
->fr_next
; /* next frame gets smaller */
5303 while (fr
!= NULL
&& offset
> 0)
5305 n
= frame_minwidth(fr
, NULL
);
5306 if (fr
->fr_width
- offset
<= n
)
5308 offset
-= fr
->fr_width
- n
;
5309 frame_new_width(fr
, n
, !left
, FALSE
);
5313 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5321 (void)win_comp_pos();
5322 redraw_all_later(NOT_VALID
);
5324 #endif /* FEAT_VERTSPLIT */
5325 #endif /* FEAT_MOUSE */
5327 #endif /* FEAT_WINDOWS */
5330 * Set the height of a window.
5331 * This takes care of the things inside the window, not what happens to the
5332 * window position, the frame or to other windows.
5335 win_new_height(wp
, height
)
5340 int sline
, line_size
;
5341 #define FRACTION_MULT 16384L
5343 /* Don't want a negative height. Happens when splitting a tiny window.
5344 * Will equalize heights soon to fix it. */
5347 if (wp
->w_height
== height
)
5348 return; /* nothing to do */
5350 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5351 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5352 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5354 wp
->w_height
= height
;
5357 /* Don't change w_topline when height is zero. Don't set w_topline when
5358 * 'scrollbind' is set and this isn't the current window. */
5360 #ifdef FEAT_SCROLLBIND
5361 && (!wp
->w_p_scb
|| wp
== curwin
)
5366 * Find a value for w_topline that shows the cursor at the same
5367 * relative position in the window as before (more or less).
5369 lnum
= wp
->w_cursor
.lnum
;
5370 if (lnum
< 1) /* can happen when starting up */
5372 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5373 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5374 sline
= wp
->w_wrow
- line_size
;
5378 /* Make sure the whole cursor line is visible, if possible. */
5379 int rows
= plines_win(wp
, lnum
, FALSE
);
5381 if (sline
> wp
->w_height
- rows
)
5383 sline
= wp
->w_height
- rows
;
5384 wp
->w_wrow
-= rows
- line_size
;
5391 * Cursor line would go off top of screen if w_wrow was this high.
5392 * Make cursor line the first line in the window. If not enough
5393 * room use w_skipcol;
5395 wp
->w_wrow
= line_size
;
5396 if (wp
->w_wrow
>= wp
->w_height
5397 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5399 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5401 while (wp
->w_wrow
>= wp
->w_height
)
5403 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5411 while (sline
> 0 && lnum
> 1)
5414 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5417 /* first line in buffer is folded */
5425 if (lnum
== wp
->w_topline
)
5426 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5430 line_size
= plines_win(wp
, lnum
, TRUE
);
5437 * Line we want at top would go off top of screen. Use next
5441 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5444 wp
->w_wrow
-= line_size
+ sline
;
5448 /* First line of file reached, use that as topline. */
5450 wp
->w_wrow
-= sline
;
5453 set_topline(wp
, lnum
);
5460 curs_columns(FALSE
); /* validate w_wrow */
5462 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5464 win_comp_scroll(wp
);
5465 redraw_win_later(wp
, SOME_VALID
);
5467 wp
->w_redr_status
= TRUE
;
5469 invalidate_botline_win(wp
);
5472 #ifdef FEAT_VERTSPLIT
5474 * Set the width of a window.
5477 win_new_width(wp
, width
)
5481 wp
->w_width
= width
;
5482 wp
->w_lines_valid
= 0;
5483 changed_line_abv_curs_win(wp
);
5484 invalidate_botline_win(wp
);
5488 curs_columns(TRUE
); /* validate w_wrow */
5490 redraw_win_later(wp
, NOT_VALID
);
5491 wp
->w_redr_status
= TRUE
;
5499 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5500 if (wp
->w_p_scr
== 0)
5505 * command_height: called whenever p_ch has been changed
5513 int old_p_ch
= curtab
->tp_ch_used
;
5515 /* Use the value of p_ch that we remembered. This is needed for when the
5516 * GUI starts up, we can't be sure in what order things happen. And when
5517 * p_ch was changed in another tab page. */
5518 curtab
->tp_ch_used
= p_ch
;
5520 /* Find bottom frame with width of screen. */
5521 frp
= lastwin
->w_frame
;
5522 # ifdef FEAT_VERTSPLIT
5523 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5524 frp
= frp
->fr_parent
;
5527 /* Avoid changing the height of a window with 'winfixheight' set. */
5528 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5529 && frp
->fr_win
->w_p_wfh
)
5532 if (starting
!= NO_SCREEN
)
5534 cmdline_row
= Rows
- p_ch
;
5536 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5538 while (p_ch
> old_p_ch
)
5544 curtab
->tp_ch_used
= p_ch
;
5545 cmdline_row
= Rows
- p_ch
;
5548 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5549 if (h
> p_ch
- old_p_ch
)
5550 h
= p_ch
- old_p_ch
;
5552 frame_add_height(frp
, -h
);
5556 /* Recompute window positions. */
5557 (void)win_comp_pos();
5559 /* clear the lines added to cmdline */
5561 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5562 (int)Columns
, ' ', ' ', 0);
5563 msg_row
= cmdline_row
;
5564 redraw_cmdline
= TRUE
;
5568 if (msg_row
< cmdline_row
)
5569 msg_row
= cmdline_row
;
5570 redraw_cmdline
= TRUE
;
5572 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5574 /* Recompute window positions. */
5575 if (frp
!= lastwin
->w_frame
)
5576 (void)win_comp_pos();
5578 cmdline_row
= Rows
- p_ch
;
5579 win_setheight(cmdline_row
);
5583 #if defined(FEAT_WINDOWS) || defined(PROTO)
5585 * Resize frame "frp" to be "n" lines higher (negative for less high).
5586 * Also resize the frames it is contained in.
5589 frame_add_height(frp
, n
)
5593 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5596 frp
= frp
->fr_parent
;
5599 frp
->fr_height
+= n
;
5604 * Add or remove a status line for the bottom window(s), according to the
5605 * value of 'laststatus'.
5608 last_status(morewin
)
5609 int morewin
; /* pretend there are two or more windows */
5611 /* Don't make a difference between horizontal or vertical split. */
5612 last_status_rec(topframe
, (p_ls
== 2
5613 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5617 last_status_rec(fr
, statusline
)
5624 if (fr
->fr_layout
== FR_LEAF
)
5627 if (wp
->w_status_height
!= 0 && !statusline
)
5629 /* remove status line */
5630 win_new_height(wp
, wp
->w_height
+ 1);
5631 wp
->w_status_height
= 0;
5634 else if (wp
->w_status_height
== 0 && statusline
)
5636 /* Find a frame to take a line from. */
5638 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5645 /* In a column of frames: go to frame above. If already at
5646 * the top or in a row of frames: go to parent. */
5647 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5652 wp
->w_status_height
= 1;
5655 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5656 frame_fix_height(wp
);
5657 (void)win_comp_pos();
5660 win_new_height(wp
, wp
->w_height
- 1);
5662 redraw_all_later(SOME_VALID
);
5665 #ifdef FEAT_VERTSPLIT
5666 else if (fr
->fr_layout
== FR_ROW
)
5668 /* vertically split windows, set status line for each one */
5669 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5670 last_status_rec(fp
, statusline
);
5675 /* horizontally split window, set status line for last one */
5676 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5678 last_status_rec(fp
, statusline
);
5683 * Return the number of lines used by the tab page line.
5688 #ifdef FEAT_GUI_TABLINE
5689 /* When the GUI has the tabline then this always returns zero. */
5690 if (gui_use_tabline())
5696 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5701 #endif /* FEAT_WINDOWS */
5703 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5705 * Get the file name at the cursor.
5706 * If Visual mode is active, use the selected text if it's in one line.
5707 * Returns the name in allocated memory, NULL for failure.
5710 grab_file_name(count
, file_lnum
)
5712 linenr_T
*file_lnum
;
5720 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5722 return find_file_name_in_path(ptr
, len
,
5723 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5726 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5732 * Return the file name under or after the cursor.
5734 * The 'path' option is searched if the file name is not absolute.
5735 * The string returned has been alloc'ed and should be freed by the caller.
5736 * NULL is returned if the file name or file is not found.
5739 * FNAME_MESS give error messages
5740 * FNAME_EXP expand to path
5741 * FNAME_HYP check for hypertext link
5742 * FNAME_INCL apply "includeexpr"
5745 file_name_at_cursor(options
, count
, file_lnum
)
5748 linenr_T
*file_lnum
;
5750 return file_name_in_line(ml_get_curline(),
5751 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5756 * Return the name of the file under or after ptr[col].
5757 * Otherwise like file_name_at_cursor().
5760 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5765 char_u
*rel_fname
; /* file we are searching relative to */
5766 linenr_T
*file_lnum
; /* line number after the file name */
5772 * search forward for what could be the start of a file name
5775 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5777 if (*ptr
== NUL
) /* nothing found */
5779 if (options
& FNAME_MESS
)
5780 EMSG(_("E446: No file name under cursor"));
5785 * Search backward for first char of the file name.
5786 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5791 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5795 if (vim_isfilec(ptr
[-1])
5796 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5803 * Search forward for the last char of the file name.
5804 * Also allow "://" when ':' is not in 'isfname'.
5807 while (vim_isfilec(ptr
[len
])
5808 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5811 len
+= (*mb_ptr2len
)(ptr
+ len
);
5817 * If there is trailing punctuation, remove it.
5818 * But don't remove "..", could be a directory name.
5820 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5821 && ptr
[len
- 2] != '.')
5824 if (file_lnum
!= NULL
)
5828 /* Get the number after the file name and a separator character */
5834 ++p
; /* skip the separator */
5837 *file_lnum
= (int)getdigits(&p
);
5841 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5844 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5845 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5848 eval_includeexpr(ptr
, len
)
5854 set_vim_var_string(VV_FNAME
, ptr
, len
);
5855 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5856 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5857 set_vim_var_string(VV_FNAME
, NULL
, 0);
5863 * Return the name of the file ptr[len] in 'path'.
5864 * Otherwise like file_name_at_cursor().
5867 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5872 char_u
*rel_fname
; /* file we are searching relative to */
5876 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5877 char_u
*tofree
= NULL
;
5879 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5881 tofree
= eval_includeexpr(ptr
, len
);
5885 len
= (int)STRLEN(ptr
);
5890 if (options
& FNAME_EXP
)
5892 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5895 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5897 * If the file could not be found in a normal way, try applying
5898 * 'includeexpr' (unless done already).
5900 if (file_name
== NULL
5901 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5903 tofree
= eval_includeexpr(ptr
, len
);
5907 len
= (int)STRLEN(ptr
);
5908 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5913 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5917 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5921 /* Repeat finding the file "count" times. This matters when it
5922 * appears several times in the path. */
5923 while (file_name
!= NULL
&& --count
> 0)
5925 vim_free(file_name
);
5926 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5930 file_name
= vim_strnsave(ptr
, len
);
5932 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5938 #endif /* FEAT_SEARCHPATH */
5941 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5942 * Also check for ":\\", which MS Internet Explorer accepts, return
5949 if (STRNCMP(p
, "://", (size_t)3) == 0)
5951 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5952 return URL_BACKSLASH
;
5957 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5958 * Return URL_BACKSLASH for "name:\\".
5959 * Return zero otherwise.
5962 path_with_url(fname
)
5967 for (p
= fname
; isalpha(*p
); ++p
)
5969 return path_is_url(p
);
5973 * Return TRUE if "name" is a full (absolute) path name or URL.
5979 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5983 * Get absolute file name into buffer "buf[len]".
5985 * return FAIL for failure, OK otherwise
5988 vim_FullName(fname
, buf
, len
, force
)
5989 char_u
*fname
, *buf
;
5991 int force
; /* force expansion even when already absolute */
6000 url
= path_with_url(fname
);
6002 retval
= mch_FullName(fname
, buf
, len
, force
);
6003 if (url
|| retval
== FAIL
)
6005 /* something failed; use the file name (truncate when too long) */
6006 vim_strncpy(buf
, fname
, len
- 1);
6008 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
6015 * Return the minimal number of rows that is needed on the screen to display
6016 * the current number of windows.
6027 if (firstwin
== NULL
) /* not initialized yet */
6032 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6034 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6038 total
+= tabline_height();
6040 total
= 1; /* at least one window should have a line! */
6042 total
+= 1; /* count the room for the command line */
6047 * Return TRUE if there is only one window (in the current tab page), not
6048 * counting a help or preview window, unless it is the current window.
6057 /* If there is another tab page there always is another window. */
6058 if (first_tabpage
->tp_next
!= NULL
)
6061 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6062 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6063 # ifdef FEAT_QUICKFIX
6068 return (count
<= 1);
6074 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6076 * Correct the cursor line number in other windows. Used after changing the
6077 * current buffer, and before applying autocommands.
6078 * When "do_curwin" is TRUE, also check current window.
6081 check_lnums(do_curwin
)
6089 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6090 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6096 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6097 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6098 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6099 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6104 #if defined(FEAT_WINDOWS) || defined(PROTO)
6107 * A snapshot of the window sizes, to restore them after closing the help
6109 * Only these fields are used:
6115 * fr_win (only valid for the old curwin, NULL otherwise)
6119 * Create a snapshot of the current frame sizes.
6124 clear_snapshot(curtab
);
6125 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6129 make_snapshot_rec(fr
, frp
)
6133 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6136 (*frp
)->fr_layout
= fr
->fr_layout
;
6137 # ifdef FEAT_VERTSPLIT
6138 (*frp
)->fr_width
= fr
->fr_width
;
6140 (*frp
)->fr_height
= fr
->fr_height
;
6141 if (fr
->fr_next
!= NULL
)
6142 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6143 if (fr
->fr_child
!= NULL
)
6144 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6145 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6146 (*frp
)->fr_win
= curwin
;
6150 * Remove any existing snapshot.
6156 clear_snapshot_rec(tp
->tp_snapshot
);
6157 tp
->tp_snapshot
= NULL
;
6161 clear_snapshot_rec(fr
)
6166 clear_snapshot_rec(fr
->fr_next
);
6167 clear_snapshot_rec(fr
->fr_child
);
6173 * Restore a previously created snapshot, if there is any.
6174 * This is only done if the screen size didn't change and the window layout is
6178 restore_snapshot(close_curwin
)
6179 int close_curwin
; /* closing current window */
6183 if (curtab
->tp_snapshot
!= NULL
6184 # ifdef FEAT_VERTSPLIT
6185 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6187 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6188 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6190 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6192 if (wp
!= NULL
&& close_curwin
)
6194 redraw_all_later(CLEAR
);
6196 clear_snapshot(curtab
);
6200 * Check if frames "sn" and "fr" have the same layout, same following frames
6201 * and same children.
6204 check_snapshot_rec(sn
, fr
)
6208 if (sn
->fr_layout
!= fr
->fr_layout
6209 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6210 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6211 || (sn
->fr_next
!= NULL
6212 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6213 || (sn
->fr_child
!= NULL
6214 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6220 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6221 * following frames and children.
6222 * Returns a pointer to the old current window, or NULL.
6225 restore_snapshot_rec(sn
, fr
)
6232 fr
->fr_height
= sn
->fr_height
;
6233 # ifdef FEAT_VERTSPLIT
6234 fr
->fr_width
= sn
->fr_width
;
6236 if (fr
->fr_layout
== FR_LEAF
)
6238 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6239 # ifdef FEAT_VERTSPLIT
6240 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6244 if (sn
->fr_next
!= NULL
)
6246 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6250 if (sn
->fr_child
!= NULL
)
6252 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6261 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6263 * Return TRUE if there is any vertically split window.
6270 if (topframe
->fr_layout
== FR_ROW
)
6273 if (topframe
->fr_layout
== FR_COL
)
6274 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6275 if (fr
->fr_layout
== FR_ROW
)
6282 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6284 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6285 * highlighted with the group 'grp' with priority 'prio'.
6286 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6287 * If no particular ID is desired, -1 must be specified for 'id'.
6288 * Return ID of added match, -1 on failure.
6291 match_add(wp
, grp
, pat
, prio
, id
)
6304 if (*grp
== NUL
|| *pat
== NUL
)
6306 if (id
< -1 || id
== 0)
6308 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6313 cur
= wp
->w_match_head
;
6318 EMSGN("E801: ID already taken: %ld", id
);
6324 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6326 EMSG2(_(e_nogroup
), grp
);
6329 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6331 EMSG2(_(e_invarg2
), pat
);
6335 /* Find available match ID. */
6338 cur
= wp
->w_match_head
;
6339 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6342 id
= wp
->w_next_match_id
;
6343 wp
->w_next_match_id
++;
6346 /* Build new match. */
6347 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6350 m
->pattern
= vim_strsave(pat
);
6352 m
->match
.regprog
= regprog
;
6353 m
->match
.rmm_ic
= FALSE
;
6354 m
->match
.rmm_maxcol
= 0;
6356 /* Insert new match. The match list is in ascending order with regard to
6357 * the match priorities. */
6358 cur
= wp
->w_match_head
;
6360 while (cur
!= NULL
&& prio
>= cur
->priority
)
6366 wp
->w_match_head
= m
;
6371 redraw_later(SOME_VALID
);
6376 * Delete match with ID 'id' in the match list of window 'wp'.
6377 * Print error messages if 'perr' is TRUE.
6380 match_delete(wp
, id
, perr
)
6385 matchitem_T
*cur
= wp
->w_match_head
;
6386 matchitem_T
*prev
= cur
;
6391 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6395 while (cur
!= NULL
&& cur
->id
!= id
)
6403 EMSGN("E803: ID not found: %ld", id
);
6407 wp
->w_match_head
= cur
->next
;
6409 prev
->next
= cur
->next
;
6410 vim_free(cur
->match
.regprog
);
6411 vim_free(cur
->pattern
);
6413 redraw_later(SOME_VALID
);
6418 * Delete all matches in the match list of window 'wp'.
6426 while (wp
->w_match_head
!= NULL
)
6428 m
= wp
->w_match_head
->next
;
6429 vim_free(wp
->w_match_head
->match
.regprog
);
6430 vim_free(wp
->w_match_head
->pattern
);
6431 vim_free(wp
->w_match_head
);
6432 wp
->w_match_head
= m
;
6434 redraw_later(SOME_VALID
);
6438 * Get match from ID 'id' in window 'wp'.
6439 * Return NULL if match not found.
6446 matchitem_T
*cur
= wp
->w_match_head
;
6448 while (cur
!= NULL
&& cur
->id
!= id
)