1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read a list of people who contributed.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
13 # include <fcntl.h> /* for chdir() */
16 static int path_is_url
__ARGS((char_u
*p
));
17 #if defined(FEAT_WINDOWS) || defined(PROTO)
18 static int win_split_ins
__ARGS((int size
, int flags
, win_T
*newwin
, int dir
));
19 static void win_init
__ARGS((win_T
*newp
, win_T
*oldp
));
20 static void frame_comp_pos
__ARGS((frame_T
*topfrp
, int *row
, int *col
));
21 static void frame_setheight
__ARGS((frame_T
*curfrp
, int height
));
23 static void frame_setwidth
__ARGS((frame_T
*curfrp
, int width
));
25 static void win_exchange
__ARGS((long));
26 static void win_rotate
__ARGS((int, int));
27 static void win_totop
__ARGS((int size
, int flags
));
28 static void win_equal_rec
__ARGS((win_T
*next_curwin
, int current
, frame_T
*topfr
, int dir
, int col
, int row
, int width
, int height
));
29 static int last_window
__ARGS((void));
30 static win_T
*win_free_mem
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
31 static win_T
*winframe_remove
__ARGS((win_T
*win
, int *dirp
, tabpage_T
*tp
));
32 static frame_T
*win_altframe
__ARGS((win_T
*win
, tabpage_T
*tp
));
33 static tabpage_T
*alt_tabpage
__ARGS((void));
34 static win_T
*frame2win
__ARGS((frame_T
*frp
));
35 static int frame_has_win
__ARGS((frame_T
*frp
, win_T
*wp
));
36 static void frame_new_height
__ARGS((frame_T
*topfrp
, int height
, int topfirst
, int wfh
));
37 static int frame_fixed_height
__ARGS((frame_T
*frp
));
39 static int frame_fixed_width
__ARGS((frame_T
*frp
));
40 static void frame_add_statusline
__ARGS((frame_T
*frp
));
41 static void frame_new_width
__ARGS((frame_T
*topfrp
, int width
, int leftfirst
, int wfw
));
42 static void frame_add_vsep
__ARGS((frame_T
*frp
));
43 static int frame_minwidth
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
44 static void frame_fix_width
__ARGS((win_T
*wp
));
47 static int win_alloc_firstwin
__ARGS((win_T
*oldwin
));
48 #if defined(FEAT_WINDOWS) || defined(PROTO)
49 static tabpage_T
*alloc_tabpage
__ARGS((void));
50 static int leave_tabpage
__ARGS((buf_T
*new_curbuf
));
51 static void enter_tabpage
__ARGS((tabpage_T
*tp
, buf_T
*old_curbuf
));
52 static void frame_fix_height
__ARGS((win_T
*wp
));
53 static int frame_minheight
__ARGS((frame_T
*topfrp
, win_T
*next_curwin
));
54 static void win_enter_ext
__ARGS((win_T
*wp
, int undo_sync
, int no_curwin
));
55 static void win_free
__ARGS((win_T
*wp
, tabpage_T
*tp
));
56 static void win_append
__ARGS((win_T
*, win_T
*));
57 static void win_remove
__ARGS((win_T
*, tabpage_T
*tp
));
58 static void frame_append
__ARGS((frame_T
*after
, frame_T
*frp
));
59 static void frame_insert
__ARGS((frame_T
*before
, frame_T
*frp
));
60 static void frame_remove
__ARGS((frame_T
*frp
));
62 static void win_new_width
__ARGS((win_T
*wp
, int width
));
63 static void win_goto_ver
__ARGS((int up
, long count
));
64 static void win_goto_hor
__ARGS((int left
, long count
));
66 static void frame_add_height
__ARGS((frame_T
*frp
, int n
));
67 static void last_status_rec
__ARGS((frame_T
*fr
, int statusline
));
69 static void make_snapshot
__ARGS((void));
70 static void make_snapshot_rec
__ARGS((frame_T
*fr
, frame_T
**frp
));
71 static void clear_snapshot
__ARGS((tabpage_T
*tp
));
72 static void clear_snapshot_rec
__ARGS((frame_T
*fr
));
73 static void restore_snapshot
__ARGS((int close_curwin
));
74 static int check_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
75 static win_T
*restore_snapshot_rec
__ARGS((frame_T
*sn
, frame_T
*fr
));
77 #endif /* FEAT_WINDOWS */
79 static win_T
*win_alloc
__ARGS((win_T
*after
));
80 static void win_new_height
__ARGS((win_T
*, int));
82 #define URL_SLASH 1 /* path_is_url() has found "://" */
83 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
85 #define NOWIN (win_T *)-1 /* non-existing window */
88 # define ROWS_AVAIL (Rows - p_ch - tabline_height())
90 # define ROWS_AVAIL (Rows - p_ch)
93 #if defined(FEAT_WINDOWS) || defined(PROTO)
95 static char *m_onlyone
= N_("Already only one window");
98 * all CTRL-W window commands are handled here, called from normal_cmd().
101 do_window(nchar
, Prenum
, xchar
)
104 int xchar
; /* extra char from ":wincmd gx" or NUL */
108 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID)
113 int type
= FIND_DEFINE
;
124 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; }
126 # define CHECK_CMDWIN
131 /* split current window in two parts, horizontally */
137 reset_VIsual_and_resel(); /* stop Visual mode */
140 /* When splitting the quickfix window open a new buffer in it,
141 * don't replicate the quickfix buffer. */
142 if (bt_quickfix(curbuf
))
146 need_mouse_correct
= TRUE
;
148 win_split((int)Prenum
, 0);
151 #ifdef FEAT_VERTSPLIT
152 /* split current window in two parts, vertically */
157 reset_VIsual_and_resel(); /* stop Visual mode */
160 need_mouse_correct
= TRUE
;
162 win_split((int)Prenum
, WSP_VERT
);
166 /* split current window and edit alternate file */
171 reset_VIsual_and_resel(); /* stop Visual mode */
173 STRCPY(cbuf
, "split #");
175 sprintf((char *)cbuf
+ 7, "%ld", Prenum
);
176 do_cmdline_cmd(cbuf
);
179 /* open new window */
184 reset_VIsual_and_resel(); /* stop Visual mode */
190 sprintf((char *)cbuf
, "%ld", Prenum
); /* window height */
194 do_cmdline_cmd(cbuf
);
197 /* quit current window */
201 reset_VIsual_and_resel(); /* stop Visual mode */
203 do_cmdline_cmd((char_u
*)"quit");
206 /* close current window */
210 reset_VIsual_and_resel(); /* stop Visual mode */
212 do_cmdline_cmd((char_u
*)"close");
215 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
216 /* close preview window */
221 reset_VIsual_and_resel(); /* stop Visual mode */
223 do_cmdline_cmd((char_u
*)"pclose");
226 /* cursor to preview window */
228 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
232 EMSG(_("E441: There is no preview window"));
238 /* close all but current window */
243 reset_VIsual_and_resel(); /* stop Visual mode */
245 do_cmdline_cmd((char_u
*)"only");
248 /* cursor to next window with wrap around */
251 /* cursor to previous window with wrap around */
254 if (lastwin
== firstwin
&& Prenum
!= 1) /* just one window */
258 if (Prenum
) /* go to specified window */
260 for (wp
= firstwin
; --Prenum
> 0; )
262 if (wp
->w_next
== NULL
)
270 if (nchar
== 'W') /* go to previous window */
274 wp
= lastwin
; /* wrap around */
276 else /* go to next window */
280 wp
= firstwin
; /* wrap around */
287 /* cursor to window below */
292 #ifdef FEAT_VERTSPLIT
293 win_goto_ver(FALSE
, Prenum1
);
295 for (wp
= curwin
; wp
->w_next
!= NULL
&& Prenum1
-- > 0;
302 /* cursor to window above */
307 #ifdef FEAT_VERTSPLIT
308 win_goto_ver(TRUE
, Prenum1
);
310 for (wp
= curwin
; wp
->w_prev
!= NULL
&& Prenum1
-- > 0;
317 #ifdef FEAT_VERTSPLIT
318 /* cursor to left window */
324 win_goto_hor(TRUE
, Prenum1
);
327 /* cursor to right window */
332 win_goto_hor(FALSE
, Prenum1
);
336 /* move window to new tab page */
338 if (firstwin
== lastwin
)
342 tabpage_T
*oldtab
= curtab
;
345 /* First create a new tab with the window, then go back to
346 * the old tab and close the window there. */
348 if (win_new_tabpage((int)Prenum
) == OK
349 && valid_tabpage(oldtab
))
352 goto_tabpage_tp(oldtab
);
354 win_close(curwin
, FALSE
);
355 if (valid_tabpage(newtab
))
356 goto_tabpage_tp(newtab
);
361 /* cursor to top-left window */
367 /* cursor to bottom-right window */
373 /* cursor to last accessed (previous) window */
382 /* exchange current and next window */
386 win_exchange(Prenum
);
389 /* rotate windows downwards */
394 reset_VIsual_and_resel(); /* stop Visual mode */
396 win_rotate(FALSE
, (int)Prenum1
); /* downwards */
399 /* rotate windows upwards */
403 reset_VIsual_and_resel(); /* stop Visual mode */
405 win_rotate(TRUE
, (int)Prenum1
); /* upwards */
408 /* move window to the very top/bottom/left/right */
411 #ifdef FEAT_VERTSPLIT
416 win_totop((int)Prenum
,
417 ((nchar
== 'H' || nchar
== 'L') ? WSP_VERT
: 0)
418 | ((nchar
== 'H' || nchar
== 'K') ? WSP_TOP
: WSP_BOT
));
421 /* make all windows the same height */
424 need_mouse_correct
= TRUE
;
426 win_equal(NULL
, FALSE
, 'b');
429 /* increase current window height */
432 need_mouse_correct
= TRUE
;
434 win_setheight(curwin
->w_height
+ (int)Prenum1
);
437 /* decrease current window height */
440 need_mouse_correct
= TRUE
;
442 win_setheight(curwin
->w_height
- (int)Prenum1
);
445 /* set current window height */
449 need_mouse_correct
= TRUE
;
451 win_setheight(Prenum
? (int)Prenum
: 9999);
454 #ifdef FEAT_VERTSPLIT
455 /* increase current window width */
458 need_mouse_correct
= TRUE
;
460 win_setwidth(curwin
->w_width
+ (int)Prenum1
);
463 /* decrease current window width */
466 need_mouse_correct
= TRUE
;
468 win_setwidth(curwin
->w_width
- (int)Prenum1
);
471 /* set current window width */
474 need_mouse_correct
= TRUE
;
476 win_setwidth(Prenum
!= 0 ? (int)Prenum
: 9999);
480 /* jump to tag and split window if tag exists (in preview window) */
481 #if defined(FEAT_QUICKFIX)
485 g_do_tagpreview
= Prenum
;
487 g_do_tagpreview
= p_pvh
;
494 reset_VIsual_and_resel(); /* stop Visual mode */
497 postponed_split
= Prenum
;
499 postponed_split
= -1;
501 /* Execute the command right here, required when
502 * "wincmd ]" was used in a function. */
503 do_nv_ident(Ctrl_RSB
, NUL
);
506 #ifdef FEAT_SEARCHPATH
507 /* edit file name under cursor in a new window */
514 ptr
= grab_file_name(Prenum1
, &lnum
);
518 need_mouse_correct
= TRUE
;
521 if (win_split(0, 0) == OK
)
523 # ifdef FEAT_SCROLLBIND
524 curwin
->w_p_scb
= FALSE
;
526 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LASTL
, ECMD_HIDE
);
527 if (nchar
== 'F' && lnum
>= 0)
529 curwin
->w_cursor
.lnum
= lnum
;
531 beginline(BL_SOL
| BL_FIX
);
540 /* Go to the first occurrence of the identifier under cursor along path in a
543 case 'i': /* Go to any match */
547 case 'd': /* Go to definition, using 'define' */
550 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
552 find_pattern_in_path(ptr
, 0, len
, TRUE
,
553 Prenum
== 0 ? TRUE
: FALSE
, type
,
554 Prenum1
, ACTION_SPLIT
, (linenr_T
)1, (linenr_T
)MAXLNUM
);
555 curwin
->w_set_curswant
= TRUE
;
561 #if defined(FEAT_QUICKFIX)
563 * In a quickfix window a <CR> jumps to the error under the
564 * cursor in a new window.
566 if (bt_quickfix(curbuf
))
568 sprintf((char *)cbuf
, "split +%ld%s",
569 (long)curwin
->w_cursor
.lnum
,
570 (curwin
->w_llist_ref
== NULL
) ? "cc" : "ll");
571 do_cmdline_cmd(cbuf
);
577 /* CTRL-W g extended commands */
581 #ifdef USE_ON_FLY_SCROLL
582 dont_scroll
= TRUE
; /* disallow scrolling here */
585 ++allow_keys
; /* no mapping for xchar, but allow key codes */
587 xchar
= plain_vgetc();
589 LANGMAP_ADJUST(xchar
, TRUE
);
593 #ifdef FEAT_CMDL_INFO
594 (void)add_to_showcmd(xchar
);
598 #if defined(FEAT_QUICKFIX)
602 g_do_tagpreview
= Prenum
;
604 g_do_tagpreview
= p_pvh
;
610 reset_VIsual_and_resel(); /* stop Visual mode */
613 postponed_split
= Prenum
;
615 postponed_split
= -1;
617 /* Execute the command right here, required when
618 * "wincmd g}" was used in a function. */
619 do_nv_ident('g', xchar
);
622 #ifdef FEAT_SEARCHPATH
623 case 'f': /* CTRL-W gf: "gf" in a new tab page */
624 case 'F': /* CTRL-W gF: "gF" in a new tab page */
635 default: beep_flush();
641 * split the current window, implements CTRL-W s and :split
643 * "size" is the height or width for the new window, 0 to use half of current
647 * WSP_ROOM: require enough room for new window
648 * WSP_VERT: vertical split.
649 * WSP_TOP: open window at the top-left of the shell (help window).
650 * WSP_BOT: open window at the bottom-right of the shell (quickfix window).
651 * WSP_HELP: creating the help window, keep layout snapshot
653 * return FAIL for failure, OK otherwise
656 win_split(size
, flags
)
660 /* When the ":tab" modifier was used open a new tab page instead. */
661 if (may_open_tabpage() == OK
)
664 /* Add flags from ":vertical", ":topleft" and ":botright". */
665 flags
|= cmdmod
.split
;
666 if ((flags
& WSP_TOP
) && (flags
& WSP_BOT
))
668 EMSG(_("E442: Can't split topleft and botright at the same time"));
672 /* When creating the help window make a snapshot of the window layout.
673 * Otherwise clear the snapshot, it's now invalid. */
674 if (flags
& WSP_HELP
)
677 clear_snapshot(curtab
);
679 return win_split_ins(size
, flags
, NULL
, 0);
683 * When "newwin" is NULL: split the current window in two.
684 * When "newwin" is not NULL: insert this window at the far
685 * top/left/right/bottom.
686 * return FAIL for failure, OK otherwise
689 win_split_ins(size
, flags
, newwin
, dir
)
700 int do_equal
= FALSE
;
703 int oldwin_height
= 0;
705 frame_T
*frp
, *curfrp
;
710 else if (flags
& WSP_BOT
)
715 /* add a status line when p_ls == 1 and splitting the first window */
716 if (lastwin
== firstwin
&& p_ls
== 1 && oldwin
->w_status_height
== 0)
718 if (oldwin
->w_height
<= p_wmh
&& newwin
== NULL
)
723 need_status
= STATUS_HEIGHT
;
727 /* May be needed for the scrollbars that are going to change. */
732 #ifdef FEAT_VERTSPLIT
733 if (flags
& WSP_VERT
)
738 * Check if we are able to split the current window and compute its
742 if (flags
& WSP_ROOM
)
743 needed
+= p_wiw
- p_wmw
;
744 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
746 available
= topframe
->fr_width
;
747 needed
+= frame_minwidth(topframe
, NULL
);
750 available
= oldwin
->w_width
;
751 if (available
< needed
&& newwin
== NULL
)
757 new_size
= oldwin
->w_width
/ 2;
758 if (new_size
> oldwin
->w_width
- p_wmw
- 1)
759 new_size
= oldwin
->w_width
- p_wmw
- 1;
760 if (new_size
< p_wmw
)
763 /* if it doesn't fit in the current window, need win_equal() */
764 if (oldwin
->w_width
- new_size
- 1 < p_wmw
)
767 /* We don't like to take lines for the new window from a
768 * 'winfixwidth' window. Take them from a window to the left or right
769 * instead, if possible. */
771 win_setwidth_win(oldwin
->w_width
+ new_size
, oldwin
);
773 /* Only make all windows the same width if one of them (except oldwin)
774 * is wider than one of the split windows. */
775 if (!do_equal
&& p_ea
&& size
== 0 && *p_ead
!= 'v'
776 && oldwin
->w_frame
->fr_parent
!= NULL
)
778 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
781 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
782 && (frp
->fr_win
->w_width
> new_size
783 || frp
->fr_win
->w_width
> oldwin
->w_width
784 - new_size
- STATUS_HEIGHT
))
799 * Check if we are able to split the current window and compute its
802 needed
= p_wmh
+ STATUS_HEIGHT
+ need_status
;
803 if (flags
& WSP_ROOM
)
804 needed
+= p_wh
- p_wmh
;
805 if (p_ea
|| (flags
& (WSP_BOT
| WSP_TOP
)))
807 available
= topframe
->fr_height
;
808 needed
+= frame_minheight(topframe
, NULL
);
812 available
= oldwin
->w_height
;
815 if (available
< needed
&& newwin
== NULL
)
820 oldwin_height
= oldwin
->w_height
;
823 oldwin
->w_status_height
= STATUS_HEIGHT
;
824 oldwin_height
-= STATUS_HEIGHT
;
827 new_size
= oldwin_height
/ 2;
829 if (new_size
> oldwin_height
- p_wmh
- STATUS_HEIGHT
)
830 new_size
= oldwin_height
- p_wmh
- STATUS_HEIGHT
;
831 if (new_size
< p_wmh
)
834 /* if it doesn't fit in the current window, need win_equal() */
835 if (oldwin_height
- new_size
- STATUS_HEIGHT
< p_wmh
)
838 /* We don't like to take lines for the new window from a
839 * 'winfixheight' window. Take them from a window above or below
840 * instead, if possible. */
843 win_setheight_win(oldwin
->w_height
+ new_size
+ STATUS_HEIGHT
,
845 oldwin_height
= oldwin
->w_height
;
847 oldwin_height
-= STATUS_HEIGHT
;
850 /* Only make all windows the same height if one of them (except oldwin)
851 * is higher than one of the split windows. */
852 if (!do_equal
&& p_ea
&& size
== 0
853 #ifdef FEAT_VERTSPLIT
856 && oldwin
->w_frame
->fr_parent
!= NULL
)
858 frp
= oldwin
->w_frame
->fr_parent
->fr_child
;
861 if (frp
->fr_win
!= oldwin
&& frp
->fr_win
!= NULL
862 && (frp
->fr_win
->w_height
> new_size
863 || frp
->fr_win
->w_height
> oldwin_height
- new_size
875 * allocate new window structure and link it in the window list
877 if ((flags
& WSP_TOP
) == 0
878 && ((flags
& WSP_BOT
)
879 || (flags
& WSP_BELOW
)
880 || (!(flags
& WSP_ABOVE
)
882 #ifdef FEAT_VERTSPLIT
883 (flags
& WSP_VERT
) ? p_spr
:
887 /* new window below/right of current one */
889 wp
= win_alloc(oldwin
);
891 win_append(oldwin
, wp
);
896 wp
= win_alloc(oldwin
->w_prev
);
898 win_append(oldwin
->w_prev
, wp
);
906 /* make the contents of the new window the same as the current one */
907 win_init(wp
, curwin
);
911 * Reorganise the tree of frames to insert the new window.
913 if (flags
& (WSP_TOP
| WSP_BOT
))
915 #ifdef FEAT_VERTSPLIT
916 if ((topframe
->fr_layout
== FR_COL
&& (flags
& WSP_VERT
) == 0)
917 || (topframe
->fr_layout
== FR_ROW
&& (flags
& WSP_VERT
) != 0))
919 if (topframe
->fr_layout
== FR_COL
)
922 curfrp
= topframe
->fr_child
;
924 while (curfrp
->fr_next
!= NULL
)
925 curfrp
= curfrp
->fr_next
;
929 before
= (flags
& WSP_TOP
);
933 curfrp
= oldwin
->w_frame
;
934 if (flags
& WSP_BELOW
)
936 else if (flags
& WSP_ABOVE
)
939 #ifdef FEAT_VERTSPLIT
940 if (flags
& WSP_VERT
)
946 if (curfrp
->fr_parent
== NULL
|| curfrp
->fr_parent
->fr_layout
!= layout
)
948 /* Need to create a new frame in the tree to make a branch. */
949 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
951 curfrp
->fr_layout
= layout
;
952 frp
->fr_parent
= curfrp
;
955 curfrp
->fr_child
= frp
;
956 curfrp
->fr_win
= NULL
;
958 if (frp
->fr_win
!= NULL
)
959 oldwin
->w_frame
= frp
;
961 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
962 frp
->fr_parent
= curfrp
;
967 /* Create a frame for the new window. */
968 frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
969 frp
->fr_layout
= FR_LEAF
;
974 frp
= newwin
->w_frame
;
975 frp
->fr_parent
= curfrp
->fr_parent
;
977 /* Insert the new frame at the right place in the frame list. */
979 frame_insert(curfrp
, frp
);
981 frame_append(curfrp
, frp
);
983 #ifdef FEAT_VERTSPLIT
984 if (flags
& WSP_VERT
)
986 wp
->w_p_scr
= curwin
->w_p_scr
;
990 oldwin
->w_status_height
= need_status
;
992 if (flags
& (WSP_TOP
| WSP_BOT
))
994 /* set height and row of new window to full height */
995 wp
->w_winrow
= tabline_height();
996 wp
->w_height
= curfrp
->fr_height
- (p_ls
> 0);
997 wp
->w_status_height
= (p_ls
> 0);
1001 /* height and row of new window is same as current window */
1002 wp
->w_winrow
= oldwin
->w_winrow
;
1003 wp
->w_height
= oldwin
->w_height
;
1004 wp
->w_status_height
= oldwin
->w_status_height
;
1006 frp
->fr_height
= curfrp
->fr_height
;
1008 /* "new_size" of the current window goes to the new window, use
1009 * one column for the vertical separator */
1010 wp
->w_width
= new_size
;
1012 wp
->w_vsep_width
= 1;
1015 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1016 oldwin
->w_vsep_width
= 1;
1018 if (flags
& (WSP_TOP
| WSP_BOT
))
1020 if (flags
& WSP_BOT
)
1021 frame_add_vsep(curfrp
);
1022 /* Set width of neighbor frame */
1023 frame_new_width(curfrp
, curfrp
->fr_width
1024 - (new_size
+ ((flags
& WSP_TOP
) != 0)), flags
& WSP_TOP
,
1028 win_new_width(oldwin
, oldwin
->w_width
- (new_size
+ 1));
1029 if (before
) /* new window left of current one */
1031 wp
->w_wincol
= oldwin
->w_wincol
;
1032 oldwin
->w_wincol
+= new_size
+ 1;
1034 else /* new window right of current one */
1035 wp
->w_wincol
= oldwin
->w_wincol
+ oldwin
->w_width
+ 1;
1036 frame_fix_width(oldwin
);
1037 frame_fix_width(wp
);
1042 /* width and column of new window is same as current window */
1043 #ifdef FEAT_VERTSPLIT
1044 if (flags
& (WSP_TOP
| WSP_BOT
))
1047 wp
->w_width
= Columns
;
1048 wp
->w_vsep_width
= 0;
1052 wp
->w_wincol
= oldwin
->w_wincol
;
1053 wp
->w_width
= oldwin
->w_width
;
1054 wp
->w_vsep_width
= oldwin
->w_vsep_width
;
1056 frp
->fr_width
= curfrp
->fr_width
;
1059 /* "new_size" of the current window goes to the new window, use
1060 * one row for the status line */
1061 win_new_height(wp
, new_size
);
1062 if (flags
& (WSP_TOP
| WSP_BOT
))
1063 frame_new_height(curfrp
, curfrp
->fr_height
1064 - (new_size
+ STATUS_HEIGHT
), flags
& WSP_TOP
, FALSE
);
1066 win_new_height(oldwin
, oldwin_height
- (new_size
+ STATUS_HEIGHT
));
1067 if (before
) /* new window above current one */
1069 wp
->w_winrow
= oldwin
->w_winrow
;
1070 wp
->w_status_height
= STATUS_HEIGHT
;
1071 oldwin
->w_winrow
+= wp
->w_height
+ STATUS_HEIGHT
;
1073 else /* new window below current one */
1075 wp
->w_winrow
= oldwin
->w_winrow
+ oldwin
->w_height
+ STATUS_HEIGHT
;
1076 wp
->w_status_height
= oldwin
->w_status_height
;
1077 oldwin
->w_status_height
= STATUS_HEIGHT
;
1079 #ifdef FEAT_VERTSPLIT
1080 if (flags
& WSP_BOT
)
1081 frame_add_statusline(curfrp
);
1083 frame_fix_height(wp
);
1084 frame_fix_height(oldwin
);
1087 if (flags
& (WSP_TOP
| WSP_BOT
))
1088 (void)win_comp_pos();
1091 * Both windows need redrawing
1093 redraw_win_later(wp
, NOT_VALID
);
1094 wp
->w_redr_status
= TRUE
;
1095 redraw_win_later(oldwin
, NOT_VALID
);
1096 oldwin
->w_redr_status
= TRUE
;
1102 msg_clr_eos_force(); /* Old command/ruler may still be there */
1105 msg_col
= 0; /* put position back at start of line */
1109 * make the new window the current window and redraw
1111 if (do_equal
|| dir
!= 0)
1113 #ifdef FEAT_VERTSPLIT
1114 (flags
& WSP_VERT
) ? (dir
== 'v' ? 'b' : 'h')
1115 : dir
== 'h' ? 'b' :
1119 /* Don't change the window height/width to 'winheight' / 'winwidth' if a
1120 * size was given. */
1121 #ifdef FEAT_VERTSPLIT
1122 if (flags
& WSP_VERT
)
1129 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */
1131 gui_init_which_components(NULL
);
1141 win_enter(wp
, FALSE
);
1142 #ifdef FEAT_VERTSPLIT
1143 if (flags
& WSP_VERT
)
1153 * Initialize window "newp" from window "oldp".
1154 * Used when splitting a window and when creating a new tab page.
1155 * The windows will both edit the same buffer.
1158 win_init(newp
, oldp
)
1164 newp
->w_buffer
= oldp
->w_buffer
;
1165 oldp
->w_buffer
->b_nwindows
++;
1166 newp
->w_cursor
= oldp
->w_cursor
;
1168 newp
->w_curswant
= oldp
->w_curswant
;
1169 newp
->w_set_curswant
= oldp
->w_set_curswant
;
1170 newp
->w_topline
= oldp
->w_topline
;
1172 newp
->w_topfill
= oldp
->w_topfill
;
1174 newp
->w_leftcol
= oldp
->w_leftcol
;
1175 newp
->w_pcmark
= oldp
->w_pcmark
;
1176 newp
->w_prev_pcmark
= oldp
->w_prev_pcmark
;
1177 newp
->w_alt_fnum
= oldp
->w_alt_fnum
;
1178 newp
->w_wrow
= oldp
->w_wrow
;
1179 newp
->w_fraction
= oldp
->w_fraction
;
1180 newp
->w_prev_fraction_row
= oldp
->w_prev_fraction_row
;
1181 #ifdef FEAT_JUMPLIST
1182 copy_jumplist(oldp
, newp
);
1184 #ifdef FEAT_QUICKFIX
1185 copy_loclist(oldp
, newp
);
1187 if (oldp
->w_localdir
!= NULL
)
1188 newp
->w_localdir
= vim_strsave(oldp
->w_localdir
);
1190 /* Use the same argument list. */
1191 newp
->w_alist
= oldp
->w_alist
;
1192 ++newp
->w_alist
->al_refcount
;
1193 newp
->w_arg_idx
= oldp
->w_arg_idx
;
1196 * copy tagstack and options from existing window
1198 for (i
= 0; i
< oldp
->w_tagstacklen
; i
++)
1200 newp
->w_tagstack
[i
] = oldp
->w_tagstack
[i
];
1201 if (newp
->w_tagstack
[i
].tagname
!= NULL
)
1202 newp
->w_tagstack
[i
].tagname
=
1203 vim_strsave(newp
->w_tagstack
[i
].tagname
);
1205 newp
->w_tagstackidx
= oldp
->w_tagstackidx
;
1206 newp
->w_tagstacklen
= oldp
->w_tagstacklen
;
1207 win_copy_options(oldp
, newp
);
1208 # ifdef FEAT_FOLDING
1209 copyFoldingState(oldp
, newp
);
1213 #endif /* FEAT_WINDOWS */
1215 #if defined(FEAT_WINDOWS) || defined(PROTO)
1217 * Check if "win" is a pointer to an existing window.
1227 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1234 * Return the number of windows.
1242 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1248 * Make "count" windows on the screen.
1249 * Return actual number of windows on the screen.
1250 * Must be called when there is just one window, filling the whole screen
1251 * (excluding the command line).
1255 make_windows(count
, vertical
)
1257 int vertical
; /* split windows vertically if TRUE */
1262 #ifdef FEAT_VERTSPLIT
1265 /* Each windows needs at least 'winminwidth' lines and a separator
1267 maxcount
= (curwin
->w_width
+ curwin
->w_vsep_width
1268 - (p_wiw
- p_wmw
)) / (p_wmw
+ 1);
1273 /* Each window needs at least 'winminheight' lines and a status line. */
1274 maxcount
= (curwin
->w_height
+ curwin
->w_status_height
1275 - (p_wh
- p_wmh
)) / (p_wmh
+ STATUS_HEIGHT
);
1280 if (count
> maxcount
)
1284 * add status line now, otherwise first window will be too big
1291 * Don't execute autocommands while creating the windows. Must do that
1292 * when putting the buffers in the windows.
1297 /* todo is number of windows left to create */
1298 for (todo
= count
- 1; todo
> 0; --todo
)
1299 #ifdef FEAT_VERTSPLIT
1302 if (win_split(curwin
->w_width
- (curwin
->w_width
- todo
)
1303 / (todo
+ 1) - 1, WSP_VERT
| WSP_ABOVE
) == FAIL
)
1309 if (win_split(curwin
->w_height
- (curwin
->w_height
- todo
1310 * STATUS_HEIGHT
) / (todo
+ 1)
1311 - STATUS_HEIGHT
, WSP_ABOVE
) == FAIL
)
1319 /* return actual number of windows */
1320 return (count
- todo
);
1324 * Exchange current and next window
1327 win_exchange(Prenum
)
1336 if (lastwin
== firstwin
) /* just one window */
1343 need_mouse_correct
= TRUE
;
1347 * find window to exchange with
1351 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1352 while (frp
!= NULL
&& --Prenum
> 0)
1355 else if (curwin
->w_frame
->fr_next
!= NULL
) /* Swap with next */
1356 frp
= curwin
->w_frame
->fr_next
;
1357 else /* Swap last window in row/col with previous */
1358 frp
= curwin
->w_frame
->fr_prev
;
1360 /* We can only exchange a window with another window, not with a frame
1361 * containing windows. */
1362 if (frp
== NULL
|| frp
->fr_win
== NULL
|| frp
->fr_win
== curwin
)
1367 * 1. remove curwin from the list. Remember after which window it was in wp2
1368 * 2. insert curwin before wp in the list
1370 * 3. remove wp from the list
1371 * 4. insert wp after wp2
1372 * 5. exchange the status line height and vsep width.
1374 wp2
= curwin
->w_prev
;
1375 frp2
= curwin
->w_frame
->fr_prev
;
1376 if (wp
->w_prev
!= curwin
)
1378 win_remove(curwin
, NULL
);
1379 frame_remove(curwin
->w_frame
);
1380 win_append(wp
->w_prev
, curwin
);
1381 frame_insert(frp
, curwin
->w_frame
);
1385 win_remove(wp
, NULL
);
1386 frame_remove(wp
->w_frame
);
1387 win_append(wp2
, wp
);
1389 frame_insert(wp
->w_frame
->fr_parent
->fr_child
, wp
->w_frame
);
1391 frame_append(frp2
, wp
->w_frame
);
1393 temp
= curwin
->w_status_height
;
1394 curwin
->w_status_height
= wp
->w_status_height
;
1395 wp
->w_status_height
= temp
;
1396 #ifdef FEAT_VERTSPLIT
1397 temp
= curwin
->w_vsep_width
;
1398 curwin
->w_vsep_width
= wp
->w_vsep_width
;
1399 wp
->w_vsep_width
= temp
;
1401 /* If the windows are not in the same frame, exchange the sizes to avoid
1402 * messing up the window layout. Otherwise fix the frame sizes. */
1403 if (curwin
->w_frame
->fr_parent
!= wp
->w_frame
->fr_parent
)
1405 temp
= curwin
->w_height
;
1406 curwin
->w_height
= wp
->w_height
;
1407 wp
->w_height
= temp
;
1408 temp
= curwin
->w_width
;
1409 curwin
->w_width
= wp
->w_width
;
1414 frame_fix_height(curwin
);
1415 frame_fix_height(wp
);
1416 frame_fix_width(curwin
);
1417 frame_fix_width(wp
);
1421 (void)win_comp_pos(); /* recompute window positions */
1423 win_enter(wp
, TRUE
);
1424 redraw_later(CLEAR
);
1428 * rotate windows: if upwards TRUE the second window becomes the first one
1429 * if upwards FALSE the first window becomes the second one
1432 win_rotate(upwards
, count
)
1441 if (firstwin
== lastwin
) /* nothing to do */
1448 need_mouse_correct
= TRUE
;
1451 #ifdef FEAT_VERTSPLIT
1452 /* Check if all frames in this row/col have one window. */
1453 for (frp
= curwin
->w_frame
->fr_parent
->fr_child
; frp
!= NULL
;
1455 if (frp
->fr_win
== NULL
)
1457 EMSG(_("E443: Cannot rotate when another window is split"));
1464 if (upwards
) /* first window becomes last window */
1466 /* remove first window/frame from the list */
1467 frp
= curwin
->w_frame
->fr_parent
->fr_child
;
1469 win_remove(wp1
, NULL
);
1472 /* find last frame and append removed window/frame after it */
1473 for ( ; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
1475 win_append(frp
->fr_win
, wp1
);
1476 frame_append(frp
, wp1
->w_frame
);
1478 wp2
= frp
->fr_win
; /* previously last window */
1480 else /* last window becomes first window */
1482 /* find last window/frame in the list and remove it */
1483 for (frp
= curwin
->w_frame
; frp
->fr_next
!= NULL
;
1487 wp2
= wp1
->w_prev
; /* will become last window */
1488 win_remove(wp1
, NULL
);
1491 /* append the removed window/frame before the first in the list */
1492 win_append(frp
->fr_parent
->fr_child
->fr_win
->w_prev
, wp1
);
1493 frame_insert(frp
->fr_parent
->fr_child
, frp
);
1496 /* exchange status height and vsep width of old and new last window */
1497 n
= wp2
->w_status_height
;
1498 wp2
->w_status_height
= wp1
->w_status_height
;
1499 wp1
->w_status_height
= n
;
1500 frame_fix_height(wp1
);
1501 frame_fix_height(wp2
);
1502 #ifdef FEAT_VERTSPLIT
1503 n
= wp2
->w_vsep_width
;
1504 wp2
->w_vsep_width
= wp1
->w_vsep_width
;
1505 wp1
->w_vsep_width
= n
;
1506 frame_fix_width(wp1
);
1507 frame_fix_width(wp2
);
1510 /* recompute w_winrow and w_wincol for all windows */
1511 (void)win_comp_pos();
1514 redraw_later(CLEAR
);
1518 * Move the current window to the very top/bottom/left/right of the screen.
1521 win_totop(size
, flags
)
1526 int height
= curwin
->w_height
;
1528 if (lastwin
== firstwin
)
1534 /* Remove the window and frame from the tree of frames. */
1535 (void)winframe_remove(curwin
, &dir
, NULL
);
1536 win_remove(curwin
, NULL
);
1537 last_status(FALSE
); /* may need to remove last status line */
1538 (void)win_comp_pos(); /* recompute window positions */
1540 /* Split a window on the desired side and put the window there. */
1541 (void)win_split_ins(size
, flags
, curwin
, dir
);
1542 if (!(flags
& WSP_VERT
))
1544 win_setheight(height
);
1546 win_equal(curwin
, TRUE
, 'v');
1549 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
1550 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
1551 * scrollbars. Have to update them anyway. */
1555 gui_init_which_components(NULL
);
1556 gui_update_scrollbars(TRUE
);
1558 need_mouse_correct
= TRUE
;
1564 * Move window "win1" to below/right of "win2" and make "win1" the current
1565 * window. Only works within the same frame!
1568 win_move_after(win1
, win2
)
1573 /* check if the arguments are reasonable */
1577 /* check if there is something to do */
1578 if (win2
->w_next
!= win1
)
1580 /* may need move the status line/vertical separator of the last window
1582 if (win1
== lastwin
)
1584 height
= win1
->w_prev
->w_status_height
;
1585 win1
->w_prev
->w_status_height
= win1
->w_status_height
;
1586 win1
->w_status_height
= height
;
1587 #ifdef FEAT_VERTSPLIT
1588 if (win1
->w_prev
->w_vsep_width
== 1)
1590 /* Remove the vertical separator from the last-but-one window,
1591 * add it to the last window. Adjust the frame widths. */
1592 win1
->w_prev
->w_vsep_width
= 0;
1593 win1
->w_prev
->w_frame
->fr_width
-= 1;
1594 win1
->w_vsep_width
= 1;
1595 win1
->w_frame
->fr_width
+= 1;
1599 else if (win2
== lastwin
)
1601 height
= win1
->w_status_height
;
1602 win1
->w_status_height
= win2
->w_status_height
;
1603 win2
->w_status_height
= height
;
1604 #ifdef FEAT_VERTSPLIT
1605 if (win1
->w_vsep_width
== 1)
1607 /* Remove the vertical separator from win1, add it to the last
1608 * window, win2. Adjust the frame widths. */
1609 win2
->w_vsep_width
= 1;
1610 win2
->w_frame
->fr_width
+= 1;
1611 win1
->w_vsep_width
= 0;
1612 win1
->w_frame
->fr_width
-= 1;
1616 win_remove(win1
, NULL
);
1617 frame_remove(win1
->w_frame
);
1618 win_append(win2
, win1
);
1619 frame_append(win2
->w_frame
, win1
->w_frame
);
1621 (void)win_comp_pos(); /* recompute w_winrow for all windows */
1622 redraw_later(NOT_VALID
);
1624 win_enter(win1
, FALSE
);
1628 * Make all windows the same height.
1629 * 'next_curwin' will soon be the current window, make sure it has enough
1633 win_equal(next_curwin
, current
, dir
)
1634 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1635 int current
; /* do only frame with current window */
1636 int dir
; /* 'v' for vertically, 'h' for horizontally,
1637 'b' for both, 0 for using p_ead */
1640 #ifdef FEAT_VERTSPLIT
1645 win_equal_rec(next_curwin
== NULL
? curwin
: next_curwin
, current
,
1646 topframe
, dir
, 0, tabline_height(),
1647 (int)Columns
, topframe
->fr_height
);
1651 * Set a frame to a new position and height, spreading the available room
1652 * equally over contained frames.
1653 * The window "next_curwin" (if not NULL) should at least get the size from
1654 * 'winheight' and 'winwidth' if possible.
1657 win_equal_rec(next_curwin
, current
, topfr
, dir
, col
, row
, width
, height
)
1658 win_T
*next_curwin
; /* pointer to current window to be or NULL */
1659 int current
; /* do only frame with current window */
1660 frame_T
*topfr
; /* frame to set size off */
1661 int dir
; /* 'v', 'h' or 'b', see win_equal() */
1662 int col
; /* horizontal position for frame */
1663 int row
; /* vertical position for frame */
1664 int width
; /* new width of frame */
1665 int height
; /* new height of frame */
1669 int wincount
, totwincount
= 0;
1671 int next_curwin_size
= 0;
1674 int has_next_curwin
= 0;
1677 if (topfr
->fr_layout
== FR_LEAF
)
1679 /* Set the width/height of this frame.
1680 * Redraw when size or position changes */
1681 if (topfr
->fr_height
!= height
|| topfr
->fr_win
->w_winrow
!= row
1682 #ifdef FEAT_VERTSPLIT
1683 || topfr
->fr_width
!= width
|| topfr
->fr_win
->w_wincol
!= col
1687 topfr
->fr_win
->w_winrow
= row
;
1688 frame_new_height(topfr
, height
, FALSE
, FALSE
);
1689 #ifdef FEAT_VERTSPLIT
1690 topfr
->fr_win
->w_wincol
= col
;
1691 frame_new_width(topfr
, width
, FALSE
, FALSE
);
1693 redraw_all_later(CLEAR
);
1696 #ifdef FEAT_VERTSPLIT
1697 else if (topfr
->fr_layout
== FR_ROW
)
1699 topfr
->fr_width
= width
;
1700 topfr
->fr_height
= height
;
1702 if (dir
!= 'v') /* equalize frame widths */
1704 /* Compute the maximum number of windows horizontally in this
1706 n
= frame_minwidth(topfr
, NOWIN
);
1707 /* add one for the rightmost window, it doesn't have a separator */
1708 if (col
+ width
== Columns
)
1712 totwincount
= (n
+ extra_sep
) / (p_wmw
+ 1);
1713 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1716 * Compute width for "next_curwin" window and room available for
1718 * "m" is the minimal width when counting p_wiw for "next_curwin".
1720 m
= frame_minwidth(topfr
, next_curwin
);
1724 next_curwin_size
= p_wiw
+ room
;
1729 next_curwin_size
= -1;
1730 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1732 /* If 'winfixwidth' set keep the window width if
1734 * Watch out for this window being the next_curwin. */
1735 if (frame_fixed_width(fr
))
1737 n
= frame_minwidth(fr
, NOWIN
);
1738 new_size
= fr
->fr_width
;
1739 if (frame_has_win(fr
, next_curwin
))
1741 room
+= p_wiw
- p_wmw
;
1742 next_curwin_size
= 0;
1743 if (new_size
< p_wiw
)
1747 /* These windows don't use up room. */
1748 totwincount
-= (n
+ (fr
->fr_next
== NULL
1749 ? extra_sep
: 0)) / (p_wmw
+ 1);
1750 room
-= new_size
- n
;
1756 fr
->fr_newwidth
= new_size
;
1759 if (next_curwin_size
== -1)
1761 if (!has_next_curwin
)
1762 next_curwin_size
= 0;
1763 else if (totwincount
> 1
1764 && (room
+ (totwincount
- 2))
1765 / (totwincount
- 1) > p_wiw
)
1767 /* Can make all windows wider than 'winwidth', spread
1768 * the room equally. */
1769 next_curwin_size
= (room
+ p_wiw
1770 + (totwincount
- 1) * p_wmw
1771 + (totwincount
- 1)) / totwincount
;
1772 room
-= next_curwin_size
- p_wiw
;
1775 next_curwin_size
= p_wiw
;
1779 if (has_next_curwin
)
1780 --totwincount
; /* don't count curwin */
1783 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1787 if (fr
->fr_next
== NULL
)
1788 /* last frame gets all that remains (avoid roundoff error) */
1790 else if (dir
== 'v')
1791 new_size
= fr
->fr_width
;
1792 else if (frame_fixed_width(fr
))
1794 new_size
= fr
->fr_newwidth
;
1795 wincount
= 0; /* doesn't count as a sizeable window */
1799 /* Compute the maximum number of windows horiz. in "fr". */
1800 n
= frame_minwidth(fr
, NOWIN
);
1801 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1803 m
= frame_minwidth(fr
, next_curwin
);
1804 if (has_next_curwin
)
1805 hnc
= frame_has_win(fr
, next_curwin
);
1808 if (hnc
) /* don't count next_curwin */
1810 if (totwincount
== 0)
1813 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1815 if (hnc
) /* add next_curwin size */
1817 next_curwin_size
-= p_wiw
- (m
- n
);
1818 new_size
+= next_curwin_size
;
1819 room
-= new_size
- next_curwin_size
;
1826 /* Skip frame that is full width when splitting or closing a
1827 * window, unless equalizing all frames. */
1828 if (!current
|| dir
!= 'v' || topfr
->fr_parent
!= NULL
1829 || (new_size
!= fr
->fr_width
)
1830 || frame_has_win(fr
, next_curwin
))
1831 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1835 totwincount
-= wincount
;
1839 else /* topfr->fr_layout == FR_COL */
1841 #ifdef FEAT_VERTSPLIT
1842 topfr
->fr_width
= width
;
1844 topfr
->fr_height
= height
;
1846 if (dir
!= 'h') /* equalize frame heights */
1848 /* Compute maximum number of windows vertically in this frame. */
1849 n
= frame_minheight(topfr
, NOWIN
);
1850 /* add one for the bottom window if it doesn't have a statusline */
1851 if (row
+ height
== cmdline_row
&& p_ls
== 0)
1855 totwincount
= (n
+ extra_sep
) / (p_wmh
+ 1);
1856 has_next_curwin
= frame_has_win(topfr
, next_curwin
);
1859 * Compute height for "next_curwin" window and room available for
1861 * "m" is the minimal height when counting p_wh for "next_curwin".
1863 m
= frame_minheight(topfr
, next_curwin
);
1867 /* The room is less then 'winheight', use all space for the
1868 * current window. */
1869 next_curwin_size
= p_wh
+ room
;
1874 next_curwin_size
= -1;
1875 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1877 /* If 'winfixheight' set keep the window height if
1879 * Watch out for this window being the next_curwin. */
1880 if (frame_fixed_height(fr
))
1882 n
= frame_minheight(fr
, NOWIN
);
1883 new_size
= fr
->fr_height
;
1884 if (frame_has_win(fr
, next_curwin
))
1886 room
+= p_wh
- p_wmh
;
1887 next_curwin_size
= 0;
1888 if (new_size
< p_wh
)
1892 /* These windows don't use up room. */
1893 totwincount
-= (n
+ (fr
->fr_next
== NULL
1894 ? extra_sep
: 0)) / (p_wmh
+ 1);
1895 room
-= new_size
- n
;
1901 fr
->fr_newheight
= new_size
;
1904 if (next_curwin_size
== -1)
1906 if (!has_next_curwin
)
1907 next_curwin_size
= 0;
1908 else if (totwincount
> 1
1909 && (room
+ (totwincount
- 2))
1910 / (totwincount
- 1) > p_wh
)
1912 /* can make all windows higher than 'winheight',
1913 * spread the room equally. */
1914 next_curwin_size
= (room
+ p_wh
1915 + (totwincount
- 1) * p_wmh
1916 + (totwincount
- 1)) / totwincount
;
1917 room
-= next_curwin_size
- p_wh
;
1920 next_curwin_size
= p_wh
;
1924 if (has_next_curwin
)
1925 --totwincount
; /* don't count curwin */
1928 for (fr
= topfr
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
1932 if (fr
->fr_next
== NULL
)
1933 /* last frame gets all that remains (avoid roundoff error) */
1935 else if (dir
== 'h')
1936 new_size
= fr
->fr_height
;
1937 else if (frame_fixed_height(fr
))
1939 new_size
= fr
->fr_newheight
;
1940 wincount
= 0; /* doesn't count as a sizeable window */
1944 /* Compute the maximum number of windows vert. in "fr". */
1945 n
= frame_minheight(fr
, NOWIN
);
1946 wincount
= (n
+ (fr
->fr_next
== NULL
? extra_sep
: 0))
1948 m
= frame_minheight(fr
, next_curwin
);
1949 if (has_next_curwin
)
1950 hnc
= frame_has_win(fr
, next_curwin
);
1953 if (hnc
) /* don't count next_curwin */
1955 if (totwincount
== 0)
1958 new_size
= (wincount
* room
+ ((unsigned)totwincount
>> 1))
1960 if (hnc
) /* add next_curwin size */
1962 next_curwin_size
-= p_wh
- (m
- n
);
1963 new_size
+= next_curwin_size
;
1964 room
-= new_size
- next_curwin_size
;
1970 /* Skip frame that is full width when splitting or closing a
1971 * window, unless equalizing all frames. */
1972 if (!current
|| dir
!= 'h' || topfr
->fr_parent
!= NULL
1973 || (new_size
!= fr
->fr_height
)
1974 || frame_has_win(fr
, next_curwin
))
1975 win_equal_rec(next_curwin
, current
, fr
, dir
, col
, row
,
1979 totwincount
-= wincount
;
1985 * close all windows for buffer 'buf'
1988 close_windows(buf
, keep_curwin
)
1990 int keep_curwin
; /* don't close "curwin" */
1993 tabpage_T
*tp
, *nexttp
;
1994 int h
= tabline_height();
1996 ++RedrawingDisabled
;
1998 for (wp
= firstwin
; wp
!= NULL
&& lastwin
!= firstwin
; )
2000 if (wp
->w_buffer
== buf
&& (!keep_curwin
|| wp
!= curwin
))
2002 win_close(wp
, FALSE
);
2004 /* Start all over, autocommands may change the window layout. */
2011 /* Also check windows in other tab pages. */
2012 for (tp
= first_tabpage
; tp
!= NULL
; tp
= nexttp
)
2014 nexttp
= tp
->tp_next
;
2016 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
2017 if (wp
->w_buffer
== buf
)
2019 win_close_othertab(wp
, FALSE
, tp
);
2021 /* Start all over, the tab page may be closed and
2022 * autocommands may change the window layout. */
2023 nexttp
= first_tabpage
;
2028 --RedrawingDisabled
;
2030 if (h
!= tabline_height())
2035 * Return TRUE if the current window is the only window that exists.
2036 * Returns FALSE if there is a window, possibly in another tab page.
2041 return (lastwin
== firstwin
&& first_tabpage
->tp_next
== NULL
);
2045 * Close window "win". Only works for the current tab page.
2046 * If "free_buf" is TRUE related buffer may be unloaded.
2048 * called by :quit, :close, :xit, :wq and findtag()
2051 win_close(win
, free_buf
)
2057 int other_buffer
= FALSE
;
2059 int close_curwin
= FALSE
;
2061 int help_window
= FALSE
;
2062 tabpage_T
*prev_curtab
= curtab
;
2066 EMSG(_("E444: Cannot close last window"));
2071 * When closing the last window in a tab page first go to another tab
2072 * page and then close the window and the tab page. This avoids that
2073 * curwin and curtab are not invalid while we are freeing memory, they may
2074 * be used in GUI events.
2076 if (firstwin
== lastwin
)
2078 goto_tabpage_tp(alt_tabpage());
2079 redraw_tabline
= TRUE
;
2081 /* Safety check: Autocommands may have closed the window when jumping
2082 * to the other tab page. */
2083 if (valid_tabpage(prev_curtab
) && prev_curtab
->tp_firstwin
== win
)
2085 int h
= tabline_height();
2087 win_close_othertab(win
, free_buf
, prev_curtab
);
2088 if (h
!= tabline_height())
2094 /* When closing the help window, try restoring a snapshot after closing
2095 * the window. Otherwise clear the snapshot, it's now invalid. */
2096 if (win
->w_buffer
->b_help
)
2099 clear_snapshot(curtab
);
2105 * Guess which window is going to be the new current window.
2106 * This may change because of the autocommands (sigh).
2108 wp
= frame2win(win_altframe(win
, NULL
));
2111 * Be careful: If autocommands delete the window, return now.
2113 if (wp
->w_buffer
!= curbuf
)
2115 other_buffer
= TRUE
;
2116 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2117 if (!win_valid(win
) || last_window())
2120 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
2121 if (!win_valid(win
) || last_window())
2124 /* autocmds may abort script processing */
2132 /* Avoid trouble with scrollbars that are going to be deleted in
2139 * Close the link to the buffer.
2141 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2143 /* Autocommands may have closed the window already, or closed the only
2144 * other window or moved to another tab page. */
2145 if (!win_valid(win
) || last_window() || curtab
!= prev_curtab
)
2148 /* Free the memory used for the window. */
2149 wp
= win_free_mem(win
, &dir
, NULL
);
2151 /* Make sure curwin isn't invalid. It can cause severe trouble when
2152 * printing an error message. For win_equal() curbuf needs to be valid
2157 #ifdef FEAT_QUICKFIX
2158 if (wp
->w_p_pvw
|| bt_quickfix(wp
->w_buffer
))
2161 * If the cursor goes to the preview or the quickfix window, try
2162 * finding another window to go to.
2166 if (wp
->w_next
== NULL
)
2172 if (!wp
->w_p_pvw
&& !bt_quickfix(wp
->w_buffer
))
2180 curbuf
= curwin
->w_buffer
;
2181 close_curwin
= TRUE
;
2184 #ifdef FEAT_VERTSPLIT
2185 && (*p_ead
== 'b' || *p_ead
== dir
)
2188 win_equal(curwin
, TRUE
,
2189 #ifdef FEAT_VERTSPLIT
2199 win_enter_ext(wp
, FALSE
, TRUE
);
2202 /* careful: after this wp and win may be invalid! */
2203 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
2208 * If last window has a status line now and we don't want one,
2209 * remove the status line.
2213 /* After closing the help window, try restoring the window layout from
2214 * before it was opened. */
2216 restore_snapshot(close_curwin
);
2218 #if defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)
2219 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */
2220 if (gui
.in_use
&& !win_hasvertsplit())
2221 gui_init_which_components(NULL
);
2224 redraw_all_later(NOT_VALID
);
2228 * Close window "win" in tab page "tp", which is not the current tab page.
2229 * This may be the last window ih that tab page and result in closing the tab,
2230 * thus "tp" may become invalid!
2231 * Caller must check if buffer is hidden and whether the tabline needs to be
2235 win_close_othertab(win
, free_buf
, tp
)
2242 tabpage_T
*ptp
= NULL
;
2244 /* Close the link to the buffer. */
2245 close_buffer(win
, win
->w_buffer
, free_buf
? DOBUF_UNLOAD
: 0);
2247 /* Careful: Autocommands may have closed the tab page or made it the
2248 * current tab page. */
2249 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
!= tp
; ptp
= ptp
->tp_next
)
2251 if (ptp
== NULL
|| tp
== curtab
)
2254 /* Autocommands may have closed the window already. */
2255 for (wp
= tp
->tp_firstwin
; wp
!= NULL
&& wp
!= win
; wp
= wp
->w_next
)
2260 /* Free the memory used for the window. */
2261 wp
= win_free_mem(win
, &dir
, tp
);
2263 /* When closing the last window in a tab page remove the tab page. */
2266 if (tp
== first_tabpage
)
2267 first_tabpage
= tp
->tp_next
;
2270 for (ptp
= first_tabpage
; ptp
!= NULL
&& ptp
->tp_next
!= tp
;
2275 EMSG2(_(e_intern2
), "win_close_othertab()");
2278 ptp
->tp_next
= tp
->tp_next
;
2285 * Free the memory used for a window.
2286 * Returns a pointer to the window that got the freed up space.
2289 win_free_mem(win
, dirp
, tp
)
2291 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2292 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2301 /* reduce the reference count to the argument list. */
2302 alist_unlink(win
->w_alist
);
2304 /* Remove the window and its frame from the tree of frames. */
2306 wp
= winframe_remove(win
, dirp
, tp
);
2310 /* When deleting the current window of another tab page select a new
2311 * current window. */
2312 if (tp
!= NULL
&& win
== tp
->tp_curwin
)
2318 #if defined(EXITFREE) || defined(PROTO)
2324 # ifdef FEAT_WINDOWS
2325 while (first_tabpage
->tp_next
!= NULL
)
2326 tabpage_close(TRUE
);
2329 while (firstwin
!= NULL
)
2330 (void)win_free_mem(firstwin
, &dummy
, NULL
);
2335 * Remove a window and its frame from the tree of frames.
2336 * Returns a pointer to the window that got the freed up space.
2340 winframe_remove(win
, dirp
, tp
)
2342 int *dirp
; /* set to 'v' or 'h' for direction if 'ea' */
2343 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2345 frame_T
*frp
, *frp2
, *frp3
;
2346 frame_T
*frp_close
= win
->w_frame
;
2350 * If there is only one window there is nothing to remove.
2352 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2356 * Remove the window from its frame.
2358 frp2
= win_altframe(win
, tp
);
2359 wp
= frame2win(frp2
);
2361 /* Remove this frame from the list of frames. */
2362 frame_remove(frp_close
);
2364 #ifdef FEAT_VERTSPLIT
2365 if (frp_close
->fr_parent
->fr_layout
== FR_COL
)
2368 /* When 'winfixheight' is set, try to find another frame in the column
2369 * (as close to the closed frame as possible) to distribute the height
2371 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfh
)
2373 frp
= frp_close
->fr_prev
;
2374 frp3
= frp_close
->fr_next
;
2375 while (frp
!= NULL
|| frp3
!= NULL
)
2379 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfh
)
2389 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfh
)
2395 frp3
= frp3
->fr_next
;
2399 frame_new_height(frp2
, frp2
->fr_height
+ frp_close
->fr_height
,
2400 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2401 #ifdef FEAT_VERTSPLIT
2406 /* When 'winfixwidth' is set, try to find another frame in the column
2407 * (as close to the closed frame as possible) to distribute the width
2409 if (frp2
->fr_win
!= NULL
&& frp2
->fr_win
->w_p_wfw
)
2411 frp
= frp_close
->fr_prev
;
2412 frp3
= frp_close
->fr_next
;
2413 while (frp
!= NULL
|| frp3
!= NULL
)
2417 if (frp
->fr_win
!= NULL
&& !frp
->fr_win
->w_p_wfw
)
2427 if (frp3
->fr_win
!= NULL
&& !frp3
->fr_win
->w_p_wfw
)
2433 frp3
= frp3
->fr_next
;
2437 frame_new_width(frp2
, frp2
->fr_width
+ frp_close
->fr_width
,
2438 frp2
== frp_close
->fr_next
? TRUE
: FALSE
, FALSE
);
2443 /* If rows/columns go to a window below/right its positions need to be
2444 * updated. Can only be done after the sizes have been updated. */
2445 if (frp2
== frp_close
->fr_next
)
2447 int row
= win
->w_winrow
;
2448 int col
= W_WINCOL(win
);
2450 frame_comp_pos(frp2
, &row
, &col
);
2453 if (frp2
->fr_next
== NULL
&& frp2
->fr_prev
== NULL
)
2455 /* There is no other frame in this list, move its info to the parent
2457 frp2
->fr_parent
->fr_layout
= frp2
->fr_layout
;
2458 frp2
->fr_parent
->fr_child
= frp2
->fr_child
;
2459 for (frp
= frp2
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2460 frp
->fr_parent
= frp2
->fr_parent
;
2461 frp2
->fr_parent
->fr_win
= frp2
->fr_win
;
2462 if (frp2
->fr_win
!= NULL
)
2463 frp2
->fr_win
->w_frame
= frp2
->fr_parent
;
2464 frp
= frp2
->fr_parent
;
2467 frp2
= frp
->fr_parent
;
2468 if (frp2
!= NULL
&& frp2
->fr_layout
== frp
->fr_layout
)
2470 /* The frame above the parent has the same layout, have to merge
2471 * the frames into this list. */
2472 if (frp2
->fr_child
== frp
)
2473 frp2
->fr_child
= frp
->fr_child
;
2474 frp
->fr_child
->fr_prev
= frp
->fr_prev
;
2475 if (frp
->fr_prev
!= NULL
)
2476 frp
->fr_prev
->fr_next
= frp
->fr_child
;
2477 for (frp3
= frp
->fr_child
; ; frp3
= frp3
->fr_next
)
2479 frp3
->fr_parent
= frp2
;
2480 if (frp3
->fr_next
== NULL
)
2482 frp3
->fr_next
= frp
->fr_next
;
2483 if (frp
->fr_next
!= NULL
)
2484 frp
->fr_next
->fr_prev
= frp3
;
2496 * Find out which frame is going to get the freed up space when "win" is
2498 * if 'splitbelow'/'splitleft' the space goes to the window above/left.
2499 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right.
2500 * This makes opening a window and closing it immediately keep the same window
2504 win_altframe(win
, tp
)
2506 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
2511 if (tp
== NULL
? firstwin
== lastwin
: tp
->tp_firstwin
== tp
->tp_lastwin
)
2512 /* Last window in this tab page, will go to next tab page. */
2513 return alt_tabpage()->tp_curwin
->w_frame
;
2516 #ifdef FEAT_VERTSPLIT
2517 if (frp
->fr_parent
!= NULL
&& frp
->fr_parent
->fr_layout
== FR_ROW
)
2522 if ((!b
&& frp
->fr_next
!= NULL
) || frp
->fr_prev
== NULL
)
2523 return frp
->fr_next
;
2524 return frp
->fr_prev
;
2528 * Return the tabpage that will be used if the current one is closed.
2535 /* Use the next tab page if possible. */
2536 if (curtab
->tp_next
!= NULL
)
2537 return curtab
->tp_next
;
2539 /* Find the last but one tab page. */
2540 for (tp
= first_tabpage
; tp
->tp_next
!= curtab
; tp
= tp
->tp_next
)
2546 * Find the left-upper window in frame "frp".
2552 while (frp
->fr_win
== NULL
)
2553 frp
= frp
->fr_child
;
2558 * Return TRUE if frame "frp" contains window "wp".
2561 frame_has_win(frp
, wp
)
2567 if (frp
->fr_layout
== FR_LEAF
)
2568 return frp
->fr_win
== wp
;
2570 for (p
= frp
->fr_child
; p
!= NULL
; p
= p
->fr_next
)
2571 if (frame_has_win(p
, wp
))
2577 * Set a new height for a frame. Recursively sets the height for contained
2578 * frames and windows. Caller must take care of positions.
2581 frame_new_height(topfrp
, height
, topfirst
, wfh
)
2584 int topfirst
; /* resize topmost contained frame first */
2585 int wfh
; /* obey 'winfixheight' when there is a choice;
2586 may cause the height not to be set */
2592 if (topfrp
->fr_win
!= NULL
)
2594 /* Simple case: just one window. */
2595 win_new_height(topfrp
->fr_win
,
2596 height
- topfrp
->fr_win
->w_status_height
);
2598 #ifdef FEAT_VERTSPLIT
2599 else if (topfrp
->fr_layout
== FR_ROW
)
2603 /* All frames in this row get the same new height. */
2604 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2606 frame_new_height(frp
, height
, topfirst
, wfh
);
2607 if (frp
->fr_height
> height
)
2609 /* Could not fit the windows, make the whole row higher. */
2610 height
= frp
->fr_height
;
2615 while (frp
!= NULL
);
2618 else /* fr_layout == FR_COL */
2620 /* Complicated case: Resize a column of frames. Resize the bottom
2621 * frame first, frames above that when needed. */
2623 frp
= topfrp
->fr_child
;
2625 /* Advance past frames with one window with 'wfh' set. */
2626 while (frame_fixed_height(frp
))
2630 return; /* no frame without 'wfh', give up */
2634 /* Find the bottom frame of this column */
2635 while (frp
->fr_next
!= NULL
)
2638 /* Advance back for frames with one window with 'wfh' set. */
2639 while (frame_fixed_height(frp
))
2643 extra_lines
= height
- topfrp
->fr_height
;
2644 if (extra_lines
< 0)
2646 /* reduce height of contained frames, bottom or top frame first */
2649 h
= frame_minheight(frp
, NULL
);
2650 if (frp
->fr_height
+ extra_lines
< h
)
2652 extra_lines
+= frp
->fr_height
- h
;
2653 frame_new_height(frp
, h
, topfirst
, wfh
);
2657 frame_new_height(frp
, frp
->fr_height
+ extra_lines
,
2665 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2671 while (wfh
&& frp
!= NULL
&& frame_fixed_height(frp
));
2673 /* Increase "height" if we could not reduce enough frames. */
2675 height
-= extra_lines
;
2678 else if (extra_lines
> 0)
2680 /* increase height of bottom or top frame */
2681 frame_new_height(frp
, frp
->fr_height
+ extra_lines
, topfirst
, wfh
);
2684 topfrp
->fr_height
= height
;
2688 * Return TRUE if height of frame "frp" should not be changed because of
2689 * the 'winfixheight' option.
2692 frame_fixed_height(frp
)
2695 /* frame with one window: fixed height if 'winfixheight' set. */
2696 if (frp
->fr_win
!= NULL
)
2697 return frp
->fr_win
->w_p_wfh
;
2699 if (frp
->fr_layout
== FR_ROW
)
2701 /* The frame is fixed height if one of the frames in the row is fixed
2703 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2704 if (frame_fixed_height(frp
))
2709 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the
2710 * frames in the row are fixed height. */
2711 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2712 if (!frame_fixed_height(frp
))
2717 #ifdef FEAT_VERTSPLIT
2719 * Return TRUE if width of frame "frp" should not be changed because of
2720 * the 'winfixwidth' option.
2723 frame_fixed_width(frp
)
2726 /* frame with one window: fixed width if 'winfixwidth' set. */
2727 if (frp
->fr_win
!= NULL
)
2728 return frp
->fr_win
->w_p_wfw
;
2730 if (frp
->fr_layout
== FR_COL
)
2732 /* The frame is fixed width if one of the frames in the row is fixed
2734 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2735 if (frame_fixed_width(frp
))
2740 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the
2741 * frames in the row are fixed width. */
2742 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2743 if (!frame_fixed_width(frp
))
2749 * Add a status line to windows at the bottom of "frp".
2750 * Note: Does not check if there is room!
2753 frame_add_statusline(frp
)
2758 if (frp
->fr_layout
== FR_LEAF
)
2761 if (wp
->w_status_height
== 0)
2763 if (wp
->w_height
> 0) /* don't make it negative */
2765 wp
->w_status_height
= STATUS_HEIGHT
;
2768 else if (frp
->fr_layout
== FR_ROW
)
2770 /* Handle all the frames in the row. */
2771 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2772 frame_add_statusline(frp
);
2774 else /* frp->fr_layout == FR_COL */
2776 /* Only need to handle the last frame in the column. */
2777 for (frp
= frp
->fr_child
; frp
->fr_next
!= NULL
; frp
= frp
->fr_next
)
2779 frame_add_statusline(frp
);
2784 * Set width of a frame. Handles recursively going through contained frames.
2785 * May remove separator line for windows at the right side (for win_close()).
2788 frame_new_width(topfrp
, width
, leftfirst
, wfw
)
2791 int leftfirst
; /* resize leftmost contained frame first */
2792 int wfw
; /* obey 'winfixwidth' when there is a choice;
2793 may cause the width not to be set */
2800 if (topfrp
->fr_layout
== FR_LEAF
)
2802 /* Simple case: just one window. */
2803 wp
= topfrp
->fr_win
;
2804 /* Find out if there are any windows right of this one. */
2805 for (frp
= topfrp
; frp
->fr_parent
!= NULL
; frp
= frp
->fr_parent
)
2806 if (frp
->fr_parent
->fr_layout
== FR_ROW
&& frp
->fr_next
!= NULL
)
2808 if (frp
->fr_parent
== NULL
)
2809 wp
->w_vsep_width
= 0;
2810 win_new_width(wp
, width
- wp
->w_vsep_width
);
2812 else if (topfrp
->fr_layout
== FR_COL
)
2816 /* All frames in this column get the same new width. */
2817 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2819 frame_new_width(frp
, width
, leftfirst
, wfw
);
2820 if (frp
->fr_width
> width
)
2822 /* Could not fit the windows, make whole column wider. */
2823 width
= frp
->fr_width
;
2827 } while (frp
!= NULL
);
2829 else /* fr_layout == FR_ROW */
2831 /* Complicated case: Resize a row of frames. Resize the rightmost
2832 * frame first, frames left of it when needed. */
2834 frp
= topfrp
->fr_child
;
2836 /* Advance past frames with one window with 'wfw' set. */
2837 while (frame_fixed_width(frp
))
2841 return; /* no frame without 'wfw', give up */
2845 /* Find the rightmost frame of this row */
2846 while (frp
->fr_next
!= NULL
)
2849 /* Advance back for frames with one window with 'wfw' set. */
2850 while (frame_fixed_width(frp
))
2854 extra_cols
= width
- topfrp
->fr_width
;
2857 /* reduce frame width, rightmost frame first */
2860 w
= frame_minwidth(frp
, NULL
);
2861 if (frp
->fr_width
+ extra_cols
< w
)
2863 extra_cols
+= frp
->fr_width
- w
;
2864 frame_new_width(frp
, w
, leftfirst
, wfw
);
2868 frame_new_width(frp
, frp
->fr_width
+ extra_cols
,
2876 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2882 while (wfw
&& frp
!= NULL
&& frame_fixed_width(frp
));
2884 /* Increase "width" if we could not reduce enough frames. */
2886 width
-= extra_cols
;
2889 else if (extra_cols
> 0)
2891 /* increase width of rightmost frame */
2892 frame_new_width(frp
, frp
->fr_width
+ extra_cols
, leftfirst
, wfw
);
2895 topfrp
->fr_width
= width
;
2899 * Add the vertical separator to windows at the right side of "frp".
2900 * Note: Does not check if there is room!
2908 if (frp
->fr_layout
== FR_LEAF
)
2911 if (wp
->w_vsep_width
== 0)
2913 if (wp
->w_width
> 0) /* don't make it negative */
2915 wp
->w_vsep_width
= 1;
2918 else if (frp
->fr_layout
== FR_COL
)
2920 /* Handle all the frames in the column. */
2921 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2922 frame_add_vsep(frp
);
2924 else /* frp->fr_layout == FR_ROW */
2926 /* Only need to handle the last frame in the row. */
2927 frp
= frp
->fr_child
;
2928 while (frp
->fr_next
!= NULL
)
2930 frame_add_vsep(frp
);
2935 * Set frame width from the window it contains.
2941 wp
->w_frame
->fr_width
= wp
->w_width
+ wp
->w_vsep_width
;
2946 * Set frame height from the window it contains.
2949 frame_fix_height(wp
)
2952 wp
->w_frame
->fr_height
= wp
->w_height
+ wp
->w_status_height
;
2956 * Compute the minimal height for frame "topfrp".
2957 * Uses the 'winminheight' option.
2958 * When "next_curwin" isn't NULL, use p_wh for this window.
2959 * When "next_curwin" is NOWIN, don't use at least one line for the current
2963 frame_minheight(topfrp
, next_curwin
)
2969 #ifdef FEAT_VERTSPLIT
2973 if (topfrp
->fr_win
!= NULL
)
2975 if (topfrp
->fr_win
== next_curwin
)
2976 m
= p_wh
+ topfrp
->fr_win
->w_status_height
;
2979 /* window: minimal height of the window plus status line */
2980 m
= p_wmh
+ topfrp
->fr_win
->w_status_height
;
2981 /* Current window is minimal one line high */
2982 if (p_wmh
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
2986 #ifdef FEAT_VERTSPLIT
2987 else if (topfrp
->fr_layout
== FR_ROW
)
2989 /* get the minimal height from each frame in this row */
2991 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
2993 n
= frame_minheight(frp
, next_curwin
);
3001 /* Add up the minimal heights for all frames in this column. */
3003 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3004 m
+= frame_minheight(frp
, next_curwin
);
3010 #ifdef FEAT_VERTSPLIT
3012 * Compute the minimal width for frame "topfrp".
3013 * When "next_curwin" isn't NULL, use p_wiw for this window.
3014 * When "next_curwin" is NOWIN, don't use at least one column for the current
3018 frame_minwidth(topfrp
, next_curwin
)
3020 win_T
*next_curwin
; /* use p_wh and p_wiw for next_curwin */
3025 if (topfrp
->fr_win
!= NULL
)
3027 if (topfrp
->fr_win
== next_curwin
)
3028 m
= p_wiw
+ topfrp
->fr_win
->w_vsep_width
;
3031 /* window: minimal width of the window plus separator column */
3032 m
= p_wmw
+ topfrp
->fr_win
->w_vsep_width
;
3033 /* Current window is minimal one column wide */
3034 if (p_wmw
== 0 && topfrp
->fr_win
== curwin
&& next_curwin
== NULL
)
3038 else if (topfrp
->fr_layout
== FR_COL
)
3040 /* get the minimal width from each frame in this column */
3042 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3044 n
= frame_minwidth(frp
, next_curwin
);
3051 /* Add up the minimal widths for all frames in this row. */
3053 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
3054 m
+= frame_minwidth(frp
, next_curwin
);
3063 * Try to close all windows except current one.
3064 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
3065 * used and the buffer was modified.
3067 * Used by ":bdel" and ":only".
3070 close_others(message
, forceit
)
3072 int forceit
; /* always hide all other windows */
3078 if (lastwin
== firstwin
)
3089 /* Be very careful here: autocommands may change the window layout. */
3090 for (wp
= firstwin
; win_valid(wp
); wp
= nextwp
)
3092 nextwp
= wp
->w_next
;
3093 if (wp
!= curwin
) /* don't close current window */
3096 /* Check if it's allowed to abandon this window */
3097 r
= can_abandon(wp
->w_buffer
, forceit
);
3099 if (!win_valid(wp
)) /* autocommands messed wp up */
3107 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3108 if (message
&& (p_confirm
|| cmdmod
.confirm
) && p_write
)
3110 dialog_changed(wp
->w_buffer
, FALSE
);
3111 # ifdef FEAT_AUTOCMD
3112 if (!win_valid(wp
)) /* autocommands messed wp up */
3119 if (bufIsChanged(wp
->w_buffer
))
3123 win_close(wp
, !P_HID(wp
->w_buffer
) && !bufIsChanged(wp
->w_buffer
));
3127 if (message
&& lastwin
!= firstwin
)
3128 EMSG(_("E445: Other window contains changes"));
3131 #endif /* FEAT_WINDOWS */
3134 * Init the current window "curwin".
3135 * Called when a new file is being edited.
3140 redraw_win_later(curwin
, NOT_VALID
);
3141 curwin
->w_lines_valid
= 0;
3142 curwin
->w_cursor
.lnum
= 1;
3143 curwin
->w_curswant
= curwin
->w_cursor
.col
= 0;
3144 #ifdef FEAT_VIRTUALEDIT
3145 curwin
->w_cursor
.coladd
= 0;
3147 curwin
->w_pcmark
.lnum
= 1; /* pcmark not cleared but set to line 1 */
3148 curwin
->w_pcmark
.col
= 0;
3149 curwin
->w_prev_pcmark
.lnum
= 0;
3150 curwin
->w_prev_pcmark
.col
= 0;
3151 curwin
->w_topline
= 1;
3153 curwin
->w_topfill
= 0;
3155 curwin
->w_botline
= 2;
3158 curwin
->w_farsi
= W_CONV
+ W_R_L
;
3160 curwin
->w_farsi
= W_CONV
;
3165 * Allocate the first window and put an empty buffer in it.
3166 * Called from main().
3167 * Return FAIL when something goes wrong (out of memory).
3172 if (win_alloc_firstwin(NULL
) == FAIL
)
3176 first_tabpage
= alloc_tabpage();
3177 if (first_tabpage
== NULL
)
3179 first_tabpage
->tp_topframe
= topframe
;
3180 curtab
= first_tabpage
;
3186 * Allocate the first window or the first window in a new tab page.
3187 * When "oldwin" is NULL create an empty buffer for it.
3188 * When "oldwin" is not NULL copy info from it to the new window (only with
3190 * Return FAIL when something goes wrong (out of memory).
3193 win_alloc_firstwin(oldwin
)
3196 curwin
= win_alloc(NULL
);
3199 /* Very first window, need to create an empty buffer for it and
3200 * initialize from scratch. */
3201 curbuf
= buflist_new(NULL
, NULL
, 1L, BLN_LISTED
);
3202 if (curwin
== NULL
|| curbuf
== NULL
)
3204 curwin
->w_buffer
= curbuf
;
3205 curbuf
->b_nwindows
= 1; /* there is one window */
3207 curwin
->w_alist
= &global_alist
;
3209 curwin_init(); /* init current window */
3214 /* First window in new tab page, initialize it from "oldwin". */
3215 win_init(curwin
, oldwin
);
3217 # ifdef FEAT_SCROLLBIND
3218 /* We don't want scroll-binding in the first window. */
3219 curwin
->w_p_scb
= FALSE
;
3224 topframe
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
3225 if (topframe
== NULL
)
3227 topframe
->fr_layout
= FR_LEAF
;
3228 #ifdef FEAT_VERTSPLIT
3229 topframe
->fr_width
= Columns
;
3231 topframe
->fr_height
= Rows
- p_ch
;
3232 topframe
->fr_win
= curwin
;
3233 curwin
->w_frame
= topframe
;
3239 * Initialize the window and frame size to the maximum.
3244 firstwin
->w_height
= ROWS_AVAIL
;
3245 topframe
->fr_height
= ROWS_AVAIL
;
3246 #ifdef FEAT_VERTSPLIT
3247 firstwin
->w_width
= Columns
;
3248 topframe
->fr_width
= Columns
;
3252 #if defined(FEAT_WINDOWS) || defined(PROTO)
3255 * Allocate a new tabpage_T and init the values.
3256 * Returns NULL when out of memory.
3263 tp
= (tabpage_T
*)alloc_clear((unsigned)sizeof(tabpage_T
));
3269 for (i
= 0; i
< 3; i
++)
3270 tp
->tp_prev_which_scrollbars
[i
] = -1;
3273 tp
->tp_diff_invalid
= TRUE
;
3276 /* init t: variables */
3277 init_var_dict(&tp
->tp_vars
, &tp
->tp_winvar
);
3279 tp
->tp_ch_used
= p_ch
;
3293 vars_clear(&tp
->tp_vars
.dv_hashtab
); /* free all t: variables */
3299 * Create a new Tab page with one window.
3300 * It will edit the current buffer, like after ":split".
3301 * When "after" is 0 put it just after the current Tab page.
3302 * Otherwise put it just before tab page "after".
3303 * Return FAIL or OK.
3306 win_new_tabpage(after
)
3309 tabpage_T
*tp
= curtab
;
3313 newtp
= alloc_tabpage();
3317 /* Remember the current windows in this Tab page. */
3318 if (leave_tabpage(curbuf
) == FAIL
)
3325 /* Create a new empty window. */
3326 if (win_alloc_firstwin(tp
->tp_curwin
) == OK
)
3328 /* Make the new Tab page the new topframe. */
3331 /* New tab page becomes the first one. */
3332 newtp
->tp_next
= first_tabpage
;
3333 first_tabpage
= newtp
;
3339 /* Put new tab page before tab page "after". */
3341 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
3342 && n
< after
; tp
= tp
->tp_next
)
3345 newtp
->tp_next
= tp
->tp_next
;
3346 tp
->tp_next
= newtp
;
3349 firstwin
->w_winrow
= tabline_height();
3350 win_comp_scroll(curwin
);
3352 newtp
->tp_topframe
= topframe
;
3355 #if defined(FEAT_GUI)
3356 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3357 * scrollbars. Have to update them anyway. */
3358 if (gui
.in_use
&& starting
== 0)
3360 gui_init_which_components(NULL
);
3361 gui_update_scrollbars(TRUE
);
3363 need_mouse_correct
= TRUE
;
3366 redraw_all_later(CLEAR
);
3368 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3369 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
3374 /* Failed, get back the previous Tab page */
3375 enter_tabpage(curtab
, curbuf
);
3380 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer,
3381 * like with ":split".
3382 * Returns OK if a new tab page was created, FAIL otherwise.
3387 int n
= (cmdmod
.tab
== 0) ? postponed_split_tab
: cmdmod
.tab
;
3391 cmdmod
.tab
= 0; /* reset it to avoid doing it twice */
3392 postponed_split_tab
= 0;
3393 return win_new_tabpage(n
);
3399 * Create up to "maxcount" tabpages with empty windows.
3400 * Returns the number of resulting tab pages.
3403 make_tabpages(maxcount
)
3406 int count
= maxcount
;
3409 /* Limit to 'tabpagemax' tabs. */
3415 * Don't execute autocommands while creating the tab pages. Must do that
3416 * when putting the buffers in the windows.
3421 for (todo
= count
- 1; todo
> 0; --todo
)
3422 if (win_new_tabpage(0) == FAIL
)
3429 /* return actual number of tab pages */
3430 return (count
- todo
);
3434 * Return TRUE when "tpc" points to a valid tab page.
3442 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3449 * Find tab page "n" (first one is 1). Returns NULL when not found.
3458 for (tp
= first_tabpage
; tp
!= NULL
&& i
!= n
; tp
= tp
->tp_next
)
3464 * Get index of tab page "tp". First one has index 1.
3465 * When not found returns number of tab pages plus one.
3474 for (tp
= first_tabpage
; tp
!= NULL
&& tp
!= ftp
; tp
= tp
->tp_next
)
3480 * Prepare for leaving the current tab page.
3481 * When autocomands change "curtab" we don't leave the tab page and return
3483 * Careful: When OK is returned need to get a new tab page very very soon!
3487 leave_tabpage(new_curbuf
)
3488 buf_T
*new_curbuf
; /* what is going to be the new curbuf,
3491 tabpage_T
*tp
= curtab
;
3494 reset_VIsual_and_resel(); /* stop Visual mode */
3497 if (new_curbuf
!= curbuf
)
3499 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3503 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3506 apply_autocmds(EVENT_TABLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3510 #if defined(FEAT_GUI)
3511 /* Remove the scrollbars. They may be added back later. */
3513 gui_remove_scrollbars();
3515 tp
->tp_curwin
= curwin
;
3516 tp
->tp_prevwin
= prevwin
;
3517 tp
->tp_firstwin
= firstwin
;
3518 tp
->tp_lastwin
= lastwin
;
3519 tp
->tp_old_Rows
= Rows
;
3520 tp
->tp_old_Columns
= Columns
;
3527 * Start using tab page "tp".
3528 * Only to be used after leave_tabpage() or freeing the current tab page.
3532 enter_tabpage(tp
, old_curbuf
)
3536 int old_off
= tp
->tp_firstwin
->w_winrow
;
3537 win_T
*next_prevwin
= tp
->tp_prevwin
;
3540 firstwin
= tp
->tp_firstwin
;
3541 lastwin
= tp
->tp_lastwin
;
3542 topframe
= tp
->tp_topframe
;
3544 /* We would like doing the TabEnter event first, but we don't have a
3545 * valid current window yet, which may break some commands.
3546 * This triggers autocommands, thus may make "tp" invalid. */
3547 win_enter_ext(tp
->tp_curwin
, FALSE
, TRUE
);
3548 prevwin
= next_prevwin
;
3551 apply_autocmds(EVENT_TABENTER
, NULL
, NULL
, FALSE
, curbuf
);
3553 if (old_curbuf
!= curbuf
)
3554 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
3557 last_status(FALSE
); /* status line may appear or disappear */
3558 (void)win_comp_pos(); /* recompute w_winrow for all windows */
3559 must_redraw
= CLEAR
; /* need to redraw everything */
3561 diff_need_scrollbind
= TRUE
;
3564 /* The tabpage line may have appeared or disappeared, may need to resize
3565 * the frames for that. When the Vim window was resized need to update
3566 * frame sizes too. Use the stored value of p_ch, so that it can be
3567 * different for each tab page. */
3568 p_ch
= curtab
->tp_ch_used
;
3569 if (curtab
->tp_old_Rows
!= Rows
|| (old_off
!= firstwin
->w_winrow
3570 #ifdef FEAT_GUI_TABLINE
3571 && !gui_use_tabline()
3575 #ifdef FEAT_VERTSPLIT
3576 if (curtab
->tp_old_Columns
!= Columns
&& starting
== 0)
3577 shell_new_columns(); /* update window widths */
3580 #if defined(FEAT_GUI)
3581 /* When 'guioptions' includes 'L' or 'R' may have to remove or add
3582 * scrollbars. Have to update them anyway. */
3583 if (gui
.in_use
&& starting
== 0)
3585 gui_init_which_components(NULL
);
3586 gui_update_scrollbars(TRUE
);
3588 need_mouse_correct
= TRUE
;
3591 redraw_all_later(CLEAR
);
3595 * Go to tab page "n". For ":tab N" and "Ngt".
3596 * When "n" is 9999 go to the last tab page.
3608 /* Not allowed when editing the command line. */
3610 if (cmdwin_type
!= 0)
3618 /* If there is only one it can't work. */
3619 if (first_tabpage
->tp_next
== NULL
)
3628 /* No count, go to next tab page, wrap around end. */
3629 if (curtab
->tp_next
== NULL
)
3632 tp
= curtab
->tp_next
;
3636 /* "gT": go to previous tab page, wrap around end. "N gT" repeats
3639 for (i
= n
; i
< 0; ++i
)
3641 for (tp
= first_tabpage
; tp
->tp_next
!= ttp
&& tp
->tp_next
!= NULL
;
3649 /* Go to last tab page. */
3650 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
; tp
= tp
->tp_next
)
3655 /* Go to tab page "n". */
3656 tp
= find_tabpage(n
);
3664 goto_tabpage_tp(tp
);
3666 #ifdef FEAT_GUI_TABLINE
3667 if (gui_use_tabline())
3668 gui_mch_set_curtab(tabpage_index(curtab
));
3673 * Go to tabpage "tp".
3674 * Note: doesn't update the GUI tab.
3680 if (tp
!= curtab
&& leave_tabpage(tp
->tp_curwin
->w_buffer
) == OK
)
3682 if (valid_tabpage(tp
))
3683 enter_tabpage(tp
, curbuf
);
3685 enter_tabpage(curtab
, curbuf
);
3690 * Enter window "wp" in tab page "tp".
3691 * Also updates the GUI tab.
3694 goto_tabpage_win(tp
, wp
)
3698 goto_tabpage_tp(tp
);
3699 if (curtab
== tp
&& win_valid(wp
))
3701 win_enter(wp
, TRUE
);
3702 # ifdef FEAT_GUI_TABLINE
3703 if (gui_use_tabline())
3704 gui_mch_set_curtab(tabpage_index(curtab
));
3710 * Move the current tab page to before tab page "nr".
3719 if (first_tabpage
->tp_next
== NULL
)
3722 /* Remove the current tab page from the list of tab pages. */
3723 if (curtab
== first_tabpage
)
3724 first_tabpage
= curtab
->tp_next
;
3727 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
3728 if (tp
->tp_next
== curtab
)
3730 if (tp
== NULL
) /* "cannot happen" */
3732 tp
->tp_next
= curtab
->tp_next
;
3735 /* Re-insert it at the specified position. */
3738 curtab
->tp_next
= first_tabpage
;
3739 first_tabpage
= curtab
;
3743 for (tp
= first_tabpage
; tp
->tp_next
!= NULL
&& n
> 1; tp
= tp
->tp_next
)
3745 curtab
->tp_next
= tp
->tp_next
;
3746 tp
->tp_next
= curtab
;
3749 /* Need to redraw the tabline. Tab page contents doesn't change. */
3750 redraw_tabline
= TRUE
;
3755 * Go to another window.
3756 * When jumping to another buffer, stop Visual mode. Do this before
3757 * changing windows so we can yank the selection into the '*' register.
3758 * When jumping to another window on the same buffer, adjust its cursor
3759 * position to keep the same Visual area.
3772 if (curbuf_locked())
3777 if (wp
->w_buffer
!= curbuf
)
3778 reset_VIsual_and_resel();
3779 else if (VIsual_active
)
3780 wp
->w_cursor
= curwin
->w_cursor
;
3784 need_mouse_correct
= TRUE
;
3786 win_enter(wp
, TRUE
);
3789 #if defined(FEAT_PERL) || defined(PROTO)
3791 * Find window number "winnr" (counting top to bottom).
3799 # ifdef FEAT_WINDOWS
3800 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3810 #ifdef FEAT_VERTSPLIT
3812 * Move to window above or below "count" times.
3815 win_goto_ver(up
, count
)
3816 int up
; /* TRUE to go to win above */
3823 foundfr
= curwin
->w_frame
;
3827 * First go upwards in the tree of frames until we find a upwards or
3828 * downwards neighbor.
3839 if (fr
->fr_parent
->fr_layout
== FR_COL
&& nfr
!= NULL
)
3845 * Now go downwards to find the bottom or top frame in it.
3849 if (nfr
->fr_layout
== FR_LEAF
)
3855 if (nfr
->fr_layout
== FR_ROW
)
3857 /* Find the frame at the cursor row. */
3858 while (fr
->fr_next
!= NULL
3859 && frame2win(fr
)->w_wincol
+ fr
->fr_width
3860 <= curwin
->w_wincol
+ curwin
->w_wcol
)
3863 if (nfr
->fr_layout
== FR_COL
&& up
)
3864 while (fr
->fr_next
!= NULL
)
3870 if (foundfr
!= NULL
)
3871 win_goto(foundfr
->fr_win
);
3875 * Move to left or right window.
3878 win_goto_hor(left
, count
)
3879 int left
; /* TRUE to go to left win */
3886 foundfr
= curwin
->w_frame
;
3890 * First go upwards in the tree of frames until we find a left or
3902 if (fr
->fr_parent
->fr_layout
== FR_ROW
&& nfr
!= NULL
)
3908 * Now go downwards to find the leftmost or rightmost frame in it.
3912 if (nfr
->fr_layout
== FR_LEAF
)
3918 if (nfr
->fr_layout
== FR_COL
)
3920 /* Find the frame at the cursor row. */
3921 while (fr
->fr_next
!= NULL
3922 && frame2win(fr
)->w_winrow
+ fr
->fr_height
3923 <= curwin
->w_winrow
+ curwin
->w_wrow
)
3926 if (nfr
->fr_layout
== FR_ROW
&& left
)
3927 while (fr
->fr_next
!= NULL
)
3933 if (foundfr
!= NULL
)
3934 win_goto(foundfr
->fr_win
);
3939 * Make window "wp" the current window.
3942 win_enter(wp
, undo_sync
)
3946 win_enter_ext(wp
, undo_sync
, FALSE
);
3950 * Make window wp the current window.
3951 * Can be called with "curwin_invalid" TRUE, which means that curwin has just
3952 * been closed and isn't valid.
3955 win_enter_ext(wp
, undo_sync
, curwin_invalid
)
3961 int other_buffer
= FALSE
;
3964 if (wp
== curwin
&& !curwin_invalid
) /* nothing to do */
3968 if (!curwin_invalid
)
3971 * Be careful: If autocommands delete the window, return now.
3973 if (wp
->w_buffer
!= curbuf
)
3975 apply_autocmds(EVENT_BUFLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3976 other_buffer
= TRUE
;
3980 apply_autocmds(EVENT_WINLEAVE
, NULL
, NULL
, FALSE
, curbuf
);
3984 /* autocmds may abort script processing */
3991 /* sync undo before leaving the current buffer */
3992 if (undo_sync
&& curbuf
!= wp
->w_buffer
)
3994 /* may have to copy the buffer options when 'cpo' contains 'S' */
3995 if (wp
->w_buffer
!= curbuf
)
3996 buf_copy_options(wp
->w_buffer
, BCO_ENTER
| BCO_NOHELP
);
3997 if (!curwin_invalid
)
3999 prevwin
= curwin
; /* remember for CTRL-W p */
4000 curwin
->w_redr_status
= TRUE
;
4003 curbuf
= wp
->w_buffer
;
4005 #ifdef FEAT_VIRTUALEDIT
4006 if (!virtual_active())
4007 curwin
->w_cursor
.coladd
= 0;
4009 changed_line_abv_curs(); /* assume cursor position needs updating */
4011 if (curwin
->w_localdir
!= NULL
)
4013 /* Window has a local directory: Save current directory as global
4014 * directory (unless that was done already) and change to the local
4016 if (globaldir
== NULL
)
4018 char_u cwd
[MAXPATHL
];
4020 if (mch_dirname(cwd
, MAXPATHL
) == OK
)
4021 globaldir
= vim_strsave(cwd
);
4023 mch_chdir((char *)curwin
->w_localdir
);
4024 shorten_fnames(TRUE
);
4026 else if (globaldir
!= NULL
)
4028 /* Window doesn't have a local directory and we are not in the global
4029 * directory: Change to the global directory. */
4030 mch_chdir((char *)globaldir
);
4031 vim_free(globaldir
);
4033 shorten_fnames(TRUE
);
4037 apply_autocmds(EVENT_WINENTER
, NULL
, NULL
, FALSE
, curbuf
);
4039 apply_autocmds(EVENT_BUFENTER
, NULL
, NULL
, FALSE
, curbuf
);
4045 curwin
->w_redr_status
= TRUE
;
4046 redraw_tabline
= TRUE
;
4048 redraw_later(VALID
); /* causes status line redraw */
4050 /* set window height to desired minimal value */
4051 if (curwin
->w_height
< p_wh
&& !curwin
->w_p_wfh
)
4052 win_setheight((int)p_wh
);
4053 else if (curwin
->w_height
== 0)
4056 #ifdef FEAT_VERTSPLIT
4057 /* set window width to desired minimal value */
4058 if (curwin
->w_width
< p_wiw
&& !curwin
->w_p_wfw
)
4059 win_setwidth((int)p_wiw
);
4063 setmouse(); /* in case jumped to/from help buffer */
4066 /* Change directories when the 'acd' option is set. */
4070 #endif /* FEAT_WINDOWS */
4072 #if defined(FEAT_WINDOWS) || defined(FEAT_SIGNS) || defined(PROTO)
4074 * Jump to the first open window that contains buffer "buf", if one exists.
4075 * Returns a pointer to the window found, otherwise NULL.
4078 buf_jump_open_win(buf
)
4081 # ifdef FEAT_WINDOWS
4084 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4085 if (wp
->w_buffer
== buf
)
4088 win_enter(wp
, FALSE
);
4091 if (curwin
->w_buffer
== buf
)
4098 * Jump to the first open window in any tab page that contains buffer "buf",
4100 * Returns a pointer to the window found, otherwise NULL.
4103 buf_jump_open_tab(buf
)
4106 # ifdef FEAT_WINDOWS
4110 /* First try the current tab page. */
4111 wp
= buf_jump_open_win(buf
);
4115 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
4118 for (wp
= tp
->tp_firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4119 if (wp
->w_buffer
== buf
)
4123 goto_tabpage_win(tp
, wp
);
4125 wp
= NULL
; /* something went wrong */
4132 if (curwin
->w_buffer
== buf
)
4140 * allocate a window structure and link it in the window list
4150 * allocate window structure and linesizes arrays
4152 newwin
= (win_T
*)alloc_clear((unsigned)sizeof(win_T
));
4153 if (newwin
!= NULL
&& win_alloc_lines(newwin
) == FAIL
)
4162 /* Don't execute autocommands while the window is not properly
4163 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4168 * link the window in the window list
4171 win_append(after
, newwin
);
4173 #ifdef FEAT_VERTSPLIT
4174 newwin
->w_wincol
= 0;
4175 newwin
->w_width
= Columns
;
4178 /* position the display and the cursor at the top of the file. */
4179 newwin
->w_topline
= 1;
4181 newwin
->w_topfill
= 0;
4183 newwin
->w_botline
= 2;
4184 newwin
->w_cursor
.lnum
= 1;
4185 #ifdef FEAT_SCROLLBIND
4186 newwin
->w_scbind_pos
= 1;
4189 /* We won't calculate w_fraction until resizing the window */
4190 newwin
->w_fraction
= 0;
4191 newwin
->w_prev_fraction_row
= -1;
4196 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_LEFT
],
4198 gui_create_scrollbar(&newwin
->w_scrollbars
[SBAR_RIGHT
],
4199 SBAR_RIGHT
, newwin
);
4203 /* init w: variables */
4204 init_var_dict(&newwin
->w_vars
, &newwin
->w_winvar
);
4207 foldInitWin(newwin
);
4212 #ifdef FEAT_SEARCH_EXTRA
4213 newwin
->w_match_head
= NULL
;
4214 newwin
->w_next_match_id
= 4;
4220 #if defined(FEAT_WINDOWS) || defined(PROTO)
4223 * remove window 'wp' from the window list and free the structure
4228 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4233 /* Don't execute autocommands while the window is halfway being deleted.
4234 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
4238 #ifdef FEAT_MZSCHEME
4239 mzscheme_window_free(wp
);
4247 python_window_free(wp
);
4251 tcl_window_free(wp
);
4255 ruby_window_free(wp
);
4258 clear_winopt(&wp
->w_onebuf_opt
);
4259 clear_winopt(&wp
->w_allbuf_opt
);
4262 vars_clear(&wp
->w_vars
.dv_hashtab
); /* free all w: variables */
4269 for (i
= 0; i
< wp
->w_tagstacklen
; ++i
)
4270 vim_free(wp
->w_tagstack
[i
].tagname
);
4272 vim_free(wp
->w_localdir
);
4274 #ifdef FEAT_SEARCH_EXTRA
4278 #ifdef FEAT_JUMPLIST
4282 #ifdef FEAT_QUICKFIX
4289 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
]);
4290 gui_mch_destroy_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
]);
4292 #endif /* FEAT_GUI */
4303 * Append window "wp" in the window list after window "after".
4306 win_append(after
, wp
)
4311 if (after
== NULL
) /* after NULL is in front of the first */
4314 before
= after
->w_next
;
4316 wp
->w_next
= before
;
4325 before
->w_prev
= wp
;
4329 * Remove a window from the window list.
4334 tabpage_T
*tp
; /* tab page "win" is in, NULL for current */
4336 if (wp
->w_prev
!= NULL
)
4337 wp
->w_prev
->w_next
= wp
->w_next
;
4338 else if (tp
== NULL
)
4339 firstwin
= wp
->w_next
;
4341 tp
->tp_firstwin
= wp
->w_next
;
4342 if (wp
->w_next
!= NULL
)
4343 wp
->w_next
->w_prev
= wp
->w_prev
;
4344 else if (tp
== NULL
)
4345 lastwin
= wp
->w_prev
;
4347 tp
->tp_lastwin
= wp
->w_prev
;
4351 * Append frame "frp" in a frame list after frame "after".
4354 frame_append(after
, frp
)
4355 frame_T
*after
, *frp
;
4357 frp
->fr_next
= after
->fr_next
;
4358 after
->fr_next
= frp
;
4359 if (frp
->fr_next
!= NULL
)
4360 frp
->fr_next
->fr_prev
= frp
;
4361 frp
->fr_prev
= after
;
4365 * Insert frame "frp" in a frame list before frame "before".
4368 frame_insert(before
, frp
)
4369 frame_T
*before
, *frp
;
4371 frp
->fr_next
= before
;
4372 frp
->fr_prev
= before
->fr_prev
;
4373 before
->fr_prev
= frp
;
4374 if (frp
->fr_prev
!= NULL
)
4375 frp
->fr_prev
->fr_next
= frp
;
4377 frp
->fr_parent
->fr_child
= frp
;
4381 * Remove a frame from a frame list.
4387 if (frp
->fr_prev
!= NULL
)
4388 frp
->fr_prev
->fr_next
= frp
->fr_next
;
4390 frp
->fr_parent
->fr_child
= frp
->fr_next
;
4391 if (frp
->fr_next
!= NULL
)
4392 frp
->fr_next
->fr_prev
= frp
->fr_prev
;
4395 #endif /* FEAT_WINDOWS */
4398 * Allocate w_lines[] for window "wp".
4399 * Return FAIL for failure, OK for success.
4405 wp
->w_lines_valid
= 0;
4406 wp
->w_lines
= (wline_T
*)alloc_clear((unsigned)(Rows
* sizeof(wline_T
)));
4407 if (wp
->w_lines
== NULL
)
4413 * free lsize arrays for a window
4419 vim_free(wp
->w_lines
);
4424 * Called from win_new_shellsize() after Rows changed.
4425 * This only does the current tab page, others must be done when made active.
4430 int h
= (int)ROWS_AVAIL
;
4432 if (firstwin
== NULL
) /* not initialized yet */
4435 if (h
< frame_minheight(topframe
, NULL
))
4436 h
= frame_minheight(topframe
, NULL
);
4438 /* First try setting the heights of windows with 'winfixheight'. If
4439 * that doesn't result in the right height, forget about that option. */
4440 frame_new_height(topframe
, h
, FALSE
, TRUE
);
4441 if (topframe
->fr_height
!= h
)
4442 frame_new_height(topframe
, h
, FALSE
, FALSE
);
4444 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4448 win_new_height(firstwin
, h
);
4452 curtab
->tp_ch_used
= p_ch
;
4456 /* Disabled: don't want making the screen smaller make a window larger. */
4458 win_equal(curwin
, FALSE
, 'v');
4462 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4464 * Called from win_new_shellsize() after Columns changed.
4469 if (firstwin
== NULL
) /* not initialized yet */
4472 /* First try setting the widths of windows with 'winfixwidth'. If that
4473 * doesn't result in the right width, forget about that option. */
4474 frame_new_width(topframe
, (int)Columns
, FALSE
, TRUE
);
4475 if (topframe
->fr_width
!= Columns
)
4476 frame_new_width(topframe
, (int)Columns
, FALSE
, FALSE
);
4478 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */
4480 /* Disabled: don't want making the screen smaller make a window larger. */
4482 win_equal(curwin
, FALSE
, 'h');
4487 #if defined(FEAT_CMDWIN) || defined(PROTO)
4489 * Save the size of all windows in "gap".
4498 ga_init2(gap
, (int)sizeof(int), 1);
4499 if (ga_grow(gap
, win_count() * 2) == OK
)
4500 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4502 ((int *)gap
->ga_data
)[gap
->ga_len
++] =
4503 wp
->w_width
+ wp
->w_vsep_width
;
4504 ((int *)gap
->ga_data
)[gap
->ga_len
++] = wp
->w_height
;
4509 * Restore window sizes, but only if the number of windows is still the same.
4510 * Does not free the growarray.
4513 win_size_restore(gap
)
4519 if (win_count() * 2 == gap
->ga_len
)
4522 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
4524 frame_setwidth(wp
->w_frame
, ((int *)gap
->ga_data
)[i
++]);
4525 win_setheight_win(((int *)gap
->ga_data
)[i
++], wp
);
4527 /* recompute the window positions */
4528 (void)win_comp_pos();
4531 #endif /* FEAT_CMDWIN */
4533 #if defined(FEAT_WINDOWS) || defined(PROTO)
4535 * Update the position for all windows, using the width and height of the
4537 * Returns the row just after the last window.
4542 int row
= tabline_height();
4545 frame_comp_pos(topframe
, &row
, &col
);
4550 * Update the position of the windows in frame "topfrp", using the width and
4551 * height of the frames.
4552 * "*row" and "*col" are the top-left position of the frame. They are updated
4553 * to the bottom-right position plus one.
4556 frame_comp_pos(topfrp
, row
, col
)
4563 #ifdef FEAT_VERTSPLIT
4568 wp
= topfrp
->fr_win
;
4571 if (wp
->w_winrow
!= *row
4572 #ifdef FEAT_VERTSPLIT
4573 || wp
->w_wincol
!= *col
4577 /* position changed, redraw */
4578 wp
->w_winrow
= *row
;
4579 #ifdef FEAT_VERTSPLIT
4580 wp
->w_wincol
= *col
;
4582 redraw_win_later(wp
, NOT_VALID
);
4583 wp
->w_redr_status
= TRUE
;
4585 *row
+= wp
->w_height
+ wp
->w_status_height
;
4586 #ifdef FEAT_VERTSPLIT
4587 *col
+= wp
->w_width
+ wp
->w_vsep_width
;
4592 #ifdef FEAT_VERTSPLIT
4596 for (frp
= topfrp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
4598 #ifdef FEAT_VERTSPLIT
4599 if (topfrp
->fr_layout
== FR_ROW
)
4600 *row
= startrow
; /* all frames are at the same row */
4602 *col
= startcol
; /* all frames are at the same col */
4604 frame_comp_pos(frp
, row
, col
);
4609 #endif /* FEAT_WINDOWS */
4612 * Set current window height and take care of repositioning other windows to
4616 win_setheight(height
)
4619 win_setheight_win(height
, curwin
);
4623 * Set the window height of window "win" and take care of repositioning other
4624 * windows to fit around it.
4627 win_setheight_win(height
, win
)
4635 /* Always keep current window at least one line high, even when
4636 * 'winminheight' is zero. */
4646 frame_setheight(win
->w_frame
, height
+ win
->w_status_height
);
4648 /* recompute the window positions */
4649 row
= win_comp_pos();
4651 if (height
> topframe
->fr_height
)
4652 height
= topframe
->fr_height
;
4653 win
->w_height
= height
;
4658 * If there is extra space created between the last window and the command
4661 if (full_screen
&& msg_scrolled
== 0 && row
< cmdline_row
)
4662 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
4667 redraw_all_later(NOT_VALID
);
4670 #if defined(FEAT_WINDOWS) || defined(PROTO)
4673 * Set the height of a frame to "height" and take care that all frames and
4674 * windows inside it are resized. Also resize frames on the left and right if
4675 * the are in the same FR_ROW frame.
4678 * If the frame is part of a FR_COL frame, try fitting the frame in that
4679 * frame. If that doesn't work (the FR_COL frame is too small), recursively
4680 * go to containing frames to resize them and make room.
4681 * If the frame is part of a FR_ROW frame, all frames must be resized as well.
4682 * Check for the minimal height of the FR_ROW frame.
4683 * At the top level we can also use change the command line height.
4686 frame_setheight(curfrp
, height
)
4690 int room
; /* total number of lines available */
4691 int take
; /* number of lines taken from other windows */
4692 int room_cmdline
; /* lines available from cmdline */
4698 /* If the height already is the desired value, nothing to do. */
4699 if (curfrp
->fr_height
== height
)
4702 if (curfrp
->fr_parent
== NULL
)
4704 /* topframe: can only change the command line */
4705 if (height
> ROWS_AVAIL
)
4706 height
= ROWS_AVAIL
;
4708 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4710 else if (curfrp
->fr_parent
->fr_layout
== FR_ROW
)
4712 /* Row of frames: Also need to resize frames left and right of this
4713 * one. First check for the minimal height of these. */
4714 h
= frame_minheight(curfrp
->fr_parent
, NULL
);
4717 frame_setheight(curfrp
->fr_parent
, height
);
4722 * Column of frames: try to change only frames in this column.
4724 #ifdef FEAT_VERTSPLIT
4727 * 1: compute room available, if it's not enough try resizing the
4729 * 2: compute the room available and adjust the height to it.
4730 * Try not to reduce the height of a window with 'winfixheight' set.
4732 for (run
= 1; run
<= 2; ++run
)
4739 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4743 && frp
->fr_win
!= NULL
4744 && frp
->fr_win
->w_p_wfh
)
4745 room_reserved
+= frp
->fr_height
;
4746 room
+= frp
->fr_height
;
4748 room
-= frame_minheight(frp
, NULL
);
4750 #ifdef FEAT_VERTSPLIT
4751 if (curfrp
->fr_width
!= Columns
)
4756 room_cmdline
= Rows
- p_ch
- (lastwin
->w_winrow
4757 + lastwin
->w_height
+ lastwin
->w_status_height
);
4758 if (room_cmdline
< 0)
4762 if (height
<= room
+ room_cmdline
)
4764 #ifdef FEAT_VERTSPLIT
4765 if (run
== 2 || curfrp
->fr_width
== Columns
)
4768 if (height
> room
+ room_cmdline
)
4769 height
= room
+ room_cmdline
;
4772 #ifdef FEAT_VERTSPLIT
4773 frame_setheight(curfrp
->fr_parent
, height
4774 + frame_minheight(curfrp
->fr_parent
, NOWIN
) - (int)p_wmh
- 1);
4780 * Compute the number of lines we will take from others frames (can be
4783 take
= height
- curfrp
->fr_height
;
4785 /* If there is not enough room, also reduce the height of a window
4786 * with 'winfixheight' set. */
4787 if (height
> room
+ room_cmdline
- room_reserved
)
4788 room_reserved
= room
+ room_cmdline
- height
;
4789 /* If there is only a 'winfixheight' window and making the
4790 * window smaller, need to make the other window taller. */
4791 if (take
< 0 && room
- curfrp
->fr_height
< room_reserved
)
4794 if (take
> 0 && room_cmdline
> 0)
4796 /* use lines from cmdline first */
4797 if (take
< room_cmdline
)
4798 room_cmdline
= take
;
4799 take
-= room_cmdline
;
4800 topframe
->fr_height
+= room_cmdline
;
4804 * set the current frame to the new height
4806 frame_new_height(curfrp
, height
, FALSE
, FALSE
);
4809 * First take lines from the frames after the current frame. If
4810 * that is not enough, takes lines from frames above the current
4813 for (run
= 0; run
< 2; ++run
)
4816 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4818 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
4819 while (frp
!= NULL
&& take
!= 0)
4821 h
= frame_minheight(frp
, NULL
);
4822 if (room_reserved
> 0
4823 && frp
->fr_win
!= NULL
4824 && frp
->fr_win
->w_p_wfh
)
4826 if (room_reserved
>= frp
->fr_height
)
4827 room_reserved
-= frp
->fr_height
;
4830 if (frp
->fr_height
- room_reserved
> take
)
4831 room_reserved
= frp
->fr_height
- take
;
4832 take
-= frp
->fr_height
- room_reserved
;
4833 frame_new_height(frp
, room_reserved
, FALSE
, FALSE
);
4839 if (frp
->fr_height
- take
< h
)
4841 take
-= frp
->fr_height
- h
;
4842 frame_new_height(frp
, h
, FALSE
, FALSE
);
4846 frame_new_height(frp
, frp
->fr_height
- take
,
4860 #if defined(FEAT_VERTSPLIT) || defined(PROTO)
4862 * Set current window width and take care of repositioning other windows to
4869 win_setwidth_win(width
, curwin
);
4873 win_setwidth_win(width
, wp
)
4877 /* Always keep current window at least one column wide, even when
4878 * 'winminwidth' is zero. */
4887 frame_setwidth(wp
->w_frame
, width
+ wp
->w_vsep_width
);
4889 /* recompute the window positions */
4890 (void)win_comp_pos();
4892 redraw_all_later(NOT_VALID
);
4896 * Set the width of a frame to "width" and take care that all frames and
4897 * windows inside it are resized. Also resize frames above and below if the
4898 * are in the same FR_ROW frame.
4900 * Strategy is similar to frame_setheight().
4903 frame_setwidth(curfrp
, width
)
4907 int room
; /* total number of lines available */
4908 int take
; /* number of lines taken from other windows */
4914 /* If the width already is the desired value, nothing to do. */
4915 if (curfrp
->fr_width
== width
)
4918 if (curfrp
->fr_parent
== NULL
)
4919 /* topframe: can't change width */
4922 if (curfrp
->fr_parent
->fr_layout
== FR_COL
)
4924 /* Column of frames: Also need to resize frames above and below of
4925 * this one. First check for the minimal width of these. */
4926 w
= frame_minwidth(curfrp
->fr_parent
, NULL
);
4929 frame_setwidth(curfrp
->fr_parent
, width
);
4934 * Row of frames: try to change only frames in this row.
4937 * 1: compute room available, if it's not enough try resizing the
4939 * 2: compute the room available and adjust the width to it.
4941 for (run
= 1; run
<= 2; ++run
)
4945 for (frp
= curfrp
->fr_parent
->fr_child
; frp
!= NULL
;
4949 && frp
->fr_win
!= NULL
4950 && frp
->fr_win
->w_p_wfw
)
4951 room_reserved
+= frp
->fr_width
;
4952 room
+= frp
->fr_width
;
4954 room
-= frame_minwidth(frp
, NULL
);
4959 if (run
== 2 || curfrp
->fr_height
>= ROWS_AVAIL
)
4965 frame_setwidth(curfrp
->fr_parent
, width
4966 + frame_minwidth(curfrp
->fr_parent
, NOWIN
) - (int)p_wmw
- 1);
4970 * Compute the number of lines we will take from others frames (can be
4973 take
= width
- curfrp
->fr_width
;
4975 /* If there is not enough room, also reduce the width of a window
4976 * with 'winfixwidth' set. */
4977 if (width
> room
- room_reserved
)
4978 room_reserved
= room
- width
;
4979 /* If there is only a 'winfixwidth' window and making the
4980 * window smaller, need to make the other window narrower. */
4981 if (take
< 0 && room
- curfrp
->fr_width
< room_reserved
)
4985 * set the current frame to the new width
4987 frame_new_width(curfrp
, width
, FALSE
, FALSE
);
4990 * First take lines from the frames right of the current frame. If
4991 * that is not enough, takes lines from frames left of the current
4994 for (run
= 0; run
< 2; ++run
)
4997 frp
= curfrp
->fr_next
; /* 1st run: start with next window */
4999 frp
= curfrp
->fr_prev
; /* 2nd run: start with prev window */
5000 while (frp
!= NULL
&& take
!= 0)
5002 w
= frame_minwidth(frp
, NULL
);
5003 if (room_reserved
> 0
5004 && frp
->fr_win
!= NULL
5005 && frp
->fr_win
->w_p_wfw
)
5007 if (room_reserved
>= frp
->fr_width
)
5008 room_reserved
-= frp
->fr_width
;
5011 if (frp
->fr_width
- room_reserved
> take
)
5012 room_reserved
= frp
->fr_width
- take
;
5013 take
-= frp
->fr_width
- room_reserved
;
5014 frame_new_width(frp
, room_reserved
, FALSE
, FALSE
);
5020 if (frp
->fr_width
- take
< w
)
5022 take
-= frp
->fr_width
- w
;
5023 frame_new_width(frp
, w
, FALSE
, FALSE
);
5027 frame_new_width(frp
, frp
->fr_width
- take
,
5040 #endif /* FEAT_VERTSPLIT */
5043 * Check 'winminheight' for a valid value.
5052 /* loop until there is a 'winminheight' that is possible */
5055 /* TODO: handle vertical splits */
5057 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
5058 room
+= wp
->w_height
- p_wmh
;
5073 * Status line of dragwin is dragged "offset" lines down (negative is up).
5076 win_drag_status_line(dragwin
, offset
)
5084 int up
; /* if TRUE, drag status line up, otherwise down */
5087 fr
= dragwin
->w_frame
;
5089 if (fr
!= topframe
) /* more than one window */
5092 /* When the parent frame is not a column of frames, its parent should
5094 if (fr
->fr_layout
!= FR_COL
)
5097 if (fr
!= topframe
) /* only a row of windows, may drag statusline */
5102 /* If this is the last frame in a column, may want to resize the parent
5103 * frame instead (go two up to skip a row of frames). */
5104 while (curfr
!= topframe
&& curfr
->fr_next
== NULL
)
5113 if (offset
< 0) /* drag up */
5117 /* sum up the room of the current frame and above it */
5120 /* only one window */
5121 room
= fr
->fr_height
- frame_minheight(fr
, NULL
);
5126 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5128 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5133 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5135 else /* drag down */
5139 * Only dragging the last status line can reduce p_ch.
5141 room
= Rows
- cmdline_row
;
5142 if (curfr
->fr_next
== NULL
)
5148 /* sum up the room of frames below of the current one */
5149 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5150 room
+= fr
->fr_height
- frame_minheight(fr
, NULL
);
5151 fr
= curfr
; /* put fr at window that grows */
5154 if (room
< offset
) /* Not enough room */
5155 offset
= room
; /* Move as far as we can */
5160 * Grow frame fr by "offset" lines.
5161 * Doesn't happen when dragging the last status line up.
5164 frame_new_height(fr
, fr
->fr_height
+ offset
, up
, FALSE
);
5167 fr
= curfr
; /* current frame gets smaller */
5169 fr
= curfr
->fr_next
; /* next frame gets smaller */
5172 * Now make the other frames smaller.
5174 while (fr
!= NULL
&& offset
> 0)
5176 n
= frame_minheight(fr
, NULL
);
5177 if (fr
->fr_height
- offset
<= n
)
5179 offset
-= fr
->fr_height
- n
;
5180 frame_new_height(fr
, n
, !up
, FALSE
);
5184 frame_new_height(fr
, fr
->fr_height
- offset
, !up
, FALSE
);
5192 row
= win_comp_pos();
5193 screen_fill(row
, cmdline_row
, 0, (int)Columns
, ' ', ' ', 0);
5195 p_ch
= Rows
- cmdline_row
;
5198 curtab
->tp_ch_used
= p_ch
;
5199 redraw_all_later(SOME_VALID
);
5203 #ifdef FEAT_VERTSPLIT
5205 * Separator line of dragwin is dragged "offset" lines right (negative is left).
5208 win_drag_vsep_line(dragwin
, offset
)
5215 int left
; /* if TRUE, drag separator line left, otherwise right */
5218 fr
= dragwin
->w_frame
;
5219 if (fr
== topframe
) /* only one window (cannot happen?) */
5223 /* When the parent frame is not a row of frames, its parent should be. */
5224 if (fr
->fr_layout
!= FR_ROW
)
5226 if (fr
== topframe
) /* only a column of windows (cannot happen?) */
5232 /* If this is the last frame in a row, may want to resize a parent
5234 while (curfr
->fr_next
== NULL
)
5247 if (offset
< 0) /* drag left */
5251 /* sum up the room of the current frame and left of it */
5253 for (fr
= fr
->fr_child
; ; fr
= fr
->fr_next
)
5255 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5259 fr
= curfr
->fr_next
; /* put fr at frame that grows */
5261 else /* drag right */
5264 /* sum up the room of frames right of the current one */
5266 for (fr
= curfr
->fr_next
; fr
!= NULL
; fr
= fr
->fr_next
)
5267 room
+= fr
->fr_width
- frame_minwidth(fr
, NULL
);
5268 fr
= curfr
; /* put fr at window that grows */
5271 if (room
< offset
) /* Not enough room */
5272 offset
= room
; /* Move as far as we can */
5273 if (offset
<= 0) /* No room at all, quit. */
5276 /* grow frame fr by offset lines */
5277 frame_new_width(fr
, fr
->fr_width
+ offset
, left
, FALSE
);
5279 /* shrink other frames: current and at the left or at the right */
5281 fr
= curfr
; /* current frame gets smaller */
5283 fr
= curfr
->fr_next
; /* next frame gets smaller */
5285 while (fr
!= NULL
&& offset
> 0)
5287 n
= frame_minwidth(fr
, NULL
);
5288 if (fr
->fr_width
- offset
<= n
)
5290 offset
-= fr
->fr_width
- n
;
5291 frame_new_width(fr
, n
, !left
, FALSE
);
5295 frame_new_width(fr
, fr
->fr_width
- offset
, !left
, FALSE
);
5303 (void)win_comp_pos();
5304 redraw_all_later(NOT_VALID
);
5306 #endif /* FEAT_VERTSPLIT */
5307 #endif /* FEAT_MOUSE */
5309 #endif /* FEAT_WINDOWS */
5312 * Set the height of a window.
5313 * This takes care of the things inside the window, not what happens to the
5314 * window position, the frame or to other windows.
5317 win_new_height(wp
, height
)
5322 int sline
, line_size
;
5323 #define FRACTION_MULT 16384L
5325 /* Don't want a negative height. Happens when splitting a tiny window.
5326 * Will equalize heights soon to fix it. */
5329 if (wp
->w_height
== height
)
5330 return; /* nothing to do */
5332 if (wp
->w_wrow
!= wp
->w_prev_fraction_row
&& wp
->w_height
> 0)
5333 wp
->w_fraction
= ((long)wp
->w_wrow
* FRACTION_MULT
5334 + FRACTION_MULT
/ 2) / (long)wp
->w_height
;
5336 wp
->w_height
= height
;
5339 /* Don't change w_topline when height is zero. Don't set w_topline when
5340 * 'scrollbind' is set and this isn't the current window. */
5342 #ifdef FEAT_SCROLLBIND
5343 && (!wp
->w_p_scb
|| wp
== curwin
)
5348 * Find a value for w_topline that shows the cursor at the same
5349 * relative position in the window as before (more or less).
5351 lnum
= wp
->w_cursor
.lnum
;
5352 if (lnum
< 1) /* can happen when starting up */
5354 wp
->w_wrow
= ((long)wp
->w_fraction
* (long)height
- 1L) / FRACTION_MULT
;
5355 line_size
= plines_win_col(wp
, lnum
, (long)(wp
->w_cursor
.col
)) - 1;
5356 sline
= wp
->w_wrow
- line_size
;
5360 /* Make sure the whole cursor line is visible, if possible. */
5361 int rows
= plines_win(wp
, lnum
, FALSE
);
5363 if (sline
> wp
->w_height
- rows
)
5365 sline
= wp
->w_height
- rows
;
5366 wp
->w_wrow
-= rows
- line_size
;
5373 * Cursor line would go off top of screen if w_wrow was this high.
5374 * Make cursor line the first line in the window. If not enough
5375 * room use w_skipcol;
5377 wp
->w_wrow
= line_size
;
5378 if (wp
->w_wrow
>= wp
->w_height
5379 && (W_WIDTH(wp
) - win_col_off(wp
)) > 0)
5381 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
);
5383 while (wp
->w_wrow
>= wp
->w_height
)
5385 wp
->w_skipcol
+= W_WIDTH(wp
) - win_col_off(wp
)
5393 while (sline
> 0 && lnum
> 1)
5396 hasFoldingWin(wp
, lnum
, &lnum
, NULL
, TRUE
, NULL
);
5399 /* first line in buffer is folded */
5407 if (lnum
== wp
->w_topline
)
5408 line_size
= plines_win_nofill(wp
, lnum
, TRUE
)
5412 line_size
= plines_win(wp
, lnum
, TRUE
);
5419 * Line we want at top would go off top of screen. Use next
5423 hasFoldingWin(wp
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
5426 wp
->w_wrow
-= line_size
+ sline
;
5430 /* First line of file reached, use that as topline. */
5432 wp
->w_wrow
-= sline
;
5435 set_topline(wp
, lnum
);
5442 curs_columns(FALSE
); /* validate w_wrow */
5444 wp
->w_prev_fraction_row
= wp
->w_wrow
;
5446 win_comp_scroll(wp
);
5447 redraw_win_later(wp
, SOME_VALID
);
5449 wp
->w_redr_status
= TRUE
;
5451 invalidate_botline_win(wp
);
5454 #ifdef FEAT_VERTSPLIT
5456 * Set the width of a window.
5459 win_new_width(wp
, width
)
5463 wp
->w_width
= width
;
5464 wp
->w_lines_valid
= 0;
5465 changed_line_abv_curs_win(wp
);
5466 invalidate_botline_win(wp
);
5470 curs_columns(TRUE
); /* validate w_wrow */
5472 redraw_win_later(wp
, NOT_VALID
);
5473 wp
->w_redr_status
= TRUE
;
5481 wp
->w_p_scr
= ((unsigned)wp
->w_height
>> 1);
5482 if (wp
->w_p_scr
== 0)
5487 * command_height: called whenever p_ch has been changed
5495 int old_p_ch
= curtab
->tp_ch_used
;
5497 /* Use the value of p_ch that we remembered. This is needed for when the
5498 * GUI starts up, we can't be sure in what order things happen. And when
5499 * p_ch was changed in another tab page. */
5500 curtab
->tp_ch_used
= p_ch
;
5502 /* Find bottom frame with width of screen. */
5503 frp
= lastwin
->w_frame
;
5504 # ifdef FEAT_VERTSPLIT
5505 while (frp
->fr_width
!= Columns
&& frp
->fr_parent
!= NULL
)
5506 frp
= frp
->fr_parent
;
5509 /* Avoid changing the height of a window with 'winfixheight' set. */
5510 while (frp
->fr_prev
!= NULL
&& frp
->fr_layout
== FR_LEAF
5511 && frp
->fr_win
->w_p_wfh
)
5514 if (starting
!= NO_SCREEN
)
5516 cmdline_row
= Rows
- p_ch
;
5518 if (p_ch
> old_p_ch
) /* p_ch got bigger */
5520 while (p_ch
> old_p_ch
)
5526 curtab
->tp_ch_used
= p_ch
;
5527 cmdline_row
= Rows
- p_ch
;
5530 h
= frp
->fr_height
- frame_minheight(frp
, NULL
);
5531 if (h
> p_ch
- old_p_ch
)
5532 h
= p_ch
- old_p_ch
;
5534 frame_add_height(frp
, -h
);
5538 /* Recompute window positions. */
5539 (void)win_comp_pos();
5541 /* clear the lines added to cmdline */
5543 screen_fill((int)(cmdline_row
), (int)Rows
, 0,
5544 (int)Columns
, ' ', ' ', 0);
5545 msg_row
= cmdline_row
;
5546 redraw_cmdline
= TRUE
;
5550 if (msg_row
< cmdline_row
)
5551 msg_row
= cmdline_row
;
5552 redraw_cmdline
= TRUE
;
5554 frame_add_height(frp
, (int)(old_p_ch
- p_ch
));
5556 /* Recompute window positions. */
5557 if (frp
!= lastwin
->w_frame
)
5558 (void)win_comp_pos();
5560 cmdline_row
= Rows
- p_ch
;
5561 win_setheight(cmdline_row
);
5565 #if defined(FEAT_WINDOWS) || defined(PROTO)
5567 * Resize frame "frp" to be "n" lines higher (negative for less high).
5568 * Also resize the frames it is contained in.
5571 frame_add_height(frp
, n
)
5575 frame_new_height(frp
, frp
->fr_height
+ n
, FALSE
, FALSE
);
5578 frp
= frp
->fr_parent
;
5581 frp
->fr_height
+= n
;
5586 * Add or remove a status line for the bottom window(s), according to the
5587 * value of 'laststatus'.
5590 last_status(morewin
)
5591 int morewin
; /* pretend there are two or more windows */
5593 /* Don't make a difference between horizontal or vertical split. */
5594 last_status_rec(topframe
, (p_ls
== 2
5595 || (p_ls
== 1 && (morewin
|| lastwin
!= firstwin
))));
5599 last_status_rec(fr
, statusline
)
5606 if (fr
->fr_layout
== FR_LEAF
)
5609 if (wp
->w_status_height
!= 0 && !statusline
)
5611 /* remove status line */
5612 win_new_height(wp
, wp
->w_height
+ 1);
5613 wp
->w_status_height
= 0;
5616 else if (wp
->w_status_height
== 0 && statusline
)
5618 /* Find a frame to take a line from. */
5620 while (fp
->fr_height
<= frame_minheight(fp
, NULL
))
5627 /* In a column of frames: go to frame above. If already at
5628 * the top or in a row of frames: go to parent. */
5629 if (fp
->fr_parent
->fr_layout
== FR_COL
&& fp
->fr_prev
!= NULL
)
5634 wp
->w_status_height
= 1;
5637 frame_new_height(fp
, fp
->fr_height
- 1, FALSE
, FALSE
);
5638 frame_fix_height(wp
);
5639 (void)win_comp_pos();
5642 win_new_height(wp
, wp
->w_height
- 1);
5644 redraw_all_later(SOME_VALID
);
5647 #ifdef FEAT_VERTSPLIT
5648 else if (fr
->fr_layout
== FR_ROW
)
5650 /* vertically split windows, set status line for each one */
5651 for (fp
= fr
->fr_child
; fp
!= NULL
; fp
= fp
->fr_next
)
5652 last_status_rec(fp
, statusline
);
5657 /* horizontally split window, set status line for last one */
5658 for (fp
= fr
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
5660 last_status_rec(fp
, statusline
);
5665 * Return the number of lines used by the tab page line.
5670 #ifdef FEAT_GUI_TABLINE
5671 /* When the GUI has the tabline then this always returns zero. */
5672 if (gui_use_tabline())
5678 case 1: return (first_tabpage
->tp_next
== NULL
) ? 0 : 1;
5683 #endif /* FEAT_WINDOWS */
5685 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
5687 * Get the file name at the cursor.
5688 * If Visual mode is active, use the selected text if it's in one line.
5689 * Returns the name in allocated memory, NULL for failure.
5692 grab_file_name(count
, file_lnum
)
5694 linenr_T
*file_lnum
;
5702 if (get_visual_text(NULL
, &ptr
, &len
) == FAIL
)
5704 return find_file_name_in_path(ptr
, len
,
5705 FNAME_MESS
|FNAME_EXP
|FNAME_REL
, count
, curbuf
->b_ffname
);
5708 return file_name_at_cursor(FNAME_MESS
|FNAME_HYP
|FNAME_EXP
|FNAME_REL
, count
,
5714 * Return the file name under or after the cursor.
5716 * The 'path' option is searched if the file name is not absolute.
5717 * The string returned has been alloc'ed and should be freed by the caller.
5718 * NULL is returned if the file name or file is not found.
5721 * FNAME_MESS give error messages
5722 * FNAME_EXP expand to path
5723 * FNAME_HYP check for hypertext link
5724 * FNAME_INCL apply "includeexpr"
5727 file_name_at_cursor(options
, count
, file_lnum
)
5730 linenr_T
*file_lnum
;
5732 return file_name_in_line(ml_get_curline(),
5733 curwin
->w_cursor
.col
, options
, count
, curbuf
->b_ffname
,
5738 * Return the name of the file under or after ptr[col].
5739 * Otherwise like file_name_at_cursor().
5742 file_name_in_line(line
, col
, options
, count
, rel_fname
, file_lnum
)
5747 char_u
*rel_fname
; /* file we are searching relative to */
5748 linenr_T
*file_lnum
; /* line number after the file name */
5754 * search forward for what could be the start of a file name
5757 while (*ptr
!= NUL
&& !vim_isfilec(*ptr
))
5759 if (*ptr
== NUL
) /* nothing found */
5761 if (options
& FNAME_MESS
)
5762 EMSG(_("E446: No file name under cursor"));
5767 * Search backward for first char of the file name.
5768 * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
5773 if (has_mbyte
&& (len
= (*mb_head_off
)(line
, ptr
- 1)) > 0)
5777 if (vim_isfilec(ptr
[-1])
5778 || ((options
& FNAME_HYP
) && path_is_url(ptr
- 1)))
5785 * Search forward for the last char of the file name.
5786 * Also allow "://" when ':' is not in 'isfname'.
5789 while (vim_isfilec(ptr
[len
])
5790 || ((options
& FNAME_HYP
) && path_is_url(ptr
+ len
)))
5793 len
+= (*mb_ptr2len
)(ptr
+ len
);
5799 * If there is trailing punctuation, remove it.
5800 * But don't remove "..", could be a directory name.
5802 if (len
> 2 && vim_strchr((char_u
*)".,:;!", ptr
[len
- 1]) != NULL
5803 && ptr
[len
- 2] != '.')
5806 if (file_lnum
!= NULL
)
5810 /* Get the number after the file name and a separator character */
5816 ++p
; /* skip the separator */
5819 *file_lnum
= (int)getdigits(&p
);
5823 return find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
);
5826 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5827 static char_u
*eval_includeexpr
__ARGS((char_u
*ptr
, int len
));
5830 eval_includeexpr(ptr
, len
)
5836 set_vim_var_string(VV_FNAME
, ptr
, len
);
5837 res
= eval_to_string_safe(curbuf
->b_p_inex
, NULL
,
5838 was_set_insecurely((char_u
*)"includeexpr", OPT_LOCAL
));
5839 set_vim_var_string(VV_FNAME
, NULL
, 0);
5845 * Return the name of the file ptr[len] in 'path'.
5846 * Otherwise like file_name_at_cursor().
5849 find_file_name_in_path(ptr
, len
, options
, count
, rel_fname
)
5854 char_u
*rel_fname
; /* file we are searching relative to */
5858 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5859 char_u
*tofree
= NULL
;
5861 if ((options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5863 tofree
= eval_includeexpr(ptr
, len
);
5867 len
= (int)STRLEN(ptr
);
5872 if (options
& FNAME_EXP
)
5874 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5877 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5879 * If the file could not be found in a normal way, try applying
5880 * 'includeexpr' (unless done already).
5882 if (file_name
== NULL
5883 && !(options
& FNAME_INCL
) && *curbuf
->b_p_inex
!= NUL
)
5885 tofree
= eval_includeexpr(ptr
, len
);
5889 len
= (int)STRLEN(ptr
);
5890 file_name
= find_file_in_path(ptr
, len
, options
& ~FNAME_MESS
,
5895 if (file_name
== NULL
&& (options
& FNAME_MESS
))
5899 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr
);
5903 /* Repeat finding the file "count" times. This matters when it
5904 * appears several times in the path. */
5905 while (file_name
!= NULL
&& --count
> 0)
5907 vim_free(file_name
);
5908 file_name
= find_file_in_path(ptr
, len
, options
, FALSE
, rel_fname
);
5912 file_name
= vim_strnsave(ptr
, len
);
5914 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
5920 #endif /* FEAT_SEARCHPATH */
5923 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
5924 * Also check for ":\\", which MS Internet Explorer accepts, return
5931 if (STRNCMP(p
, "://", (size_t)3) == 0)
5933 else if (STRNCMP(p
, ":\\\\", (size_t)3) == 0)
5934 return URL_BACKSLASH
;
5939 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
5940 * Return URL_BACKSLASH for "name:\\".
5941 * Return zero otherwise.
5944 path_with_url(fname
)
5949 for (p
= fname
; isalpha(*p
); ++p
)
5951 return path_is_url(p
);
5955 * Return TRUE if "name" is a full (absolute) path name or URL.
5961 return (path_with_url(name
) != 0 || mch_isFullName(name
));
5965 * Get absolute file name into buffer "buf[len]".
5967 * return FAIL for failure, OK otherwise
5970 vim_FullName(fname
, buf
, len
, force
)
5971 char_u
*fname
, *buf
;
5973 int force
; /* force expansion even when already absolute */
5982 url
= path_with_url(fname
);
5984 retval
= mch_FullName(fname
, buf
, len
, force
);
5985 if (url
|| retval
== FAIL
)
5987 /* something failed; use the file name (truncate when too long) */
5988 vim_strncpy(buf
, fname
, len
- 1);
5990 #if defined(MACOS_CLASSIC) || defined(OS2) || defined(MSDOS) || defined(MSWIN)
5997 * Return the minimal number of rows that is needed on the screen to display
5998 * the current number of windows.
6009 if (firstwin
== NULL
) /* not initialized yet */
6014 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
6016 n
= frame_minheight(tp
->tp_topframe
, NULL
);
6020 total
+= tabline_height();
6022 total
= 1; /* at least one window should have a line! */
6024 total
+= 1; /* count the room for the command line */
6029 * Return TRUE if there is only one window (in the current tab page), not
6030 * counting a help or preview window, unless it is the current window.
6039 /* If there is another tab page there always is another window. */
6040 if (first_tabpage
->tp_next
!= NULL
)
6043 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
6044 if (!((wp
->w_buffer
->b_help
&& !curbuf
->b_help
)
6045 # ifdef FEAT_QUICKFIX
6050 return (count
<= 1);
6056 #if defined(FEAT_WINDOWS) || defined(FEAT_AUTOCMD) || defined(PROTO)
6058 * Correct the cursor line number in other windows. Used after changing the
6059 * current buffer, and before applying autocommands.
6060 * When "do_curwin" is TRUE, also check current window.
6063 check_lnums(do_curwin
)
6071 FOR_ALL_TAB_WINDOWS(tp
, wp
)
6072 if ((do_curwin
|| wp
!= curwin
) && wp
->w_buffer
== curbuf
)
6078 if (wp
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6079 wp
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6080 if (wp
->w_topline
> curbuf
->b_ml
.ml_line_count
)
6081 wp
->w_topline
= curbuf
->b_ml
.ml_line_count
;
6086 #if defined(FEAT_WINDOWS) || defined(PROTO)
6089 * A snapshot of the window sizes, to restore them after closing the help
6091 * Only these fields are used:
6097 * fr_win (only valid for the old curwin, NULL otherwise)
6101 * Create a snapshot of the current frame sizes.
6106 clear_snapshot(curtab
);
6107 make_snapshot_rec(topframe
, &curtab
->tp_snapshot
);
6111 make_snapshot_rec(fr
, frp
)
6115 *frp
= (frame_T
*)alloc_clear((unsigned)sizeof(frame_T
));
6118 (*frp
)->fr_layout
= fr
->fr_layout
;
6119 # ifdef FEAT_VERTSPLIT
6120 (*frp
)->fr_width
= fr
->fr_width
;
6122 (*frp
)->fr_height
= fr
->fr_height
;
6123 if (fr
->fr_next
!= NULL
)
6124 make_snapshot_rec(fr
->fr_next
, &((*frp
)->fr_next
));
6125 if (fr
->fr_child
!= NULL
)
6126 make_snapshot_rec(fr
->fr_child
, &((*frp
)->fr_child
));
6127 if (fr
->fr_layout
== FR_LEAF
&& fr
->fr_win
== curwin
)
6128 (*frp
)->fr_win
= curwin
;
6132 * Remove any existing snapshot.
6138 clear_snapshot_rec(tp
->tp_snapshot
);
6139 tp
->tp_snapshot
= NULL
;
6143 clear_snapshot_rec(fr
)
6148 clear_snapshot_rec(fr
->fr_next
);
6149 clear_snapshot_rec(fr
->fr_child
);
6155 * Restore a previously created snapshot, if there is any.
6156 * This is only done if the screen size didn't change and the window layout is
6160 restore_snapshot(close_curwin
)
6161 int close_curwin
; /* closing current window */
6165 if (curtab
->tp_snapshot
!= NULL
6166 # ifdef FEAT_VERTSPLIT
6167 && curtab
->tp_snapshot
->fr_width
== topframe
->fr_width
6169 && curtab
->tp_snapshot
->fr_height
== topframe
->fr_height
6170 && check_snapshot_rec(curtab
->tp_snapshot
, topframe
) == OK
)
6172 wp
= restore_snapshot_rec(curtab
->tp_snapshot
, topframe
);
6174 if (wp
!= NULL
&& close_curwin
)
6176 redraw_all_later(CLEAR
);
6178 clear_snapshot(curtab
);
6182 * Check if frames "sn" and "fr" have the same layout, same following frames
6183 * and same children.
6186 check_snapshot_rec(sn
, fr
)
6190 if (sn
->fr_layout
!= fr
->fr_layout
6191 || (sn
->fr_next
== NULL
) != (fr
->fr_next
== NULL
)
6192 || (sn
->fr_child
== NULL
) != (fr
->fr_child
== NULL
)
6193 || (sn
->fr_next
!= NULL
6194 && check_snapshot_rec(sn
->fr_next
, fr
->fr_next
) == FAIL
)
6195 || (sn
->fr_child
!= NULL
6196 && check_snapshot_rec(sn
->fr_child
, fr
->fr_child
) == FAIL
))
6202 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all
6203 * following frames and children.
6204 * Returns a pointer to the old current window, or NULL.
6207 restore_snapshot_rec(sn
, fr
)
6214 fr
->fr_height
= sn
->fr_height
;
6215 # ifdef FEAT_VERTSPLIT
6216 fr
->fr_width
= sn
->fr_width
;
6218 if (fr
->fr_layout
== FR_LEAF
)
6220 frame_new_height(fr
, fr
->fr_height
, FALSE
, FALSE
);
6221 # ifdef FEAT_VERTSPLIT
6222 frame_new_width(fr
, fr
->fr_width
, FALSE
, FALSE
);
6226 if (sn
->fr_next
!= NULL
)
6228 wp2
= restore_snapshot_rec(sn
->fr_next
, fr
->fr_next
);
6232 if (sn
->fr_child
!= NULL
)
6234 wp2
= restore_snapshot_rec(sn
->fr_child
, fr
->fr_child
);
6243 #if (defined(FEAT_GUI) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
6245 * Return TRUE if there is any vertically split window.
6252 if (topframe
->fr_layout
== FR_ROW
)
6255 if (topframe
->fr_layout
== FR_COL
)
6256 for (fr
= topframe
->fr_child
; fr
!= NULL
; fr
= fr
->fr_next
)
6257 if (fr
->fr_layout
== FR_ROW
)
6264 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6266 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6267 * highligted with the group 'grp' with priority 'prio'.
6268 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6269 * If no particular ID is desired, -1 must be specified for 'id'.
6270 * Return ID of added match, -1 on failure.
6273 match_add(wp
, grp
, pat
, prio
, id
)
6286 if (*grp
== NUL
|| *pat
== NUL
)
6288 if (id
< -1 || id
== 0)
6290 EMSGN("E799: Invalid ID: %ld (must be greater than or equal to 1)", id
);
6295 cur
= wp
->w_match_head
;
6300 EMSGN("E801: ID already taken: %ld", id
);
6306 if ((hlg_id
= syn_namen2id(grp
, (int)STRLEN(grp
))) == 0)
6308 EMSG2(_(e_nogroup
), grp
);
6311 if ((regprog
= vim_regcomp(pat
, RE_MAGIC
)) == NULL
)
6313 EMSG2(_(e_invarg2
), pat
);
6317 /* Find available match ID. */
6320 cur
= wp
->w_match_head
;
6321 while (cur
!= NULL
&& cur
->id
!= wp
->w_next_match_id
)
6324 id
= wp
->w_next_match_id
;
6325 wp
->w_next_match_id
++;
6328 /* Build new match. */
6329 m
= (matchitem_T
*)alloc(sizeof(matchitem_T
));
6332 m
->pattern
= vim_strsave(pat
);
6334 m
->match
.regprog
= regprog
;
6335 m
->match
.rmm_ic
= FALSE
;
6336 m
->match
.rmm_maxcol
= 0;
6338 /* Insert new match. The match list is in ascending order with regard to
6339 * the match priorities. */
6340 cur
= wp
->w_match_head
;
6342 while (cur
!= NULL
&& prio
>= cur
->priority
)
6348 wp
->w_match_head
= m
;
6353 redraw_later(SOME_VALID
);
6358 * Delete match with ID 'id' in the match list of window 'wp'.
6359 * Print error messages if 'perr' is TRUE.
6362 match_delete(wp
, id
, perr
)
6367 matchitem_T
*cur
= wp
->w_match_head
;
6368 matchitem_T
*prev
= cur
;
6373 EMSGN("E802: Invalid ID: %ld (must be greater than or equal to 1)",
6377 while (cur
!= NULL
&& cur
->id
!= id
)
6385 EMSGN("E803: ID not found: %ld", id
);
6389 wp
->w_match_head
= cur
->next
;
6391 prev
->next
= cur
->next
;
6392 vim_free(cur
->match
.regprog
);
6393 vim_free(cur
->pattern
);
6395 redraw_later(SOME_VALID
);
6400 * Delete all matches in the match list of window 'wp'.
6408 while (wp
->w_match_head
!= NULL
)
6410 m
= wp
->w_match_head
->next
;
6411 vim_free(wp
->w_match_head
->match
.regprog
);
6412 vim_free(wp
->w_match_head
->pattern
);
6413 vim_free(wp
->w_match_head
);
6414 wp
->w_match_head
= m
;
6416 redraw_later(SOME_VALID
);
6420 * Get match from ID 'id' in window 'wp'.
6421 * Return NULL if match not found.
6428 matchitem_T
*cur
= wp
->w_match_head
;
6430 while (cur
!= NULL
&& cur
->id
!= id
)