Mercurial > vim
annotate src/window.c @ 13144:20fb8c711050 v8.0.1446
patch 8.0.1446: acessing freed memory after window command in auto command
commit https://github.com/vim/vim/commit/6f361c991221e96d5068c77b854967d997b1529b
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 31 19:06:50 2018 +0100
patch 8.0.1446: acessing freed memory after window command in auto command
Problem: Acessing freed memory after window command in auto command.
(gy741)
Solution: Adjust the pointer in the parent frame. (Christian Brabandt,
closes #2467)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 31 Jan 2018 19:15:06 +0100 |
parents | 788d01164bb2 |
children | ac42c4b11dbc |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10013
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
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. | |
8 */ | |
9 | |
10 #include "vim.h" | |
11 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
12 static int path_is_url(char_u *p); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
13 static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize, long Prenum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
14 static void win_init(win_T *newp, win_T *oldp, int flags); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
15 static void win_init_some(win_T *newp, win_T *oldp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
16 static void frame_comp_pos(frame_T *topfrp, int *row, int *col); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
17 static void frame_setheight(frame_T *curfrp, int height); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
18 static void frame_setwidth(frame_T *curfrp, int width); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
19 static void win_exchange(long); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
20 static void win_rotate(int, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
21 static void win_totop(int size, int flags); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
22 static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
23 static int last_window(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
24 static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_curtab); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
25 static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
26 static frame_T *win_altframe(win_T *win, tabpage_T *tp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
27 static tabpage_T *alt_tabpage(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
28 static win_T *frame2win(frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
29 static int frame_has_win(frame_T *frp, win_T *wp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
30 static void frame_new_height(frame_T *topfrp, int height, int topfirst, int wfh); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
31 static int frame_fixed_height(frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
32 static int frame_fixed_width(frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
33 static void frame_add_statusline(frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
34 static void frame_new_width(frame_T *topfrp, int width, int leftfirst, int wfw); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
35 static void frame_add_vsep(frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
36 static int frame_minwidth(frame_T *topfrp, win_T *next_curwin); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
37 static void frame_fix_width(win_T *wp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
38 static int win_alloc_firstwin(win_T *oldwin); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
39 static void new_frame(win_T *wp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
40 static tabpage_T *alloc_tabpage(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
41 static int leave_tabpage(buf_T *new_curbuf, int trigger_leave_autocmds); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
42 static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_autocmds, int trigger_leave_autocmds); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
43 static void frame_fix_height(win_T *wp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
44 static int frame_minheight(frame_T *topfrp, win_T *next_curwin); |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
45 static void win_enter_ext(win_T *wp, int undo_sync, int no_curwin, int trigger_new_autocmds, int trigger_enter_autocmds, int trigger_leave_autocmds); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
46 static void win_free(win_T *wp, tabpage_T *tp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
47 static void frame_append(frame_T *after, frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
48 static void frame_insert(frame_T *before, frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
49 static void frame_remove(frame_T *frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
50 static void win_goto_ver(int up, long count); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
51 static void win_goto_hor(int left, long count); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
52 static void frame_add_height(frame_T *frp, int n); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
53 static void last_status_rec(frame_T *fr, int statusline); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
54 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
55 static void make_snapshot_rec(frame_T *fr, frame_T **frp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
56 static void clear_snapshot(tabpage_T *tp, int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
57 static void clear_snapshot_rec(frame_T *fr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
58 static int check_snapshot_rec(frame_T *sn, frame_T *fr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
59 static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
60 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
61 static int frame_check_height(frame_T *topfrp, int height); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
62 static int frame_check_width(frame_T *topfrp, int width); |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
63 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
64 static win_T *win_alloc(win_T *after, int hidden); |
7 | 65 |
66 #define URL_SLASH 1 /* path_is_url() has found "://" */ | |
67 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */ | |
68 | |
1187 | 69 #define NOWIN (win_T *)-1 /* non-existing window */ |
7 | 70 |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
71 #define ROWS_AVAIL (Rows - p_ch - tabline_height()) |
826 | 72 |
73 static char *m_onlyone = N_("Already only one window"); | |
74 | |
7 | 75 /* |
76 * all CTRL-W window commands are handled here, called from normal_cmd(). | |
77 */ | |
78 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
79 do_window( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
80 int nchar, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
81 long Prenum, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
82 int xchar) /* extra char from ":wincmd gx" or NUL */ |
7 | 83 { |
84 long Prenum1; | |
85 win_T *wp; | |
86 #if defined(FEAT_SEARCHPATH) || defined(FEAT_FIND_ID) | |
87 char_u *ptr; | |
681 | 88 linenr_T lnum = -1; |
7 | 89 #endif |
90 #ifdef FEAT_FIND_ID | |
91 int type = FIND_DEFINE; | |
92 int len; | |
93 #endif | |
94 char_u cbuf[40]; | |
95 | |
96 if (Prenum == 0) | |
97 Prenum1 = 1; | |
98 else | |
99 Prenum1 = Prenum; | |
100 | |
101 #ifdef FEAT_CMDWIN | |
102 # define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; } | |
103 #else | |
104 # define CHECK_CMDWIN | |
105 #endif | |
106 | |
107 switch (nchar) | |
108 { | |
109 /* split current window in two parts, horizontally */ | |
110 case 'S': | |
111 case Ctrl_S: | |
112 case 's': | |
113 CHECK_CMDWIN | |
114 reset_VIsual_and_resel(); /* stop Visual mode */ | |
635 | 115 #ifdef FEAT_QUICKFIX |
116 /* When splitting the quickfix window open a new buffer in it, | |
117 * don't replicate the quickfix buffer. */ | |
118 if (bt_quickfix(curbuf)) | |
119 goto newwindow; | |
120 #endif | |
7 | 121 #ifdef FEAT_GUI |
122 need_mouse_correct = TRUE; | |
123 #endif | |
7009 | 124 (void)win_split((int)Prenum, 0); |
7 | 125 break; |
126 | |
127 /* split current window in two parts, vertically */ | |
128 case Ctrl_V: | |
129 case 'v': | |
130 CHECK_CMDWIN | |
131 reset_VIsual_and_resel(); /* stop Visual mode */ | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
132 #ifdef FEAT_QUICKFIX |
1664 | 133 /* When splitting the quickfix window open a new buffer in it, |
134 * don't replicate the quickfix buffer. */ | |
135 if (bt_quickfix(curbuf)) | |
136 goto newwindow; | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
137 #endif |
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
138 #ifdef FEAT_GUI |
7 | 139 need_mouse_correct = TRUE; |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
140 #endif |
7009 | 141 (void)win_split((int)Prenum, WSP_VERT); |
7 | 142 break; |
143 | |
144 /* split current window and edit alternate file */ | |
145 case Ctrl_HAT: | |
146 case '^': | |
147 CHECK_CMDWIN | |
148 reset_VIsual_and_resel(); /* stop Visual mode */ | |
6432 | 149 cmd_with_count("split #", cbuf, sizeof(cbuf), Prenum); |
7 | 150 do_cmdline_cmd(cbuf); |
151 break; | |
152 | |
153 /* open new window */ | |
154 case Ctrl_N: | |
155 case 'n': | |
156 CHECK_CMDWIN | |
157 reset_VIsual_and_resel(); /* stop Visual mode */ | |
635 | 158 #ifdef FEAT_QUICKFIX |
159 newwindow: | |
160 #endif | |
7 | 161 if (Prenum) |
1664 | 162 /* window height */ |
163 vim_snprintf((char *)cbuf, sizeof(cbuf) - 5, "%ld", Prenum); | |
7 | 164 else |
165 cbuf[0] = NUL; | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
166 #if defined(FEAT_QUICKFIX) |
1664 | 167 if (nchar == 'v' || nchar == Ctrl_V) |
168 STRCAT(cbuf, "v"); | |
169 #endif | |
7 | 170 STRCAT(cbuf, "new"); |
171 do_cmdline_cmd(cbuf); | |
172 break; | |
173 | |
174 /* quit current window */ | |
175 case Ctrl_Q: | |
176 case 'q': | |
177 reset_VIsual_and_resel(); /* stop Visual mode */ | |
6432 | 178 cmd_with_count("quit", cbuf, sizeof(cbuf), Prenum); |
6398 | 179 do_cmdline_cmd(cbuf); |
7 | 180 break; |
181 | |
182 /* close current window */ | |
183 case Ctrl_C: | |
184 case 'c': | |
185 reset_VIsual_and_resel(); /* stop Visual mode */ | |
6432 | 186 cmd_with_count("close", cbuf, sizeof(cbuf), Prenum); |
6398 | 187 do_cmdline_cmd(cbuf); |
7 | 188 break; |
189 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
190 #if defined(FEAT_QUICKFIX) |
7 | 191 /* close preview window */ |
192 case Ctrl_Z: | |
193 case 'z': | |
194 CHECK_CMDWIN | |
195 reset_VIsual_and_resel(); /* stop Visual mode */ | |
196 do_cmdline_cmd((char_u *)"pclose"); | |
197 break; | |
198 | |
199 /* cursor to preview window */ | |
200 case 'P': | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
201 FOR_ALL_WINDOWS(wp) |
7 | 202 if (wp->w_p_pvw) |
203 break; | |
204 if (wp == NULL) | |
205 EMSG(_("E441: There is no preview window")); | |
206 else | |
207 win_goto(wp); | |
208 break; | |
209 #endif | |
210 | |
211 /* close all but current window */ | |
212 case Ctrl_O: | |
213 case 'o': | |
214 CHECK_CMDWIN | |
215 reset_VIsual_and_resel(); /* stop Visual mode */ | |
6432 | 216 cmd_with_count("only", cbuf, sizeof(cbuf), Prenum); |
6398 | 217 do_cmdline_cmd(cbuf); |
7 | 218 break; |
219 | |
220 /* cursor to next window with wrap around */ | |
221 case Ctrl_W: | |
222 case 'w': | |
223 /* cursor to previous window with wrap around */ | |
224 case 'W': | |
225 CHECK_CMDWIN | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
226 if (ONE_WINDOW && Prenum != 1) /* just one window */ |
7 | 227 beep_flush(); |
228 else | |
229 { | |
230 if (Prenum) /* go to specified window */ | |
231 { | |
232 for (wp = firstwin; --Prenum > 0; ) | |
233 { | |
234 if (wp->w_next == NULL) | |
235 break; | |
236 else | |
237 wp = wp->w_next; | |
238 } | |
239 } | |
240 else | |
241 { | |
242 if (nchar == 'W') /* go to previous window */ | |
243 { | |
244 wp = curwin->w_prev; | |
245 if (wp == NULL) | |
246 wp = lastwin; /* wrap around */ | |
247 } | |
248 else /* go to next window */ | |
249 { | |
250 wp = curwin->w_next; | |
251 if (wp == NULL) | |
252 wp = firstwin; /* wrap around */ | |
253 } | |
254 } | |
255 win_goto(wp); | |
256 } | |
257 break; | |
258 | |
259 /* cursor to window below */ | |
260 case 'j': | |
261 case K_DOWN: | |
262 case Ctrl_J: | |
263 CHECK_CMDWIN | |
264 win_goto_ver(FALSE, Prenum1); | |
265 break; | |
266 | |
267 /* cursor to window above */ | |
268 case 'k': | |
269 case K_UP: | |
270 case Ctrl_K: | |
271 CHECK_CMDWIN | |
272 win_goto_ver(TRUE, Prenum1); | |
273 break; | |
274 | |
275 /* cursor to left window */ | |
276 case 'h': | |
277 case K_LEFT: | |
278 case Ctrl_H: | |
279 case K_BS: | |
280 CHECK_CMDWIN | |
281 win_goto_hor(TRUE, Prenum1); | |
282 break; | |
283 | |
284 /* cursor to right window */ | |
285 case 'l': | |
286 case K_RIGHT: | |
287 case Ctrl_L: | |
288 CHECK_CMDWIN | |
289 win_goto_hor(FALSE, Prenum1); | |
290 break; | |
291 | |
826 | 292 /* move window to new tab page */ |
293 case 'T': | |
1906 | 294 if (one_window()) |
826 | 295 MSG(_(m_onlyone)); |
296 else | |
297 { | |
298 tabpage_T *oldtab = curtab; | |
299 tabpage_T *newtab; | |
300 | |
301 /* First create a new tab with the window, then go back to | |
302 * the old tab and close the window there. */ | |
944 | 303 wp = curwin; |
826 | 304 if (win_new_tabpage((int)Prenum) == OK |
305 && valid_tabpage(oldtab)) | |
306 { | |
307 newtab = curtab; | |
4354 | 308 goto_tabpage_tp(oldtab, TRUE, TRUE); |
826 | 309 if (curwin == wp) |
310 win_close(curwin, FALSE); | |
311 if (valid_tabpage(newtab)) | |
4354 | 312 goto_tabpage_tp(newtab, TRUE, TRUE); |
826 | 313 } |
314 } | |
315 break; | |
316 | |
7 | 317 /* cursor to top-left window */ |
318 case 't': | |
319 case Ctrl_T: | |
320 win_goto(firstwin); | |
321 break; | |
322 | |
323 /* cursor to bottom-right window */ | |
324 case 'b': | |
325 case Ctrl_B: | |
326 win_goto(lastwin); | |
327 break; | |
328 | |
329 /* cursor to last accessed (previous) window */ | |
330 case 'p': | |
331 case Ctrl_P: | |
8833
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
332 if (!win_valid(prevwin)) |
7 | 333 beep_flush(); |
334 else | |
335 win_goto(prevwin); | |
336 break; | |
337 | |
338 /* exchange current and next window */ | |
339 case 'x': | |
340 case Ctrl_X: | |
341 CHECK_CMDWIN | |
342 win_exchange(Prenum); | |
343 break; | |
344 | |
345 /* rotate windows downwards */ | |
346 case Ctrl_R: | |
347 case 'r': | |
348 CHECK_CMDWIN | |
349 reset_VIsual_and_resel(); /* stop Visual mode */ | |
350 win_rotate(FALSE, (int)Prenum1); /* downwards */ | |
351 break; | |
352 | |
353 /* rotate windows upwards */ | |
354 case 'R': | |
355 CHECK_CMDWIN | |
356 reset_VIsual_and_resel(); /* stop Visual mode */ | |
357 win_rotate(TRUE, (int)Prenum1); /* upwards */ | |
358 break; | |
359 | |
360 /* move window to the very top/bottom/left/right */ | |
361 case 'K': | |
362 case 'J': | |
363 case 'H': | |
364 case 'L': | |
365 CHECK_CMDWIN | |
366 win_totop((int)Prenum, | |
367 ((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0) | |
368 | ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); | |
369 break; | |
370 | |
371 /* make all windows the same height */ | |
372 case '=': | |
373 #ifdef FEAT_GUI | |
374 need_mouse_correct = TRUE; | |
375 #endif | |
376 win_equal(NULL, FALSE, 'b'); | |
377 break; | |
378 | |
379 /* increase current window height */ | |
380 case '+': | |
381 #ifdef FEAT_GUI | |
382 need_mouse_correct = TRUE; | |
383 #endif | |
384 win_setheight(curwin->w_height + (int)Prenum1); | |
385 break; | |
386 | |
387 /* decrease current window height */ | |
388 case '-': | |
389 #ifdef FEAT_GUI | |
390 need_mouse_correct = TRUE; | |
391 #endif | |
392 win_setheight(curwin->w_height - (int)Prenum1); | |
393 break; | |
394 | |
395 /* set current window height */ | |
396 case Ctrl__: | |
397 case '_': | |
398 #ifdef FEAT_GUI | |
399 need_mouse_correct = TRUE; | |
400 #endif | |
401 win_setheight(Prenum ? (int)Prenum : 9999); | |
402 break; | |
403 | |
404 /* increase current window width */ | |
405 case '>': | |
406 #ifdef FEAT_GUI | |
407 need_mouse_correct = TRUE; | |
408 #endif | |
409 win_setwidth(curwin->w_width + (int)Prenum1); | |
410 break; | |
411 | |
412 /* decrease current window width */ | |
413 case '<': | |
414 #ifdef FEAT_GUI | |
415 need_mouse_correct = TRUE; | |
416 #endif | |
417 win_setwidth(curwin->w_width - (int)Prenum1); | |
418 break; | |
419 | |
420 /* set current window width */ | |
421 case '|': | |
422 #ifdef FEAT_GUI | |
423 need_mouse_correct = TRUE; | |
424 #endif | |
425 win_setwidth(Prenum != 0 ? (int)Prenum : 9999); | |
426 break; | |
427 | |
428 /* jump to tag and split window if tag exists (in preview window) */ | |
429 #if defined(FEAT_QUICKFIX) | |
430 case '}': | |
431 CHECK_CMDWIN | |
432 if (Prenum) | |
433 g_do_tagpreview = Prenum; | |
434 else | |
435 g_do_tagpreview = p_pvh; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12564
diff
changeset
|
436 #endif |
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12564
diff
changeset
|
437 /* FALLTHROUGH */ |
7 | 438 case ']': |
439 case Ctrl_RSB: | |
440 CHECK_CMDWIN | |
6239 | 441 /* keep Visual mode, can select words to use as a tag */ |
7 | 442 if (Prenum) |
443 postponed_split = Prenum; | |
444 else | |
445 postponed_split = -1; | |
6251 | 446 #ifdef FEAT_QUICKFIX |
6264 | 447 if (nchar != '}') |
448 g_do_tagpreview = 0; | |
6251 | 449 #endif |
6239 | 450 |
451 /* Execute the command right here, required when "wincmd ]" | |
452 * was used in a function. */ | |
7 | 453 do_nv_ident(Ctrl_RSB, NUL); |
454 break; | |
455 | |
456 #ifdef FEAT_SEARCHPATH | |
457 /* edit file name under cursor in a new window */ | |
458 case 'f': | |
681 | 459 case 'F': |
7 | 460 case Ctrl_F: |
820 | 461 wingotofile: |
7 | 462 CHECK_CMDWIN |
344 | 463 |
681 | 464 ptr = grab_file_name(Prenum1, &lnum); |
7 | 465 if (ptr != NULL) |
466 { | |
9349
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
467 tabpage_T *oldtab = curtab; |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
468 win_T *oldwin = curwin; |
820 | 469 # ifdef FEAT_GUI |
7 | 470 need_mouse_correct = TRUE; |
820 | 471 # endif |
7 | 472 setpcmark(); |
473 if (win_split(0, 0) == OK) | |
474 { | |
2583 | 475 RESET_BINDING(curwin); |
9349
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
476 if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
477 ECMD_HIDE, NULL) == FAIL) |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
478 { |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
479 /* Failed to open the file, close the window |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
480 * opened for it. */ |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
481 win_close(curwin, FALSE); |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
482 goto_tabpage_win(oldtab, oldwin); |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
483 } |
b24900b73f90
commit https://github.com/vim/vim/commit/5d2ca0402954ff79b73d9c86cc16c8a6454b75a7
Christian Brabandt <cb@256bit.org>
parents:
9223
diff
changeset
|
484 else if (nchar == 'F' && lnum >= 0) |
681 | 485 { |
486 curwin->w_cursor.lnum = lnum; | |
487 check_cursor_lnum(); | |
488 beginline(BL_SOL | BL_FIX); | |
489 } | |
7 | 490 } |
491 vim_free(ptr); | |
492 } | |
493 break; | |
494 #endif | |
495 | |
496 #ifdef FEAT_FIND_ID | |
1187 | 497 /* Go to the first occurrence of the identifier under cursor along path in a |
7 | 498 * new window -- webb |
499 */ | |
500 case 'i': /* Go to any match */ | |
501 case Ctrl_I: | |
502 type = FIND_ANY; | |
503 /* FALLTHROUGH */ | |
504 case 'd': /* Go to definition, using 'define' */ | |
505 case Ctrl_D: | |
506 CHECK_CMDWIN | |
507 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
508 break; | |
509 find_pattern_in_path(ptr, 0, len, TRUE, | |
510 Prenum == 0 ? TRUE : FALSE, type, | |
511 Prenum1, ACTION_SPLIT, (linenr_T)1, (linenr_T)MAXLNUM); | |
512 curwin->w_set_curswant = TRUE; | |
513 break; | |
514 #endif | |
515 | |
170 | 516 case K_KENTER: |
517 case CAR: | |
518 #if defined(FEAT_QUICKFIX) | |
519 /* | |
520 * In a quickfix window a <CR> jumps to the error under the | |
521 * cursor in a new window. | |
522 */ | |
523 if (bt_quickfix(curbuf)) | |
524 { | |
643 | 525 sprintf((char *)cbuf, "split +%ld%s", |
526 (long)curwin->w_cursor.lnum, | |
527 (curwin->w_llist_ref == NULL) ? "cc" : "ll"); | |
170 | 528 do_cmdline_cmd(cbuf); |
529 } | |
530 #endif | |
531 break; | |
532 | |
533 | |
7 | 534 /* CTRL-W g extended commands */ |
535 case 'g': | |
536 case Ctrl_G: | |
537 CHECK_CMDWIN | |
538 #ifdef USE_ON_FLY_SCROLL | |
539 dont_scroll = TRUE; /* disallow scrolling here */ | |
540 #endif | |
541 ++no_mapping; | |
542 ++allow_keys; /* no mapping for xchar, but allow key codes */ | |
543 if (xchar == NUL) | |
1389 | 544 xchar = plain_vgetc(); |
7 | 545 LANGMAP_ADJUST(xchar, TRUE); |
546 --no_mapping; | |
547 --allow_keys; | |
548 #ifdef FEAT_CMDL_INFO | |
549 (void)add_to_showcmd(xchar); | |
550 #endif | |
551 switch (xchar) | |
552 { | |
553 #if defined(FEAT_QUICKFIX) | |
554 case '}': | |
555 xchar = Ctrl_RSB; | |
556 if (Prenum) | |
557 g_do_tagpreview = Prenum; | |
558 else | |
559 g_do_tagpreview = p_pvh; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12564
diff
changeset
|
560 #endif |
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12564
diff
changeset
|
561 /* FALLTHROUGH */ |
7 | 562 case ']': |
563 case Ctrl_RSB: | |
6239 | 564 /* keep Visual mode, can select words to use as a tag */ |
7 | 565 if (Prenum) |
566 postponed_split = Prenum; | |
567 else | |
568 postponed_split = -1; | |
569 | |
570 /* Execute the command right here, required when | |
571 * "wincmd g}" was used in a function. */ | |
572 do_nv_ident('g', xchar); | |
573 break; | |
574 | |
820 | 575 #ifdef FEAT_SEARCHPATH |
576 case 'f': /* CTRL-W gf: "gf" in a new tab page */ | |
839 | 577 case 'F': /* CTRL-W gF: "gF" in a new tab page */ |
2064
f398e0cc5b7a
updated for version 7.2.349
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
578 cmdmod.tab = tabpage_index(curtab) + 1; |
839 | 579 nchar = xchar; |
820 | 580 goto wingotofile; |
581 #endif | |
7 | 582 default: |
583 beep_flush(); | |
584 break; | |
585 } | |
586 break; | |
587 | |
588 default: beep_flush(); | |
589 break; | |
590 } | |
591 } | |
592 | |
6489 | 593 /* |
594 * Figure out the address type for ":wnncmd". | |
595 */ | |
596 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
597 get_wincmd_addr_type(char_u *arg, exarg_T *eap) |
6489 | 598 { |
599 switch (*arg) | |
600 { | |
601 case 'S': | |
602 case Ctrl_S: | |
603 case 's': | |
604 case Ctrl_N: | |
605 case 'n': | |
606 case 'j': | |
607 case Ctrl_J: | |
608 case 'k': | |
609 case Ctrl_K: | |
610 case 'T': | |
611 case Ctrl_R: | |
612 case 'r': | |
613 case 'R': | |
614 case 'K': | |
615 case 'J': | |
616 case '+': | |
617 case '-': | |
618 case Ctrl__: | |
619 case '_': | |
620 case '|': | |
621 case ']': | |
622 case Ctrl_RSB: | |
623 case 'g': | |
624 case Ctrl_G: | |
625 case Ctrl_V: | |
626 case 'v': | |
627 case 'h': | |
628 case Ctrl_H: | |
629 case 'l': | |
630 case Ctrl_L: | |
631 case 'H': | |
632 case 'L': | |
633 case '>': | |
634 case '<': | |
635 #if defined(FEAT_QUICKFIX) | |
636 case '}': | |
637 #endif | |
638 #ifdef FEAT_SEARCHPATH | |
639 case 'f': | |
640 case 'F': | |
641 case Ctrl_F: | |
642 #endif | |
643 #ifdef FEAT_FIND_ID | |
644 case 'i': | |
645 case Ctrl_I: | |
646 case 'd': | |
647 case Ctrl_D: | |
648 #endif | |
649 /* window size or any count */ | |
650 eap->addr_type = ADDR_LINES; | |
651 break; | |
652 | |
653 case Ctrl_HAT: | |
654 case '^': | |
655 /* buffer number */ | |
656 eap->addr_type = ADDR_BUFFERS; | |
657 break; | |
658 | |
659 case Ctrl_Q: | |
660 case 'q': | |
661 case Ctrl_C: | |
662 case 'c': | |
663 case Ctrl_O: | |
664 case 'o': | |
665 case Ctrl_W: | |
666 case 'w': | |
667 case 'W': | |
668 case 'x': | |
669 case Ctrl_X: | |
670 /* window number */ | |
671 eap->addr_type = ADDR_WINDOWS; | |
672 break; | |
673 | |
674 #if defined(FEAT_QUICKFIX) | |
675 case Ctrl_Z: | |
676 case 'z': | |
677 case 'P': | |
678 #endif | |
679 case 't': | |
680 case Ctrl_T: | |
681 case 'b': | |
682 case Ctrl_B: | |
683 case 'p': | |
684 case Ctrl_P: | |
685 case '=': | |
686 case CAR: | |
687 /* no count */ | |
688 eap->addr_type = 0; | |
689 break; | |
690 } | |
691 } | |
692 | |
6432 | 693 static void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
694 cmd_with_count( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
695 char *cmd, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
696 char_u *bufp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
697 size_t bufsize, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
698 long Prenum) |
6432 | 699 { |
700 size_t len = STRLEN(cmd); | |
701 | |
702 STRCPY(bufp, cmd); | |
703 if (Prenum > 0) | |
704 vim_snprintf((char *)bufp + len, bufsize - len, "%ld", Prenum); | |
705 } | |
706 | |
7 | 707 /* |
708 * split the current window, implements CTRL-W s and :split | |
709 * | |
710 * "size" is the height or width for the new window, 0 to use half of current | |
711 * height or width. | |
712 * | |
713 * "flags": | |
714 * WSP_ROOM: require enough room for new window | |
715 * WSP_VERT: vertical split. | |
716 * WSP_TOP: open window at the top-left of the shell (help window). | |
717 * WSP_BOT: open window at the bottom-right of the shell (quickfix window). | |
718 * WSP_HELP: creating the help window, keep layout snapshot | |
719 * | |
720 * return FAIL for failure, OK otherwise | |
721 */ | |
722 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
723 win_split(int size, int flags) |
7 | 724 { |
682 | 725 /* When the ":tab" modifier was used open a new tab page instead. */ |
726 if (may_open_tabpage() == OK) | |
727 return OK; | |
728 | |
7 | 729 /* Add flags from ":vertical", ":topleft" and ":botright". */ |
730 flags |= cmdmod.split; | |
731 if ((flags & WSP_TOP) && (flags & WSP_BOT)) | |
732 { | |
733 EMSG(_("E442: Can't split topleft and botright at the same time")); | |
734 return FAIL; | |
735 } | |
736 | |
737 /* When creating the help window make a snapshot of the window layout. | |
738 * Otherwise clear the snapshot, it's now invalid. */ | |
739 if (flags & WSP_HELP) | |
1906 | 740 make_snapshot(SNAP_HELP_IDX); |
7 | 741 else |
1906 | 742 clear_snapshot(curtab, SNAP_HELP_IDX); |
7 | 743 |
744 return win_split_ins(size, flags, NULL, 0); | |
745 } | |
746 | |
747 /* | |
3263 | 748 * When "new_wp" is NULL: split the current window in two. |
749 * When "new_wp" is not NULL: insert this window at the far | |
7 | 750 * top/left/right/bottom. |
751 * return FAIL for failure, OK otherwise | |
752 */ | |
1906 | 753 int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
754 win_split_ins( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
755 int size, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
756 int flags, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
757 win_T *new_wp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
758 int dir) |
7 | 759 { |
3263 | 760 win_T *wp = new_wp; |
7 | 761 win_T *oldwin; |
762 int new_size = size; | |
763 int i; | |
764 int need_status = 0; | |
765 int do_equal = FALSE; | |
766 int needed; | |
767 int available; | |
768 int oldwin_height = 0; | |
769 int layout; | |
6077 | 770 frame_T *frp, *curfrp, *frp2, *prevfrp; |
7 | 771 int before; |
6052 | 772 int minheight; |
6066 | 773 int wmh1; |
7 | 774 |
775 if (flags & WSP_TOP) | |
776 oldwin = firstwin; | |
777 else if (flags & WSP_BOT) | |
778 oldwin = lastwin; | |
779 else | |
780 oldwin = curwin; | |
781 | |
782 /* add a status line when p_ls == 1 and splitting the first window */ | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
783 if (ONE_WINDOW && p_ls == 1 && oldwin->w_status_height == 0) |
7 | 784 { |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
785 if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL) |
7 | 786 { |
787 EMSG(_(e_noroom)); | |
788 return FAIL; | |
789 } | |
790 need_status = STATUS_HEIGHT; | |
791 } | |
792 | |
1114 | 793 #ifdef FEAT_GUI |
794 /* May be needed for the scrollbars that are going to change. */ | |
795 if (gui.in_use) | |
796 out_flush(); | |
797 #endif | |
798 | |
7 | 799 if (flags & WSP_VERT) |
800 { | |
6068 | 801 int wmw1; |
802 int minwidth; | |
803 | |
7 | 804 layout = FR_ROW; |
805 | |
806 /* | |
807 * Check if we are able to split the current window and compute its | |
808 * width. | |
809 */ | |
6066 | 810 /* Current window requires at least 1 space. */ |
811 wmw1 = (p_wmw == 0 ? 1 : p_wmw); | |
812 needed = wmw1 + 1; | |
7 | 813 if (flags & WSP_ROOM) |
6066 | 814 needed += p_wiw - wmw1; |
6077 | 815 if (flags & (WSP_BOT | WSP_TOP)) |
7 | 816 { |
6066 | 817 minwidth = frame_minwidth(topframe, NOWIN); |
7 | 818 available = topframe->fr_width; |
6052 | 819 needed += minwidth; |
7 | 820 } |
6077 | 821 else if (p_ea) |
822 { | |
823 minwidth = frame_minwidth(oldwin->w_frame, NOWIN); | |
824 prevfrp = oldwin->w_frame; | |
825 for (frp = oldwin->w_frame->fr_parent; frp != NULL; | |
826 frp = frp->fr_parent) | |
827 { | |
828 if (frp->fr_layout == FR_ROW) | |
829 for (frp2 = frp->fr_child; frp2 != NULL; | |
830 frp2 = frp2->fr_next) | |
831 if (frp2 != prevfrp) | |
832 minwidth += frame_minwidth(frp2, NOWIN); | |
833 prevfrp = frp; | |
834 } | |
835 available = topframe->fr_width; | |
836 needed += minwidth; | |
837 } | |
7 | 838 else |
6052 | 839 { |
6066 | 840 minwidth = frame_minwidth(oldwin->w_frame, NOWIN); |
841 available = oldwin->w_frame->fr_width; | |
842 needed += minwidth; | |
6052 | 843 } |
3263 | 844 if (available < needed && new_wp == NULL) |
7 | 845 { |
846 EMSG(_(e_noroom)); | |
847 return FAIL; | |
848 } | |
849 if (new_size == 0) | |
850 new_size = oldwin->w_width / 2; | |
6052 | 851 if (new_size > available - minwidth - 1) |
852 new_size = available - minwidth - 1; | |
6066 | 853 if (new_size < wmw1) |
854 new_size = wmw1; | |
7 | 855 |
856 /* if it doesn't fit in the current window, need win_equal() */ | |
857 if (oldwin->w_width - new_size - 1 < p_wmw) | |
858 do_equal = TRUE; | |
779 | 859 |
860 /* We don't like to take lines for the new window from a | |
861 * 'winfixwidth' window. Take them from a window to the left or right | |
11207
e6140f3d2be7
patch 8.0.0490: vertical split makes 'winfixwidth' window smaller
Christian Brabandt <cb@256bit.org>
parents:
11199
diff
changeset
|
862 * instead, if possible. Add one for the separator. */ |
779 | 863 if (oldwin->w_p_wfw) |
11207
e6140f3d2be7
patch 8.0.0490: vertical split makes 'winfixwidth' window smaller
Christian Brabandt <cb@256bit.org>
parents:
11199
diff
changeset
|
864 win_setwidth_win(oldwin->w_width + new_size + 1, oldwin); |
1354 | 865 |
866 /* Only make all windows the same width if one of them (except oldwin) | |
867 * is wider than one of the split windows. */ | |
868 if (!do_equal && p_ea && size == 0 && *p_ead != 'v' | |
869 && oldwin->w_frame->fr_parent != NULL) | |
870 { | |
871 frp = oldwin->w_frame->fr_parent->fr_child; | |
872 while (frp != NULL) | |
873 { | |
874 if (frp->fr_win != oldwin && frp->fr_win != NULL | |
875 && (frp->fr_win->w_width > new_size | |
876 || frp->fr_win->w_width > oldwin->w_width | |
6373 | 877 - new_size - 1)) |
1354 | 878 { |
879 do_equal = TRUE; | |
880 break; | |
881 } | |
882 frp = frp->fr_next; | |
883 } | |
884 } | |
7 | 885 } |
886 else | |
887 { | |
888 layout = FR_COL; | |
889 | |
890 /* | |
891 * Check if we are able to split the current window and compute its | |
892 * height. | |
893 */ | |
6066 | 894 /* Current window requires at least 1 space. */ |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
895 wmh1 = (p_wmh == 0 ? 1 : p_wmh) + WINBAR_HEIGHT(curwin); |
6066 | 896 needed = wmh1 + STATUS_HEIGHT; |
7 | 897 if (flags & WSP_ROOM) |
6066 | 898 needed += p_wh - wmh1; |
6077 | 899 if (flags & (WSP_BOT | WSP_TOP)) |
7 | 900 { |
6066 | 901 minheight = frame_minheight(topframe, NOWIN) + need_status; |
7 | 902 available = topframe->fr_height; |
6052 | 903 needed += minheight; |
7 | 904 } |
6077 | 905 else if (p_ea) |
906 { | |
907 minheight = frame_minheight(oldwin->w_frame, NOWIN) + need_status; | |
908 prevfrp = oldwin->w_frame; | |
909 for (frp = oldwin->w_frame->fr_parent; frp != NULL; | |
910 frp = frp->fr_parent) | |
911 { | |
912 if (frp->fr_layout == FR_COL) | |
913 for (frp2 = frp->fr_child; frp2 != NULL; | |
914 frp2 = frp2->fr_next) | |
915 if (frp2 != prevfrp) | |
916 minheight += frame_minheight(frp2, NOWIN); | |
917 prevfrp = frp; | |
918 } | |
919 available = topframe->fr_height; | |
920 needed += minheight; | |
921 } | |
7 | 922 else |
923 { | |
6066 | 924 minheight = frame_minheight(oldwin->w_frame, NOWIN) + need_status; |
925 available = oldwin->w_frame->fr_height; | |
926 needed += minheight; | |
7 | 927 } |
3263 | 928 if (available < needed && new_wp == NULL) |
7 | 929 { |
930 EMSG(_(e_noroom)); | |
931 return FAIL; | |
932 } | |
933 oldwin_height = oldwin->w_height; | |
934 if (need_status) | |
935 { | |
936 oldwin->w_status_height = STATUS_HEIGHT; | |
937 oldwin_height -= STATUS_HEIGHT; | |
938 } | |
939 if (new_size == 0) | |
940 new_size = oldwin_height / 2; | |
6052 | 941 if (new_size > available - minheight - STATUS_HEIGHT) |
942 new_size = available - minheight - STATUS_HEIGHT; | |
6066 | 943 if (new_size < wmh1) |
944 new_size = wmh1; | |
7 | 945 |
946 /* if it doesn't fit in the current window, need win_equal() */ | |
947 if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh) | |
948 do_equal = TRUE; | |
949 | |
950 /* We don't like to take lines for the new window from a | |
951 * 'winfixheight' window. Take them from a window above or below | |
952 * instead, if possible. */ | |
953 if (oldwin->w_p_wfh) | |
954 { | |
955 win_setheight_win(oldwin->w_height + new_size + STATUS_HEIGHT, | |
956 oldwin); | |
957 oldwin_height = oldwin->w_height; | |
958 if (need_status) | |
959 oldwin_height -= STATUS_HEIGHT; | |
960 } | |
1354 | 961 |
962 /* Only make all windows the same height if one of them (except oldwin) | |
963 * is higher than one of the split windows. */ | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
964 if (!do_equal && p_ea && size == 0 && *p_ead != 'h' |
1354 | 965 && oldwin->w_frame->fr_parent != NULL) |
966 { | |
967 frp = oldwin->w_frame->fr_parent->fr_child; | |
968 while (frp != NULL) | |
969 { | |
970 if (frp->fr_win != oldwin && frp->fr_win != NULL | |
971 && (frp->fr_win->w_height > new_size | |
972 || frp->fr_win->w_height > oldwin_height - new_size | |
973 - STATUS_HEIGHT)) | |
974 { | |
975 do_equal = TRUE; | |
976 break; | |
977 } | |
978 frp = frp->fr_next; | |
979 } | |
980 } | |
7 | 981 } |
982 | |
983 /* | |
984 * allocate new window structure and link it in the window list | |
985 */ | |
986 if ((flags & WSP_TOP) == 0 | |
987 && ((flags & WSP_BOT) | |
988 || (flags & WSP_BELOW) | |
989 || (!(flags & WSP_ABOVE) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
990 && ( (flags & WSP_VERT) ? p_spr : p_sb)))) |
7 | 991 { |
992 /* new window below/right of current one */ | |
3263 | 993 if (new_wp == NULL) |
1906 | 994 wp = win_alloc(oldwin, FALSE); |
7 | 995 else |
996 win_append(oldwin, wp); | |
997 } | |
998 else | |
999 { | |
3263 | 1000 if (new_wp == NULL) |
1906 | 1001 wp = win_alloc(oldwin->w_prev, FALSE); |
7 | 1002 else |
1003 win_append(oldwin->w_prev, wp); | |
1004 } | |
1005 | |
3263 | 1006 if (new_wp == NULL) |
7 | 1007 { |
1008 if (wp == NULL) | |
1009 return FAIL; | |
1010 | |
1906 | 1011 new_frame(wp); |
1012 if (wp->w_frame == NULL) | |
1013 { | |
1014 win_free(wp, NULL); | |
1015 return FAIL; | |
1016 } | |
1017 | |
675 | 1018 /* make the contents of the new window the same as the current one */ |
1822 | 1019 win_init(wp, curwin, flags); |
7 | 1020 } |
1021 | |
1022 /* | |
1023 * Reorganise the tree of frames to insert the new window. | |
1024 */ | |
1025 if (flags & (WSP_TOP | WSP_BOT)) | |
1026 { | |
1027 if ((topframe->fr_layout == FR_COL && (flags & WSP_VERT) == 0) | |
1028 || (topframe->fr_layout == FR_ROW && (flags & WSP_VERT) != 0)) | |
1029 { | |
1030 curfrp = topframe->fr_child; | |
1031 if (flags & WSP_BOT) | |
1032 while (curfrp->fr_next != NULL) | |
1033 curfrp = curfrp->fr_next; | |
1034 } | |
1035 else | |
1036 curfrp = topframe; | |
1037 before = (flags & WSP_TOP); | |
1038 } | |
1039 else | |
1040 { | |
1041 curfrp = oldwin->w_frame; | |
1042 if (flags & WSP_BELOW) | |
1043 before = FALSE; | |
1044 else if (flags & WSP_ABOVE) | |
1045 before = TRUE; | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1046 else if (flags & WSP_VERT) |
7 | 1047 before = !p_spr; |
1048 else | |
1049 before = !p_sb; | |
1050 } | |
1051 if (curfrp->fr_parent == NULL || curfrp->fr_parent->fr_layout != layout) | |
1052 { | |
1053 /* Need to create a new frame in the tree to make a branch. */ | |
1054 frp = (frame_T *)alloc_clear((unsigned)sizeof(frame_T)); | |
1055 *frp = *curfrp; | |
1056 curfrp->fr_layout = layout; | |
1057 frp->fr_parent = curfrp; | |
1058 frp->fr_next = NULL; | |
1059 frp->fr_prev = NULL; | |
1060 curfrp->fr_child = frp; | |
1061 curfrp->fr_win = NULL; | |
1062 curfrp = frp; | |
1063 if (frp->fr_win != NULL) | |
1064 oldwin->w_frame = frp; | |
1065 else | |
1066 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
1067 frp->fr_parent = curfrp; | |
1068 } | |
1069 | |
3263 | 1070 if (new_wp == NULL) |
1906 | 1071 frp = wp->w_frame; |
7 | 1072 else |
3263 | 1073 frp = new_wp->w_frame; |
7 | 1074 frp->fr_parent = curfrp->fr_parent; |
1075 | |
1076 /* Insert the new frame at the right place in the frame list. */ | |
1077 if (before) | |
1078 frame_insert(curfrp, frp); | |
1079 else | |
1080 frame_append(curfrp, frp); | |
1081 | |
2665 | 1082 /* Set w_fraction now so that the cursor keeps the same relative |
1083 * vertical position. */ | |
12910
d21adefd4a50
patch 8.0.1331: possible crash when window can be zero lines high
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1084 set_fraction(oldwin); |
2665 | 1085 wp->w_fraction = oldwin->w_fraction; |
1086 | |
7 | 1087 if (flags & WSP_VERT) |
1088 { | |
1089 wp->w_p_scr = curwin->w_p_scr; | |
2665 | 1090 |
7 | 1091 if (need_status) |
1092 { | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1093 win_new_height(oldwin, oldwin->w_height - 1); |
7 | 1094 oldwin->w_status_height = need_status; |
1095 } | |
1096 if (flags & (WSP_TOP | WSP_BOT)) | |
1097 { | |
1098 /* set height and row of new window to full height */ | |
685 | 1099 wp->w_winrow = tabline_height(); |
12491
7ab796b041bd
patch 8.0.1125: wrong window height when splitting window with window toolbar
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
1100 win_new_height(wp, curfrp->fr_height - (p_ls > 0) |
12916
af2e0401eb8c
patch 8.0.1334: splitting a window with a WinBar damages window layout
Christian Brabandt <cb@256bit.org>
parents:
12910
diff
changeset
|
1101 - WINBAR_HEIGHT(wp)); |
7 | 1102 wp->w_status_height = (p_ls > 0); |
1103 } | |
1104 else | |
1105 { | |
1106 /* height and row of new window is same as current window */ | |
1107 wp->w_winrow = oldwin->w_winrow; | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
1108 win_new_height(wp, VISIBLE_HEIGHT(oldwin)); |
7 | 1109 wp->w_status_height = oldwin->w_status_height; |
1110 } | |
1111 frp->fr_height = curfrp->fr_height; | |
1112 | |
1113 /* "new_size" of the current window goes to the new window, use | |
1114 * one column for the vertical separator */ | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1115 win_new_width(wp, new_size); |
7 | 1116 if (before) |
1117 wp->w_vsep_width = 1; | |
1118 else | |
1119 { | |
1120 wp->w_vsep_width = oldwin->w_vsep_width; | |
1121 oldwin->w_vsep_width = 1; | |
1122 } | |
1123 if (flags & (WSP_TOP | WSP_BOT)) | |
1124 { | |
1125 if (flags & WSP_BOT) | |
1126 frame_add_vsep(curfrp); | |
1127 /* Set width of neighbor frame */ | |
1128 frame_new_width(curfrp, curfrp->fr_width | |
779 | 1129 - (new_size + ((flags & WSP_TOP) != 0)), flags & WSP_TOP, |
1130 FALSE); | |
7 | 1131 } |
1132 else | |
779 | 1133 win_new_width(oldwin, oldwin->w_width - (new_size + 1)); |
7 | 1134 if (before) /* new window left of current one */ |
1135 { | |
1136 wp->w_wincol = oldwin->w_wincol; | |
1137 oldwin->w_wincol += new_size + 1; | |
1138 } | |
1139 else /* new window right of current one */ | |
1140 wp->w_wincol = oldwin->w_wincol + oldwin->w_width + 1; | |
1141 frame_fix_width(oldwin); | |
1142 frame_fix_width(wp); | |
1143 } | |
1144 else | |
1145 { | |
1146 /* width and column of new window is same as current window */ | |
1147 if (flags & (WSP_TOP | WSP_BOT)) | |
1148 { | |
1149 wp->w_wincol = 0; | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1150 win_new_width(wp, Columns); |
7 | 1151 wp->w_vsep_width = 0; |
1152 } | |
1153 else | |
1154 { | |
1155 wp->w_wincol = oldwin->w_wincol; | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1156 win_new_width(wp, oldwin->w_width); |
7 | 1157 wp->w_vsep_width = oldwin->w_vsep_width; |
1158 } | |
1159 frp->fr_width = curfrp->fr_width; | |
1160 | |
1161 /* "new_size" of the current window goes to the new window, use | |
1162 * one row for the status line */ | |
1163 win_new_height(wp, new_size); | |
1164 if (flags & (WSP_TOP | WSP_BOT)) | |
9102
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1165 { |
12491
7ab796b041bd
patch 8.0.1125: wrong window height when splitting window with window toolbar
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
1166 int new_fr_height = curfrp->fr_height - new_size |
12916
af2e0401eb8c
patch 8.0.1334: splitting a window with a WinBar damages window layout
Christian Brabandt <cb@256bit.org>
parents:
12910
diff
changeset
|
1167 + WINBAR_HEIGHT(wp) ; |
9102
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1168 |
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1169 if (!((flags & WSP_BOT) && p_ls == 0)) |
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1170 new_fr_height -= STATUS_HEIGHT; |
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1171 frame_new_height(curfrp, new_fr_height, flags & WSP_TOP, FALSE); |
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1172 } |
7 | 1173 else |
1174 win_new_height(oldwin, oldwin_height - (new_size + STATUS_HEIGHT)); | |
1175 if (before) /* new window above current one */ | |
1176 { | |
1177 wp->w_winrow = oldwin->w_winrow; | |
1178 wp->w_status_height = STATUS_HEIGHT; | |
1179 oldwin->w_winrow += wp->w_height + STATUS_HEIGHT; | |
1180 } | |
1181 else /* new window below current one */ | |
1182 { | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
1183 wp->w_winrow = oldwin->w_winrow + VISIBLE_HEIGHT(oldwin) |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
1184 + STATUS_HEIGHT; |
7 | 1185 wp->w_status_height = oldwin->w_status_height; |
9102
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1186 if (!(flags & WSP_BOT)) |
0e90f3e13d88
commit https://github.com/vim/vim/commit/991dea3ab185fb35e577ab0bdfd443cd4b43ccc6
Christian Brabandt <cb@256bit.org>
parents:
8833
diff
changeset
|
1187 oldwin->w_status_height = STATUS_HEIGHT; |
7 | 1188 } |
1189 if (flags & WSP_BOT) | |
1190 frame_add_statusline(curfrp); | |
1191 frame_fix_height(wp); | |
1192 frame_fix_height(oldwin); | |
1193 } | |
1194 | |
1195 if (flags & (WSP_TOP | WSP_BOT)) | |
1196 (void)win_comp_pos(); | |
1197 | |
1198 /* | |
1199 * Both windows need redrawing | |
1200 */ | |
1201 redraw_win_later(wp, NOT_VALID); | |
1202 wp->w_redr_status = TRUE; | |
1203 redraw_win_later(oldwin, NOT_VALID); | |
1204 oldwin->w_redr_status = TRUE; | |
1205 | |
1206 if (need_status) | |
1207 { | |
1208 msg_row = Rows - 1; | |
1209 msg_col = sc_col; | |
1210 msg_clr_eos_force(); /* Old command/ruler may still be there */ | |
1211 comp_col(); | |
1212 msg_row = Rows - 1; | |
1213 msg_col = 0; /* put position back at start of line */ | |
1214 } | |
1215 | |
1216 /* | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1217 * equalize the window sizes. |
7 | 1218 */ |
1219 if (do_equal || dir != 0) | |
1220 win_equal(wp, TRUE, | |
1221 (flags & WSP_VERT) ? (dir == 'v' ? 'b' : 'h') | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1222 : dir == 'h' ? 'b' : 'v'); |
7 | 1223 |
1224 /* Don't change the window height/width to 'winheight' / 'winwidth' if a | |
1225 * size was given. */ | |
1226 if (flags & WSP_VERT) | |
1227 { | |
1228 i = p_wiw; | |
1229 if (size != 0) | |
1230 p_wiw = size; | |
1231 | |
1232 # ifdef FEAT_GUI | |
1233 /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */ | |
1234 if (gui.in_use) | |
1235 gui_init_which_components(NULL); | |
1236 # endif | |
1237 } | |
1238 else | |
1239 { | |
1240 i = p_wh; | |
1241 if (size != 0) | |
1242 p_wh = size; | |
1243 } | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1244 |
6096 | 1245 #ifdef FEAT_JUMPLIST |
1246 /* Keep same changelist position in new window. */ | |
1247 wp->w_changelistidx = oldwin->w_changelistidx; | |
1248 #endif | |
1249 | |
2115
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1250 /* |
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1251 * make the new window the current window |
5fd44cf99b6d
updated for version 7.2.398
Bram Moolenaar <bram@zimbu.org>
parents:
2064
diff
changeset
|
1252 */ |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1253 win_enter_ext(wp, FALSE, FALSE, TRUE, TRUE, TRUE); |
7 | 1254 if (flags & WSP_VERT) |
1255 p_wiw = i; | |
1256 else | |
1257 p_wh = i; | |
1258 | |
1259 return OK; | |
1260 } | |
1261 | |
1906 | 1262 |
675 | 1263 /* |
1264 * Initialize window "newp" from window "oldp". | |
1265 * Used when splitting a window and when creating a new tab page. | |
1266 * The windows will both edit the same buffer. | |
1822 | 1267 * WSP_NEWLOC may be specified in flags to prevent the location list from |
1268 * being copied. | |
675 | 1269 */ |
1270 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1271 win_init(win_T *newp, win_T *oldp, int flags UNUSED) |
675 | 1272 { |
1273 int i; | |
1274 | |
1275 newp->w_buffer = oldp->w_buffer; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1276 #ifdef FEAT_SYN_HL |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
1277 newp->w_s = &(oldp->w_buffer->b_s); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1278 #endif |
675 | 1279 oldp->w_buffer->b_nwindows++; |
1280 newp->w_cursor = oldp->w_cursor; | |
1281 newp->w_valid = 0; | |
1282 newp->w_curswant = oldp->w_curswant; | |
1283 newp->w_set_curswant = oldp->w_set_curswant; | |
1284 newp->w_topline = oldp->w_topline; | |
1285 #ifdef FEAT_DIFF | |
1286 newp->w_topfill = oldp->w_topfill; | |
1287 #endif | |
1288 newp->w_leftcol = oldp->w_leftcol; | |
1289 newp->w_pcmark = oldp->w_pcmark; | |
1290 newp->w_prev_pcmark = oldp->w_prev_pcmark; | |
1291 newp->w_alt_fnum = oldp->w_alt_fnum; | |
826 | 1292 newp->w_wrow = oldp->w_wrow; |
675 | 1293 newp->w_fraction = oldp->w_fraction; |
1294 newp->w_prev_fraction_row = oldp->w_prev_fraction_row; | |
1295 #ifdef FEAT_JUMPLIST | |
1296 copy_jumplist(oldp, newp); | |
1297 #endif | |
1298 #ifdef FEAT_QUICKFIX | |
1822 | 1299 if (flags & WSP_NEWLOC) |
1300 { | |
1301 /* Don't copy the location list. */ | |
1302 newp->w_llist = NULL; | |
1303 newp->w_llist_ref = NULL; | |
1304 } | |
1305 else | |
1306 copy_loclist(oldp, newp); | |
675 | 1307 #endif |
5584 | 1308 newp->w_localdir = (oldp->w_localdir == NULL) |
1309 ? NULL : vim_strsave(oldp->w_localdir); | |
675 | 1310 |
1906 | 1311 /* copy tagstack and folds */ |
675 | 1312 for (i = 0; i < oldp->w_tagstacklen; i++) |
1313 { | |
1314 newp->w_tagstack[i] = oldp->w_tagstack[i]; | |
1315 if (newp->w_tagstack[i].tagname != NULL) | |
1316 newp->w_tagstack[i].tagname = | |
1317 vim_strsave(newp->w_tagstack[i].tagname); | |
1318 } | |
1319 newp->w_tagstackidx = oldp->w_tagstackidx; | |
1320 newp->w_tagstacklen = oldp->w_tagstacklen; | |
3068 | 1321 #ifdef FEAT_FOLDING |
675 | 1322 copyFoldingState(oldp, newp); |
3068 | 1323 #endif |
1906 | 1324 |
1325 win_init_some(newp, oldp); | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2306
diff
changeset
|
1326 |
3068 | 1327 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2306
diff
changeset
|
1328 check_colorcolumn(newp); |
3068 | 1329 #endif |
1906 | 1330 } |
1331 | |
1332 /* | |
6222 | 1333 * Initialize window "newp" from window "old". |
1906 | 1334 * Only the essential things are copied. |
1335 */ | |
1336 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1337 win_init_some(win_T *newp, win_T *oldp) |
1906 | 1338 { |
1339 /* Use the same argument list. */ | |
1340 newp->w_alist = oldp->w_alist; | |
1341 ++newp->w_alist->al_refcount; | |
1342 newp->w_arg_idx = oldp->w_arg_idx; | |
1343 | |
1344 /* copy options from existing window */ | |
1345 win_copy_options(oldp, newp); | |
675 | 1346 } |
1347 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
1348 |
7 | 1349 /* |
9875
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1350 * Check if "win" is a pointer to an existing window in the current tab page. |
7 | 1351 */ |
1352 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1353 win_valid(win_T *win) |
7 | 1354 { |
1355 win_T *wp; | |
1356 | |
1357 if (win == NULL) | |
1358 return FALSE; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
1359 FOR_ALL_WINDOWS(wp) |
7 | 1360 if (wp == win) |
1361 return TRUE; | |
1362 return FALSE; | |
1363 } | |
1364 | |
1365 /* | |
9875
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1366 * Check if "win" is a pointer to an existing window in any tab page. |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1367 */ |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1368 int |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1369 win_valid_any_tab(win_T *win) |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1370 { |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1371 win_T *wp; |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1372 tabpage_T *tp; |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1373 |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1374 if (win == NULL) |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1375 return FALSE; |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1376 FOR_ALL_TABPAGES(tp) |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1377 { |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1378 FOR_ALL_WINDOWS_IN_TAB(tp, wp) |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1379 { |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1380 if (wp == win) |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1381 return TRUE; |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1382 } |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1383 } |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1384 return FALSE; |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1385 } |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1386 |
42adbf172ecd
commit https://github.com/vim/vim/commit/e59215c7dcae17b03daf39517560cfaa03314f5a
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1387 /* |
7 | 1388 * Return the number of windows. |
1389 */ | |
1390 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1391 win_count(void) |
7 | 1392 { |
1393 win_T *wp; | |
1394 int count = 0; | |
1395 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
1396 FOR_ALL_WINDOWS(wp) |
7 | 1397 ++count; |
1398 return count; | |
1399 } | |
1400 | |
1401 /* | |
1402 * Make "count" windows on the screen. | |
1403 * Return actual number of windows on the screen. | |
1404 * Must be called when there is just one window, filling the whole screen | |
1405 * (excluding the command line). | |
1406 */ | |
1407 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1408 make_windows( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1409 int count, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1410 int vertical UNUSED) /* split windows vertically if TRUE */ |
7 | 1411 { |
1412 int maxcount; | |
1413 int todo; | |
1414 | |
1415 if (vertical) | |
1416 { | |
1417 /* Each windows needs at least 'winminwidth' lines and a separator | |
1418 * column. */ | |
1419 maxcount = (curwin->w_width + curwin->w_vsep_width | |
1420 - (p_wiw - p_wmw)) / (p_wmw + 1); | |
1421 } | |
1422 else | |
1423 { | |
1424 /* Each window needs at least 'winminheight' lines and a status line. */ | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
1425 maxcount = (VISIBLE_HEIGHT(curwin) + curwin->w_status_height |
7 | 1426 - (p_wh - p_wmh)) / (p_wmh + STATUS_HEIGHT); |
1427 } | |
1428 | |
1429 if (maxcount < 2) | |
1430 maxcount = 2; | |
1431 if (count > maxcount) | |
1432 count = maxcount; | |
1433 | |
1434 /* | |
1435 * add status line now, otherwise first window will be too big | |
1436 */ | |
1437 if (count > 1) | |
1438 last_status(TRUE); | |
1439 | |
1440 #ifdef FEAT_AUTOCMD | |
1441 /* | |
1442 * Don't execute autocommands while creating the windows. Must do that | |
1443 * when putting the buffers in the windows. | |
1444 */ | |
1410 | 1445 block_autocmds(); |
7 | 1446 #endif |
1447 | |
1448 /* todo is number of windows left to create */ | |
1449 for (todo = count - 1; todo > 0; --todo) | |
1450 if (vertical) | |
1451 { | |
1452 if (win_split(curwin->w_width - (curwin->w_width - todo) | |
1453 / (todo + 1) - 1, WSP_VERT | WSP_ABOVE) == FAIL) | |
1454 break; | |
1455 } | |
1456 else | |
1457 { | |
1458 if (win_split(curwin->w_height - (curwin->w_height - todo | |
1459 * STATUS_HEIGHT) / (todo + 1) | |
1460 - STATUS_HEIGHT, WSP_ABOVE) == FAIL) | |
1461 break; | |
1462 } | |
1463 | |
1464 #ifdef FEAT_AUTOCMD | |
1410 | 1465 unblock_autocmds(); |
7 | 1466 #endif |
1467 | |
1468 /* return actual number of windows */ | |
1469 return (count - todo); | |
1470 } | |
1471 | |
1472 /* | |
1473 * Exchange current and next window | |
1474 */ | |
1475 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1476 win_exchange(long Prenum) |
7 | 1477 { |
1478 frame_T *frp; | |
1479 frame_T *frp2; | |
1480 win_T *wp; | |
1481 win_T *wp2; | |
1482 int temp; | |
1483 | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
1484 if (ONE_WINDOW) /* just one window */ |
7 | 1485 { |
1486 beep_flush(); | |
1487 return; | |
1488 } | |
1489 | |
1490 #ifdef FEAT_GUI | |
1491 need_mouse_correct = TRUE; | |
1492 #endif | |
1493 | |
1494 /* | |
1495 * find window to exchange with | |
1496 */ | |
1497 if (Prenum) | |
1498 { | |
1499 frp = curwin->w_frame->fr_parent->fr_child; | |
1500 while (frp != NULL && --Prenum > 0) | |
1501 frp = frp->fr_next; | |
1502 } | |
1503 else if (curwin->w_frame->fr_next != NULL) /* Swap with next */ | |
1504 frp = curwin->w_frame->fr_next; | |
1505 else /* Swap last window in row/col with previous */ | |
1506 frp = curwin->w_frame->fr_prev; | |
1507 | |
1508 /* We can only exchange a window with another window, not with a frame | |
1509 * containing windows. */ | |
1510 if (frp == NULL || frp->fr_win == NULL || frp->fr_win == curwin) | |
1511 return; | |
1512 wp = frp->fr_win; | |
1513 | |
1514 /* | |
1515 * 1. remove curwin from the list. Remember after which window it was in wp2 | |
1516 * 2. insert curwin before wp in the list | |
1517 * if wp != wp2 | |
1518 * 3. remove wp from the list | |
1519 * 4. insert wp after wp2 | |
1520 * 5. exchange the status line height and vsep width. | |
1521 */ | |
1522 wp2 = curwin->w_prev; | |
1523 frp2 = curwin->w_frame->fr_prev; | |
1524 if (wp->w_prev != curwin) | |
1525 { | |
671 | 1526 win_remove(curwin, NULL); |
7 | 1527 frame_remove(curwin->w_frame); |
1528 win_append(wp->w_prev, curwin); | |
1529 frame_insert(frp, curwin->w_frame); | |
1530 } | |
1531 if (wp != wp2) | |
1532 { | |
671 | 1533 win_remove(wp, NULL); |
7 | 1534 frame_remove(wp->w_frame); |
1535 win_append(wp2, wp); | |
1536 if (frp2 == NULL) | |
1537 frame_insert(wp->w_frame->fr_parent->fr_child, wp->w_frame); | |
1538 else | |
1539 frame_append(frp2, wp->w_frame); | |
1540 } | |
1541 temp = curwin->w_status_height; | |
1542 curwin->w_status_height = wp->w_status_height; | |
1543 wp->w_status_height = temp; | |
1544 temp = curwin->w_vsep_width; | |
1545 curwin->w_vsep_width = wp->w_vsep_width; | |
1546 wp->w_vsep_width = temp; | |
1547 | |
1548 /* If the windows are not in the same frame, exchange the sizes to avoid | |
1549 * messing up the window layout. Otherwise fix the frame sizes. */ | |
1550 if (curwin->w_frame->fr_parent != wp->w_frame->fr_parent) | |
1551 { | |
1552 temp = curwin->w_height; | |
1553 curwin->w_height = wp->w_height; | |
1554 wp->w_height = temp; | |
1555 temp = curwin->w_width; | |
1556 curwin->w_width = wp->w_width; | |
1557 wp->w_width = temp; | |
1558 } | |
1559 else | |
1560 { | |
1561 frame_fix_height(curwin); | |
1562 frame_fix_height(wp); | |
1563 frame_fix_width(curwin); | |
1564 frame_fix_width(wp); | |
1565 } | |
1566 | |
1567 (void)win_comp_pos(); /* recompute window positions */ | |
1568 | |
1569 win_enter(wp, TRUE); | |
1570 redraw_later(CLEAR); | |
1571 } | |
1572 | |
1573 /* | |
1574 * rotate windows: if upwards TRUE the second window becomes the first one | |
1575 * if upwards FALSE the first window becomes the second one | |
1576 */ | |
1577 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1578 win_rotate(int upwards, int count) |
7 | 1579 { |
1580 win_T *wp1; | |
1581 win_T *wp2; | |
1582 frame_T *frp; | |
1583 int n; | |
1584 | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
1585 if (ONE_WINDOW) /* nothing to do */ |
7 | 1586 { |
1587 beep_flush(); | |
1588 return; | |
1589 } | |
1590 | |
1591 #ifdef FEAT_GUI | |
1592 need_mouse_correct = TRUE; | |
1593 #endif | |
1594 | |
1595 /* Check if all frames in this row/col have one window. */ | |
1596 for (frp = curwin->w_frame->fr_parent->fr_child; frp != NULL; | |
1597 frp = frp->fr_next) | |
1598 if (frp->fr_win == NULL) | |
1599 { | |
1600 EMSG(_("E443: Cannot rotate when another window is split")); | |
1601 return; | |
1602 } | |
1603 | |
1604 while (count--) | |
1605 { | |
1606 if (upwards) /* first window becomes last window */ | |
1607 { | |
1608 /* remove first window/frame from the list */ | |
1609 frp = curwin->w_frame->fr_parent->fr_child; | |
1610 wp1 = frp->fr_win; | |
671 | 1611 win_remove(wp1, NULL); |
7 | 1612 frame_remove(frp); |
1613 | |
1614 /* find last frame and append removed window/frame after it */ | |
1615 for ( ; frp->fr_next != NULL; frp = frp->fr_next) | |
1616 ; | |
1617 win_append(frp->fr_win, wp1); | |
1618 frame_append(frp, wp1->w_frame); | |
1619 | |
1620 wp2 = frp->fr_win; /* previously last window */ | |
1621 } | |
1622 else /* last window becomes first window */ | |
1623 { | |
1624 /* find last window/frame in the list and remove it */ | |
1625 for (frp = curwin->w_frame; frp->fr_next != NULL; | |
1626 frp = frp->fr_next) | |
1627 ; | |
1628 wp1 = frp->fr_win; | |
1629 wp2 = wp1->w_prev; /* will become last window */ | |
671 | 1630 win_remove(wp1, NULL); |
7 | 1631 frame_remove(frp); |
1632 | |
1633 /* append the removed window/frame before the first in the list */ | |
1634 win_append(frp->fr_parent->fr_child->fr_win->w_prev, wp1); | |
1635 frame_insert(frp->fr_parent->fr_child, frp); | |
1636 } | |
1637 | |
1638 /* exchange status height and vsep width of old and new last window */ | |
1639 n = wp2->w_status_height; | |
1640 wp2->w_status_height = wp1->w_status_height; | |
1641 wp1->w_status_height = n; | |
1642 frame_fix_height(wp1); | |
1643 frame_fix_height(wp2); | |
1644 n = wp2->w_vsep_width; | |
1645 wp2->w_vsep_width = wp1->w_vsep_width; | |
1646 wp1->w_vsep_width = n; | |
1647 frame_fix_width(wp1); | |
1648 frame_fix_width(wp2); | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1649 |
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1650 /* recompute w_winrow and w_wincol for all windows */ |
7 | 1651 (void)win_comp_pos(); |
1652 } | |
1653 | |
1654 redraw_later(CLEAR); | |
1655 } | |
1656 | |
1657 /* | |
1658 * Move the current window to the very top/bottom/left/right of the screen. | |
1659 */ | |
1660 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1661 win_totop(int size, int flags) |
7 | 1662 { |
1663 int dir; | |
1664 int height = curwin->w_height; | |
1665 | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
1666 if (ONE_WINDOW) |
7 | 1667 { |
1668 beep_flush(); | |
1669 return; | |
1670 } | |
1671 | |
1672 /* Remove the window and frame from the tree of frames. */ | |
671 | 1673 (void)winframe_remove(curwin, &dir, NULL); |
1674 win_remove(curwin, NULL); | |
7 | 1675 last_status(FALSE); /* may need to remove last status line */ |
1676 (void)win_comp_pos(); /* recompute window positions */ | |
1677 | |
1678 /* Split a window on the desired side and put the window there. */ | |
1679 (void)win_split_ins(size, flags, curwin, dir); | |
1680 if (!(flags & WSP_VERT)) | |
1681 { | |
1682 win_setheight(height); | |
1683 if (p_ea) | |
1684 win_equal(curwin, TRUE, 'v'); | |
1685 } | |
1686 | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1687 #if defined(FEAT_GUI) |
7 | 1688 /* When 'guioptions' includes 'L' or 'R' may have to remove or add |
1689 * scrollbars. Have to update them anyway. */ | |
1906 | 1690 gui_may_update_scrollbars(); |
1691 #endif | |
7 | 1692 } |
1693 | |
1694 /* | |
1695 * Move window "win1" to below/right of "win2" and make "win1" the current | |
1696 * window. Only works within the same frame! | |
1697 */ | |
1698 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1699 win_move_after(win_T *win1, win_T *win2) |
7 | 1700 { |
1701 int height; | |
1702 | |
1703 /* check if the arguments are reasonable */ | |
1704 if (win1 == win2) | |
1705 return; | |
1706 | |
1707 /* check if there is something to do */ | |
1708 if (win2->w_next != win1) | |
1709 { | |
1710 /* may need move the status line/vertical separator of the last window | |
1711 * */ | |
1712 if (win1 == lastwin) | |
1713 { | |
1714 height = win1->w_prev->w_status_height; | |
1715 win1->w_prev->w_status_height = win1->w_status_height; | |
1716 win1->w_status_height = height; | |
1070 | 1717 if (win1->w_prev->w_vsep_width == 1) |
1718 { | |
1719 /* Remove the vertical separator from the last-but-one window, | |
1720 * add it to the last window. Adjust the frame widths. */ | |
1721 win1->w_prev->w_vsep_width = 0; | |
1722 win1->w_prev->w_frame->fr_width -= 1; | |
1723 win1->w_vsep_width = 1; | |
1724 win1->w_frame->fr_width += 1; | |
1725 } | |
7 | 1726 } |
1727 else if (win2 == lastwin) | |
1728 { | |
1729 height = win1->w_status_height; | |
1730 win1->w_status_height = win2->w_status_height; | |
1731 win2->w_status_height = height; | |
1070 | 1732 if (win1->w_vsep_width == 1) |
1733 { | |
1734 /* Remove the vertical separator from win1, add it to the last | |
1735 * window, win2. Adjust the frame widths. */ | |
1736 win2->w_vsep_width = 1; | |
1737 win2->w_frame->fr_width += 1; | |
1738 win1->w_vsep_width = 0; | |
1739 win1->w_frame->fr_width -= 1; | |
1740 } | |
7 | 1741 } |
671 | 1742 win_remove(win1, NULL); |
7 | 1743 frame_remove(win1->w_frame); |
1744 win_append(win2, win1); | |
1745 frame_append(win2->w_frame, win1->w_frame); | |
1746 | |
1747 (void)win_comp_pos(); /* recompute w_winrow for all windows */ | |
1748 redraw_later(NOT_VALID); | |
1749 } | |
1750 win_enter(win1, FALSE); | |
1751 } | |
1752 | |
1753 /* | |
1754 * Make all windows the same height. | |
1755 * 'next_curwin' will soon be the current window, make sure it has enough | |
1756 * rows. | |
1757 */ | |
1758 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1759 win_equal( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1760 win_T *next_curwin, /* pointer to current window to be or NULL */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1761 int current, /* do only frame with current window */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1762 int dir) /* 'v' for vertically, 'h' for horizontally, |
7 | 1763 'b' for both, 0 for using p_ead */ |
1764 { | |
1765 if (dir == 0) | |
1766 dir = *p_ead; | |
1767 win_equal_rec(next_curwin == NULL ? curwin : next_curwin, current, | |
685 | 1768 topframe, dir, 0, tabline_height(), |
667 | 1769 (int)Columns, topframe->fr_height); |
7 | 1770 } |
1771 | |
1772 /* | |
1773 * Set a frame to a new position and height, spreading the available room | |
1774 * equally over contained frames. | |
1775 * The window "next_curwin" (if not NULL) should at least get the size from | |
1776 * 'winheight' and 'winwidth' if possible. | |
1777 */ | |
1778 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1779 win_equal_rec( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1780 win_T *next_curwin, /* pointer to current window to be or NULL */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1781 int current, /* do only frame with current window */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1782 frame_T *topfr, /* frame to set size off */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1783 int dir, /* 'v', 'h' or 'b', see win_equal() */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1784 int col, /* horizontal position for frame */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1785 int row, /* vertical position for frame */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1786 int width, /* new width of frame */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1787 int height) /* new height of frame */ |
7 | 1788 { |
1789 int n, m; | |
1790 int extra_sep = 0; | |
1791 int wincount, totwincount = 0; | |
1792 frame_T *fr; | |
1793 int next_curwin_size = 0; | |
1794 int room = 0; | |
1795 int new_size; | |
1796 int has_next_curwin = 0; | |
1797 int hnc; | |
1798 | |
1799 if (topfr->fr_layout == FR_LEAF) | |
1800 { | |
1801 /* Set the width/height of this frame. | |
1802 * Redraw when size or position changes */ | |
1803 if (topfr->fr_height != height || topfr->fr_win->w_winrow != row | |
1804 || topfr->fr_width != width || topfr->fr_win->w_wincol != col | |
1805 ) | |
1806 { | |
1807 topfr->fr_win->w_winrow = row; | |
1808 frame_new_height(topfr, height, FALSE, FALSE); | |
1809 topfr->fr_win->w_wincol = col; | |
779 | 1810 frame_new_width(topfr, width, FALSE, FALSE); |
7 | 1811 redraw_all_later(CLEAR); |
1812 } | |
1813 } | |
1814 else if (topfr->fr_layout == FR_ROW) | |
1815 { | |
1816 topfr->fr_width = width; | |
1817 topfr->fr_height = height; | |
1818 | |
1819 if (dir != 'v') /* equalize frame widths */ | |
1820 { | |
1821 /* Compute the maximum number of windows horizontally in this | |
1822 * frame. */ | |
1823 n = frame_minwidth(topfr, NOWIN); | |
1824 /* add one for the rightmost window, it doesn't have a separator */ | |
1825 if (col + width == Columns) | |
1826 extra_sep = 1; | |
1827 else | |
1828 extra_sep = 0; | |
1829 totwincount = (n + extra_sep) / (p_wmw + 1); | |
779 | 1830 has_next_curwin = frame_has_win(topfr, next_curwin); |
1831 | |
1832 /* | |
1833 * Compute width for "next_curwin" window and room available for | |
1834 * other windows. | |
1835 * "m" is the minimal width when counting p_wiw for "next_curwin". | |
1836 */ | |
7 | 1837 m = frame_minwidth(topfr, next_curwin); |
1838 room = width - m; | |
1839 if (room < 0) | |
1840 { | |
1841 next_curwin_size = p_wiw + room; | |
1842 room = 0; | |
1843 } | |
1844 else | |
1845 { | |
779 | 1846 next_curwin_size = -1; |
1847 for (fr = topfr->fr_child; fr != NULL; fr = fr->fr_next) | |
1848 { | |
1849 /* If 'winfixwidth' set keep the window width if | |
1850 * possible. | |
1851 * Watch out for this window being the next_curwin. */ | |
1852 if (frame_fixed_width(fr)) | |
1853 { | |
1854 n = frame_minwidth(fr, NOWIN); | |
1855 new_size = fr->fr_width; | |
1856 if (frame_has_win(fr, next_curwin)) | |
1857 { | |
1858 room += p_wiw - p_wmw; | |
1859 next_curwin_size = 0; | |
1860 if (new_size < p_wiw) | |
1861 new_size = p_wiw; | |
1862 } | |
1863 else | |
1864 /* These windows don't use up room. */ | |
1865 totwincount -= (n + (fr->fr_next == NULL | |
1866 ? extra_sep : 0)) / (p_wmw + 1); | |
1867 room -= new_size - n; | |
1868 if (room < 0) | |
1869 { | |
1870 new_size += room; | |
1871 room = 0; | |
1872 } | |
1873 fr->fr_newwidth = new_size; | |
1874 } | |
1875 } | |
1876 if (next_curwin_size == -1) | |
1877 { | |
1878 if (!has_next_curwin) | |
1879 next_curwin_size = 0; | |
1880 else if (totwincount > 1 | |
1881 && (room + (totwincount - 2)) | |
1882 / (totwincount - 1) > p_wiw) | |
1883 { | |
834 | 1884 /* Can make all windows wider than 'winwidth', spread |
1885 * the room equally. */ | |
1886 next_curwin_size = (room + p_wiw | |
1887 + (totwincount - 1) * p_wmw | |
1888 + (totwincount - 1)) / totwincount; | |
779 | 1889 room -= next_curwin_size - p_wiw; |
1890 } | |
1891 else | |
1892 next_curwin_size = p_wiw; | |
1893 } | |
7 | 1894 } |
779 | 1895 |
1896 if (has_next_curwin) | |
7 | 1897 --totwincount; /* don't count curwin */ |
1898 } | |
1899 | |
1900 for (fr = topfr->fr_child; fr != NULL; fr = fr->fr_next) | |
1901 { | |
1902 n = m = 0; | |
1903 wincount = 1; | |
1904 if (fr->fr_next == NULL) | |
1905 /* last frame gets all that remains (avoid roundoff error) */ | |
1906 new_size = width; | |
1907 else if (dir == 'v') | |
1908 new_size = fr->fr_width; | |
779 | 1909 else if (frame_fixed_width(fr)) |
1910 { | |
1911 new_size = fr->fr_newwidth; | |
1912 wincount = 0; /* doesn't count as a sizeable window */ | |
1913 } | |
7 | 1914 else |
1915 { | |
1916 /* Compute the maximum number of windows horiz. in "fr". */ | |
1917 n = frame_minwidth(fr, NOWIN); | |
1918 wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) | |
1919 / (p_wmw + 1); | |
1920 m = frame_minwidth(fr, next_curwin); | |
779 | 1921 if (has_next_curwin) |
1922 hnc = frame_has_win(fr, next_curwin); | |
1923 else | |
1924 hnc = FALSE; | |
1925 if (hnc) /* don't count next_curwin */ | |
7 | 1926 --wincount; |
779 | 1927 if (totwincount == 0) |
1928 new_size = room; | |
1929 else | |
1930 new_size = (wincount * room + ((unsigned)totwincount >> 1)) | |
7 | 1931 / totwincount; |
779 | 1932 if (hnc) /* add next_curwin size */ |
7 | 1933 { |
1934 next_curwin_size -= p_wiw - (m - n); | |
1935 new_size += next_curwin_size; | |
779 | 1936 room -= new_size - next_curwin_size; |
7 | 1937 } |
779 | 1938 else |
1939 room -= new_size; | |
1940 new_size += n; | |
7 | 1941 } |
1942 | |
779 | 1943 /* Skip frame that is full width when splitting or closing a |
7 | 1944 * window, unless equalizing all frames. */ |
1945 if (!current || dir != 'v' || topfr->fr_parent != NULL | |
1946 || (new_size != fr->fr_width) | |
1947 || frame_has_win(fr, next_curwin)) | |
1948 win_equal_rec(next_curwin, current, fr, dir, col, row, | |
779 | 1949 new_size, height); |
1950 col += new_size; | |
1951 width -= new_size; | |
7 | 1952 totwincount -= wincount; |
1953 } | |
1954 } | |
1955 else /* topfr->fr_layout == FR_COL */ | |
1956 { | |
1957 topfr->fr_width = width; | |
1958 topfr->fr_height = height; | |
1959 | |
1960 if (dir != 'h') /* equalize frame heights */ | |
1961 { | |
1962 /* Compute maximum number of windows vertically in this frame. */ | |
1963 n = frame_minheight(topfr, NOWIN); | |
1964 /* add one for the bottom window if it doesn't have a statusline */ | |
1965 if (row + height == cmdline_row && p_ls == 0) | |
1966 extra_sep = 1; | |
1967 else | |
1968 extra_sep = 0; | |
1969 totwincount = (n + extra_sep) / (p_wmh + 1); | |
1970 has_next_curwin = frame_has_win(topfr, next_curwin); | |
1971 | |
1972 /* | |
1973 * Compute height for "next_curwin" window and room available for | |
1974 * other windows. | |
1975 * "m" is the minimal height when counting p_wh for "next_curwin". | |
1976 */ | |
1977 m = frame_minheight(topfr, next_curwin); | |
1978 room = height - m; | |
1979 if (room < 0) | |
1980 { | |
1981 /* The room is less then 'winheight', use all space for the | |
1982 * current window. */ | |
1983 next_curwin_size = p_wh + room; | |
1984 room = 0; | |
1985 } | |
1986 else | |
1987 { | |
1988 next_curwin_size = -1; | |
1989 for (fr = topfr->fr_child; fr != NULL; fr = fr->fr_next) | |
1990 { | |
1991 /* If 'winfixheight' set keep the window height if | |
1992 * possible. | |
1993 * Watch out for this window being the next_curwin. */ | |
1994 if (frame_fixed_height(fr)) | |
1995 { | |
1996 n = frame_minheight(fr, NOWIN); | |
1997 new_size = fr->fr_height; | |
1998 if (frame_has_win(fr, next_curwin)) | |
1999 { | |
2000 room += p_wh - p_wmh; | |
2001 next_curwin_size = 0; | |
2002 if (new_size < p_wh) | |
2003 new_size = p_wh; | |
2004 } | |
2005 else | |
2006 /* These windows don't use up room. */ | |
2007 totwincount -= (n + (fr->fr_next == NULL | |
2008 ? extra_sep : 0)) / (p_wmh + 1); | |
2009 room -= new_size - n; | |
2010 if (room < 0) | |
2011 { | |
2012 new_size += room; | |
2013 room = 0; | |
2014 } | |
2015 fr->fr_newheight = new_size; | |
2016 } | |
2017 } | |
2018 if (next_curwin_size == -1) | |
2019 { | |
2020 if (!has_next_curwin) | |
2021 next_curwin_size = 0; | |
2022 else if (totwincount > 1 | |
2023 && (room + (totwincount - 2)) | |
2024 / (totwincount - 1) > p_wh) | |
2025 { | |
834 | 2026 /* can make all windows higher than 'winheight', |
2027 * spread the room equally. */ | |
2028 next_curwin_size = (room + p_wh | |
2029 + (totwincount - 1) * p_wmh | |
7 | 2030 + (totwincount - 1)) / totwincount; |
2031 room -= next_curwin_size - p_wh; | |
2032 } | |
2033 else | |
2034 next_curwin_size = p_wh; | |
2035 } | |
2036 } | |
2037 | |
2038 if (has_next_curwin) | |
2039 --totwincount; /* don't count curwin */ | |
2040 } | |
2041 | |
2042 for (fr = topfr->fr_child; fr != NULL; fr = fr->fr_next) | |
2043 { | |
2044 n = m = 0; | |
2045 wincount = 1; | |
2046 if (fr->fr_next == NULL) | |
2047 /* last frame gets all that remains (avoid roundoff error) */ | |
2048 new_size = height; | |
2049 else if (dir == 'h') | |
2050 new_size = fr->fr_height; | |
2051 else if (frame_fixed_height(fr)) | |
2052 { | |
2053 new_size = fr->fr_newheight; | |
2054 wincount = 0; /* doesn't count as a sizeable window */ | |
2055 } | |
2056 else | |
2057 { | |
2058 /* Compute the maximum number of windows vert. in "fr". */ | |
2059 n = frame_minheight(fr, NOWIN); | |
2060 wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) | |
2061 / (p_wmh + 1); | |
2062 m = frame_minheight(fr, next_curwin); | |
2063 if (has_next_curwin) | |
2064 hnc = frame_has_win(fr, next_curwin); | |
2065 else | |
2066 hnc = FALSE; | |
2067 if (hnc) /* don't count next_curwin */ | |
2068 --wincount; | |
2069 if (totwincount == 0) | |
2070 new_size = room; | |
2071 else | |
2072 new_size = (wincount * room + ((unsigned)totwincount >> 1)) | |
2073 / totwincount; | |
2074 if (hnc) /* add next_curwin size */ | |
2075 { | |
2076 next_curwin_size -= p_wh - (m - n); | |
2077 new_size += next_curwin_size; | |
2078 room -= new_size - next_curwin_size; | |
2079 } | |
2080 else | |
2081 room -= new_size; | |
2082 new_size += n; | |
2083 } | |
2084 /* Skip frame that is full width when splitting or closing a | |
2085 * window, unless equalizing all frames. */ | |
2086 if (!current || dir != 'h' || topfr->fr_parent != NULL | |
2087 || (new_size != fr->fr_height) | |
2088 || frame_has_win(fr, next_curwin)) | |
2089 win_equal_rec(next_curwin, current, fr, dir, col, row, | |
2090 width, new_size); | |
2091 row += new_size; | |
2092 height -= new_size; | |
2093 totwincount -= wincount; | |
2094 } | |
2095 } | |
2096 } | |
2097 | |
2098 /* | |
11199
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
2099 * Close all windows for buffer "buf". |
7 | 2100 */ |
2101 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2102 close_windows( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2103 buf_T *buf, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2104 int keep_curwin) /* don't close "curwin" */ |
7 | 2105 { |
671 | 2106 win_T *wp; |
2107 tabpage_T *tp, *nexttp; | |
685 | 2108 int h = tabline_height(); |
9599
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2109 #ifdef FEAT_AUTOCMD |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2110 int count = tabpage_index(NULL); |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2111 #endif |
7 | 2112 |
2113 ++RedrawingDisabled; | |
671 | 2114 |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
2115 for (wp = firstwin; wp != NULL && !ONE_WINDOW; ) |
7 | 2116 { |
3570 | 2117 if (wp->w_buffer == buf && (!keep_curwin || wp != curwin) |
2118 #ifdef FEAT_AUTOCMD | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2119 && !(wp->w_closing || wp->w_buffer->b_locked > 0) |
3570 | 2120 #endif |
2121 ) | |
7 | 2122 { |
11199
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
2123 if (win_close(wp, FALSE) == FAIL) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
2124 /* If closing the window fails give up, to avoid looping |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
2125 * forever. */ |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
2126 break; |
671 | 2127 |
2128 /* Start all over, autocommands may change the window layout. */ | |
2129 wp = firstwin; | |
7 | 2130 } |
2131 else | |
671 | 2132 wp = wp->w_next; |
7 | 2133 } |
671 | 2134 |
2135 /* Also check windows in other tab pages. */ | |
2136 for (tp = first_tabpage; tp != NULL; tp = nexttp) | |
2137 { | |
2138 nexttp = tp->tp_next; | |
672 | 2139 if (tp != curtab) |
671 | 2140 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) |
3570 | 2141 if (wp->w_buffer == buf |
2142 #ifdef FEAT_AUTOCMD | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2143 && !(wp->w_closing || wp->w_buffer->b_locked > 0) |
3570 | 2144 #endif |
2145 ) | |
671 | 2146 { |
2147 win_close_othertab(wp, FALSE, tp); | |
2148 | |
2149 /* Start all over, the tab page may be closed and | |
2150 * autocommands may change the window layout. */ | |
2151 nexttp = first_tabpage; | |
2152 break; | |
2153 } | |
2154 } | |
2155 | |
7 | 2156 --RedrawingDisabled; |
671 | 2157 |
9599
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2158 #ifdef FEAT_AUTOCMD |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2159 if (count != tabpage_index(NULL)) |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2160 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2161 #endif |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2162 |
4305 | 2163 redraw_tabline = TRUE; |
685 | 2164 if (h != tabline_height()) |
671 | 2165 shell_new_rows(); |
7 | 2166 } |
2167 | |
2168 /* | |
1906 | 2169 * Return TRUE if the current window is the only window that exists (ignoring |
2170 * "aucmd_win"). | |
672 | 2171 * Returns FALSE if there is a window, possibly in another tab page. |
667 | 2172 */ |
672 | 2173 static int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2174 last_window(void) |
667 | 2175 { |
1906 | 2176 return (one_window() && first_tabpage->tp_next == NULL); |
2177 } | |
2178 | |
2179 /* | |
2180 * Return TRUE if there is only one window other than "aucmd_win" in the | |
2181 * current tab page. | |
2182 */ | |
3365 | 2183 int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2184 one_window(void) |
1906 | 2185 { |
2186 #ifdef FEAT_AUTOCMD | |
2187 win_T *wp; | |
2188 int seen_one = FALSE; | |
2189 | |
2190 FOR_ALL_WINDOWS(wp) | |
2191 { | |
2192 if (wp != aucmd_win) | |
2193 { | |
2194 if (seen_one) | |
2195 return FALSE; | |
2196 seen_one = TRUE; | |
2197 } | |
2198 } | |
2199 return TRUE; | |
2200 #else | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
2201 return ONE_WINDOW; |
1906 | 2202 #endif |
667 | 2203 } |
2204 | |
2205 /* | |
3535 | 2206 * Close the possibly last window in a tab page. |
2207 * Returns TRUE when the window was closed already. | |
2208 */ | |
2209 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2210 close_last_window_tabpage( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2211 win_T *win, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2212 int free_buf, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2213 tabpage_T *prev_curtab) |
3535 | 2214 { |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
2215 if (ONE_WINDOW) |
3535 | 2216 { |
4423 | 2217 #ifdef FEAT_AUTOCMD |
4354 | 2218 buf_T *old_curbuf = curbuf; |
4423 | 2219 #endif |
4354 | 2220 |
3535 | 2221 /* |
2222 * Closing the last window in a tab page. First go to another tab | |
2223 * page and then close the window and the tab page. This avoids that | |
2224 * curwin and curtab are invalid while we are freeing memory, they may | |
2225 * be used in GUI events. | |
3582 | 2226 * Don't trigger autocommands yet, they may use wrong values, so do |
2227 * that below. | |
3535 | 2228 */ |
4354 | 2229 goto_tabpage_tp(alt_tabpage(), FALSE, TRUE); |
3535 | 2230 redraw_tabline = TRUE; |
2231 | |
2232 /* Safety check: Autocommands may have closed the window when jumping | |
2233 * to the other tab page. */ | |
2234 if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win) | |
2235 { | |
2236 int h = tabline_height(); | |
2237 | |
2238 win_close_othertab(win, free_buf, prev_curtab); | |
2239 if (h != tabline_height()) | |
2240 shell_new_rows(); | |
2241 } | |
3582 | 2242 /* Since goto_tabpage_tp above did not trigger *Enter autocommands, do |
2243 * that now. */ | |
2244 #ifdef FEAT_AUTOCMD | |
9599
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
2245 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); |
4354 | 2246 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); |
3582 | 2247 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); |
4354 | 2248 if (old_curbuf != curbuf) |
2249 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
3582 | 2250 #endif |
3535 | 2251 return TRUE; |
2252 } | |
2253 return FALSE; | |
2254 } | |
2255 | |
2256 /* | |
819 | 2257 * Close window "win". Only works for the current tab page. |
7 | 2258 * If "free_buf" is TRUE related buffer may be unloaded. |
2259 * | |
3365 | 2260 * Called by :quit, :close, :xit, :wq and findtag(). |
5302 | 2261 * Returns FAIL when the window was not closed. |
7 | 2262 */ |
5302 | 2263 int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2264 win_close(win_T *win, int free_buf) |
7 | 2265 { |
2266 win_T *wp; | |
2267 #ifdef FEAT_AUTOCMD | |
2268 int other_buffer = FALSE; | |
2269 #endif | |
2270 int close_curwin = FALSE; | |
2271 int dir; | |
2272 int help_window = FALSE; | |
847 | 2273 tabpage_T *prev_curtab = curtab; |
11593
c4e7fe672a72
patch 8.0.0679: using freed memory
Christian Brabandt <cb@256bit.org>
parents:
11591
diff
changeset
|
2274 frame_T *win_frame = win->w_frame->fr_parent; |
7 | 2275 |
667 | 2276 if (last_window()) |
7 | 2277 { |
2278 EMSG(_("E444: Cannot close last window")); | |
5302 | 2279 return FAIL; |
7 | 2280 } |
2281 | |
1906 | 2282 #ifdef FEAT_AUTOCMD |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2283 if (win->w_closing || (win->w_buffer != NULL |
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2284 && win->w_buffer->b_locked > 0)) |
5302 | 2285 return FAIL; /* window is already being closed */ |
1906 | 2286 if (win == aucmd_win) |
2287 { | |
2288 EMSG(_("E813: Cannot close autocmd window")); | |
5302 | 2289 return FAIL; |
1906 | 2290 } |
2291 if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) | |
2292 { | |
2293 EMSG(_("E814: Cannot close window, only autocmd window would remain")); | |
5302 | 2294 return FAIL; |
1906 | 2295 } |
2296 #endif | |
2297 | |
3535 | 2298 /* When closing the last window in a tab page first go to another tab page |
2299 * and then close the window and the tab page to avoid that curwin and | |
2300 * curtab are invalid while we are freeing memory. */ | |
2301 if (close_last_window_tabpage(win, free_buf, prev_curtab)) | |
5302 | 2302 return FAIL; |
856 | 2303 |
7 | 2304 /* When closing the help window, try restoring a snapshot after closing |
2305 * the window. Otherwise clear the snapshot, it's now invalid. */ | |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11593
diff
changeset
|
2306 if (bt_help(win->w_buffer)) |
7 | 2307 help_window = TRUE; |
2308 else | |
1906 | 2309 clear_snapshot(curtab, SNAP_HELP_IDX); |
7 | 2310 |
2311 #ifdef FEAT_AUTOCMD | |
2312 if (win == curwin) | |
2313 { | |
2314 /* | |
2315 * Guess which window is going to be the new current window. | |
2316 * This may change because of the autocommands (sigh). | |
2317 */ | |
671 | 2318 wp = frame2win(win_altframe(win, NULL)); |
7 | 2319 |
2320 /* | |
3570 | 2321 * Be careful: If autocommands delete the window or cause this window |
2322 * to be the last one left, return now. | |
7 | 2323 */ |
2324 if (wp->w_buffer != curbuf) | |
2325 { | |
2326 other_buffer = TRUE; | |
3570 | 2327 win->w_closing = TRUE; |
7 | 2328 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); |
3570 | 2329 if (!win_valid(win)) |
5302 | 2330 return FAIL; |
3570 | 2331 win->w_closing = FALSE; |
2332 if (last_window()) | |
5302 | 2333 return FAIL; |
7 | 2334 } |
3570 | 2335 win->w_closing = TRUE; |
7 | 2336 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf); |
3570 | 2337 if (!win_valid(win)) |
5302 | 2338 return FAIL; |
3570 | 2339 win->w_closing = FALSE; |
2340 if (last_window()) | |
5302 | 2341 return FAIL; |
7 | 2342 # ifdef FEAT_EVAL |
2343 /* autocmds may abort script processing */ | |
2344 if (aborting()) | |
5302 | 2345 return FAIL; |
7 | 2346 # endif |
2347 } | |
2348 #endif | |
2349 | |
1101 | 2350 #ifdef FEAT_GUI |
2351 /* Avoid trouble with scrollbars that are going to be deleted in | |
2352 * win_free(). */ | |
2353 if (gui.in_use) | |
2354 out_flush(); | |
2355 #endif | |
2356 | |
3068 | 2357 #ifdef FEAT_SYN_HL |
2358 /* Free independent synblock before the buffer is freed. */ | |
3242 | 2359 if (win->w_buffer != NULL) |
2360 reset_synblock(win); | |
3068 | 2361 #endif |
2362 | |
7 | 2363 /* |
2364 * Close the link to the buffer. | |
2365 */ | |
3242 | 2366 if (win->w_buffer != NULL) |
3570 | 2367 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
2368 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
2369 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
2370 set_bufref(&bufref, curbuf); |
3570 | 2371 #ifdef FEAT_AUTOCMD |
2372 win->w_closing = TRUE; | |
2373 #endif | |
3768 | 2374 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, TRUE); |
3570 | 2375 #ifdef FEAT_AUTOCMD |
10076
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2376 if (win_valid_any_tab(win)) |
3570 | 2377 win->w_closing = FALSE; |
2378 #endif | |
7677
85a7a945fb87
commit https://github.com/vim/vim/commit/62ef797496c6243d111c596a592a8ef8c1d1e710
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2379 /* Make sure curbuf is valid. It can become invalid if 'bufhidden' is |
85a7a945fb87
commit https://github.com/vim/vim/commit/62ef797496c6243d111c596a592a8ef8c1d1e710
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2380 * "wipe". */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
2381 if (!bufref_valid(&bufref)) |
7677
85a7a945fb87
commit https://github.com/vim/vim/commit/62ef797496c6243d111c596a592a8ef8c1d1e710
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2382 curbuf = firstbuf; |
3570 | 2383 } |
847 | 2384 |
4021 | 2385 if (only_one_window() && win_valid(win) && win->w_buffer == NULL |
2386 && (last_window() || curtab != prev_curtab | |
2387 || close_last_window_tabpage(win, free_buf, prev_curtab))) | |
5233
1899acc5aebd
updated for version 7.4a.042
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
2388 { |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11593
diff
changeset
|
2389 /* Autocommands have closed all windows, quit now. Restore |
5233
1899acc5aebd
updated for version 7.4a.042
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
2390 * curwin->w_buffer, otherwise writing viminfo may fail. */ |
1899acc5aebd
updated for version 7.4a.042
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
2391 if (curwin->w_buffer == NULL) |
1899acc5aebd
updated for version 7.4a.042
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
2392 curwin->w_buffer = curbuf; |
4021 | 2393 getout(0); |
5233
1899acc5aebd
updated for version 7.4a.042
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
2394 } |
4021 | 2395 |
10076
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2396 /* Autocommands may have moved to another tab page. */ |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2397 if (curtab != prev_curtab && win_valid_any_tab(win) |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2398 && win->w_buffer == NULL) |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2399 { |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2400 /* Need to close the window anyway, since the buffer is NULL. */ |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2401 win_close_othertab(win, FALSE, prev_curtab); |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2402 return FAIL; |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2403 } |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2404 |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2405 /* Autocommands may have closed the window already or closed the only |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2406 * other window. */ |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2407 if (!win_valid(win) || last_window() |
3535 | 2408 || close_last_window_tabpage(win, free_buf, prev_curtab)) |
5302 | 2409 return FAIL; |
7 | 2410 |
3068 | 2411 /* Free the memory used for the window and get the window that received |
2412 * the screen space. */ | |
847 | 2413 wp = win_free_mem(win, &dir, NULL); |
2414 | |
7 | 2415 /* Make sure curwin isn't invalid. It can cause severe trouble when |
2416 * printing an error message. For win_equal() curbuf needs to be valid | |
2417 * too. */ | |
847 | 2418 if (win == curwin) |
7 | 2419 { |
2420 curwin = wp; | |
2421 #ifdef FEAT_QUICKFIX | |
2422 if (wp->w_p_pvw || bt_quickfix(wp->w_buffer)) | |
2423 { | |
2424 /* | |
1346 | 2425 * If the cursor goes to the preview or the quickfix window, try |
7 | 2426 * finding another window to go to. |
2427 */ | |
2428 for (;;) | |
2429 { | |
2430 if (wp->w_next == NULL) | |
2431 wp = firstwin; | |
2432 else | |
2433 wp = wp->w_next; | |
2434 if (wp == curwin) | |
2435 break; | |
2436 if (!wp->w_p_pvw && !bt_quickfix(wp->w_buffer)) | |
2437 { | |
2438 curwin = wp; | |
2439 break; | |
2440 } | |
2441 } | |
2442 } | |
2443 #endif | |
2444 curbuf = curwin->w_buffer; | |
2445 close_curwin = TRUE; | |
11193
75ccc8a15a51
patch 8.0.0483: illegal memory access when using :all
Christian Brabandt <cb@256bit.org>
parents:
11191
diff
changeset
|
2446 |
75ccc8a15a51
patch 8.0.0483: illegal memory access when using :all
Christian Brabandt <cb@256bit.org>
parents:
11191
diff
changeset
|
2447 /* The cursor position may be invalid if the buffer changed after last |
75ccc8a15a51
patch 8.0.0483: illegal memory access when using :all
Christian Brabandt <cb@256bit.org>
parents:
11191
diff
changeset
|
2448 * using the window. */ |
75ccc8a15a51
patch 8.0.0483: illegal memory access when using :all
Christian Brabandt <cb@256bit.org>
parents:
11191
diff
changeset
|
2449 check_cursor(); |
7 | 2450 } |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
2451 if (p_ea && (*p_ead == 'b' || *p_ead == dir)) |
11591
d06a3db9b651
patch 8.0.0678: closing a window does not trigger resizing
Christian Brabandt <cb@256bit.org>
parents:
11232
diff
changeset
|
2452 /* If the frame of the closed window contains the new current window, |
d06a3db9b651
patch 8.0.0678: closing a window does not trigger resizing
Christian Brabandt <cb@256bit.org>
parents:
11232
diff
changeset
|
2453 * only resize that frame. Otherwise resize all windows. */ |
11593
c4e7fe672a72
patch 8.0.0679: using freed memory
Christian Brabandt <cb@256bit.org>
parents:
11591
diff
changeset
|
2454 win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir); |
7 | 2455 else |
2456 win_comp_pos(); | |
2457 if (close_curwin) | |
2458 { | |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2459 win_enter_ext(wp, FALSE, TRUE, FALSE, TRUE, TRUE); |
7 | 2460 #ifdef FEAT_AUTOCMD |
2461 if (other_buffer) | |
2462 /* careful: after this wp and win may be invalid! */ | |
2463 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
2464 #endif | |
2465 } | |
2466 | |
2467 /* | |
667 | 2468 * If last window has a status line now and we don't want one, |
2469 * remove the status line. | |
7 | 2470 */ |
2471 last_status(FALSE); | |
2472 | |
2473 /* After closing the help window, try restoring the window layout from | |
2474 * before it was opened. */ | |
2475 if (help_window) | |
1906 | 2476 restore_snapshot(SNAP_HELP_IDX, close_curwin); |
7 | 2477 |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
2478 #if defined(FEAT_GUI) |
7 | 2479 /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */ |
2480 if (gui.in_use && !win_hasvertsplit()) | |
2481 gui_init_which_components(NULL); | |
2482 #endif | |
2483 | |
2484 redraw_all_later(NOT_VALID); | |
5302 | 2485 return OK; |
7 | 2486 } |
2487 | |
2488 /* | |
671 | 2489 * Close window "win" in tab page "tp", which is not the current tab page. |
3535 | 2490 * This may be the last window in that tab page and result in closing the tab, |
671 | 2491 * thus "tp" may become invalid! |
856 | 2492 * Caller must check if buffer is hidden and whether the tabline needs to be |
2493 * updated. | |
671 | 2494 */ |
2495 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2496 win_close_othertab(win_T *win, int free_buf, tabpage_T *tp) |
671 | 2497 { |
2498 win_T *wp; | |
2499 int dir; | |
2500 tabpage_T *ptp = NULL; | |
2191 | 2501 int free_tp = FALSE; |
671 | 2502 |
3570 | 2503 #ifdef FEAT_AUTOCMD |
10076
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2504 /* Get here with win->w_buffer == NULL when win_close() detects the tab |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2505 * page changed. */ |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2506 if (win->w_closing || (win->w_buffer != NULL |
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2507 && win->w_buffer->b_locked > 0)) |
3570 | 2508 return; /* window is already being closed */ |
2509 #endif | |
2510 | |
10076
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2511 if (win->w_buffer != NULL) |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2512 /* Close the link to the buffer. */ |
bc30991c3e98
commit https://github.com/vim/vim/commit/11fbc2866ccc11b4dd1726abdaf582a78ef3f743
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2513 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, FALSE); |
671 | 2514 |
2515 /* Careful: Autocommands may have closed the tab page or made it the | |
2516 * current tab page. */ | |
2517 for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next) | |
2518 ; | |
672 | 2519 if (ptp == NULL || tp == curtab) |
671 | 2520 return; |
2521 | |
2522 /* Autocommands may have closed the window already. */ | |
2523 for (wp = tp->tp_firstwin; wp != NULL && wp != win; wp = wp->w_next) | |
2524 ; | |
2525 if (wp == NULL) | |
2526 return; | |
2527 | |
2528 /* When closing the last window in a tab page remove the tab page. */ | |
7009 | 2529 if (tp->tp_firstwin == tp->tp_lastwin) |
671 | 2530 { |
2531 if (tp == first_tabpage) | |
2532 first_tabpage = tp->tp_next; | |
2533 else | |
2534 { | |
2535 for (ptp = first_tabpage; ptp != NULL && ptp->tp_next != tp; | |
2536 ptp = ptp->tp_next) | |
2537 ; | |
2538 if (ptp == NULL) | |
2539 { | |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10357
diff
changeset
|
2540 internal_error("win_close_othertab()"); |
671 | 2541 return; |
2542 } | |
2543 ptp->tp_next = tp->tp_next; | |
2544 } | |
2191 | 2545 free_tp = TRUE; |
2546 } | |
2547 | |
2548 /* Free the memory used for the window. */ | |
2549 win_free_mem(win, &dir, tp); | |
2550 | |
2551 if (free_tp) | |
847 | 2552 free_tabpage(tp); |
671 | 2553 } |
2554 | |
2555 /* | |
355 | 2556 * Free the memory used for a window. |
2557 * Returns a pointer to the window that got the freed up space. | |
2558 */ | |
2559 static win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2560 win_free_mem( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2561 win_T *win, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2562 int *dirp, /* set to 'v' or 'h' for direction if 'ea' */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2563 tabpage_T *tp) /* tab page "win" is in, NULL for current */ |
355 | 2564 { |
2565 frame_T *frp; | |
2566 win_T *wp; | |
2567 | |
667 | 2568 /* Remove the window and its frame from the tree of frames. */ |
355 | 2569 frp = win->w_frame; |
671 | 2570 wp = winframe_remove(win, dirp, tp); |
355 | 2571 vim_free(frp); |
671 | 2572 win_free(win, tp); |
355 | 2573 |
819 | 2574 /* When deleting the current window of another tab page select a new |
2575 * current window. */ | |
2576 if (tp != NULL && win == tp->tp_curwin) | |
2577 tp->tp_curwin = wp; | |
2578 | |
355 | 2579 return wp; |
2580 } | |
2581 | |
2582 #if defined(EXITFREE) || defined(PROTO) | |
2583 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2584 win_free_all(void) |
355 | 2585 { |
2586 int dummy; | |
2587 | |
671 | 2588 while (first_tabpage->tp_next != NULL) |
2589 tabpage_close(TRUE); | |
2590 | |
1906 | 2591 # ifdef FEAT_AUTOCMD |
2592 if (aucmd_win != NULL) | |
2593 { | |
2594 (void)win_free_mem(aucmd_win, &dummy, NULL); | |
2595 aucmd_win = NULL; | |
2596 } | |
2597 # endif | |
1918 | 2598 |
2599 while (firstwin != NULL) | |
2600 (void)win_free_mem(firstwin, &dummy, NULL); | |
6060 | 2601 |
2602 /* No window should be used after this. Set curwin to NULL to crash | |
2603 * instead of using freed memory. */ | |
2604 curwin = NULL; | |
355 | 2605 } |
2606 #endif | |
2607 | |
2608 /* | |
7 | 2609 * Remove a window and its frame from the tree of frames. |
2610 * Returns a pointer to the window that got the freed up space. | |
2611 */ | |
1906 | 2612 win_T * |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2613 winframe_remove( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2614 win_T *win, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2615 int *dirp UNUSED, /* set to 'v' or 'h' for direction if 'ea' */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2616 tabpage_T *tp) /* tab page "win" is in, NULL for current */ |
7 | 2617 { |
2618 frame_T *frp, *frp2, *frp3; | |
2619 frame_T *frp_close = win->w_frame; | |
2620 win_T *wp; | |
2621 | |
2622 /* | |
671 | 2623 * If there is only one window there is nothing to remove. |
2624 */ | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
2625 if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin) |
671 | 2626 return NULL; |
2627 | |
2628 /* | |
7 | 2629 * Remove the window from its frame. |
2630 */ | |
671 | 2631 frp2 = win_altframe(win, tp); |
7 | 2632 wp = frame2win(frp2); |
2633 | |
2634 /* Remove this frame from the list of frames. */ | |
2635 frame_remove(frp_close); | |
2636 | |
2637 if (frp_close->fr_parent->fr_layout == FR_COL) | |
2638 { | |
1346 | 2639 /* When 'winfixheight' is set, try to find another frame in the column |
2640 * (as close to the closed frame as possible) to distribute the height | |
2641 * to. */ | |
2642 if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfh) | |
2643 { | |
2644 frp = frp_close->fr_prev; | |
2645 frp3 = frp_close->fr_next; | |
2646 while (frp != NULL || frp3 != NULL) | |
2647 { | |
2648 if (frp != NULL) | |
2649 { | |
2650 if (frp->fr_win != NULL && !frp->fr_win->w_p_wfh) | |
2651 { | |
2652 frp2 = frp; | |
2653 wp = frp->fr_win; | |
2654 break; | |
2655 } | |
2656 frp = frp->fr_prev; | |
2657 } | |
2658 if (frp3 != NULL) | |
2659 { | |
2660 if (frp3->fr_win != NULL && !frp3->fr_win->w_p_wfh) | |
2661 { | |
2662 frp2 = frp3; | |
2663 wp = frp3->fr_win; | |
2664 break; | |
2665 } | |
2666 frp3 = frp3->fr_next; | |
2667 } | |
2668 } | |
2669 } | |
7 | 2670 frame_new_height(frp2, frp2->fr_height + frp_close->fr_height, |
2671 frp2 == frp_close->fr_next ? TRUE : FALSE, FALSE); | |
2672 *dirp = 'v'; | |
2673 } | |
2674 else | |
2675 { | |
1346 | 2676 /* When 'winfixwidth' is set, try to find another frame in the column |
2677 * (as close to the closed frame as possible) to distribute the width | |
2678 * to. */ | |
2679 if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfw) | |
2680 { | |
2681 frp = frp_close->fr_prev; | |
2682 frp3 = frp_close->fr_next; | |
2683 while (frp != NULL || frp3 != NULL) | |
2684 { | |
2685 if (frp != NULL) | |
2686 { | |
2687 if (frp->fr_win != NULL && !frp->fr_win->w_p_wfw) | |
2688 { | |
2689 frp2 = frp; | |
2690 wp = frp->fr_win; | |
2691 break; | |
2692 } | |
2693 frp = frp->fr_prev; | |
2694 } | |
2695 if (frp3 != NULL) | |
2696 { | |
2697 if (frp3->fr_win != NULL && !frp3->fr_win->w_p_wfw) | |
2698 { | |
2699 frp2 = frp3; | |
2700 wp = frp3->fr_win; | |
2701 break; | |
2702 } | |
2703 frp3 = frp3->fr_next; | |
2704 } | |
2705 } | |
2706 } | |
7 | 2707 frame_new_width(frp2, frp2->fr_width + frp_close->fr_width, |
779 | 2708 frp2 == frp_close->fr_next ? TRUE : FALSE, FALSE); |
7 | 2709 *dirp = 'h'; |
2710 } | |
2711 | |
2712 /* If rows/columns go to a window below/right its positions need to be | |
2713 * updated. Can only be done after the sizes have been updated. */ | |
2714 if (frp2 == frp_close->fr_next) | |
2715 { | |
2716 int row = win->w_winrow; | |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12491
diff
changeset
|
2717 int col = win->w_wincol; |
7 | 2718 |
2719 frame_comp_pos(frp2, &row, &col); | |
2720 } | |
2721 | |
2722 if (frp2->fr_next == NULL && frp2->fr_prev == NULL) | |
2723 { | |
2724 /* There is no other frame in this list, move its info to the parent | |
2725 * and remove it. */ | |
2726 frp2->fr_parent->fr_layout = frp2->fr_layout; | |
2727 frp2->fr_parent->fr_child = frp2->fr_child; | |
2728 for (frp = frp2->fr_child; frp != NULL; frp = frp->fr_next) | |
2729 frp->fr_parent = frp2->fr_parent; | |
2730 frp2->fr_parent->fr_win = frp2->fr_win; | |
2731 if (frp2->fr_win != NULL) | |
2732 frp2->fr_win->w_frame = frp2->fr_parent; | |
2733 frp = frp2->fr_parent; | |
13144
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
2734 if (topframe->fr_child == frp2) |
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
2735 topframe->fr_child = frp; |
7 | 2736 vim_free(frp2); |
2737 | |
2738 frp2 = frp->fr_parent; | |
2739 if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) | |
2740 { | |
2741 /* The frame above the parent has the same layout, have to merge | |
2742 * the frames into this list. */ | |
2743 if (frp2->fr_child == frp) | |
2744 frp2->fr_child = frp->fr_child; | |
2745 frp->fr_child->fr_prev = frp->fr_prev; | |
2746 if (frp->fr_prev != NULL) | |
2747 frp->fr_prev->fr_next = frp->fr_child; | |
2748 for (frp3 = frp->fr_child; ; frp3 = frp3->fr_next) | |
2749 { | |
2750 frp3->fr_parent = frp2; | |
2751 if (frp3->fr_next == NULL) | |
2752 { | |
2753 frp3->fr_next = frp->fr_next; | |
2754 if (frp->fr_next != NULL) | |
2755 frp->fr_next->fr_prev = frp3; | |
2756 break; | |
2757 } | |
2758 } | |
13144
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
2759 if (topframe->fr_child == frp) |
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
2760 topframe->fr_child = frp2; |
7 | 2761 vim_free(frp); |
2762 } | |
2763 } | |
2764 | |
2765 return wp; | |
2766 } | |
2767 | |
2768 /* | |
2769 * Find out which frame is going to get the freed up space when "win" is | |
2770 * closed. | |
2771 * if 'splitbelow'/'splitleft' the space goes to the window above/left. | |
2772 * if 'nosplitbelow'/'nosplitleft' the space goes to the window below/right. | |
2773 * This makes opening a window and closing it immediately keep the same window | |
2774 * layout. | |
2775 */ | |
2776 static frame_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2777 win_altframe( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2778 win_T *win, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2779 tabpage_T *tp) /* tab page "win" is in, NULL for current */ |
7 | 2780 { |
2781 frame_T *frp; | |
2782 int b; | |
2783 | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
2784 if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin) |
667 | 2785 /* Last window in this tab page, will go to next tab page. */ |
2786 return alt_tabpage()->tp_curwin->w_frame; | |
2787 | |
7 | 2788 frp = win->w_frame; |
355 | 2789 if (frp->fr_parent != NULL && frp->fr_parent->fr_layout == FR_ROW) |
7 | 2790 b = p_spr; |
2791 else | |
2792 b = p_sb; | |
2793 if ((!b && frp->fr_next != NULL) || frp->fr_prev == NULL) | |
2794 return frp->fr_next; | |
2795 return frp->fr_prev; | |
2796 } | |
2797 | |
2798 /* | |
667 | 2799 * Return the tabpage that will be used if the current one is closed. |
2800 */ | |
2801 static tabpage_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2802 alt_tabpage(void) |
667 | 2803 { |
672 | 2804 tabpage_T *tp; |
2805 | |
682 | 2806 /* Use the next tab page if possible. */ |
2807 if (curtab->tp_next != NULL) | |
672 | 2808 return curtab->tp_next; |
2809 | |
682 | 2810 /* Find the last but one tab page. */ |
2811 for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) | |
2812 ; | |
674 | 2813 return tp; |
667 | 2814 } |
2815 | |
2816 /* | |
7 | 2817 * Find the left-upper window in frame "frp". |
2818 */ | |
2819 static win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2820 frame2win(frame_T *frp) |
7 | 2821 { |
2822 while (frp->fr_win == NULL) | |
2823 frp = frp->fr_child; | |
2824 return frp->fr_win; | |
2825 } | |
2826 | |
2827 /* | |
2828 * Return TRUE if frame "frp" contains window "wp". | |
2829 */ | |
2830 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2831 frame_has_win(frame_T *frp, win_T *wp) |
7 | 2832 { |
2833 frame_T *p; | |
2834 | |
2835 if (frp->fr_layout == FR_LEAF) | |
2836 return frp->fr_win == wp; | |
2837 | |
2838 for (p = frp->fr_child; p != NULL; p = p->fr_next) | |
2839 if (frame_has_win(p, wp)) | |
2840 return TRUE; | |
2841 return FALSE; | |
2842 } | |
2843 | |
2844 /* | |
2845 * Set a new height for a frame. Recursively sets the height for contained | |
2846 * frames and windows. Caller must take care of positions. | |
2847 */ | |
2848 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2849 frame_new_height( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2850 frame_T *topfrp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2851 int height, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2852 int topfirst, /* resize topmost contained frame first */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2853 int wfh) /* obey 'winfixheight' when there is a choice; |
7 | 2854 may cause the height not to be set */ |
2855 { | |
2856 frame_T *frp; | |
2857 int extra_lines; | |
2858 int h; | |
2859 | |
2860 if (topfrp->fr_win != NULL) | |
2861 { | |
2862 /* Simple case: just one window. */ | |
2863 win_new_height(topfrp->fr_win, | |
12491
7ab796b041bd
patch 8.0.1125: wrong window height when splitting window with window toolbar
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2864 height - topfrp->fr_win->w_status_height |
12916
af2e0401eb8c
patch 8.0.1334: splitting a window with a WinBar damages window layout
Christian Brabandt <cb@256bit.org>
parents:
12910
diff
changeset
|
2865 - WINBAR_HEIGHT(topfrp->fr_win)); |
7 | 2866 } |
2867 else if (topfrp->fr_layout == FR_ROW) | |
2868 { | |
2869 do | |
2870 { | |
2871 /* All frames in this row get the same new height. */ | |
2872 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
2873 { | |
2874 frame_new_height(frp, height, topfirst, wfh); | |
2875 if (frp->fr_height > height) | |
2876 { | |
2877 /* Could not fit the windows, make the whole row higher. */ | |
2878 height = frp->fr_height; | |
2879 break; | |
2880 } | |
2881 } | |
2882 } | |
2883 while (frp != NULL); | |
2884 } | |
779 | 2885 else /* fr_layout == FR_COL */ |
7 | 2886 { |
2887 /* Complicated case: Resize a column of frames. Resize the bottom | |
2888 * frame first, frames above that when needed. */ | |
2889 | |
2890 frp = topfrp->fr_child; | |
2891 if (wfh) | |
2892 /* Advance past frames with one window with 'wfh' set. */ | |
2893 while (frame_fixed_height(frp)) | |
2894 { | |
2895 frp = frp->fr_next; | |
2896 if (frp == NULL) | |
2897 return; /* no frame without 'wfh', give up */ | |
2898 } | |
2899 if (!topfirst) | |
2900 { | |
2901 /* Find the bottom frame of this column */ | |
2902 while (frp->fr_next != NULL) | |
2903 frp = frp->fr_next; | |
2904 if (wfh) | |
2905 /* Advance back for frames with one window with 'wfh' set. */ | |
2906 while (frame_fixed_height(frp)) | |
2907 frp = frp->fr_prev; | |
2908 } | |
2909 | |
2910 extra_lines = height - topfrp->fr_height; | |
2911 if (extra_lines < 0) | |
2912 { | |
2913 /* reduce height of contained frames, bottom or top frame first */ | |
2914 while (frp != NULL) | |
2915 { | |
2916 h = frame_minheight(frp, NULL); | |
2917 if (frp->fr_height + extra_lines < h) | |
2918 { | |
2919 extra_lines += frp->fr_height - h; | |
2920 frame_new_height(frp, h, topfirst, wfh); | |
2921 } | |
2922 else | |
2923 { | |
2924 frame_new_height(frp, frp->fr_height + extra_lines, | |
2925 topfirst, wfh); | |
2926 break; | |
2927 } | |
2928 if (topfirst) | |
2929 { | |
2930 do | |
2931 frp = frp->fr_next; | |
2932 while (wfh && frp != NULL && frame_fixed_height(frp)); | |
2933 } | |
2934 else | |
2935 { | |
2936 do | |
2937 frp = frp->fr_prev; | |
2938 while (wfh && frp != NULL && frame_fixed_height(frp)); | |
2939 } | |
2940 /* Increase "height" if we could not reduce enough frames. */ | |
2941 if (frp == NULL) | |
2942 height -= extra_lines; | |
2943 } | |
2944 } | |
2945 else if (extra_lines > 0) | |
2946 { | |
2947 /* increase height of bottom or top frame */ | |
2948 frame_new_height(frp, frp->fr_height + extra_lines, topfirst, wfh); | |
2949 } | |
2950 } | |
2951 topfrp->fr_height = height; | |
2952 } | |
2953 | |
2954 /* | |
2955 * Return TRUE if height of frame "frp" should not be changed because of | |
2956 * the 'winfixheight' option. | |
2957 */ | |
2958 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2959 frame_fixed_height(frame_T *frp) |
7 | 2960 { |
2961 /* frame with one window: fixed height if 'winfixheight' set. */ | |
2962 if (frp->fr_win != NULL) | |
2963 return frp->fr_win->w_p_wfh; | |
2964 | |
2965 if (frp->fr_layout == FR_ROW) | |
2966 { | |
2967 /* The frame is fixed height if one of the frames in the row is fixed | |
2968 * height. */ | |
2969 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
2970 if (frame_fixed_height(frp)) | |
2971 return TRUE; | |
2972 return FALSE; | |
2973 } | |
2974 | |
2975 /* frp->fr_layout == FR_COL: The frame is fixed height if all of the | |
2976 * frames in the row are fixed height. */ | |
2977 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
2978 if (!frame_fixed_height(frp)) | |
2979 return FALSE; | |
2980 return TRUE; | |
2981 } | |
2982 | |
2983 /* | |
779 | 2984 * Return TRUE if width of frame "frp" should not be changed because of |
2985 * the 'winfixwidth' option. | |
2986 */ | |
2987 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2988 frame_fixed_width(frame_T *frp) |
779 | 2989 { |
2990 /* frame with one window: fixed width if 'winfixwidth' set. */ | |
2991 if (frp->fr_win != NULL) | |
2992 return frp->fr_win->w_p_wfw; | |
2993 | |
2994 if (frp->fr_layout == FR_COL) | |
2995 { | |
2996 /* The frame is fixed width if one of the frames in the row is fixed | |
2997 * width. */ | |
2998 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
2999 if (frame_fixed_width(frp)) | |
3000 return TRUE; | |
3001 return FALSE; | |
3002 } | |
3003 | |
3004 /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the | |
3005 * frames in the row are fixed width. */ | |
3006 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
3007 if (!frame_fixed_width(frp)) | |
3008 return FALSE; | |
3009 return TRUE; | |
3010 } | |
3011 | |
3012 /* | |
7 | 3013 * Add a status line to windows at the bottom of "frp". |
3014 * Note: Does not check if there is room! | |
3015 */ | |
3016 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3017 frame_add_statusline(frame_T *frp) |
7 | 3018 { |
3019 win_T *wp; | |
3020 | |
3021 if (frp->fr_layout == FR_LEAF) | |
3022 { | |
3023 wp = frp->fr_win; | |
3024 if (wp->w_status_height == 0) | |
3025 { | |
3026 if (wp->w_height > 0) /* don't make it negative */ | |
3027 --wp->w_height; | |
3028 wp->w_status_height = STATUS_HEIGHT; | |
3029 } | |
3030 } | |
3031 else if (frp->fr_layout == FR_ROW) | |
3032 { | |
3033 /* Handle all the frames in the row. */ | |
3034 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
3035 frame_add_statusline(frp); | |
3036 } | |
3037 else /* frp->fr_layout == FR_COL */ | |
3038 { | |
3039 /* Only need to handle the last frame in the column. */ | |
3040 for (frp = frp->fr_child; frp->fr_next != NULL; frp = frp->fr_next) | |
3041 ; | |
3042 frame_add_statusline(frp); | |
3043 } | |
3044 } | |
3045 | |
3046 /* | |
3047 * Set width of a frame. Handles recursively going through contained frames. | |
3048 * May remove separator line for windows at the right side (for win_close()). | |
3049 */ | |
3050 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3051 frame_new_width( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3052 frame_T *topfrp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3053 int width, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3054 int leftfirst, /* resize leftmost contained frame first */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3055 int wfw) /* obey 'winfixwidth' when there is a choice; |
779 | 3056 may cause the width not to be set */ |
7 | 3057 { |
3058 frame_T *frp; | |
3059 int extra_cols; | |
3060 int w; | |
3061 win_T *wp; | |
3062 | |
3063 if (topfrp->fr_layout == FR_LEAF) | |
3064 { | |
3065 /* Simple case: just one window. */ | |
3066 wp = topfrp->fr_win; | |
3067 /* Find out if there are any windows right of this one. */ | |
3068 for (frp = topfrp; frp->fr_parent != NULL; frp = frp->fr_parent) | |
3069 if (frp->fr_parent->fr_layout == FR_ROW && frp->fr_next != NULL) | |
3070 break; | |
3071 if (frp->fr_parent == NULL) | |
3072 wp->w_vsep_width = 0; | |
3073 win_new_width(wp, width - wp->w_vsep_width); | |
3074 } | |
3075 else if (topfrp->fr_layout == FR_COL) | |
3076 { | |
779 | 3077 do |
3078 { | |
3079 /* All frames in this column get the same new width. */ | |
3080 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
3081 { | |
3082 frame_new_width(frp, width, leftfirst, wfw); | |
3083 if (frp->fr_width > width) | |
3084 { | |
3085 /* Could not fit the windows, make whole column wider. */ | |
3086 width = frp->fr_width; | |
3087 break; | |
3088 } | |
3089 } | |
3090 } while (frp != NULL); | |
7 | 3091 } |
3092 else /* fr_layout == FR_ROW */ | |
3093 { | |
3094 /* Complicated case: Resize a row of frames. Resize the rightmost | |
3095 * frame first, frames left of it when needed. */ | |
3096 | |
3097 frp = topfrp->fr_child; | |
779 | 3098 if (wfw) |
3099 /* Advance past frames with one window with 'wfw' set. */ | |
3100 while (frame_fixed_width(frp)) | |
3101 { | |
3102 frp = frp->fr_next; | |
3103 if (frp == NULL) | |
3104 return; /* no frame without 'wfw', give up */ | |
3105 } | |
7 | 3106 if (!leftfirst) |
779 | 3107 { |
3108 /* Find the rightmost frame of this row */ | |
7 | 3109 while (frp->fr_next != NULL) |
3110 frp = frp->fr_next; | |
779 | 3111 if (wfw) |
3112 /* Advance back for frames with one window with 'wfw' set. */ | |
3113 while (frame_fixed_width(frp)) | |
3114 frp = frp->fr_prev; | |
3115 } | |
7 | 3116 |
3117 extra_cols = width - topfrp->fr_width; | |
3118 if (extra_cols < 0) | |
3119 { | |
3120 /* reduce frame width, rightmost frame first */ | |
3121 while (frp != NULL) | |
3122 { | |
3123 w = frame_minwidth(frp, NULL); | |
3124 if (frp->fr_width + extra_cols < w) | |
3125 { | |
3126 extra_cols += frp->fr_width - w; | |
779 | 3127 frame_new_width(frp, w, leftfirst, wfw); |
7 | 3128 } |
3129 else | |
3130 { | |
779 | 3131 frame_new_width(frp, frp->fr_width + extra_cols, |
3132 leftfirst, wfw); | |
7 | 3133 break; |
3134 } | |
3135 if (leftfirst) | |
779 | 3136 { |
3137 do | |
3138 frp = frp->fr_next; | |
3139 while (wfw && frp != NULL && frame_fixed_width(frp)); | |
3140 } | |
7 | 3141 else |
779 | 3142 { |
3143 do | |
3144 frp = frp->fr_prev; | |
3145 while (wfw && frp != NULL && frame_fixed_width(frp)); | |
3146 } | |
3147 /* Increase "width" if we could not reduce enough frames. */ | |
3148 if (frp == NULL) | |
3149 width -= extra_cols; | |
7 | 3150 } |
3151 } | |
3152 else if (extra_cols > 0) | |
3153 { | |
3154 /* increase width of rightmost frame */ | |
779 | 3155 frame_new_width(frp, frp->fr_width + extra_cols, leftfirst, wfw); |
7 | 3156 } |
3157 } | |
3158 topfrp->fr_width = width; | |
3159 } | |
3160 | |
3161 /* | |
3162 * Add the vertical separator to windows at the right side of "frp". | |
3163 * Note: Does not check if there is room! | |
3164 */ | |
3165 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3166 frame_add_vsep(frame_T *frp) |
7 | 3167 { |
3168 win_T *wp; | |
3169 | |
3170 if (frp->fr_layout == FR_LEAF) | |
3171 { | |
3172 wp = frp->fr_win; | |
3173 if (wp->w_vsep_width == 0) | |
3174 { | |
3175 if (wp->w_width > 0) /* don't make it negative */ | |
3176 --wp->w_width; | |
3177 wp->w_vsep_width = 1; | |
3178 } | |
3179 } | |
3180 else if (frp->fr_layout == FR_COL) | |
3181 { | |
3182 /* Handle all the frames in the column. */ | |
3183 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
3184 frame_add_vsep(frp); | |
3185 } | |
3186 else /* frp->fr_layout == FR_ROW */ | |
3187 { | |
3188 /* Only need to handle the last frame in the row. */ | |
3189 frp = frp->fr_child; | |
3190 while (frp->fr_next != NULL) | |
3191 frp = frp->fr_next; | |
3192 frame_add_vsep(frp); | |
3193 } | |
3194 } | |
3195 | |
3196 /* | |
3197 * Set frame width from the window it contains. | |
3198 */ | |
3199 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3200 frame_fix_width(win_T *wp) |
7 | 3201 { |
3202 wp->w_frame->fr_width = wp->w_width + wp->w_vsep_width; | |
3203 } | |
3204 | |
3205 /* | |
3206 * Set frame height from the window it contains. | |
3207 */ | |
3208 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3209 frame_fix_height(win_T *wp) |
7 | 3210 { |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3211 wp->w_frame->fr_height = VISIBLE_HEIGHT(wp) + wp->w_status_height; |
7 | 3212 } |
3213 | |
3214 /* | |
3215 * Compute the minimal height for frame "topfrp". | |
3216 * Uses the 'winminheight' option. | |
3217 * When "next_curwin" isn't NULL, use p_wh for this window. | |
3218 * When "next_curwin" is NOWIN, don't use at least one line for the current | |
3219 * window. | |
3220 */ | |
3221 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3222 frame_minheight(frame_T *topfrp, win_T *next_curwin) |
7 | 3223 { |
3224 frame_T *frp; | |
3225 int m; | |
3226 int n; | |
3227 | |
3228 if (topfrp->fr_win != NULL) | |
3229 { | |
3230 if (topfrp->fr_win == next_curwin) | |
3231 m = p_wh + topfrp->fr_win->w_status_height; | |
3232 else | |
3233 { | |
3234 /* window: minimal height of the window plus status line */ | |
3235 m = p_wmh + topfrp->fr_win->w_status_height; | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3236 if (topfrp->fr_win == curwin && next_curwin == NULL) |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3237 { |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3238 /* Current window is minimal one line high and WinBar is |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3239 * visible. */ |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3240 if (p_wmh == 0) |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3241 ++m; |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3242 m += WINBAR_HEIGHT(curwin); |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
3243 } |
7 | 3244 } |
3245 } | |
3246 else if (topfrp->fr_layout == FR_ROW) | |
3247 { | |
3248 /* get the minimal height from each frame in this row */ | |
3249 m = 0; | |
3250 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
3251 { | |
3252 n = frame_minheight(frp, next_curwin); | |
3253 if (n > m) | |
3254 m = n; | |
3255 } | |
3256 } | |
3257 else | |
3258 { | |
3259 /* Add up the minimal heights for all frames in this column. */ | |
3260 m = 0; | |
3261 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
3262 m += frame_minheight(frp, next_curwin); | |
3263 } | |
3264 | |
3265 return m; | |
3266 } | |
3267 | |
3268 /* | |
3269 * Compute the minimal width for frame "topfrp". | |
3270 * When "next_curwin" isn't NULL, use p_wiw for this window. | |
3271 * When "next_curwin" is NOWIN, don't use at least one column for the current | |
3272 * window. | |
3273 */ | |
3274 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3275 frame_minwidth( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3276 frame_T *topfrp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3277 win_T *next_curwin) /* use p_wh and p_wiw for next_curwin */ |
7 | 3278 { |
3279 frame_T *frp; | |
3280 int m, n; | |
3281 | |
3282 if (topfrp->fr_win != NULL) | |
3283 { | |
3284 if (topfrp->fr_win == next_curwin) | |
3285 m = p_wiw + topfrp->fr_win->w_vsep_width; | |
3286 else | |
3287 { | |
3288 /* window: minimal width of the window plus separator column */ | |
3289 m = p_wmw + topfrp->fr_win->w_vsep_width; | |
3290 /* Current window is minimal one column wide */ | |
3291 if (p_wmw == 0 && topfrp->fr_win == curwin && next_curwin == NULL) | |
3292 ++m; | |
3293 } | |
3294 } | |
3295 else if (topfrp->fr_layout == FR_COL) | |
3296 { | |
3297 /* get the minimal width from each frame in this column */ | |
3298 m = 0; | |
3299 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
3300 { | |
3301 n = frame_minwidth(frp, next_curwin); | |
3302 if (n > m) | |
3303 m = n; | |
3304 } | |
3305 } | |
3306 else | |
3307 { | |
3308 /* Add up the minimal widths for all frames in this row. */ | |
3309 m = 0; | |
3310 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
3311 m += frame_minwidth(frp, next_curwin); | |
3312 } | |
3313 | |
3314 return m; | |
3315 } | |
3316 | |
3317 | |
3318 /* | |
3319 * Try to close all windows except current one. | |
3320 * Buffers in the other windows become hidden if 'hidden' is set, or '!' is | |
3321 * used and the buffer was modified. | |
3322 * | |
3323 * Used by ":bdel" and ":only". | |
3324 */ | |
3325 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3326 close_others( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3327 int message, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3328 int forceit) /* always hide all other windows */ |
7 | 3329 { |
3330 win_T *wp; | |
3331 win_T *nextwp; | |
3332 int r; | |
3333 | |
1906 | 3334 if (one_window()) |
7 | 3335 { |
3336 if (message | |
3337 #ifdef FEAT_AUTOCMD | |
3338 && !autocmd_busy | |
3339 #endif | |
3340 ) | |
826 | 3341 MSG(_(m_onlyone)); |
7 | 3342 return; |
3343 } | |
3344 | |
3345 /* Be very careful here: autocommands may change the window layout. */ | |
3346 for (wp = firstwin; win_valid(wp); wp = nextwp) | |
3347 { | |
3348 nextwp = wp->w_next; | |
3349 if (wp != curwin) /* don't close current window */ | |
3350 { | |
3351 | |
3352 /* Check if it's allowed to abandon this window */ | |
3353 r = can_abandon(wp->w_buffer, forceit); | |
3354 #ifdef FEAT_AUTOCMD | |
3355 if (!win_valid(wp)) /* autocommands messed wp up */ | |
3356 { | |
3357 nextwp = firstwin; | |
3358 continue; | |
3359 } | |
3360 #endif | |
3361 if (!r) | |
3362 { | |
3363 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3364 if (message && (p_confirm || cmdmod.confirm) && p_write) | |
3365 { | |
3366 dialog_changed(wp->w_buffer, FALSE); | |
3367 # ifdef FEAT_AUTOCMD | |
3368 if (!win_valid(wp)) /* autocommands messed wp up */ | |
3369 { | |
3370 nextwp = firstwin; | |
3371 continue; | |
3372 } | |
3373 # endif | |
3374 } | |
3375 if (bufIsChanged(wp->w_buffer)) | |
3376 #endif | |
3377 continue; | |
3378 } | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
3379 win_close(wp, !buf_hide(wp->w_buffer) |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
3380 && !bufIsChanged(wp->w_buffer)); |
7 | 3381 } |
3382 } | |
3383 | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
3384 if (message && !ONE_WINDOW) |
7 | 3385 EMSG(_("E445: Other window contains changes")); |
3386 } | |
3387 | |
3388 /* | |
675 | 3389 * Init the current window "curwin". |
3390 * Called when a new file is being edited. | |
7 | 3391 */ |
3392 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3393 curwin_init(void) |
7 | 3394 { |
1918 | 3395 win_init_empty(curwin); |
3396 } | |
3397 | |
3398 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3399 win_init_empty(win_T *wp) |
1918 | 3400 { |
3401 redraw_win_later(wp, NOT_VALID); | |
3402 wp->w_lines_valid = 0; | |
3403 wp->w_cursor.lnum = 1; | |
3404 wp->w_curswant = wp->w_cursor.col = 0; | |
7 | 3405 #ifdef FEAT_VIRTUALEDIT |
1918 | 3406 wp->w_cursor.coladd = 0; |
3407 #endif | |
3408 wp->w_pcmark.lnum = 1; /* pcmark not cleared but set to line 1 */ | |
3409 wp->w_pcmark.col = 0; | |
3410 wp->w_prev_pcmark.lnum = 0; | |
3411 wp->w_prev_pcmark.col = 0; | |
3412 wp->w_topline = 1; | |
7 | 3413 #ifdef FEAT_DIFF |
1918 | 3414 wp->w_topfill = 0; |
3415 #endif | |
3416 wp->w_botline = 2; | |
7 | 3417 #ifdef FEAT_FKMAP |
1918 | 3418 if (wp->w_p_rl) |
3419 wp->w_farsi = W_CONV + W_R_L; | |
7 | 3420 else |
1918 | 3421 wp->w_farsi = W_CONV; |
7 | 3422 #endif |
3068 | 3423 #ifdef FEAT_SYN_HL |
3424 wp->w_s = &wp->w_buffer->b_s; | |
3425 #endif | |
7 | 3426 } |
3427 | |
3428 /* | |
3429 * Allocate the first window and put an empty buffer in it. | |
3430 * Called from main(). | |
667 | 3431 * Return FAIL when something goes wrong (out of memory). |
7 | 3432 */ |
667 | 3433 int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3434 win_alloc_first(void) |
7 | 3435 { |
675 | 3436 if (win_alloc_firstwin(NULL) == FAIL) |
667 | 3437 return FAIL; |
3438 | |
672 | 3439 first_tabpage = alloc_tabpage(); |
667 | 3440 if (first_tabpage == NULL) |
3441 return FAIL; | |
3442 first_tabpage->tp_topframe = topframe; | |
672 | 3443 curtab = first_tabpage; |
1906 | 3444 |
667 | 3445 return OK; |
3446 } | |
3447 | |
1906 | 3448 #if defined(FEAT_AUTOCMD) || defined(PROTO) |
3449 /* | |
3450 * Init "aucmd_win". This can only be done after the first | |
3451 * window is fully initialized, thus it can't be in win_alloc_first(). | |
3452 */ | |
3453 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3454 win_alloc_aucmd_win(void) |
1906 | 3455 { |
3456 aucmd_win = win_alloc(NULL, TRUE); | |
3457 if (aucmd_win != NULL) | |
3458 { | |
3459 win_init_some(aucmd_win, curwin); | |
2583 | 3460 RESET_BINDING(aucmd_win); |
1906 | 3461 new_frame(aucmd_win); |
3462 } | |
3463 } | |
3464 #endif | |
3465 | |
667 | 3466 /* |
675 | 3467 * Allocate the first window or the first window in a new tab page. |
3468 * When "oldwin" is NULL create an empty buffer for it. | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
3469 * When "oldwin" is not NULL copy info from it to the new window. |
667 | 3470 * Return FAIL when something goes wrong (out of memory). |
3471 */ | |
3472 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3473 win_alloc_firstwin(win_T *oldwin) |
667 | 3474 { |
1906 | 3475 curwin = win_alloc(NULL, FALSE); |
675 | 3476 if (oldwin == NULL) |
3477 { | |
3478 /* Very first window, need to create an empty buffer for it and | |
3479 * initialize from scratch. */ | |
3480 curbuf = buflist_new(NULL, NULL, 1L, BLN_LISTED); | |
3481 if (curwin == NULL || curbuf == NULL) | |
3482 return FAIL; | |
3483 curwin->w_buffer = curbuf; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
3484 #ifdef FEAT_SYN_HL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
3485 curwin->w_s = &(curbuf->b_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
3486 #endif |
675 | 3487 curbuf->b_nwindows = 1; /* there is one window */ |
3488 curwin->w_alist = &global_alist; | |
3489 curwin_init(); /* init current window */ | |
3490 } | |
3491 else | |
3492 { | |
3493 /* First window in new tab page, initialize it from "oldwin". */ | |
1822 | 3494 win_init(curwin, oldwin, 0); |
675 | 3495 |
2583 | 3496 /* We don't want cursor- and scroll-binding in the first window. */ |
3497 RESET_BINDING(curwin); | |
675 | 3498 } |
7 | 3499 |
1906 | 3500 new_frame(curwin); |
3501 if (curwin->w_frame == NULL) | |
667 | 3502 return FAIL; |
1906 | 3503 topframe = curwin->w_frame; |
7 | 3504 topframe->fr_width = Columns; |
3505 topframe->fr_height = Rows - p_ch; | |
667 | 3506 |
3507 return OK; | |
3508 } | |
3509 | |
3510 /* | |
1906 | 3511 * Create a frame for window "wp". |
3512 */ | |
3513 static void | |
3514 new_frame(win_T *wp) | |
3515 { | |
3516 frame_T *frp = (frame_T *)alloc_clear((unsigned)sizeof(frame_T)); | |
3517 | |
3518 wp->w_frame = frp; | |
3519 if (frp != NULL) | |
3520 { | |
3521 frp->fr_layout = FR_LEAF; | |
3522 frp->fr_win = wp; | |
3523 } | |
3524 } | |
3525 | |
3526 /* | |
667 | 3527 * Initialize the window and frame size to the maximum. |
3528 */ | |
3529 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3530 win_init_size(void) |
667 | 3531 { |
3532 firstwin->w_height = ROWS_AVAIL; | |
3533 topframe->fr_height = ROWS_AVAIL; | |
3534 firstwin->w_width = Columns; | |
3535 topframe->fr_width = Columns; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
3536 } |
672 | 3537 |
3538 /* | |
3539 * Allocate a new tabpage_T and init the values. | |
3540 * Returns NULL when out of memory. | |
3541 */ | |
3542 static tabpage_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3543 alloc_tabpage(void) |
672 | 3544 { |
3545 tabpage_T *tp; | |
4287 | 3546 # ifdef FEAT_GUI |
3547 int i; | |
3548 # endif | |
3549 | |
672 | 3550 |
3551 tp = (tabpage_T *)alloc_clear((unsigned)sizeof(tabpage_T)); | |
4287 | 3552 if (tp == NULL) |
3553 return NULL; | |
3554 | |
3555 # ifdef FEAT_EVAL | |
3556 /* init t: variables */ | |
3557 tp->tp_vars = dict_alloc(); | |
3558 if (tp->tp_vars == NULL) | |
3559 { | |
3560 vim_free(tp); | |
3561 return NULL; | |
3562 } | |
3563 init_var_dict(tp->tp_vars, &tp->tp_winvar, VAR_SCOPE); | |
3564 # endif | |
3565 | |
788 | 3566 # ifdef FEAT_GUI |
4287 | 3567 for (i = 0; i < 3; i++) |
3568 tp->tp_prev_which_scrollbars[i] = -1; | |
788 | 3569 # endif |
672 | 3570 # ifdef FEAT_DIFF |
4287 | 3571 tp->tp_diff_invalid = TRUE; |
672 | 3572 # endif |
4287 | 3573 tp->tp_ch_used = p_ch; |
3574 | |
672 | 3575 return tp; |
3576 } | |
3577 | |
852 | 3578 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3579 free_tabpage(tabpage_T *tp) |
672 | 3580 { |
1906 | 3581 int idx; |
3582 | |
672 | 3583 # ifdef FEAT_DIFF |
3584 diff_clear(tp); | |
3585 # endif | |
1906 | 3586 for (idx = 0; idx < SNAP_COUNT; ++idx) |
3587 clear_snapshot(tp, idx); | |
819 | 3588 #ifdef FEAT_EVAL |
4287 | 3589 vars_clear(&tp->tp_vars->dv_hashtab); /* free all t: variables */ |
3590 hash_init(&tp->tp_vars->dv_hashtab); | |
3591 unref_var_dict(tp->tp_vars); | |
819 | 3592 #endif |
4401 | 3593 |
3594 #ifdef FEAT_PYTHON | |
3595 python_tabpage_free(tp); | |
3596 #endif | |
3597 | |
3598 #ifdef FEAT_PYTHON3 | |
3599 python3_tabpage_free(tp); | |
3600 #endif | |
3601 | |
672 | 3602 vim_free(tp); |
3603 } | |
3604 | |
667 | 3605 /* |
675 | 3606 * Create a new Tab page with one window. |
3607 * It will edit the current buffer, like after ":split". | |
682 | 3608 * When "after" is 0 put it just after the current Tab page. |
3609 * Otherwise put it just before tab page "after". | |
667 | 3610 * Return FAIL or OK. |
3611 */ | |
3612 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3613 win_new_tabpage(int after) |
667 | 3614 { |
672 | 3615 tabpage_T *tp = curtab; |
667 | 3616 tabpage_T *newtp; |
682 | 3617 int n; |
667 | 3618 |
672 | 3619 newtp = alloc_tabpage(); |
667 | 3620 if (newtp == NULL) |
3621 return FAIL; | |
3622 | |
3623 /* Remember the current windows in this Tab page. */ | |
4354 | 3624 if (leave_tabpage(curbuf, TRUE) == FAIL) |
674 | 3625 { |
3626 vim_free(newtp); | |
3627 return FAIL; | |
3628 } | |
672 | 3629 curtab = newtp; |
667 | 3630 |
3631 /* Create a new empty window. */ | |
675 | 3632 if (win_alloc_firstwin(tp->tp_curwin) == OK) |
667 | 3633 { |
3634 /* Make the new Tab page the new topframe. */ | |
682 | 3635 if (after == 1) |
3636 { | |
3637 /* New tab page becomes the first one. */ | |
3638 newtp->tp_next = first_tabpage; | |
3639 first_tabpage = newtp; | |
3640 } | |
3641 else | |
3642 { | |
3643 if (after > 0) | |
3644 { | |
3645 /* Put new tab page before tab page "after". */ | |
3646 n = 2; | |
3647 for (tp = first_tabpage; tp->tp_next != NULL | |
3648 && n < after; tp = tp->tp_next) | |
3649 ++n; | |
3650 } | |
3651 newtp->tp_next = tp->tp_next; | |
3652 tp->tp_next = newtp; | |
3653 } | |
667 | 3654 win_init_size(); |
685 | 3655 firstwin->w_winrow = tabline_height(); |
819 | 3656 win_comp_scroll(curwin); |
667 | 3657 |
3658 newtp->tp_topframe = topframe; | |
671 | 3659 last_status(FALSE); |
815 | 3660 |
3661 #if defined(FEAT_GUI) | |
3662 /* When 'guioptions' includes 'L' or 'R' may have to remove or add | |
3663 * scrollbars. Have to update them anyway. */ | |
1906 | 3664 gui_may_update_scrollbars(); |
815 | 3665 #endif |
3666 | |
667 | 3667 redraw_all_later(CLEAR); |
675 | 3668 #ifdef FEAT_AUTOCMD |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3669 apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf); |
4354 | 3670 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3671 apply_autocmds(EVENT_TABNEW, NULL, NULL, FALSE, curbuf); |
675 | 3672 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); |
3673 #endif | |
667 | 3674 return OK; |
3675 } | |
3676 | |
3677 /* Failed, get back the previous Tab page */ | |
4354 | 3678 enter_tabpage(curtab, curbuf, TRUE, TRUE); |
667 | 3679 return FAIL; |
3680 } | |
3681 | |
3682 /* | |
682 | 3683 * Open a new tab page if ":tab cmd" was used. It will edit the same buffer, |
3684 * like with ":split". | |
3685 * Returns OK if a new tab page was created, FAIL otherwise. | |
3686 */ | |
3687 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3688 may_open_tabpage(void) |
682 | 3689 { |
1090 | 3690 int n = (cmdmod.tab == 0) ? postponed_split_tab : cmdmod.tab; |
3691 | |
3692 if (n != 0) | |
682 | 3693 { |
3694 cmdmod.tab = 0; /* reset it to avoid doing it twice */ | |
1090 | 3695 postponed_split_tab = 0; |
682 | 3696 return win_new_tabpage(n); |
3697 } | |
3698 return FAIL; | |
3699 } | |
3700 | |
3701 /* | |
672 | 3702 * Create up to "maxcount" tabpages with empty windows. |
3703 * Returns the number of resulting tab pages. | |
667 | 3704 */ |
672 | 3705 int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3706 make_tabpages(int maxcount) |
667 | 3707 { |
672 | 3708 int count = maxcount; |
3709 int todo; | |
3710 | |
698 | 3711 /* Limit to 'tabpagemax' tabs. */ |
3712 if (count > p_tpm) | |
3713 count = p_tpm; | |
672 | 3714 |
3715 #ifdef FEAT_AUTOCMD | |
3716 /* | |
3717 * Don't execute autocommands while creating the tab pages. Must do that | |
3718 * when putting the buffers in the windows. | |
3719 */ | |
1410 | 3720 block_autocmds(); |
672 | 3721 #endif |
3722 | |
3723 for (todo = count - 1; todo > 0; --todo) | |
682 | 3724 if (win_new_tabpage(0) == FAIL) |
667 | 3725 break; |
672 | 3726 |
3727 #ifdef FEAT_AUTOCMD | |
1410 | 3728 unblock_autocmds(); |
672 | 3729 #endif |
3730 | |
3731 /* return actual number of tab pages */ | |
3732 return (count - todo); | |
667 | 3733 } |
3734 | |
3735 /* | |
671 | 3736 * Return TRUE when "tpc" points to a valid tab page. |
3737 */ | |
3738 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3739 valid_tabpage(tabpage_T *tpc) |
671 | 3740 { |
3741 tabpage_T *tp; | |
3742 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
3743 FOR_ALL_TABPAGES(tp) |
671 | 3744 if (tp == tpc) |
3745 return TRUE; | |
3746 return FALSE; | |
3747 } | |
3748 | |
3749 /* | |
11199
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3750 * Return TRUE when "tpc" points to a valid tab page and at least one window is |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3751 * valid. |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3752 */ |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3753 int |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3754 valid_tabpage_win(tabpage_T *tpc) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3755 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3756 tabpage_T *tp; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3757 win_T *wp; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3758 |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3759 FOR_ALL_TABPAGES(tp) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3760 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3761 if (tp == tpc) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3762 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3763 FOR_ALL_WINDOWS_IN_TAB(tp, wp) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3764 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3765 if (win_valid_any_tab(wp)) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3766 return TRUE; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3767 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3768 return FALSE; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3769 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3770 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3771 /* shouldn't happen */ |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3772 return FALSE; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3773 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3774 |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3775 /* |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3776 * Close tabpage "tab", assuming it has no windows in it. |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3777 * There must be another tabpage or this will crash. |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3778 */ |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3779 void |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3780 close_tabpage(tabpage_T *tab) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3781 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3782 tabpage_T *ptp; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3783 |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3784 if (tab == first_tabpage) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3785 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3786 first_tabpage = tab->tp_next; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3787 ptp = first_tabpage; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3788 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3789 else |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3790 { |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3791 for (ptp = first_tabpage; ptp != NULL && ptp->tp_next != tab; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3792 ptp = ptp->tp_next) |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3793 ; |
11232
a14090a30a3f
patch 8.0.0502: Coverity complains about possible NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11207
diff
changeset
|
3794 assert(ptp != NULL); |
11199
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3795 ptp->tp_next = tab->tp_next; |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3796 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3797 |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3798 goto_tabpage_tp(ptp, FALSE, FALSE); |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3799 free_tabpage(tab); |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3800 } |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3801 |
e08ead1d269f
patch 8.0.0486: crash and endless loop when closing windows in autocmd
Christian Brabandt <cb@256bit.org>
parents:
11193
diff
changeset
|
3802 /* |
671 | 3803 * Find tab page "n" (first one is 1). Returns NULL when not found. |
3804 */ | |
3805 tabpage_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3806 find_tabpage(int n) |
671 | 3807 { |
3808 tabpage_T *tp; | |
3809 int i = 1; | |
3810 | |
3811 for (tp = first_tabpage; tp != NULL && i != n; tp = tp->tp_next) | |
3812 ++i; | |
3813 return tp; | |
3814 } | |
3815 | |
3816 /* | |
685 | 3817 * Get index of tab page "tp". First one has index 1. |
686 | 3818 * When not found returns number of tab pages plus one. |
685 | 3819 */ |
3820 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3821 tabpage_index(tabpage_T *ftp) |
685 | 3822 { |
3823 int i = 1; | |
3824 tabpage_T *tp; | |
3825 | |
3826 for (tp = first_tabpage; tp != NULL && tp != ftp; tp = tp->tp_next) | |
3827 ++i; | |
3828 return i; | |
3829 } | |
3830 | |
3831 /* | |
674 | 3832 * Prepare for leaving the current tab page. |
4352 | 3833 * When autocommands change "curtab" we don't leave the tab page and return |
674 | 3834 * FAIL. |
3835 * Careful: When OK is returned need to get a new tab page very very soon! | |
667 | 3836 */ |
674 | 3837 static int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3838 leave_tabpage( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3839 buf_T *new_curbuf UNUSED, /* what is going to be the new curbuf, |
674 | 3840 NULL if unknown */ |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3841 int trigger_leave_autocmds UNUSED) |
667 | 3842 { |
674 | 3843 tabpage_T *tp = curtab; |
3844 | |
819 | 3845 reset_VIsual_and_resel(); /* stop Visual mode */ |
674 | 3846 #ifdef FEAT_AUTOCMD |
4354 | 3847 if (trigger_leave_autocmds) |
3848 { | |
3849 if (new_curbuf != curbuf) | |
3850 { | |
3851 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); | |
3852 if (curtab != tp) | |
3853 return FAIL; | |
3854 } | |
3855 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf); | |
674 | 3856 if (curtab != tp) |
3857 return FAIL; | |
4354 | 3858 apply_autocmds(EVENT_TABLEAVE, NULL, NULL, FALSE, curbuf); |
3859 if (curtab != tp) | |
3860 return FAIL; | |
3861 } | |
674 | 3862 #endif |
668 | 3863 #if defined(FEAT_GUI) |
3864 /* Remove the scrollbars. They may be added back later. */ | |
3865 if (gui.in_use) | |
3866 gui_remove_scrollbars(); | |
3867 #endif | |
667 | 3868 tp->tp_curwin = curwin; |
671 | 3869 tp->tp_prevwin = prevwin; |
667 | 3870 tp->tp_firstwin = firstwin; |
3871 tp->tp_lastwin = lastwin; | |
668 | 3872 tp->tp_old_Rows = Rows; |
3873 tp->tp_old_Columns = Columns; | |
667 | 3874 firstwin = NULL; |
3875 lastwin = NULL; | |
674 | 3876 return OK; |
667 | 3877 } |
3878 | |
3879 /* | |
3880 * Start using tab page "tp". | |
675 | 3881 * Only to be used after leave_tabpage() or freeing the current tab page. |
4354 | 3882 * Only trigger *Enter autocommands when trigger_enter_autocmds is TRUE. |
3883 * Only trigger *Leave autocommands when trigger_leave_autocmds is TRUE. | |
667 | 3884 */ |
3885 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3886 enter_tabpage( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3887 tabpage_T *tp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3888 buf_T *old_curbuf UNUSED, |
8368
db2a07b710ed
commit https://github.com/vim/vim/commit/f1d2501ebe33e148886c2914acd33140e20ee222
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
3889 int trigger_enter_autocmds, |
db2a07b710ed
commit https://github.com/vim/vim/commit/f1d2501ebe33e148886c2914acd33140e20ee222
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
3890 int trigger_leave_autocmds) |
667 | 3891 { |
668 | 3892 int old_off = tp->tp_firstwin->w_winrow; |
870 | 3893 win_T *next_prevwin = tp->tp_prevwin; |
668 | 3894 |
672 | 3895 curtab = tp; |
667 | 3896 firstwin = tp->tp_firstwin; |
3897 lastwin = tp->tp_lastwin; | |
3898 topframe = tp->tp_topframe; | |
870 | 3899 |
3900 /* We would like doing the TabEnter event first, but we don't have a | |
3901 * valid current window yet, which may break some commands. | |
3902 * This triggers autocommands, thus may make "tp" invalid. */ | |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3903 win_enter_ext(tp->tp_curwin, FALSE, TRUE, FALSE, |
4918
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3904 trigger_enter_autocmds, trigger_leave_autocmds); |
870 | 3905 prevwin = next_prevwin; |
3906 | |
668 | 3907 last_status(FALSE); /* status line may appear or disappear */ |
3908 (void)win_comp_pos(); /* recompute w_winrow for all windows */ | |
672 | 3909 must_redraw = CLEAR; /* need to redraw everything */ |
3910 #ifdef FEAT_DIFF | |
3911 diff_need_scrollbind = TRUE; | |
3912 #endif | |
668 | 3913 |
3914 /* The tabpage line may have appeared or disappeared, may need to resize | |
3915 * the frames for that. When the Vim window was resized need to update | |
824 | 3916 * frame sizes too. Use the stored value of p_ch, so that it can be |
3917 * different for each tab page. */ | |
3918 p_ch = curtab->tp_ch_used; | |
685 | 3919 if (curtab->tp_old_Rows != Rows || (old_off != firstwin->w_winrow |
3920 #ifdef FEAT_GUI_TABLINE | |
3921 && !gui_use_tabline() | |
3922 #endif | |
3923 )) | |
668 | 3924 shell_new_rows(); |
674 | 3925 if (curtab->tp_old_Columns != Columns && starting == 0) |
668 | 3926 shell_new_columns(); /* update window widths */ |
3927 | |
3928 #if defined(FEAT_GUI) | |
3929 /* When 'guioptions' includes 'L' or 'R' may have to remove or add | |
3930 * scrollbars. Have to update them anyway. */ | |
1906 | 3931 gui_may_update_scrollbars(); |
667 | 3932 #endif |
3933 | |
3413 | 3934 #ifdef FEAT_AUTOCMD |
3935 /* Apply autocommands after updating the display, when 'rows' and | |
3936 * 'columns' have been set correctly. */ | |
4354 | 3937 if (trigger_enter_autocmds) |
3582 | 3938 { |
3939 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); | |
3940 if (old_curbuf != curbuf) | |
3941 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
3942 } | |
3413 | 3943 #endif |
3944 | |
667 | 3945 redraw_all_later(CLEAR); |
3946 } | |
3947 | |
3948 /* | |
3949 * Go to tab page "n". For ":tab N" and "Ngt". | |
685 | 3950 * When "n" is 9999 go to the last tab page. |
667 | 3951 */ |
3952 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3953 goto_tabpage(int n) |
667 | 3954 { |
3955 tabpage_T *tp; | |
682 | 3956 tabpage_T *ttp; |
667 | 3957 int i; |
3958 | |
857 | 3959 if (text_locked()) |
3960 { | |
3961 /* Not allowed when editing the command line. */ | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10076
diff
changeset
|
3962 text_locked_msg(); |
857 | 3963 return; |
3964 } | |
3965 | |
675 | 3966 /* If there is only one it can't work. */ |
3967 if (first_tabpage->tp_next == NULL) | |
3968 { | |
3969 if (n > 1) | |
3970 beep_flush(); | |
3971 return; | |
3972 } | |
3973 | |
667 | 3974 if (n == 0) |
3975 { | |
3976 /* No count, go to next tab page, wrap around end. */ | |
674 | 3977 if (curtab->tp_next == NULL) |
667 | 3978 tp = first_tabpage; |
3979 else | |
674 | 3980 tp = curtab->tp_next; |
667 | 3981 } |
682 | 3982 else if (n < 0) |
3983 { | |
3984 /* "gT": go to previous tab page, wrap around end. "N gT" repeats | |
3985 * this N times. */ | |
3986 ttp = curtab; | |
3987 for (i = n; i < 0; ++i) | |
3988 { | |
3989 for (tp = first_tabpage; tp->tp_next != ttp && tp->tp_next != NULL; | |
3990 tp = tp->tp_next) | |
3991 ; | |
3992 ttp = tp; | |
3993 } | |
3994 } | |
685 | 3995 else if (n == 9999) |
3996 { | |
3997 /* Go to last tab page. */ | |
3998 for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next) | |
3999 ; | |
4000 } | |
667 | 4001 else |
4002 { | |
4003 /* Go to tab page "n". */ | |
685 | 4004 tp = find_tabpage(n); |
671 | 4005 if (tp == NULL) |
4006 { | |
4007 beep_flush(); | |
4008 return; | |
4009 } | |
667 | 4010 } |
4011 | |
4354 | 4012 goto_tabpage_tp(tp, TRUE, TRUE); |
685 | 4013 |
4014 #ifdef FEAT_GUI_TABLINE | |
4015 if (gui_use_tabline()) | |
690 | 4016 gui_mch_set_curtab(tabpage_index(curtab)); |
685 | 4017 #endif |
4018 } | |
4019 | |
4020 /* | |
4021 * Go to tabpage "tp". | |
4354 | 4022 * Only trigger *Enter autocommands when trigger_enter_autocmds is TRUE. |
4023 * Only trigger *Leave autocommands when trigger_leave_autocmds is TRUE. | |
685 | 4024 * Note: doesn't update the GUI tab. |
4025 */ | |
4026 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4027 goto_tabpage_tp( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4028 tabpage_T *tp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4029 int trigger_enter_autocmds, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4030 int trigger_leave_autocmds) |
685 | 4031 { |
2201
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2115
diff
changeset
|
4032 /* Don't repeat a message in another tab page. */ |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2115
diff
changeset
|
4033 set_keep_msg(NULL, 0); |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2115
diff
changeset
|
4034 |
4354 | 4035 if (tp != curtab && leave_tabpage(tp->tp_curwin->w_buffer, |
4036 trigger_leave_autocmds) == OK) | |
674 | 4037 { |
4038 if (valid_tabpage(tp)) | |
4354 | 4039 enter_tabpage(tp, curbuf, trigger_enter_autocmds, |
4040 trigger_leave_autocmds); | |
674 | 4041 else |
4354 | 4042 enter_tabpage(curtab, curbuf, trigger_enter_autocmds, |
4043 trigger_leave_autocmds); | |
674 | 4044 } |
667 | 4045 } |
7 | 4046 |
4047 /* | |
825 | 4048 * Enter window "wp" in tab page "tp". |
4049 * Also updates the GUI tab. | |
4050 */ | |
4051 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4052 goto_tabpage_win(tabpage_T *tp, win_T *wp) |
825 | 4053 { |
4354 | 4054 goto_tabpage_tp(tp, TRUE, TRUE); |
825 | 4055 if (curtab == tp && win_valid(wp)) |
4056 { | |
4057 win_enter(wp, TRUE); | |
4058 # ifdef FEAT_GUI_TABLINE | |
4059 if (gui_use_tabline()) | |
4060 gui_mch_set_curtab(tabpage_index(curtab)); | |
4061 # endif | |
4062 } | |
4063 } | |
4064 | |
4065 /* | |
6775 | 4066 * Move the current tab page to after tab page "nr". |
682 | 4067 */ |
4068 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4069 tabpage_move(int nr) |
682 | 4070 { |
6775 | 4071 int n = 1; |
4072 tabpage_T *tp, *tp_dst; | |
682 | 4073 |
4074 if (first_tabpage->tp_next == NULL) | |
4075 return; | |
4076 | |
6775 | 4077 for (tp = first_tabpage; tp->tp_next != NULL && n < nr; tp = tp->tp_next) |
4078 ++n; | |
4079 | |
4080 if (tp == curtab || (nr > 0 && tp->tp_next != NULL | |
4081 && tp->tp_next == curtab)) | |
4082 return; | |
4083 | |
4084 tp_dst = tp; | |
4085 | |
682 | 4086 /* Remove the current tab page from the list of tab pages. */ |
4087 if (curtab == first_tabpage) | |
4088 first_tabpage = curtab->tp_next; | |
4089 else | |
4090 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4091 FOR_ALL_TABPAGES(tp) |
682 | 4092 if (tp->tp_next == curtab) |
4093 break; | |
4094 if (tp == NULL) /* "cannot happen" */ | |
4095 return; | |
4096 tp->tp_next = curtab->tp_next; | |
4097 } | |
4098 | |
4099 /* Re-insert it at the specified position. */ | |
6775 | 4100 if (nr <= 0) |
682 | 4101 { |
4102 curtab->tp_next = first_tabpage; | |
4103 first_tabpage = curtab; | |
4104 } | |
4105 else | |
4106 { | |
6775 | 4107 curtab->tp_next = tp_dst->tp_next; |
4108 tp_dst->tp_next = curtab; | |
682 | 4109 } |
4110 | |
4111 /* Need to redraw the tabline. Tab page contents doesn't change. */ | |
4112 redraw_tabline = TRUE; | |
4113 } | |
4114 | |
4115 | |
4116 /* | |
7 | 4117 * Go to another window. |
4118 * When jumping to another buffer, stop Visual mode. Do this before | |
4119 * changing windows so we can yank the selection into the '*' register. | |
4120 * When jumping to another window on the same buffer, adjust its cursor | |
4121 * position to keep the same Visual area. | |
4122 */ | |
4123 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4124 win_goto(win_T *wp) |
7 | 4125 { |
2316
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4126 #ifdef FEAT_CONCEAL |
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4127 win_T *owp = curwin; |
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4128 #endif |
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4129 |
633 | 4130 if (text_locked()) |
7 | 4131 { |
4132 beep_flush(); | |
633 | 4133 text_locked_msg(); |
7 | 4134 return; |
4135 } | |
819 | 4136 #ifdef FEAT_AUTOCMD |
4137 if (curbuf_locked()) | |
4138 return; | |
4139 #endif | |
631 | 4140 |
7 | 4141 if (wp->w_buffer != curbuf) |
4142 reset_VIsual_and_resel(); | |
4143 else if (VIsual_active) | |
4144 wp->w_cursor = curwin->w_cursor; | |
4145 | |
4146 #ifdef FEAT_GUI | |
4147 need_mouse_correct = TRUE; | |
4148 #endif | |
4149 win_enter(wp, TRUE); | |
2316
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4150 |
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4151 #ifdef FEAT_CONCEAL |
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4152 /* Conceal cursor line in previous window, unconceal in current window. */ |
4094 | 4153 if (win_valid(owp) && owp->w_p_cole > 0 && !msg_scrolled) |
2316
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4154 update_single_line(owp, owp->w_cursor.lnum); |
4094 | 4155 if (curwin->w_p_cole > 0 && !msg_scrolled) |
4156 need_cursor_line_redraw = TRUE; | |
2316
db0ea641e382
Fix: cursor line not properly concealed when moving between windows.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4157 #endif |
7 | 4158 } |
4159 | |
4160 #if defined(FEAT_PERL) || defined(PROTO) | |
4161 /* | |
4162 * Find window number "winnr" (counting top to bottom). | |
4163 */ | |
4164 win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4165 win_find_nr(int winnr) |
7 | 4166 { |
4167 win_T *wp; | |
4168 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4169 FOR_ALL_WINDOWS(wp) |
7 | 4170 if (--winnr == 0) |
4171 break; | |
4172 return wp; | |
4173 } | |
4174 #endif | |
4175 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4176 #if ((defined(FEAT_PYTHON) || defined(FEAT_PYTHON3))) || defined(PROTO) |
4429 | 4177 /* |
4178 * Find the tabpage for window "win". | |
4179 */ | |
4180 tabpage_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4181 win_find_tabpage(win_T *win) |
4429 | 4182 { |
4183 win_T *wp; | |
4184 tabpage_T *tp; | |
4185 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4186 FOR_ALL_TAB_WINDOWS(tp, wp) |
4429 | 4187 if (wp == win) |
4188 return tp; | |
4189 return NULL; | |
4190 } | |
4191 #endif | |
4192 | |
7 | 4193 /* |
4194 * Move to window above or below "count" times. | |
4195 */ | |
4196 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4197 win_goto_ver( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4198 int up, /* TRUE to go to win above */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4199 long count) |
7 | 4200 { |
4201 frame_T *fr; | |
4202 frame_T *nfr; | |
4203 frame_T *foundfr; | |
4204 | |
4205 foundfr = curwin->w_frame; | |
4206 while (count--) | |
4207 { | |
4208 /* | |
4209 * First go upwards in the tree of frames until we find a upwards or | |
4210 * downwards neighbor. | |
4211 */ | |
4212 fr = foundfr; | |
4213 for (;;) | |
4214 { | |
4215 if (fr == topframe) | |
4216 goto end; | |
4217 if (up) | |
4218 nfr = fr->fr_prev; | |
4219 else | |
4220 nfr = fr->fr_next; | |
4221 if (fr->fr_parent->fr_layout == FR_COL && nfr != NULL) | |
4222 break; | |
4223 fr = fr->fr_parent; | |
4224 } | |
4225 | |
4226 /* | |
4227 * Now go downwards to find the bottom or top frame in it. | |
4228 */ | |
4229 for (;;) | |
4230 { | |
4231 if (nfr->fr_layout == FR_LEAF) | |
4232 { | |
4233 foundfr = nfr; | |
4234 break; | |
4235 } | |
4236 fr = nfr->fr_child; | |
4237 if (nfr->fr_layout == FR_ROW) | |
4238 { | |
4239 /* Find the frame at the cursor row. */ | |
4240 while (fr->fr_next != NULL | |
4241 && frame2win(fr)->w_wincol + fr->fr_width | |
4242 <= curwin->w_wincol + curwin->w_wcol) | |
4243 fr = fr->fr_next; | |
4244 } | |
4245 if (nfr->fr_layout == FR_COL && up) | |
4246 while (fr->fr_next != NULL) | |
4247 fr = fr->fr_next; | |
4248 nfr = fr; | |
4249 } | |
4250 } | |
4251 end: | |
4252 if (foundfr != NULL) | |
4253 win_goto(foundfr->fr_win); | |
4254 } | |
4255 | |
4256 /* | |
4257 * Move to left or right window. | |
4258 */ | |
4259 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4260 win_goto_hor( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4261 int left, /* TRUE to go to left win */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4262 long count) |
7 | 4263 { |
4264 frame_T *fr; | |
4265 frame_T *nfr; | |
4266 frame_T *foundfr; | |
4267 | |
4268 foundfr = curwin->w_frame; | |
4269 while (count--) | |
4270 { | |
4271 /* | |
4272 * First go upwards in the tree of frames until we find a left or | |
4273 * right neighbor. | |
4274 */ | |
4275 fr = foundfr; | |
4276 for (;;) | |
4277 { | |
4278 if (fr == topframe) | |
4279 goto end; | |
4280 if (left) | |
4281 nfr = fr->fr_prev; | |
4282 else | |
4283 nfr = fr->fr_next; | |
4284 if (fr->fr_parent->fr_layout == FR_ROW && nfr != NULL) | |
4285 break; | |
4286 fr = fr->fr_parent; | |
4287 } | |
4288 | |
4289 /* | |
4290 * Now go downwards to find the leftmost or rightmost frame in it. | |
4291 */ | |
4292 for (;;) | |
4293 { | |
4294 if (nfr->fr_layout == FR_LEAF) | |
4295 { | |
4296 foundfr = nfr; | |
4297 break; | |
4298 } | |
4299 fr = nfr->fr_child; | |
4300 if (nfr->fr_layout == FR_COL) | |
4301 { | |
4302 /* Find the frame at the cursor row. */ | |
4303 while (fr->fr_next != NULL | |
4304 && frame2win(fr)->w_winrow + fr->fr_height | |
4305 <= curwin->w_winrow + curwin->w_wrow) | |
4306 fr = fr->fr_next; | |
4307 } | |
4308 if (nfr->fr_layout == FR_ROW && left) | |
4309 while (fr->fr_next != NULL) | |
4310 fr = fr->fr_next; | |
4311 nfr = fr; | |
4312 } | |
4313 } | |
4314 end: | |
4315 if (foundfr != NULL) | |
4316 win_goto(foundfr->fr_win); | |
4317 } | |
4318 | |
4319 /* | |
4320 * Make window "wp" the current window. | |
4321 */ | |
4322 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4323 win_enter(win_T *wp, int undo_sync) |
7 | 4324 { |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
4325 win_enter_ext(wp, undo_sync, FALSE, FALSE, TRUE, TRUE); |
7 | 4326 } |
4327 | |
4328 /* | |
4329 * Make window wp the current window. | |
4330 * Can be called with "curwin_invalid" TRUE, which means that curwin has just | |
4331 * been closed and isn't valid. | |
4332 */ | |
4333 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4334 win_enter_ext( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4335 win_T *wp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4336 int undo_sync, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4337 int curwin_invalid, |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
4338 int trigger_new_autocmds UNUSED, |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4339 int trigger_enter_autocmds UNUSED, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4340 int trigger_leave_autocmds UNUSED) |
7 | 4341 { |
4342 #ifdef FEAT_AUTOCMD | |
4343 int other_buffer = FALSE; | |
4344 #endif | |
4345 | |
4346 if (wp == curwin && !curwin_invalid) /* nothing to do */ | |
4347 return; | |
4348 | |
4349 #ifdef FEAT_AUTOCMD | |
4354 | 4350 if (!curwin_invalid && trigger_leave_autocmds) |
7 | 4351 { |
4352 /* | |
4353 * Be careful: If autocommands delete the window, return now. | |
4354 */ | |
4355 if (wp->w_buffer != curbuf) | |
4356 { | |
4357 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); | |
4358 other_buffer = TRUE; | |
4359 if (!win_valid(wp)) | |
4360 return; | |
4361 } | |
4362 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf); | |
4363 if (!win_valid(wp)) | |
4364 return; | |
4365 # ifdef FEAT_EVAL | |
4366 /* autocmds may abort script processing */ | |
4367 if (aborting()) | |
4368 return; | |
4369 # endif | |
4370 } | |
4371 #endif | |
4372 | |
4373 /* sync undo before leaving the current buffer */ | |
4374 if (undo_sync && curbuf != wp->w_buffer) | |
825 | 4375 u_sync(FALSE); |
5977 | 4376 |
4377 /* Might need to scroll the old window before switching, e.g., when the | |
4378 * cursor was moved. */ | |
4379 update_topline(); | |
4380 | |
7 | 4381 /* may have to copy the buffer options when 'cpo' contains 'S' */ |
4382 if (wp->w_buffer != curbuf) | |
4383 buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP); | |
4384 if (!curwin_invalid) | |
4385 { | |
4386 prevwin = curwin; /* remember for CTRL-W p */ | |
4387 curwin->w_redr_status = TRUE; | |
4388 } | |
4389 curwin = wp; | |
4390 curbuf = wp->w_buffer; | |
4391 check_cursor(); | |
4392 #ifdef FEAT_VIRTUALEDIT | |
4393 if (!virtual_active()) | |
4394 curwin->w_cursor.coladd = 0; | |
4395 #endif | |
4396 changed_line_abv_curs(); /* assume cursor position needs updating */ | |
4397 | |
4398 if (curwin->w_localdir != NULL) | |
4399 { | |
4400 /* Window has a local directory: Save current directory as global | |
4401 * directory (unless that was done already) and change to the local | |
4402 * directory. */ | |
4403 if (globaldir == NULL) | |
4404 { | |
4405 char_u cwd[MAXPATHL]; | |
4406 | |
4407 if (mch_dirname(cwd, MAXPATHL) == OK) | |
4408 globaldir = vim_strsave(cwd); | |
4409 } | |
1757 | 4410 if (mch_chdir((char *)curwin->w_localdir) == 0) |
4411 shorten_fnames(TRUE); | |
7 | 4412 } |
4413 else if (globaldir != NULL) | |
4414 { | |
4415 /* Window doesn't have a local directory and we are not in the global | |
4416 * directory: Change to the global directory. */ | |
1757 | 4417 ignored = mch_chdir((char *)globaldir); |
7 | 4418 vim_free(globaldir); |
4419 globaldir = NULL; | |
4420 shorten_fnames(TRUE); | |
4421 } | |
4422 | |
4423 #ifdef FEAT_AUTOCMD | |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
4424 if (trigger_new_autocmds) |
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
4425 apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf); |
4354 | 4426 if (trigger_enter_autocmds) |
4427 { | |
4428 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); | |
4429 if (other_buffer) | |
4430 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
4431 } | |
7 | 4432 #endif |
4433 | |
4434 #ifdef FEAT_TITLE | |
4435 maketitle(); | |
4436 #endif | |
4437 curwin->w_redr_status = TRUE; | |
672 | 4438 redraw_tabline = TRUE; |
7 | 4439 if (restart_edit) |
4440 redraw_later(VALID); /* causes status line redraw */ | |
4441 | |
4442 /* set window height to desired minimal value */ | |
4443 if (curwin->w_height < p_wh && !curwin->w_p_wfh) | |
4444 win_setheight((int)p_wh); | |
4445 else if (curwin->w_height == 0) | |
4446 win_setheight(1); | |
4447 | |
4448 /* set window width to desired minimal value */ | |
779 | 4449 if (curwin->w_width < p_wiw && !curwin->w_p_wfw) |
7 | 4450 win_setwidth((int)p_wiw); |
4451 | |
4452 #ifdef FEAT_MOUSE | |
4453 setmouse(); /* in case jumped to/from help buffer */ | |
4454 #endif | |
4455 | |
961 | 4456 /* Change directories when the 'acd' option is set. */ |
4457 DO_AUTOCHDIR | |
7 | 4458 } |
4459 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4460 |
7 | 4461 /* |
825 | 4462 * Jump to the first open window that contains buffer "buf", if one exists. |
4463 * Returns a pointer to the window found, otherwise NULL. | |
7 | 4464 */ |
4465 win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4466 buf_jump_open_win(buf_T *buf) |
7 | 4467 { |
6307 | 4468 win_T *wp = NULL; |
4469 | |
4470 if (curwin->w_buffer == buf) | |
4471 wp = curwin; | |
4472 else | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4473 FOR_ALL_WINDOWS(wp) |
6307 | 4474 if (wp->w_buffer == buf) |
4475 break; | |
7 | 4476 if (wp != NULL) |
4477 win_enter(wp, FALSE); | |
4478 return wp; | |
4479 } | |
825 | 4480 |
4481 /* | |
4482 * Jump to the first open window in any tab page that contains buffer "buf", | |
4483 * if one exists. | |
4484 * Returns a pointer to the window found, otherwise NULL. | |
4485 */ | |
4486 win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4487 buf_jump_open_tab(buf_T *buf) |
825 | 4488 { |
6307 | 4489 win_T *wp = buf_jump_open_win(buf); |
825 | 4490 tabpage_T *tp; |
4491 | |
4492 if (wp != NULL) | |
4493 return wp; | |
4494 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4495 FOR_ALL_TABPAGES(tp) |
825 | 4496 if (tp != curtab) |
4497 { | |
4498 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) | |
4499 if (wp->w_buffer == buf) | |
4500 break; | |
4501 if (wp != NULL) | |
4502 { | |
4503 goto_tabpage_win(tp, wp); | |
4504 if (curwin != wp) | |
4505 wp = NULL; /* something went wrong */ | |
4506 break; | |
4507 } | |
4508 } | |
4509 return wp; | |
4510 } | |
7 | 4511 |
9223
6c4d610fce0a
commit https://github.com/vim/vim/commit/888ccac8902cee186fbd47e971881f6d9b19c068
Christian Brabandt <cb@256bit.org>
parents:
9102
diff
changeset
|
4512 static int last_win_id = LOWEST_WIN_ID - 1; |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
4513 |
7 | 4514 /* |
1906 | 4515 * Allocate a window structure and link it in the window list when "hidden" is |
4516 * FALSE. | |
7 | 4517 */ |
4518 static win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4519 win_alloc(win_T *after UNUSED, int hidden UNUSED) |
7 | 4520 { |
3263 | 4521 win_T *new_wp; |
7 | 4522 |
4523 /* | |
4524 * allocate window structure and linesizes arrays | |
4525 */ | |
3263 | 4526 new_wp = (win_T *)alloc_clear((unsigned)sizeof(win_T)); |
4287 | 4527 if (new_wp == NULL) |
4528 return NULL; | |
4529 | |
4530 if (win_alloc_lines(new_wp) == FAIL) | |
3263 | 4531 { |
4532 vim_free(new_wp); | |
4287 | 4533 return NULL; |
4534 } | |
4535 | |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
4536 new_wp->w_id = ++last_win_id; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
4537 |
4287 | 4538 #ifdef FEAT_EVAL |
4539 /* init w: variables */ | |
4540 new_wp->w_vars = dict_alloc(); | |
4541 if (new_wp->w_vars == NULL) | |
4542 { | |
4543 win_free_lsize(new_wp); | |
4544 vim_free(new_wp); | |
4545 return NULL; | |
4546 } | |
4547 init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE); | |
4548 #endif | |
4549 | |
1114 | 4550 #ifdef FEAT_AUTOCMD |
4287 | 4551 /* Don't execute autocommands while the window is not properly |
4552 * initialized yet. gui_create_scrollbar() may trigger a FocusGained | |
4553 * event. */ | |
4554 block_autocmds(); | |
4555 #endif | |
4556 /* | |
4557 * link the window in the window list | |
4558 */ | |
4559 if (!hidden) | |
4560 win_append(after, new_wp); | |
4561 new_wp->w_wincol = 0; | |
4562 new_wp->w_width = Columns; | |
4563 | |
4564 /* position the display and the cursor at the top of the file. */ | |
4565 new_wp->w_topline = 1; | |
7 | 4566 #ifdef FEAT_DIFF |
4287 | 4567 new_wp->w_topfill = 0; |
4568 #endif | |
4569 new_wp->w_botline = 2; | |
4570 new_wp->w_cursor.lnum = 1; | |
7 | 4571 #ifdef FEAT_SCROLLBIND |
4287 | 4572 new_wp->w_scbind_pos = 1; |
4573 #endif | |
4574 | |
4575 /* We won't calculate w_fraction until resizing the window */ | |
4576 new_wp->w_fraction = 0; | |
4577 new_wp->w_prev_fraction_row = -1; | |
7 | 4578 |
4579 #ifdef FEAT_GUI | |
4287 | 4580 if (gui.in_use) |
4581 { | |
4582 gui_create_scrollbar(&new_wp->w_scrollbars[SBAR_LEFT], | |
4583 SBAR_LEFT, new_wp); | |
4584 gui_create_scrollbar(&new_wp->w_scrollbars[SBAR_RIGHT], | |
4585 SBAR_RIGHT, new_wp); | |
4586 } | |
7 | 4587 #endif |
4588 #ifdef FEAT_FOLDING | |
4287 | 4589 foldInitWin(new_wp); |
7 | 4590 #endif |
1114 | 4591 #ifdef FEAT_AUTOCMD |
4287 | 4592 unblock_autocmds(); |
1114 | 4593 #endif |
1326 | 4594 #ifdef FEAT_SEARCH_EXTRA |
4287 | 4595 new_wp->w_match_head = NULL; |
4596 new_wp->w_next_match_id = 4; | |
4597 #endif | |
3263 | 4598 return new_wp; |
7 | 4599 } |
4600 | |
4601 /* | |
5237
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4602 * Remove window 'wp' from the window list and free the structure. |
7 | 4603 */ |
4604 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4605 win_free( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4606 win_T *wp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4607 tabpage_T *tp) /* tab page "win" is in, NULL for current */ |
7 | 4608 { |
4609 int i; | |
5237
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4610 buf_T *buf; |
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4611 wininfo_T *wip; |
7 | 4612 |
1918 | 4613 #ifdef FEAT_FOLDING |
4614 clearFolding(wp); | |
4615 #endif | |
4616 | |
4617 /* reduce the reference count to the argument list. */ | |
4618 alist_unlink(wp->w_alist); | |
4619 | |
1114 | 4620 #ifdef FEAT_AUTOCMD |
4621 /* Don't execute autocommands while the window is halfway being deleted. | |
4622 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */ | |
1410 | 4623 block_autocmds(); |
1114 | 4624 #endif |
4625 | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2316
diff
changeset
|
4626 #ifdef FEAT_LUA |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2316
diff
changeset
|
4627 lua_window_free(wp); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2316
diff
changeset
|
4628 #endif |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2316
diff
changeset
|
4629 |
14 | 4630 #ifdef FEAT_MZSCHEME |
4631 mzscheme_window_free(wp); | |
4632 #endif | |
4633 | |
7 | 4634 #ifdef FEAT_PERL |
4635 perl_win_free(wp); | |
4636 #endif | |
4637 | |
4638 #ifdef FEAT_PYTHON | |
4639 python_window_free(wp); | |
4640 #endif | |
4641 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
4642 #ifdef FEAT_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
4643 python3_window_free(wp); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
4644 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
4645 |
7 | 4646 #ifdef FEAT_TCL |
4647 tcl_window_free(wp); | |
4648 #endif | |
4649 | |
4650 #ifdef FEAT_RUBY | |
4651 ruby_window_free(wp); | |
4652 #endif | |
4653 | |
4654 clear_winopt(&wp->w_onebuf_opt); | |
4655 clear_winopt(&wp->w_allbuf_opt); | |
4656 | |
4657 #ifdef FEAT_EVAL | |
4287 | 4658 vars_clear(&wp->w_vars->dv_hashtab); /* free all w: variables */ |
4659 hash_init(&wp->w_vars->dv_hashtab); | |
4660 unref_var_dict(wp->w_vars); | |
7 | 4661 #endif |
4662 | |
8833
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4663 { |
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4664 tabpage_T *ttp; |
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4665 |
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4666 if (prevwin == wp) |
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4667 prevwin = NULL; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4668 FOR_ALL_TABPAGES(ttp) |
8833
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4669 if (ttp->tp_prevwin == wp) |
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4670 ttp->tp_prevwin = NULL; |
dc10bd23f918
commit https://github.com/vim/vim/commit/3dda7db4e1f7c4a8110a1f83001ec36b46693d27
Christian Brabandt <cb@256bit.org>
parents:
8804
diff
changeset
|
4671 } |
7 | 4672 win_free_lsize(wp); |
4673 | |
4674 for (i = 0; i < wp->w_tagstacklen; ++i) | |
4675 vim_free(wp->w_tagstack[i].tagname); | |
4676 | |
4677 vim_free(wp->w_localdir); | |
1326 | 4678 |
5237
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4679 /* Remove the window from the b_wininfo lists, it may happen that the |
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4680 * freed memory is re-used for another window. */ |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4681 FOR_ALL_BUFFERS(buf) |
5237
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4682 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) |
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4683 if (wip->wi_win == wp) |
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4684 wip->wi_win = NULL; |
647596ab1ae2
updated for version 7.4a.044
Bram Moolenaar <bram@vim.org>
parents:
5233
diff
changeset
|
4685 |
7 | 4686 #ifdef FEAT_SEARCH_EXTRA |
1326 | 4687 clear_matches(wp); |
4688 #endif | |
4689 | |
7 | 4690 #ifdef FEAT_JUMPLIST |
4691 free_jumplist(wp); | |
4692 #endif | |
4693 | |
643 | 4694 #ifdef FEAT_QUICKFIX |
4695 qf_free_all(wp); | |
4696 #endif | |
4697 | |
7 | 4698 #ifdef FEAT_GUI |
4699 if (gui.in_use) | |
4700 { | |
4701 gui_mch_destroy_scrollbar(&wp->w_scrollbars[SBAR_LEFT]); | |
4702 gui_mch_destroy_scrollbar(&wp->w_scrollbars[SBAR_RIGHT]); | |
4703 } | |
4704 #endif /* FEAT_GUI */ | |
4705 | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4706 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4707 remove_winbar(wp); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4708 #endif |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4709 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
4710 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2306
diff
changeset
|
4711 vim_free(wp->w_p_cc_cols); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
4712 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
4713 |
1918 | 4714 #ifdef FEAT_AUTOCMD |
4715 if (wp != aucmd_win) | |
4716 #endif | |
4717 win_remove(wp, tp); | |
5971 | 4718 #ifdef FEAT_AUTOCMD |
5958 | 4719 if (autocmd_busy) |
4720 { | |
4721 wp->w_next = au_pending_free_win; | |
4722 au_pending_free_win = wp; | |
4723 } | |
4724 else | |
5971 | 4725 #endif |
5958 | 4726 vim_free(wp); |
1114 | 4727 |
4728 #ifdef FEAT_AUTOCMD | |
1410 | 4729 unblock_autocmds(); |
1114 | 4730 #endif |
7 | 4731 } |
4732 | |
4733 /* | |
4734 * Append window "wp" in the window list after window "after". | |
4735 */ | |
1906 | 4736 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4737 win_append(win_T *after, win_T *wp) |
7 | 4738 { |
4739 win_T *before; | |
4740 | |
4741 if (after == NULL) /* after NULL is in front of the first */ | |
4742 before = firstwin; | |
4743 else | |
4744 before = after->w_next; | |
4745 | |
4746 wp->w_next = before; | |
4747 wp->w_prev = after; | |
4748 if (after == NULL) | |
4749 firstwin = wp; | |
4750 else | |
4751 after->w_next = wp; | |
4752 if (before == NULL) | |
4753 lastwin = wp; | |
4754 else | |
4755 before->w_prev = wp; | |
4756 } | |
4757 | |
4758 /* | |
4759 * Remove a window from the window list. | |
4760 */ | |
1906 | 4761 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4762 win_remove( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4763 win_T *wp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4764 tabpage_T *tp) /* tab page "win" is in, NULL for current */ |
7 | 4765 { |
4766 if (wp->w_prev != NULL) | |
4767 wp->w_prev->w_next = wp->w_next; | |
671 | 4768 else if (tp == NULL) |
12564
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4769 firstwin = curtab->tp_firstwin = wp->w_next; |
7 | 4770 else |
671 | 4771 tp->tp_firstwin = wp->w_next; |
12564
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4772 |
7 | 4773 if (wp->w_next != NULL) |
4774 wp->w_next->w_prev = wp->w_prev; | |
671 | 4775 else if (tp == NULL) |
12564
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4776 lastwin = curtab->tp_lastwin = wp->w_prev; |
7 | 4777 else |
671 | 4778 tp->tp_lastwin = wp->w_prev; |
7 | 4779 } |
4780 | |
4781 /* | |
4782 * Append frame "frp" in a frame list after frame "after". | |
4783 */ | |
4784 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4785 frame_append(frame_T *after, frame_T *frp) |
7 | 4786 { |
4787 frp->fr_next = after->fr_next; | |
4788 after->fr_next = frp; | |
4789 if (frp->fr_next != NULL) | |
4790 frp->fr_next->fr_prev = frp; | |
4791 frp->fr_prev = after; | |
4792 } | |
4793 | |
4794 /* | |
4795 * Insert frame "frp" in a frame list before frame "before". | |
4796 */ | |
4797 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4798 frame_insert(frame_T *before, frame_T *frp) |
7 | 4799 { |
4800 frp->fr_next = before; | |
4801 frp->fr_prev = before->fr_prev; | |
4802 before->fr_prev = frp; | |
4803 if (frp->fr_prev != NULL) | |
4804 frp->fr_prev->fr_next = frp; | |
4805 else | |
4806 frp->fr_parent->fr_child = frp; | |
4807 } | |
4808 | |
4809 /* | |
4810 * Remove a frame from a frame list. | |
4811 */ | |
4812 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4813 frame_remove(frame_T *frp) |
7 | 4814 { |
4815 if (frp->fr_prev != NULL) | |
4816 frp->fr_prev->fr_next = frp->fr_next; | |
4817 else | |
13144
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
4818 { |
7 | 4819 frp->fr_parent->fr_child = frp->fr_next; |
13144
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
4820 /* special case: topframe->fr_child == frp */ |
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
4821 if (topframe->fr_child == frp) |
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
4822 topframe->fr_child = frp->fr_next; |
20fb8c711050
patch 8.0.1446: acessing freed memory after window command in auto command
Christian Brabandt <cb@256bit.org>
parents:
13103
diff
changeset
|
4823 } |
7 | 4824 if (frp->fr_next != NULL) |
4825 frp->fr_next->fr_prev = frp->fr_prev; | |
4826 } | |
4827 | |
4828 /* | |
4829 * Allocate w_lines[] for window "wp". | |
4830 * Return FAIL for failure, OK for success. | |
4831 */ | |
4832 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4833 win_alloc_lines(win_T *wp) |
7 | 4834 { |
4835 wp->w_lines_valid = 0; | |
1042 | 4836 wp->w_lines = (wline_T *)alloc_clear((unsigned)(Rows * sizeof(wline_T))); |
7 | 4837 if (wp->w_lines == NULL) |
4838 return FAIL; | |
4839 return OK; | |
4840 } | |
4841 | |
4842 /* | |
4843 * free lsize arrays for a window | |
4844 */ | |
4845 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4846 win_free_lsize(win_T *wp) |
7 | 4847 { |
5952 | 4848 /* TODO: why would wp be NULL here? */ |
4849 if (wp != NULL) | |
4850 { | |
4851 vim_free(wp->w_lines); | |
4852 wp->w_lines = NULL; | |
4853 } | |
7 | 4854 } |
4855 | |
4856 /* | |
4857 * Called from win_new_shellsize() after Rows changed. | |
671 | 4858 * This only does the current tab page, others must be done when made active. |
7 | 4859 */ |
4860 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4861 shell_new_rows(void) |
7 | 4862 { |
667 | 4863 int h = (int)ROWS_AVAIL; |
7 | 4864 |
4865 if (firstwin == NULL) /* not initialized yet */ | |
4866 return; | |
4867 if (h < frame_minheight(topframe, NULL)) | |
4868 h = frame_minheight(topframe, NULL); | |
779 | 4869 |
4870 /* First try setting the heights of windows with 'winfixheight'. If | |
7 | 4871 * that doesn't result in the right height, forget about that option. */ |
4872 frame_new_height(topframe, h, FALSE, TRUE); | |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
4873 if (!frame_check_height(topframe, h)) |
7 | 4874 frame_new_height(topframe, h, FALSE, FALSE); |
4875 | |
4876 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */ | |
4877 compute_cmdrow(); | |
824 | 4878 curtab->tp_ch_used = p_ch; |
170 | 4879 |
7 | 4880 #if 0 |
4881 /* Disabled: don't want making the screen smaller make a window larger. */ | |
4882 if (p_ea) | |
4883 win_equal(curwin, FALSE, 'v'); | |
4884 #endif | |
4885 } | |
4886 | |
4887 /* | |
4888 * Called from win_new_shellsize() after Columns changed. | |
4889 */ | |
4890 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4891 shell_new_columns(void) |
7 | 4892 { |
4893 if (firstwin == NULL) /* not initialized yet */ | |
4894 return; | |
779 | 4895 |
4896 /* First try setting the widths of windows with 'winfixwidth'. If that | |
4897 * doesn't result in the right width, forget about that option. */ | |
4898 frame_new_width(topframe, (int)Columns, FALSE, TRUE); | |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
4899 if (!frame_check_width(topframe, Columns)) |
779 | 4900 frame_new_width(topframe, (int)Columns, FALSE, FALSE); |
4901 | |
7 | 4902 (void)win_comp_pos(); /* recompute w_winrow and w_wincol */ |
4903 #if 0 | |
4904 /* Disabled: don't want making the screen smaller make a window larger. */ | |
4905 if (p_ea) | |
4906 win_equal(curwin, FALSE, 'h'); | |
4907 #endif | |
4908 } | |
4909 | |
4910 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
4911 /* | |
4912 * Save the size of all windows in "gap". | |
4913 */ | |
4914 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4915 win_size_save(garray_T *gap) |
7 | 4916 |
4917 { | |
4918 win_T *wp; | |
4919 | |
4920 ga_init2(gap, (int)sizeof(int), 1); | |
4921 if (ga_grow(gap, win_count() * 2) == OK) | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4922 FOR_ALL_WINDOWS(wp) |
7 | 4923 { |
4924 ((int *)gap->ga_data)[gap->ga_len++] = | |
4925 wp->w_width + wp->w_vsep_width; | |
4926 ((int *)gap->ga_data)[gap->ga_len++] = wp->w_height; | |
4927 } | |
4928 } | |
4929 | |
4930 /* | |
4931 * Restore window sizes, but only if the number of windows is still the same. | |
4932 * Does not free the growarray. | |
4933 */ | |
4934 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4935 win_size_restore(garray_T *gap) |
7 | 4936 { |
4937 win_T *wp; | |
6058 | 4938 int i, j; |
7 | 4939 |
4940 if (win_count() * 2 == gap->ga_len) | |
4941 { | |
6058 | 4942 /* The order matters, because frames contain other frames, but it's |
4943 * difficult to get right. The easy way out is to do it twice. */ | |
4944 for (j = 0; j < 2; ++j) | |
7 | 4945 { |
6058 | 4946 i = 0; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
4947 FOR_ALL_WINDOWS(wp) |
6058 | 4948 { |
4949 frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]); | |
4950 win_setheight_win(((int *)gap->ga_data)[i++], wp); | |
4951 } | |
7 | 4952 } |
4953 /* recompute the window positions */ | |
4954 (void)win_comp_pos(); | |
4955 } | |
4956 } | |
4957 #endif /* FEAT_CMDWIN */ | |
4958 | |
4959 /* | |
4960 * Update the position for all windows, using the width and height of the | |
4961 * frames. | |
4962 * Returns the row just after the last window. | |
4963 */ | |
668 | 4964 int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4965 win_comp_pos(void) |
7 | 4966 { |
685 | 4967 int row = tabline_height(); |
7 | 4968 int col = 0; |
4969 | |
4970 frame_comp_pos(topframe, &row, &col); | |
4971 return row; | |
4972 } | |
4973 | |
4974 /* | |
4975 * Update the position of the windows in frame "topfrp", using the width and | |
4976 * height of the frames. | |
4977 * "*row" and "*col" are the top-left position of the frame. They are updated | |
4978 * to the bottom-right position plus one. | |
4979 */ | |
4980 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4981 frame_comp_pos(frame_T *topfrp, int *row, int *col) |
7 | 4982 { |
4983 win_T *wp; | |
4984 frame_T *frp; | |
4985 int startcol; | |
4986 int startrow; | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
4987 int h; |
7 | 4988 |
4989 wp = topfrp->fr_win; | |
4990 if (wp != NULL) | |
4991 { | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4992 if (wp->w_winrow != *row || wp->w_wincol != *col) |
7 | 4993 { |
4994 /* position changed, redraw */ | |
4995 wp->w_winrow = *row; | |
4996 wp->w_wincol = *col; | |
4997 redraw_win_later(wp, NOT_VALID); | |
4998 wp->w_redr_status = TRUE; | |
4999 } | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5000 /* WinBar will not show if the window height is zero */ |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5001 h = VISIBLE_HEIGHT(wp) + wp->w_status_height; |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5002 *row += h > topfrp->fr_height ? topfrp->fr_height : h; |
7 | 5003 *col += wp->w_width + wp->w_vsep_width; |
5004 } | |
5005 else | |
5006 { | |
5007 startrow = *row; | |
5008 startcol = *col; | |
5009 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) | |
5010 { | |
5011 if (topfrp->fr_layout == FR_ROW) | |
5012 *row = startrow; /* all frames are at the same row */ | |
5013 else | |
5014 *col = startcol; /* all frames are at the same col */ | |
5015 frame_comp_pos(frp, row, col); | |
5016 } | |
5017 } | |
5018 } | |
5019 | |
5020 /* | |
5021 * Set current window height and take care of repositioning other windows to | |
5022 * fit around it. | |
5023 */ | |
5024 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5025 win_setheight(int height) |
7 | 5026 { |
5027 win_setheight_win(height, curwin); | |
5028 } | |
5029 | |
5030 /* | |
5031 * Set the window height of window "win" and take care of repositioning other | |
5032 * windows to fit around it. | |
5033 */ | |
5034 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5035 win_setheight_win(int height, win_T *win) |
7 | 5036 { |
5037 int row; | |
5038 | |
5039 if (win == curwin) | |
5040 { | |
5041 /* Always keep current window at least one line high, even when | |
5042 * 'winminheight' is zero. */ | |
5043 if (height < p_wmh) | |
5044 height = p_wmh; | |
5045 if (height == 0) | |
5046 height = 1; | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5047 height += WINBAR_HEIGHT(curwin); |
7 | 5048 } |
5049 | |
5050 frame_setheight(win->w_frame, height + win->w_status_height); | |
5051 | |
5052 /* recompute the window positions */ | |
5053 row = win_comp_pos(); | |
5054 | |
5055 /* | |
5056 * If there is extra space created between the last window and the command | |
5057 * line, clear it. | |
5058 */ | |
5059 if (full_screen && msg_scrolled == 0 && row < cmdline_row) | |
5060 screen_fill(row, cmdline_row, 0, (int)Columns, ' ', ' ', 0); | |
5061 cmdline_row = row; | |
5062 msg_row = row; | |
5063 msg_col = 0; | |
5064 | |
5065 redraw_all_later(NOT_VALID); | |
5066 } | |
5067 | |
5068 /* | |
5069 * Set the height of a frame to "height" and take care that all frames and | |
5070 * windows inside it are resized. Also resize frames on the left and right if | |
5071 * the are in the same FR_ROW frame. | |
5072 * | |
5073 * Strategy: | |
5074 * If the frame is part of a FR_COL frame, try fitting the frame in that | |
5075 * frame. If that doesn't work (the FR_COL frame is too small), recursively | |
5076 * go to containing frames to resize them and make room. | |
5077 * If the frame is part of a FR_ROW frame, all frames must be resized as well. | |
5078 * Check for the minimal height of the FR_ROW frame. | |
5079 * At the top level we can also use change the command line height. | |
5080 */ | |
5081 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5082 frame_setheight(frame_T *curfrp, int height) |
7 | 5083 { |
5084 int room; /* total number of lines available */ | |
5085 int take; /* number of lines taken from other windows */ | |
5086 int room_cmdline; /* lines available from cmdline */ | |
5087 int run; | |
5088 frame_T *frp; | |
5089 int h; | |
5090 int room_reserved; | |
5091 | |
5092 /* If the height already is the desired value, nothing to do. */ | |
5093 if (curfrp->fr_height == height) | |
5094 return; | |
5095 | |
5096 if (curfrp->fr_parent == NULL) | |
5097 { | |
5098 /* topframe: can only change the command line */ | |
667 | 5099 if (height > ROWS_AVAIL) |
5100 height = ROWS_AVAIL; | |
7 | 5101 if (height > 0) |
5102 frame_new_height(curfrp, height, FALSE, FALSE); | |
5103 } | |
5104 else if (curfrp->fr_parent->fr_layout == FR_ROW) | |
5105 { | |
5106 /* Row of frames: Also need to resize frames left and right of this | |
5107 * one. First check for the minimal height of these. */ | |
5108 h = frame_minheight(curfrp->fr_parent, NULL); | |
5109 if (height < h) | |
5110 height = h; | |
5111 frame_setheight(curfrp->fr_parent, height); | |
5112 } | |
5113 else | |
5114 { | |
5115 /* | |
5116 * Column of frames: try to change only frames in this column. | |
5117 */ | |
5118 /* | |
5119 * Do this twice: | |
5120 * 1: compute room available, if it's not enough try resizing the | |
5121 * containing frame. | |
5122 * 2: compute the room available and adjust the height to it. | |
5123 * Try not to reduce the height of a window with 'winfixheight' set. | |
5124 */ | |
5125 for (run = 1; run <= 2; ++run) | |
5126 { | |
5127 room = 0; | |
5128 room_reserved = 0; | |
5129 for (frp = curfrp->fr_parent->fr_child; frp != NULL; | |
5130 frp = frp->fr_next) | |
5131 { | |
5132 if (frp != curfrp | |
5133 && frp->fr_win != NULL | |
5134 && frp->fr_win->w_p_wfh) | |
5135 room_reserved += frp->fr_height; | |
5136 room += frp->fr_height; | |
5137 if (frp != curfrp) | |
5138 room -= frame_minheight(frp, NULL); | |
5139 } | |
5140 if (curfrp->fr_width != Columns) | |
5141 room_cmdline = 0; | |
5142 else | |
5143 { | |
5144 room_cmdline = Rows - p_ch - (lastwin->w_winrow | |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5145 + VISIBLE_HEIGHT(lastwin) |
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5146 + lastwin->w_status_height); |
7 | 5147 if (room_cmdline < 0) |
5148 room_cmdline = 0; | |
5149 } | |
5150 | |
5151 if (height <= room + room_cmdline) | |
5152 break; | |
5153 if (run == 2 || curfrp->fr_width == Columns) | |
5154 { | |
5155 if (height > room + room_cmdline) | |
5156 height = room + room_cmdline; | |
5157 break; | |
5158 } | |
5159 frame_setheight(curfrp->fr_parent, height | |
5160 + frame_minheight(curfrp->fr_parent, NOWIN) - (int)p_wmh - 1); | |
5161 } | |
5162 | |
5163 /* | |
5164 * Compute the number of lines we will take from others frames (can be | |
5165 * negative!). | |
5166 */ | |
5167 take = height - curfrp->fr_height; | |
5168 | |
5169 /* If there is not enough room, also reduce the height of a window | |
5170 * with 'winfixheight' set. */ | |
5171 if (height > room + room_cmdline - room_reserved) | |
5172 room_reserved = room + room_cmdline - height; | |
5173 /* If there is only a 'winfixheight' window and making the | |
5174 * window smaller, need to make the other window taller. */ | |
5175 if (take < 0 && room - curfrp->fr_height < room_reserved) | |
5176 room_reserved = 0; | |
5177 | |
5178 if (take > 0 && room_cmdline > 0) | |
5179 { | |
5180 /* use lines from cmdline first */ | |
5181 if (take < room_cmdline) | |
5182 room_cmdline = take; | |
5183 take -= room_cmdline; | |
5184 topframe->fr_height += room_cmdline; | |
5185 } | |
5186 | |
5187 /* | |
5188 * set the current frame to the new height | |
5189 */ | |
5190 frame_new_height(curfrp, height, FALSE, FALSE); | |
5191 | |
5192 /* | |
5193 * First take lines from the frames after the current frame. If | |
5194 * that is not enough, takes lines from frames above the current | |
5195 * frame. | |
5196 */ | |
5197 for (run = 0; run < 2; ++run) | |
5198 { | |
5199 if (run == 0) | |
5200 frp = curfrp->fr_next; /* 1st run: start with next window */ | |
5201 else | |
5202 frp = curfrp->fr_prev; /* 2nd run: start with prev window */ | |
5203 while (frp != NULL && take != 0) | |
5204 { | |
5205 h = frame_minheight(frp, NULL); | |
5206 if (room_reserved > 0 | |
5207 && frp->fr_win != NULL | |
5208 && frp->fr_win->w_p_wfh) | |
5209 { | |
5210 if (room_reserved >= frp->fr_height) | |
5211 room_reserved -= frp->fr_height; | |
5212 else | |
5213 { | |
5214 if (frp->fr_height - room_reserved > take) | |
5215 room_reserved = frp->fr_height - take; | |
5216 take -= frp->fr_height - room_reserved; | |
5217 frame_new_height(frp, room_reserved, FALSE, FALSE); | |
5218 room_reserved = 0; | |
5219 } | |
5220 } | |
5221 else | |
5222 { | |
5223 if (frp->fr_height - take < h) | |
5224 { | |
5225 take -= frp->fr_height - h; | |
5226 frame_new_height(frp, h, FALSE, FALSE); | |
5227 } | |
5228 else | |
5229 { | |
5230 frame_new_height(frp, frp->fr_height - take, | |
5231 FALSE, FALSE); | |
5232 take = 0; | |
5233 } | |
5234 } | |
5235 if (run == 0) | |
5236 frp = frp->fr_next; | |
5237 else | |
5238 frp = frp->fr_prev; | |
5239 } | |
5240 } | |
5241 } | |
5242 } | |
5243 | |
5244 /* | |
5245 * Set current window width and take care of repositioning other windows to | |
5246 * fit around it. | |
5247 */ | |
5248 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5249 win_setwidth(int width) |
7 | 5250 { |
5251 win_setwidth_win(width, curwin); | |
5252 } | |
5253 | |
5254 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5255 win_setwidth_win(int width, win_T *wp) |
7 | 5256 { |
5257 /* Always keep current window at least one column wide, even when | |
5258 * 'winminwidth' is zero. */ | |
5259 if (wp == curwin) | |
5260 { | |
5261 if (width < p_wmw) | |
5262 width = p_wmw; | |
5263 if (width == 0) | |
5264 width = 1; | |
5265 } | |
5266 | |
5267 frame_setwidth(wp->w_frame, width + wp->w_vsep_width); | |
5268 | |
5269 /* recompute the window positions */ | |
5270 (void)win_comp_pos(); | |
5271 | |
5272 redraw_all_later(NOT_VALID); | |
5273 } | |
5274 | |
5275 /* | |
5276 * Set the width of a frame to "width" and take care that all frames and | |
5277 * windows inside it are resized. Also resize frames above and below if the | |
5278 * are in the same FR_ROW frame. | |
5279 * | |
5280 * Strategy is similar to frame_setheight(). | |
5281 */ | |
5282 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5283 frame_setwidth(frame_T *curfrp, int width) |
7 | 5284 { |
5285 int room; /* total number of lines available */ | |
5286 int take; /* number of lines taken from other windows */ | |
5287 int run; | |
5288 frame_T *frp; | |
5289 int w; | |
779 | 5290 int room_reserved; |
7 | 5291 |
5292 /* If the width already is the desired value, nothing to do. */ | |
5293 if (curfrp->fr_width == width) | |
5294 return; | |
5295 | |
5296 if (curfrp->fr_parent == NULL) | |
5297 /* topframe: can't change width */ | |
5298 return; | |
5299 | |
5300 if (curfrp->fr_parent->fr_layout == FR_COL) | |
5301 { | |
5302 /* Column of frames: Also need to resize frames above and below of | |
5303 * this one. First check for the minimal width of these. */ | |
5304 w = frame_minwidth(curfrp->fr_parent, NULL); | |
5305 if (width < w) | |
5306 width = w; | |
5307 frame_setwidth(curfrp->fr_parent, width); | |
5308 } | |
5309 else | |
5310 { | |
5311 /* | |
5312 * Row of frames: try to change only frames in this row. | |
5313 * | |
5314 * Do this twice: | |
5315 * 1: compute room available, if it's not enough try resizing the | |
5316 * containing frame. | |
5317 * 2: compute the room available and adjust the width to it. | |
5318 */ | |
5319 for (run = 1; run <= 2; ++run) | |
5320 { | |
5321 room = 0; | |
779 | 5322 room_reserved = 0; |
7 | 5323 for (frp = curfrp->fr_parent->fr_child; frp != NULL; |
5324 frp = frp->fr_next) | |
5325 { | |
779 | 5326 if (frp != curfrp |
5327 && frp->fr_win != NULL | |
5328 && frp->fr_win->w_p_wfw) | |
5329 room_reserved += frp->fr_width; | |
7 | 5330 room += frp->fr_width; |
5331 if (frp != curfrp) | |
5332 room -= frame_minwidth(frp, NULL); | |
5333 } | |
5334 | |
5335 if (width <= room) | |
5336 break; | |
667 | 5337 if (run == 2 || curfrp->fr_height >= ROWS_AVAIL) |
7 | 5338 { |
5339 if (width > room) | |
5340 width = room; | |
5341 break; | |
5342 } | |
5343 frame_setwidth(curfrp->fr_parent, width | |
5344 + frame_minwidth(curfrp->fr_parent, NOWIN) - (int)p_wmw - 1); | |
5345 } | |
5346 | |
5347 /* | |
5348 * Compute the number of lines we will take from others frames (can be | |
5349 * negative!). | |
5350 */ | |
5351 take = width - curfrp->fr_width; | |
5352 | |
779 | 5353 /* If there is not enough room, also reduce the width of a window |
5354 * with 'winfixwidth' set. */ | |
5355 if (width > room - room_reserved) | |
5356 room_reserved = room - width; | |
5357 /* If there is only a 'winfixwidth' window and making the | |
5358 * window smaller, need to make the other window narrower. */ | |
5359 if (take < 0 && room - curfrp->fr_width < room_reserved) | |
5360 room_reserved = 0; | |
5361 | |
7 | 5362 /* |
5363 * set the current frame to the new width | |
5364 */ | |
779 | 5365 frame_new_width(curfrp, width, FALSE, FALSE); |
7 | 5366 |
5367 /* | |
5368 * First take lines from the frames right of the current frame. If | |
5369 * that is not enough, takes lines from frames left of the current | |
5370 * frame. | |
5371 */ | |
5372 for (run = 0; run < 2; ++run) | |
5373 { | |
5374 if (run == 0) | |
5375 frp = curfrp->fr_next; /* 1st run: start with next window */ | |
5376 else | |
5377 frp = curfrp->fr_prev; /* 2nd run: start with prev window */ | |
5378 while (frp != NULL && take != 0) | |
5379 { | |
5380 w = frame_minwidth(frp, NULL); | |
779 | 5381 if (room_reserved > 0 |
5382 && frp->fr_win != NULL | |
5383 && frp->fr_win->w_p_wfw) | |
7 | 5384 { |
779 | 5385 if (room_reserved >= frp->fr_width) |
5386 room_reserved -= frp->fr_width; | |
5387 else | |
5388 { | |
5389 if (frp->fr_width - room_reserved > take) | |
5390 room_reserved = frp->fr_width - take; | |
5391 take -= frp->fr_width - room_reserved; | |
5392 frame_new_width(frp, room_reserved, FALSE, FALSE); | |
5393 room_reserved = 0; | |
5394 } | |
7 | 5395 } |
5396 else | |
5397 { | |
779 | 5398 if (frp->fr_width - take < w) |
5399 { | |
5400 take -= frp->fr_width - w; | |
5401 frame_new_width(frp, w, FALSE, FALSE); | |
5402 } | |
5403 else | |
5404 { | |
5405 frame_new_width(frp, frp->fr_width - take, | |
5406 FALSE, FALSE); | |
5407 take = 0; | |
5408 } | |
7 | 5409 } |
5410 if (run == 0) | |
5411 frp = frp->fr_next; | |
5412 else | |
5413 frp = frp->fr_prev; | |
5414 } | |
5415 } | |
5416 } | |
5417 } | |
5418 | |
5419 /* | |
5420 * Check 'winminheight' for a valid value. | |
5421 */ | |
5422 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5423 win_setminheight(void) |
7 | 5424 { |
5425 int room; | |
5426 int first = TRUE; | |
5427 win_T *wp; | |
5428 | |
5429 /* loop until there is a 'winminheight' that is possible */ | |
5430 while (p_wmh > 0) | |
5431 { | |
5432 /* TODO: handle vertical splits */ | |
5433 room = -p_wh; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
5434 FOR_ALL_WINDOWS(wp) |
12998
dd734ee3e2fe
patch 8.0.1375: window size wrong after maximizing with WinBar
Christian Brabandt <cb@256bit.org>
parents:
12916
diff
changeset
|
5435 room += VISIBLE_HEIGHT(wp) - p_wmh; |
7 | 5436 if (room >= 0) |
5437 break; | |
5438 --p_wmh; | |
5439 if (first) | |
5440 { | |
5441 EMSG(_(e_noroom)); | |
5442 first = FALSE; | |
5443 } | |
5444 } | |
5445 } | |
5446 | |
7229
ae360f1df2aa
commit https://github.com/vim/vim/commit/6a2697ffd7e894861853b351689b0ddec8901c96
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
5447 #if defined(FEAT_MOUSE) || defined(PROTO) |
7 | 5448 |
5449 /* | |
5450 * Status line of dragwin is dragged "offset" lines down (negative is up). | |
5451 */ | |
5452 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5453 win_drag_status_line(win_T *dragwin, int offset) |
7 | 5454 { |
5455 frame_T *curfr; | |
5456 frame_T *fr; | |
5457 int room; | |
5458 int row; | |
5459 int up; /* if TRUE, drag status line up, otherwise down */ | |
5460 int n; | |
5461 | |
5462 fr = dragwin->w_frame; | |
5463 curfr = fr; | |
5464 if (fr != topframe) /* more than one window */ | |
5465 { | |
5466 fr = fr->fr_parent; | |
5467 /* When the parent frame is not a column of frames, its parent should | |
5468 * be. */ | |
5469 if (fr->fr_layout != FR_COL) | |
5470 { | |
5471 curfr = fr; | |
5472 if (fr != topframe) /* only a row of windows, may drag statusline */ | |
5473 fr = fr->fr_parent; | |
5474 } | |
5475 } | |
5476 | |
5477 /* If this is the last frame in a column, may want to resize the parent | |
5478 * frame instead (go two up to skip a row of frames). */ | |
5479 while (curfr != topframe && curfr->fr_next == NULL) | |
5480 { | |
5481 if (fr != topframe) | |
5482 fr = fr->fr_parent; | |
5483 curfr = fr; | |
5484 if (fr != topframe) | |
5485 fr = fr->fr_parent; | |
5486 } | |
5487 | |
5488 if (offset < 0) /* drag up */ | |
5489 { | |
5490 up = TRUE; | |
5491 offset = -offset; | |
5492 /* sum up the room of the current frame and above it */ | |
5493 if (fr == curfr) | |
5494 { | |
5495 /* only one window */ | |
5496 room = fr->fr_height - frame_minheight(fr, NULL); | |
5497 } | |
5498 else | |
5499 { | |
5500 room = 0; | |
5501 for (fr = fr->fr_child; ; fr = fr->fr_next) | |
5502 { | |
5503 room += fr->fr_height - frame_minheight(fr, NULL); | |
5504 if (fr == curfr) | |
5505 break; | |
5506 } | |
5507 } | |
5508 fr = curfr->fr_next; /* put fr at frame that grows */ | |
5509 } | |
5510 else /* drag down */ | |
5511 { | |
5512 up = FALSE; | |
5513 /* | |
5514 * Only dragging the last status line can reduce p_ch. | |
5515 */ | |
5516 room = Rows - cmdline_row; | |
5517 if (curfr->fr_next == NULL) | |
5518 room -= 1; | |
5519 else | |
5520 room -= p_ch; | |
5521 if (room < 0) | |
5522 room = 0; | |
5523 /* sum up the room of frames below of the current one */ | |
5524 for (fr = curfr->fr_next; fr != NULL; fr = fr->fr_next) | |
5525 room += fr->fr_height - frame_minheight(fr, NULL); | |
5526 fr = curfr; /* put fr at window that grows */ | |
5527 } | |
5528 | |
5529 if (room < offset) /* Not enough room */ | |
5530 offset = room; /* Move as far as we can */ | |
5531 if (offset <= 0) | |
5532 return; | |
5533 | |
5534 /* | |
5535 * Grow frame fr by "offset" lines. | |
5536 * Doesn't happen when dragging the last status line up. | |
5537 */ | |
5538 if (fr != NULL) | |
5539 frame_new_height(fr, fr->fr_height + offset, up, FALSE); | |
5540 | |
5541 if (up) | |
5542 fr = curfr; /* current frame gets smaller */ | |
5543 else | |
5544 fr = curfr->fr_next; /* next frame gets smaller */ | |
5545 | |
5546 /* | |
5547 * Now make the other frames smaller. | |
5548 */ | |
5549 while (fr != NULL && offset > 0) | |
5550 { | |
5551 n = frame_minheight(fr, NULL); | |
5552 if (fr->fr_height - offset <= n) | |
5553 { | |
5554 offset -= fr->fr_height - n; | |
5555 frame_new_height(fr, n, !up, FALSE); | |
5556 } | |
5557 else | |
5558 { | |
5559 frame_new_height(fr, fr->fr_height - offset, !up, FALSE); | |
5560 break; | |
5561 } | |
5562 if (up) | |
5563 fr = fr->fr_prev; | |
5564 else | |
5565 fr = fr->fr_next; | |
5566 } | |
5567 row = win_comp_pos(); | |
5568 screen_fill(row, cmdline_row, 0, (int)Columns, ' ', ' ', 0); | |
5569 cmdline_row = row; | |
5570 p_ch = Rows - cmdline_row; | |
5571 if (p_ch < 1) | |
5572 p_ch = 1; | |
824 | 5573 curtab->tp_ch_used = p_ch; |
737 | 5574 redraw_all_later(SOME_VALID); |
7 | 5575 showmode(); |
5576 } | |
5577 | |
5578 /* | |
5579 * Separator line of dragwin is dragged "offset" lines right (negative is left). | |
5580 */ | |
5581 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5582 win_drag_vsep_line(win_T *dragwin, int offset) |
7 | 5583 { |
5584 frame_T *curfr; | |
5585 frame_T *fr; | |
5586 int room; | |
5587 int left; /* if TRUE, drag separator line left, otherwise right */ | |
5588 int n; | |
5589 | |
5590 fr = dragwin->w_frame; | |
840 | 5591 if (fr == topframe) /* only one window (cannot happen?) */ |
7 | 5592 return; |
5593 curfr = fr; | |
5594 fr = fr->fr_parent; | |
5595 /* When the parent frame is not a row of frames, its parent should be. */ | |
5596 if (fr->fr_layout != FR_ROW) | |
5597 { | |
5598 if (fr == topframe) /* only a column of windows (cannot happen?) */ | |
5599 return; | |
5600 curfr = fr; | |
5601 fr = fr->fr_parent; | |
5602 } | |
5603 | |
5604 /* If this is the last frame in a row, may want to resize a parent | |
5605 * frame instead. */ | |
5606 while (curfr->fr_next == NULL) | |
5607 { | |
5608 if (fr == topframe) | |
5609 break; | |
5610 curfr = fr; | |
5611 fr = fr->fr_parent; | |
5612 if (fr != topframe) | |
5613 { | |
5614 curfr = fr; | |
5615 fr = fr->fr_parent; | |
5616 } | |
5617 } | |
5618 | |
5619 if (offset < 0) /* drag left */ | |
5620 { | |
5621 left = TRUE; | |
5622 offset = -offset; | |
5623 /* sum up the room of the current frame and left of it */ | |
5624 room = 0; | |
5625 for (fr = fr->fr_child; ; fr = fr->fr_next) | |
5626 { | |
5627 room += fr->fr_width - frame_minwidth(fr, NULL); | |
5628 if (fr == curfr) | |
5629 break; | |
5630 } | |
5631 fr = curfr->fr_next; /* put fr at frame that grows */ | |
5632 } | |
5633 else /* drag right */ | |
5634 { | |
5635 left = FALSE; | |
5636 /* sum up the room of frames right of the current one */ | |
5637 room = 0; | |
5638 for (fr = curfr->fr_next; fr != NULL; fr = fr->fr_next) | |
5639 room += fr->fr_width - frame_minwidth(fr, NULL); | |
5640 fr = curfr; /* put fr at window that grows */ | |
5641 } | |
5642 | |
5643 if (room < offset) /* Not enough room */ | |
5644 offset = room; /* Move as far as we can */ | |
5645 if (offset <= 0) /* No room at all, quit. */ | |
5646 return; | |
7256
79270eaac6de
commit https://github.com/vim/vim/commit/294a7e55b01149154807a23323038784549b8946
Christian Brabandt <cb@256bit.org>
parents:
7229
diff
changeset
|
5647 if (fr == NULL) |
79270eaac6de
commit https://github.com/vim/vim/commit/294a7e55b01149154807a23323038784549b8946
Christian Brabandt <cb@256bit.org>
parents:
7229
diff
changeset
|
5648 return; /* Safety check, should not happen. */ |
7 | 5649 |
5650 /* grow frame fr by offset lines */ | |
779 | 5651 frame_new_width(fr, fr->fr_width + offset, left, FALSE); |
7 | 5652 |
5653 /* shrink other frames: current and at the left or at the right */ | |
5654 if (left) | |
5655 fr = curfr; /* current frame gets smaller */ | |
5656 else | |
5657 fr = curfr->fr_next; /* next frame gets smaller */ | |
5658 | |
5659 while (fr != NULL && offset > 0) | |
5660 { | |
5661 n = frame_minwidth(fr, NULL); | |
5662 if (fr->fr_width - offset <= n) | |
5663 { | |
5664 offset -= fr->fr_width - n; | |
779 | 5665 frame_new_width(fr, n, !left, FALSE); |
7 | 5666 } |
5667 else | |
5668 { | |
779 | 5669 frame_new_width(fr, fr->fr_width - offset, !left, FALSE); |
7 | 5670 break; |
5671 } | |
5672 if (left) | |
5673 fr = fr->fr_prev; | |
5674 else | |
5675 fr = fr->fr_next; | |
5676 } | |
5677 (void)win_comp_pos(); | |
5678 redraw_all_later(NOT_VALID); | |
5679 } | |
5680 #endif /* FEAT_MOUSE */ | |
5681 | |
2665 | 5682 #define FRACTION_MULT 16384L |
5683 | |
5684 /* | |
5685 * Set wp->w_fraction for the current w_wrow and w_height. | |
12910
d21adefd4a50
patch 8.0.1331: possible crash when window can be zero lines high
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
5686 * Has no effect when the window is less than two lines. |
2665 | 5687 */ |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7256
diff
changeset
|
5688 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5689 set_fraction(win_T *wp) |
2665 | 5690 { |
12910
d21adefd4a50
patch 8.0.1331: possible crash when window can be zero lines high
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
5691 if (wp->w_height > 1) |
d21adefd4a50
patch 8.0.1331: possible crash when window can be zero lines high
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
5692 wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT |
5875 | 5693 + wp->w_height / 2) / (long)wp->w_height; |
2665 | 5694 } |
5695 | |
7 | 5696 /* |
5697 * Set the height of a window. | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
5698 * "height" excludes any window toolbar. |
7 | 5699 * This takes care of the things inside the window, not what happens to the |
5700 * window position, the frame or to other windows. | |
5701 */ | |
3697 | 5702 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5703 win_new_height(win_T *wp, int height) |
7 | 5704 { |
5875 | 5705 int prev_height = wp->w_height; |
7 | 5706 |
5707 /* Don't want a negative height. Happens when splitting a tiny window. | |
5708 * Will equalize heights soon to fix it. */ | |
5709 if (height < 0) | |
5710 height = 0; | |
826 | 5711 if (wp->w_height == height) |
5712 return; /* nothing to do */ | |
7 | 5713 |
5875 | 5714 if (wp->w_height > 0) |
5715 { | |
5716 if (wp == curwin) | |
5969 | 5717 /* w_wrow needs to be valid. When setting 'laststatus' this may |
5718 * call win_new_height() recursively. */ | |
5719 validate_cursor(); | |
5720 if (wp->w_height != prev_height) | |
5721 return; /* Recursive call already changed the size, bail out here | |
5722 to avoid the following to mess things up. */ | |
5875 | 5723 if (wp->w_wrow != wp->w_prev_fraction_row) |
5724 set_fraction(wp); | |
5725 } | |
7 | 5726 |
5727 wp->w_height = height; | |
5728 wp->w_skipcol = 0; | |
5729 | |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10377
diff
changeset
|
5730 /* There is no point in adjusting the scroll position when exiting. Some |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10377
diff
changeset
|
5731 * values might be invalid. */ |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10377
diff
changeset
|
5732 if (!exiting) |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10377
diff
changeset
|
5733 scroll_to_fraction(wp, prev_height); |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5734 } |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5735 |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5736 void |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5737 scroll_to_fraction(win_T *wp, int prev_height) |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5738 { |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5739 linenr_T lnum; |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5740 int sline, line_size; |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5741 int height = wp->w_height; |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
5742 |
7 | 5743 /* Don't change w_topline when height is zero. Don't set w_topline when |
5744 * 'scrollbind' is set and this isn't the current window. */ | |
5745 if (height > 0 | |
5746 #ifdef FEAT_SCROLLBIND | |
5747 && (!wp->w_p_scb || wp == curwin) | |
5748 #endif | |
5749 ) | |
5750 { | |
47 | 5751 /* |
5752 * Find a value for w_topline that shows the cursor at the same | |
5753 * relative position in the window as before (more or less). | |
5754 */ | |
7 | 5755 lnum = wp->w_cursor.lnum; |
5756 if (lnum < 1) /* can happen when starting up */ | |
5757 lnum = 1; | |
5875 | 5758 wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L |
5759 + FRACTION_MULT / 2) / FRACTION_MULT; | |
7 | 5760 line_size = plines_win_col(wp, lnum, (long)(wp->w_cursor.col)) - 1; |
5761 sline = wp->w_wrow - line_size; | |
1023 | 5762 |
5763 if (sline >= 0) | |
5764 { | |
5765 /* Make sure the whole cursor line is visible, if possible. */ | |
5766 int rows = plines_win(wp, lnum, FALSE); | |
5767 | |
5768 if (sline > wp->w_height - rows) | |
5769 { | |
5770 sline = wp->w_height - rows; | |
5771 wp->w_wrow -= rows - line_size; | |
5772 } | |
5773 } | |
5774 | |
7 | 5775 if (sline < 0) |
5776 { | |
5777 /* | |
5778 * Cursor line would go off top of screen if w_wrow was this high. | |
1023 | 5779 * Make cursor line the first line in the window. If not enough |
5780 * room use w_skipcol; | |
7 | 5781 */ |
5782 wp->w_wrow = line_size; | |
1023 | 5783 if (wp->w_wrow >= wp->w_height |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
5784 && (wp->w_width - win_col_off(wp)) > 0) |
1023 | 5785 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
5786 wp->w_skipcol += wp->w_width - win_col_off(wp); |
1023 | 5787 --wp->w_wrow; |
5788 while (wp->w_wrow >= wp->w_height) | |
5789 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
5790 wp->w_skipcol += wp->w_width - win_col_off(wp) |
1023 | 5791 + win_col_off2(wp); |
5792 --wp->w_wrow; | |
5793 } | |
5794 } | |
6052 | 5795 set_topline(wp, lnum); |
7 | 5796 } |
5936 | 5797 else if (sline > 0) |
7 | 5798 { |
1023 | 5799 while (sline > 0 && lnum > 1) |
7 | 5800 { |
5801 #ifdef FEAT_FOLDING | |
5802 hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); | |
5803 if (lnum == 1) | |
5804 { | |
5805 /* first line in buffer is folded */ | |
5806 line_size = 1; | |
5807 --sline; | |
5808 break; | |
5809 } | |
5810 #endif | |
5811 --lnum; | |
5812 #ifdef FEAT_DIFF | |
5813 if (lnum == wp->w_topline) | |
5814 line_size = plines_win_nofill(wp, lnum, TRUE) | |
5815 + wp->w_topfill; | |
5816 else | |
5817 #endif | |
5818 line_size = plines_win(wp, lnum, TRUE); | |
5819 sline -= line_size; | |
5820 } | |
47 | 5821 |
7 | 5822 if (sline < 0) |
5823 { | |
5824 /* | |
5825 * Line we want at top would go off top of screen. Use next | |
5826 * line instead. | |
5827 */ | |
5828 #ifdef FEAT_FOLDING | |
5829 hasFoldingWin(wp, lnum, NULL, &lnum, TRUE, NULL); | |
5830 #endif | |
5831 lnum++; | |
5832 wp->w_wrow -= line_size + sline; | |
5833 } | |
5936 | 5834 else if (sline > 0) |
7 | 5835 { |
5836 /* First line of file reached, use that as topline. */ | |
5837 lnum = 1; | |
5838 wp->w_wrow -= sline; | |
5839 } | |
5936 | 5840 |
6052 | 5841 set_topline(wp, lnum); |
7 | 5842 } |
5843 } | |
5844 | |
5845 if (wp == curwin) | |
5846 { | |
5847 if (p_so) | |
5848 update_topline(); | |
5849 curs_columns(FALSE); /* validate w_wrow */ | |
5850 } | |
5875 | 5851 if (prev_height > 0) |
5852 wp->w_prev_fraction_row = wp->w_wrow; | |
7 | 5853 |
5854 win_comp_scroll(wp); | |
737 | 5855 redraw_win_later(wp, SOME_VALID); |
7 | 5856 wp->w_redr_status = TRUE; |
5857 invalidate_botline_win(wp); | |
5858 } | |
5859 | |
5860 /* | |
5861 * Set the width of a window. | |
5862 */ | |
3697 | 5863 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5864 win_new_width(win_T *wp, int width) |
7 | 5865 { |
5866 wp->w_width = width; | |
5867 wp->w_lines_valid = 0; | |
5868 changed_line_abv_curs_win(wp); | |
5869 invalidate_botline_win(wp); | |
5870 if (wp == curwin) | |
5871 { | |
5872 update_topline(); | |
5873 curs_columns(TRUE); /* validate w_wrow */ | |
5874 } | |
5875 redraw_win_later(wp, NOT_VALID); | |
5876 wp->w_redr_status = TRUE; | |
5877 } | |
5878 | |
5879 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5880 win_comp_scroll(win_T *wp) |
7 | 5881 { |
5882 wp->w_p_scr = ((unsigned)wp->w_height >> 1); | |
5883 if (wp->w_p_scr == 0) | |
5884 wp->w_p_scr = 1; | |
5885 } | |
5886 | |
5887 /* | |
5888 * command_height: called whenever p_ch has been changed | |
5889 */ | |
5890 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5891 command_height(void) |
7 | 5892 { |
5893 int h; | |
5894 frame_T *frp; | |
824 | 5895 int old_p_ch = curtab->tp_ch_used; |
5896 | |
5897 /* Use the value of p_ch that we remembered. This is needed for when the | |
5898 * GUI starts up, we can't be sure in what order things happen. And when | |
5899 * p_ch was changed in another tab page. */ | |
5900 curtab->tp_ch_used = p_ch; | |
170 | 5901 |
7 | 5902 /* Find bottom frame with width of screen. */ |
5903 frp = lastwin->w_frame; | |
5904 while (frp->fr_width != Columns && frp->fr_parent != NULL) | |
5905 frp = frp->fr_parent; | |
5906 | |
5907 /* Avoid changing the height of a window with 'winfixheight' set. */ | |
5908 while (frp->fr_prev != NULL && frp->fr_layout == FR_LEAF | |
5909 && frp->fr_win->w_p_wfh) | |
5910 frp = frp->fr_prev; | |
5911 | |
5912 if (starting != NO_SCREEN) | |
5913 { | |
5914 cmdline_row = Rows - p_ch; | |
5915 | |
5916 if (p_ch > old_p_ch) /* p_ch got bigger */ | |
5917 { | |
5918 while (p_ch > old_p_ch) | |
5919 { | |
5920 if (frp == NULL) | |
5921 { | |
5922 EMSG(_(e_noroom)); | |
5923 p_ch = old_p_ch; | |
1404 | 5924 curtab->tp_ch_used = p_ch; |
7 | 5925 cmdline_row = Rows - p_ch; |
5926 break; | |
5927 } | |
5928 h = frp->fr_height - frame_minheight(frp, NULL); | |
5929 if (h > p_ch - old_p_ch) | |
5930 h = p_ch - old_p_ch; | |
5931 old_p_ch += h; | |
5932 frame_add_height(frp, -h); | |
5933 frp = frp->fr_prev; | |
5934 } | |
5935 | |
5936 /* Recompute window positions. */ | |
5937 (void)win_comp_pos(); | |
5938 | |
5939 /* clear the lines added to cmdline */ | |
5940 if (full_screen) | |
5941 screen_fill((int)(cmdline_row), (int)Rows, 0, | |
5942 (int)Columns, ' ', ' ', 0); | |
5943 msg_row = cmdline_row; | |
5944 redraw_cmdline = TRUE; | |
5945 return; | |
5946 } | |
5947 | |
5948 if (msg_row < cmdline_row) | |
5949 msg_row = cmdline_row; | |
5950 redraw_cmdline = TRUE; | |
5951 } | |
5952 frame_add_height(frp, (int)(old_p_ch - p_ch)); | |
5953 | |
5954 /* Recompute window positions. */ | |
5955 if (frp != lastwin->w_frame) | |
5956 (void)win_comp_pos(); | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
5957 } |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
5958 |
7 | 5959 /* |
5960 * Resize frame "frp" to be "n" lines higher (negative for less high). | |
5961 * Also resize the frames it is contained in. | |
5962 */ | |
5963 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5964 frame_add_height(frame_T *frp, int n) |
7 | 5965 { |
5966 frame_new_height(frp, frp->fr_height + n, FALSE, FALSE); | |
5967 for (;;) | |
5968 { | |
5969 frp = frp->fr_parent; | |
5970 if (frp == NULL) | |
5971 break; | |
5972 frp->fr_height += n; | |
5973 } | |
5974 } | |
5975 | |
5976 /* | |
5977 * Add or remove a status line for the bottom window(s), according to the | |
5978 * value of 'laststatus'. | |
5979 */ | |
5980 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5981 last_status( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5982 int morewin) /* pretend there are two or more windows */ |
7 | 5983 { |
5984 /* Don't make a difference between horizontal or vertical split. */ | |
5985 last_status_rec(topframe, (p_ls == 2 | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
5986 || (p_ls == 1 && (morewin || !ONE_WINDOW)))); |
7 | 5987 } |
5988 | |
5989 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5990 last_status_rec(frame_T *fr, int statusline) |
7 | 5991 { |
5992 frame_T *fp; | |
5993 win_T *wp; | |
5994 | |
5995 if (fr->fr_layout == FR_LEAF) | |
5996 { | |
5997 wp = fr->fr_win; | |
5998 if (wp->w_status_height != 0 && !statusline) | |
5999 { | |
6000 /* remove status line */ | |
6001 win_new_height(wp, wp->w_height + 1); | |
6002 wp->w_status_height = 0; | |
6003 comp_col(); | |
6004 } | |
6005 else if (wp->w_status_height == 0 && statusline) | |
6006 { | |
6007 /* Find a frame to take a line from. */ | |
6008 fp = fr; | |
6009 while (fp->fr_height <= frame_minheight(fp, NULL)) | |
6010 { | |
6011 if (fp == topframe) | |
6012 { | |
6013 EMSG(_(e_noroom)); | |
6014 return; | |
6015 } | |
6016 /* In a column of frames: go to frame above. If already at | |
6017 * the top or in a row of frames: go to parent. */ | |
6018 if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL) | |
6019 fp = fp->fr_prev; | |
6020 else | |
6021 fp = fp->fr_parent; | |
6022 } | |
6023 wp->w_status_height = 1; | |
6024 if (fp != fr) | |
6025 { | |
6026 frame_new_height(fp, fp->fr_height - 1, FALSE, FALSE); | |
6027 frame_fix_height(wp); | |
6028 (void)win_comp_pos(); | |
6029 } | |
6030 else | |
6031 win_new_height(wp, wp->w_height - 1); | |
6032 comp_col(); | |
737 | 6033 redraw_all_later(SOME_VALID); |
7 | 6034 } |
6035 } | |
6036 else if (fr->fr_layout == FR_ROW) | |
6037 { | |
6038 /* vertically split windows, set status line for each one */ | |
6039 for (fp = fr->fr_child; fp != NULL; fp = fp->fr_next) | |
6040 last_status_rec(fp, statusline); | |
6041 } | |
6042 else | |
6043 { | |
6044 /* horizontally split window, set status line for last one */ | |
6045 for (fp = fr->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
6046 ; | |
6047 last_status_rec(fp, statusline); | |
6048 } | |
6049 } | |
6050 | |
667 | 6051 /* |
668 | 6052 * Return the number of lines used by the tab page line. |
667 | 6053 */ |
6054 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6055 tabline_height(void) |
667 | 6056 { |
685 | 6057 #ifdef FEAT_GUI_TABLINE |
6058 /* When the GUI has the tabline then this always returns zero. */ | |
6059 if (gui_use_tabline()) | |
6060 return 0; | |
6061 #endif | |
675 | 6062 switch (p_stal) |
668 | 6063 { |
6064 case 0: return 0; | |
6065 case 1: return (first_tabpage->tp_next == NULL) ? 0 : 1; | |
6066 } | |
667 | 6067 return 1; |
6068 } | |
6069 | |
7 | 6070 #if defined(FEAT_SEARCHPATH) || defined(PROTO) |
6071 /* | |
344 | 6072 * Get the file name at the cursor. |
6073 * If Visual mode is active, use the selected text if it's in one line. | |
6074 * Returns the name in allocated memory, NULL for failure. | |
6075 */ | |
6076 char_u * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6077 grab_file_name(long count, linenr_T *file_lnum) |
344 | 6078 { |
6633 | 6079 int options = FNAME_MESS|FNAME_EXP|FNAME_REL|FNAME_UNESC; |
6080 | |
344 | 6081 if (VIsual_active) |
6082 { | |
6083 int len; | |
6084 char_u *ptr; | |
6085 | |
6086 if (get_visual_text(NULL, &ptr, &len) == FAIL) | |
6087 return NULL; | |
6633 | 6088 return find_file_name_in_path(ptr, len, options, |
6089 count, curbuf->b_ffname); | |
6090 } | |
6091 return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); | |
344 | 6092 } |
6093 | |
6094 /* | |
7 | 6095 * Return the file name under or after the cursor. |
6096 * | |
6097 * The 'path' option is searched if the file name is not absolute. | |
6098 * The string returned has been alloc'ed and should be freed by the caller. | |
6099 * NULL is returned if the file name or file is not found. | |
6100 * | |
6101 * options: | |
6102 * FNAME_MESS give error messages | |
6103 * FNAME_EXP expand to path | |
6104 * FNAME_HYP check for hypertext link | |
6105 * FNAME_INCL apply "includeexpr" | |
6106 */ | |
6107 char_u * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6108 file_name_at_cursor(int options, long count, linenr_T *file_lnum) |
7 | 6109 { |
6110 return file_name_in_line(ml_get_curline(), | |
681 | 6111 curwin->w_cursor.col, options, count, curbuf->b_ffname, |
6112 file_lnum); | |
7 | 6113 } |
6114 | |
6115 /* | |
6116 * Return the name of the file under or after ptr[col]. | |
6117 * Otherwise like file_name_at_cursor(). | |
6118 */ | |
6119 char_u * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6120 file_name_in_line( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6121 char_u *line, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6122 int col, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6123 int options, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6124 long count, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6125 char_u *rel_fname, /* file we are searching relative to */ |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6126 linenr_T *file_lnum) /* line number after the file name */ |
7 | 6127 { |
6128 char_u *ptr; | |
6129 int len; | |
13103
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6130 int in_type = TRUE; |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6131 int is_url = FALSE; |
7 | 6132 |
6133 /* | |
6134 * search forward for what could be the start of a file name | |
6135 */ | |
6136 ptr = line + col; | |
6137 while (*ptr != NUL && !vim_isfilec(*ptr)) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10883
diff
changeset
|
6138 MB_PTR_ADV(ptr); |
7 | 6139 if (*ptr == NUL) /* nothing found */ |
6140 { | |
6141 if (options & FNAME_MESS) | |
6142 EMSG(_("E446: No file name under cursor")); | |
6143 return NULL; | |
6144 } | |
6145 | |
6146 /* | |
6147 * Search backward for first char of the file name. | |
6148 * Go one char back to ":" before "//" even when ':' is not in 'isfname'. | |
6149 */ | |
6150 while (ptr > line) | |
6151 { | |
6152 #ifdef FEAT_MBYTE | |
6153 if (has_mbyte && (len = (*mb_head_off)(line, ptr - 1)) > 0) | |
6154 ptr -= len + 1; | |
6155 else | |
6156 #endif | |
6157 if (vim_isfilec(ptr[-1]) | |
6158 || ((options & FNAME_HYP) && path_is_url(ptr - 1))) | |
6159 --ptr; | |
6160 else | |
6161 break; | |
6162 } | |
6163 | |
6164 /* | |
6165 * Search forward for the last char of the file name. | |
6166 * Also allow "://" when ':' is not in 'isfname'. | |
6167 */ | |
6168 len = 0; | |
6633 | 6169 while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') |
13103
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6170 || ((options & FNAME_HYP) && path_is_url(ptr + len)) |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6171 || (is_url && vim_strchr((char_u *)"?&=", ptr[len]) != NULL)) |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6172 { |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6173 /* After type:// we also include ?, & and = as valid characters, so that |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6174 * http://google.com?q=this&that=ok works. */ |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6175 if ((ptr[len] >= 'A' && ptr[len] <= 'Z') || (ptr[len] >= 'a' && ptr[len] <= 'z')) |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6176 { |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6177 if (in_type && path_is_url(ptr + len + 1)) |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6178 is_url = TRUE; |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6179 } |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6180 else |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6181 in_type = FALSE; |
788d01164bb2
patch 8.0.1426: "gf" and <cfile> don't accept ? and & in URL
Christian Brabandt <cb@256bit.org>
parents:
12998
diff
changeset
|
6182 |
6633 | 6183 if (ptr[len] == '\\') |
6184 /* Skip over the "\" in "\ ". */ | |
6185 ++len; | |
7 | 6186 #ifdef FEAT_MBYTE |
6187 if (has_mbyte) | |
474 | 6188 len += (*mb_ptr2len)(ptr + len); |
7 | 6189 else |
6190 #endif | |
6191 ++len; | |
6633 | 6192 } |
7 | 6193 |
6194 /* | |
6195 * If there is trailing punctuation, remove it. | |
6196 * But don't remove "..", could be a directory name. | |
6197 */ | |
6198 if (len > 2 && vim_strchr((char_u *)".,:;!", ptr[len - 1]) != NULL | |
6199 && ptr[len - 2] != '.') | |
6200 --len; | |
6201 | |
681 | 6202 if (file_lnum != NULL) |
6203 { | |
6204 char_u *p; | |
6205 | |
6206 /* Get the number after the file name and a separator character */ | |
6207 p = ptr + len; | |
6208 p = skipwhite(p); | |
6209 if (*p != NUL) | |
6210 { | |
6211 if (!isdigit(*p)) | |
6212 ++p; /* skip the separator */ | |
6213 p = skipwhite(p); | |
6214 if (isdigit(*p)) | |
6215 *file_lnum = (int)getdigits(&p); | |
6216 } | |
6217 } | |
6218 | |
7 | 6219 return find_file_name_in_path(ptr, len, options, count, rel_fname); |
6220 } | |
6221 | |
6222 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7677
diff
changeset
|
6223 static char_u *eval_includeexpr(char_u *ptr, int len); |
7 | 6224 |
6225 static char_u * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6226 eval_includeexpr(char_u *ptr, int len) |
7 | 6227 { |
6228 char_u *res; | |
6229 | |
6230 set_vim_var_string(VV_FNAME, ptr, len); | |
633 | 6231 res = eval_to_string_safe(curbuf->b_p_inex, NULL, |
681 | 6232 was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL)); |
7 | 6233 set_vim_var_string(VV_FNAME, NULL, 0); |
6234 return res; | |
6235 } | |
6236 #endif | |
6237 | |
6238 /* | |
6239 * Return the name of the file ptr[len] in 'path'. | |
6240 * Otherwise like file_name_at_cursor(). | |
6241 */ | |
6242 char_u * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6243 find_file_name_in_path( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6244 char_u *ptr, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6245 int len, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6246 int options, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6247 long count, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6248 char_u *rel_fname) /* file we are searching relative to */ |
7 | 6249 { |
6250 char_u *file_name; | |
6251 int c; | |
6252 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) | |
6253 char_u *tofree = NULL; | |
6254 | |
6255 if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) | |
6256 { | |
6257 tofree = eval_includeexpr(ptr, len); | |
6258 if (tofree != NULL) | |
6259 { | |
6260 ptr = tofree; | |
6261 len = (int)STRLEN(ptr); | |
6262 } | |
6263 } | |
6264 # endif | |
6265 | |
6266 if (options & FNAME_EXP) | |
6267 { | |
6268 file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, | |
6269 TRUE, rel_fname); | |
6270 | |
6271 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) | |
6272 /* | |
6273 * If the file could not be found in a normal way, try applying | |
6274 * 'includeexpr' (unless done already). | |
6275 */ | |
6276 if (file_name == NULL | |
6277 && !(options & FNAME_INCL) && *curbuf->b_p_inex != NUL) | |
6278 { | |
6279 tofree = eval_includeexpr(ptr, len); | |
6280 if (tofree != NULL) | |
6281 { | |
6282 ptr = tofree; | |
6283 len = (int)STRLEN(ptr); | |
6284 file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, | |
6285 TRUE, rel_fname); | |
6286 } | |
6287 } | |
6288 # endif | |
6289 if (file_name == NULL && (options & FNAME_MESS)) | |
6290 { | |
6291 c = ptr[len]; | |
6292 ptr[len] = NUL; | |
6293 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr); | |
6294 ptr[len] = c; | |
6295 } | |
6296 | |
6297 /* Repeat finding the file "count" times. This matters when it | |
6298 * appears several times in the path. */ | |
6299 while (file_name != NULL && --count > 0) | |
6300 { | |
6301 vim_free(file_name); | |
6302 file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname); | |
6303 } | |
6304 } | |
6305 else | |
6306 file_name = vim_strnsave(ptr, len); | |
6307 | |
6308 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) | |
6309 vim_free(tofree); | |
6310 # endif | |
6311 | |
6312 return file_name; | |
6313 } | |
6314 #endif /* FEAT_SEARCHPATH */ | |
6315 | |
6316 /* | |
6317 * Check if the "://" of a URL is at the pointer, return URL_SLASH. | |
6318 * Also check for ":\\", which MS Internet Explorer accepts, return | |
6319 * URL_BACKSLASH. | |
6320 */ | |
6321 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6322 path_is_url(char_u *p) |
7 | 6323 { |
6324 if (STRNCMP(p, "://", (size_t)3) == 0) | |
6325 return URL_SLASH; | |
6326 else if (STRNCMP(p, ":\\\\", (size_t)3) == 0) | |
6327 return URL_BACKSLASH; | |
6328 return 0; | |
6329 } | |
6330 | |
6331 /* | |
6332 * Check if "fname" starts with "name://". Return URL_SLASH if it does. | |
6333 * Return URL_BACKSLASH for "name:\\". | |
6334 * Return zero otherwise. | |
6335 */ | |
6336 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6337 path_with_url(char_u *fname) |
7 | 6338 { |
6339 char_u *p; | |
6340 | |
6341 for (p = fname; isalpha(*p); ++p) | |
6342 ; | |
6343 return path_is_url(p); | |
6344 } | |
6345 | |
6346 /* | |
6347 * Return TRUE if "name" is a full (absolute) path name or URL. | |
6348 */ | |
6349 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6350 vim_isAbsName(char_u *name) |
7 | 6351 { |
6352 return (path_with_url(name) != 0 || mch_isFullName(name)); | |
6353 } | |
6354 | |
6355 /* | |
592 | 6356 * Get absolute file name into buffer "buf[len]". |
7 | 6357 * |
6358 * return FAIL for failure, OK otherwise | |
6359 */ | |
6360 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6361 vim_FullName( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6362 char_u *fname, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6363 char_u *buf, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6364 int len, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6365 int force) /* force expansion even when already absolute */ |
7 | 6366 { |
6367 int retval = OK; | |
6368 int url; | |
6369 | |
6370 *buf = NUL; | |
6371 if (fname == NULL) | |
6372 return FAIL; | |
6373 | |
6374 url = path_with_url(fname); | |
6375 if (!url) | |
6376 retval = mch_FullName(fname, buf, len, force); | |
6377 if (url || retval == FAIL) | |
6378 { | |
6379 /* something failed; use the file name (truncate when too long) */ | |
416 | 6380 vim_strncpy(buf, fname, len - 1); |
7 | 6381 } |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
6382 #if defined(MSWIN) |
7 | 6383 slash_adjust(buf); |
6384 #endif | |
6385 return retval; | |
6386 } | |
6387 | |
6388 /* | |
6389 * Return the minimal number of rows that is needed on the screen to display | |
6390 * the current number of windows. | |
6391 */ | |
6392 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6393 min_rows(void) |
7 | 6394 { |
6395 int total; | |
671 | 6396 tabpage_T *tp; |
6397 int n; | |
7 | 6398 |
6399 if (firstwin == NULL) /* not initialized yet */ | |
6400 return MIN_LINES; | |
6401 | |
671 | 6402 total = 0; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
6403 FOR_ALL_TABPAGES(tp) |
671 | 6404 { |
6405 n = frame_minheight(tp->tp_topframe, NULL); | |
6406 if (total < n) | |
6407 total = n; | |
6408 } | |
685 | 6409 total += tabline_height(); |
671 | 6410 total += 1; /* count the room for the command line */ |
7 | 6411 return total; |
6412 } | |
6413 | |
6414 /* | |
672 | 6415 * Return TRUE if there is only one window (in the current tab page), not |
6416 * counting a help or preview window, unless it is the current window. | |
1906 | 6417 * Does not count "aucmd_win". |
7 | 6418 */ |
6419 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6420 only_one_window(void) |
7 | 6421 { |
6422 int count = 0; | |
6423 win_T *wp; | |
6424 | |
667 | 6425 /* If there is another tab page there always is another window. */ |
6426 if (first_tabpage->tp_next != NULL) | |
6427 return FALSE; | |
6428 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
6429 FOR_ALL_WINDOWS(wp) |
4021 | 6430 if (wp->w_buffer != NULL |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11593
diff
changeset
|
6431 && (!((bt_help(wp->w_buffer) && !bt_help(curbuf)) |
7 | 6432 # ifdef FEAT_QUICKFIX |
6433 || wp->w_p_pvw | |
6434 # endif | |
6435 ) || wp == curwin) | |
1906 | 6436 # ifdef FEAT_AUTOCMD |
6437 && wp != aucmd_win | |
6438 # endif | |
6439 ) | |
7 | 6440 ++count; |
6441 return (count <= 1); | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
6442 } |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
6443 |
7 | 6444 /* |
6445 * Correct the cursor line number in other windows. Used after changing the | |
6446 * current buffer, and before applying autocommands. | |
6447 * When "do_curwin" is TRUE, also check current window. | |
6448 */ | |
6449 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6450 check_lnums(int do_curwin) |
7 | 6451 { |
6452 win_T *wp; | |
671 | 6453 tabpage_T *tp; |
6454 | |
6455 FOR_ALL_TAB_WINDOWS(tp, wp) | |
7 | 6456 if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) |
6457 { | |
6458 if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6459 wp->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6460 if (wp->w_topline > curbuf->b_ml.ml_line_count) | |
6461 wp->w_topline = curbuf->b_ml.ml_line_count; | |
6462 } | |
6463 } | |
6464 | |
6465 /* | |
6466 * A snapshot of the window sizes, to restore them after closing the help | |
6467 * window. | |
6468 * Only these fields are used: | |
6469 * fr_layout | |
6470 * fr_width | |
6471 * fr_height | |
6472 * fr_next | |
6473 * fr_child | |
6474 * fr_win (only valid for the old curwin, NULL otherwise) | |
6475 */ | |
6476 | |
6477 /* | |
6478 * Create a snapshot of the current frame sizes. | |
6479 */ | |
1906 | 6480 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6481 make_snapshot(int idx) |
7 | 6482 { |
1906 | 6483 clear_snapshot(curtab, idx); |
6484 make_snapshot_rec(topframe, &curtab->tp_snapshot[idx]); | |
7 | 6485 } |
6486 | |
6487 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6488 make_snapshot_rec(frame_T *fr, frame_T **frp) |
7 | 6489 { |
6490 *frp = (frame_T *)alloc_clear((unsigned)sizeof(frame_T)); | |
6491 if (*frp == NULL) | |
6492 return; | |
6493 (*frp)->fr_layout = fr->fr_layout; | |
6494 (*frp)->fr_width = fr->fr_width; | |
6495 (*frp)->fr_height = fr->fr_height; | |
6496 if (fr->fr_next != NULL) | |
6497 make_snapshot_rec(fr->fr_next, &((*frp)->fr_next)); | |
6498 if (fr->fr_child != NULL) | |
6499 make_snapshot_rec(fr->fr_child, &((*frp)->fr_child)); | |
6500 if (fr->fr_layout == FR_LEAF && fr->fr_win == curwin) | |
6501 (*frp)->fr_win = curwin; | |
6502 } | |
6503 | |
6504 /* | |
6505 * Remove any existing snapshot. | |
6506 */ | |
6507 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6508 clear_snapshot(tabpage_T *tp, int idx) |
7 | 6509 { |
1906 | 6510 clear_snapshot_rec(tp->tp_snapshot[idx]); |
6511 tp->tp_snapshot[idx] = NULL; | |
7 | 6512 } |
6513 | |
6514 static void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6515 clear_snapshot_rec(frame_T *fr) |
7 | 6516 { |
6517 if (fr != NULL) | |
6518 { | |
6519 clear_snapshot_rec(fr->fr_next); | |
6520 clear_snapshot_rec(fr->fr_child); | |
6521 vim_free(fr); | |
6522 } | |
6523 } | |
6524 | |
6525 /* | |
6526 * Restore a previously created snapshot, if there is any. | |
6527 * This is only done if the screen size didn't change and the window layout is | |
6528 * still the same. | |
6529 */ | |
1906 | 6530 void |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6531 restore_snapshot( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6532 int idx, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6533 int close_curwin) /* closing current window */ |
7 | 6534 { |
6535 win_T *wp; | |
6536 | |
1906 | 6537 if (curtab->tp_snapshot[idx] != NULL |
6538 && curtab->tp_snapshot[idx]->fr_width == topframe->fr_width | |
6539 && curtab->tp_snapshot[idx]->fr_height == topframe->fr_height | |
6540 && check_snapshot_rec(curtab->tp_snapshot[idx], topframe) == OK) | |
6541 { | |
6542 wp = restore_snapshot_rec(curtab->tp_snapshot[idx], topframe); | |
7 | 6543 win_comp_pos(); |
6544 if (wp != NULL && close_curwin) | |
6545 win_goto(wp); | |
6546 redraw_all_later(CLEAR); | |
6547 } | |
1906 | 6548 clear_snapshot(curtab, idx); |
7 | 6549 } |
6550 | |
6551 /* | |
6552 * Check if frames "sn" and "fr" have the same layout, same following frames | |
10883
cb71a5468aca
patch 8.0.0331: restoring help snapshot accesses freed memory
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
6553 * and same children. And the window pointer is valid. |
7 | 6554 */ |
6555 static int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6556 check_snapshot_rec(frame_T *sn, frame_T *fr) |
7 | 6557 { |
6558 if (sn->fr_layout != fr->fr_layout | |
6559 || (sn->fr_next == NULL) != (fr->fr_next == NULL) | |
6560 || (sn->fr_child == NULL) != (fr->fr_child == NULL) | |
6561 || (sn->fr_next != NULL | |
6562 && check_snapshot_rec(sn->fr_next, fr->fr_next) == FAIL) | |
6563 || (sn->fr_child != NULL | |
10883
cb71a5468aca
patch 8.0.0331: restoring help snapshot accesses freed memory
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
6564 && check_snapshot_rec(sn->fr_child, fr->fr_child) == FAIL) |
11191
445fd6be2009
patch 8.0.0482: the setbufvar() function may mess up the window layout
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6565 || (sn->fr_win != NULL && !win_valid(sn->fr_win))) |
7 | 6566 return FAIL; |
6567 return OK; | |
6568 } | |
6569 | |
6570 /* | |
6571 * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all | |
6572 * following frames and children. | |
6573 * Returns a pointer to the old current window, or NULL. | |
6574 */ | |
6575 static win_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6576 restore_snapshot_rec(frame_T *sn, frame_T *fr) |
7 | 6577 { |
6578 win_T *wp = NULL; | |
6579 win_T *wp2; | |
6580 | |
6581 fr->fr_height = sn->fr_height; | |
6582 fr->fr_width = sn->fr_width; | |
6583 if (fr->fr_layout == FR_LEAF) | |
6584 { | |
6585 frame_new_height(fr, fr->fr_height, FALSE, FALSE); | |
779 | 6586 frame_new_width(fr, fr->fr_width, FALSE, FALSE); |
7 | 6587 wp = sn->fr_win; |
6588 } | |
6589 if (sn->fr_next != NULL) | |
6590 { | |
6591 wp2 = restore_snapshot_rec(sn->fr_next, fr->fr_next); | |
6592 if (wp2 != NULL) | |
6593 wp = wp2; | |
6594 } | |
6595 if (sn->fr_child != NULL) | |
6596 { | |
6597 wp2 = restore_snapshot_rec(sn->fr_child, fr->fr_child); | |
6598 if (wp2 != NULL) | |
6599 wp = wp2; | |
6600 } | |
6601 return wp; | |
6602 } | |
6603 | |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5098
diff
changeset
|
6604 #if defined(FEAT_EVAL) || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \ |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5098
diff
changeset
|
6605 || defined(PROTO) |
4429 | 6606 /* |
6607 * Set "win" to be the curwin and "tp" to be the current tab page. | |
6222 | 6608 * restore_win() MUST be called to undo, also when FAIL is returned. |
6609 * No autocommands will be executed until restore_win() is called. | |
4918
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6610 * When "no_display" is TRUE the display won't be affected, no redraw is |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6611 * triggered, another tabpage access is limited. |
4429 | 6612 * Returns FAIL if switching to "win" failed. |
6613 */ | |
6614 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6615 switch_win( |
12564
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6616 win_T **save_curwin, |
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6617 tabpage_T **save_curtab, |
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6618 win_T *win, |
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6619 tabpage_T *tp, |
183dc24cf861
patch 8.0.1160: getting tab-local variable fails after closing window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6620 int no_display) |
4429 | 6621 { |
6622 # ifdef FEAT_AUTOCMD | |
6623 block_autocmds(); | |
6624 # endif | |
6625 *save_curwin = curwin; | |
6626 if (tp != NULL) | |
6627 { | |
6628 *save_curtab = curtab; | |
4918
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6629 if (no_display) |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6630 { |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6631 curtab->tp_firstwin = firstwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6632 curtab->tp_lastwin = lastwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6633 curtab = tp; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6634 firstwin = curtab->tp_firstwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6635 lastwin = curtab->tp_lastwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6636 } |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6637 else |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6638 goto_tabpage_tp(tp, FALSE, FALSE); |
4429 | 6639 } |
6640 if (!win_valid(win)) | |
6641 return FAIL; | |
6642 curwin = win; | |
6643 curbuf = curwin->w_buffer; | |
6644 return OK; | |
6645 } | |
6646 | |
6647 /* | |
6648 * Restore current tabpage and window saved by switch_win(), if still valid. | |
4918
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6649 * When "no_display" is TRUE the display won't be affected, no redraw is |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6650 * triggered. |
4429 | 6651 */ |
6652 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6653 restore_win( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6654 win_T *save_curwin UNUSED, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6655 tabpage_T *save_curtab UNUSED, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6656 int no_display UNUSED) |
4429 | 6657 { |
6658 if (save_curtab != NULL && valid_tabpage(save_curtab)) | |
4918
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6659 { |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6660 if (no_display) |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6661 { |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6662 curtab->tp_firstwin = firstwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6663 curtab->tp_lastwin = lastwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6664 curtab = save_curtab; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6665 firstwin = curtab->tp_firstwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6666 lastwin = curtab->tp_lastwin; |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6667 } |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6668 else |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6669 goto_tabpage_tp(save_curtab, FALSE, FALSE); |
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6670 } |
4429 | 6671 if (win_valid(save_curwin)) |
6672 { | |
6673 curwin = save_curwin; | |
6674 curbuf = curwin->w_buffer; | |
6675 } | |
6676 # ifdef FEAT_AUTOCMD | |
6677 unblock_autocmds(); | |
6678 # endif | |
6679 } | |
6680 | |
6681 /* | |
6682 * Make "buf" the current buffer. restore_buffer() MUST be called to undo. | |
6683 * No autocommands will be executed. Use aucmd_prepbuf() if there are any. | |
6684 */ | |
6685 void | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
6686 switch_buffer(bufref_T *save_curbuf, buf_T *buf) |
4429 | 6687 { |
6688 # ifdef FEAT_AUTOCMD | |
6689 block_autocmds(); | |
6690 # endif | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
6691 set_bufref(save_curbuf, curbuf); |
4429 | 6692 --curbuf->b_nwindows; |
6693 curbuf = buf; | |
6694 curwin->w_buffer = buf; | |
6695 ++curbuf->b_nwindows; | |
6696 } | |
6697 | |
6698 /* | |
6699 * Restore the current buffer after using switch_buffer(). | |
6700 */ | |
6701 void | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
6702 restore_buffer(bufref_T *save_curbuf) |
4429 | 6703 { |
6704 # ifdef FEAT_AUTOCMD | |
6705 unblock_autocmds(); | |
6706 # endif | |
6707 /* Check for valid buffer, just in case. */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
6708 if (bufref_valid(save_curbuf)) |
4429 | 6709 { |
6710 --curbuf->b_nwindows; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
6711 curwin->w_buffer = save_curbuf->br_buf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9349
diff
changeset
|
6712 curbuf = save_curbuf->br_buf; |
4429 | 6713 ++curbuf->b_nwindows; |
6714 } | |
6715 } | |
6716 #endif | |
6717 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
6718 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 6719 /* |
6720 * Return TRUE if there is any vertically split window. | |
6721 */ | |
6722 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6723 win_hasvertsplit(void) |
7 | 6724 { |
6725 frame_T *fr; | |
6726 | |
6727 if (topframe->fr_layout == FR_ROW) | |
6728 return TRUE; | |
6729 | |
6730 if (topframe->fr_layout == FR_COL) | |
6731 for (fr = topframe->fr_child; fr != NULL; fr = fr->fr_next) | |
6732 if (fr->fr_layout == FR_ROW) | |
6733 return TRUE; | |
6734 | |
6735 return FALSE; | |
6736 } | |
6737 #endif | |
1326 | 6738 |
6739 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) | |
6740 /* | |
6741 * Add match to the match list of window 'wp'. The pattern 'pat' will be | |
1698 | 6742 * highlighted with the group 'grp' with priority 'prio'. |
1326 | 6743 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1). |
6744 * If no particular ID is desired, -1 must be specified for 'id'. | |
6745 * Return ID of added match, -1 on failure. | |
6746 */ | |
6747 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6748 match_add( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6749 win_T *wp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6750 char_u *grp, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6751 char_u *pat, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6752 int prio, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6753 int id, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6754 list_T *pos_list, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6755 char_u *conceal_char UNUSED) /* pointer to conceal replacement char */ |
1326 | 6756 { |
5979 | 6757 matchitem_T *cur; |
6758 matchitem_T *prev; | |
6759 matchitem_T *m; | |
1326 | 6760 int hlg_id; |
5979 | 6761 regprog_T *regprog = NULL; |
6762 int rtype = SOME_VALID; | |
6763 | |
6764 if (*grp == NUL || (pat != NULL && *pat == NUL)) | |
1326 | 6765 return -1; |
6766 if (id < -1 || id == 0) | |
6767 { | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
6768 EMSGN(_("E799: Invalid ID: %ld (must be greater than or equal to 1)"), id); |
1326 | 6769 return -1; |
6770 } | |
6771 if (id != -1) | |
6772 { | |
6773 cur = wp->w_match_head; | |
6774 while (cur != NULL) | |
6775 { | |
6776 if (cur->id == id) | |
6777 { | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
6778 EMSGN(_("E801: ID already taken: %ld"), id); |
1326 | 6779 return -1; |
6780 } | |
6781 cur = cur->next; | |
6782 } | |
6783 } | |
1570 | 6784 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0) |
1326 | 6785 { |
6786 EMSG2(_(e_nogroup), grp); | |
6787 return -1; | |
6788 } | |
5979 | 6789 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) |
1326 | 6790 { |
6791 EMSG2(_(e_invarg2), pat); | |
6792 return -1; | |
6793 } | |
6794 | |
6795 /* Find available match ID. */ | |
6796 while (id == -1) | |
6797 { | |
6798 cur = wp->w_match_head; | |
6799 while (cur != NULL && cur->id != wp->w_next_match_id) | |
6800 cur = cur->next; | |
6801 if (cur == NULL) | |
6802 id = wp->w_next_match_id; | |
6803 wp->w_next_match_id++; | |
6804 } | |
6805 | |
6806 /* Build new match. */ | |
5987 | 6807 m = (matchitem_T *)alloc_clear(sizeof(matchitem_T)); |
1326 | 6808 m->id = id; |
6809 m->priority = prio; | |
5979 | 6810 m->pattern = pat == NULL ? NULL : vim_strsave(pat); |
1326 | 6811 m->hlg_id = hlg_id; |
1338 | 6812 m->match.regprog = regprog; |
6813 m->match.rmm_ic = FALSE; | |
6814 m->match.rmm_maxcol = 0; | |
8804
75446578a52f
commit https://github.com/vim/vim/commit/42356150badca33b4e42dc8172abbceff2e86cbe
Christian Brabandt <cb@256bit.org>
parents:
8651
diff
changeset
|
6815 # if defined(FEAT_CONCEAL) && defined(FEAT_MBYTE) |
6947 | 6816 m->conceal_char = 0; |
6817 if (conceal_char != NULL) | |
6818 m->conceal_char = (*mb_ptr2char)(conceal_char); | |
8804
75446578a52f
commit https://github.com/vim/vim/commit/42356150badca33b4e42dc8172abbceff2e86cbe
Christian Brabandt <cb@256bit.org>
parents:
8651
diff
changeset
|
6819 # endif |
1326 | 6820 |
5979 | 6821 /* Set up position matches */ |
6822 if (pos_list != NULL) | |
6823 { | |
6824 linenr_T toplnum = 0; | |
6825 linenr_T botlnum = 0; | |
6826 listitem_T *li; | |
6827 int i; | |
6828 | |
6007 | 6829 for (i = 0, li = pos_list->lv_first; li != NULL && i < MAXPOSMATCH; |
5979 | 6830 i++, li = li->li_next) |
6831 { | |
6832 linenr_T lnum = 0; | |
6833 colnr_T col = 0; | |
6834 int len = 1; | |
6835 list_T *subl; | |
6836 listitem_T *subli; | |
5987 | 6837 int error = FALSE; |
5979 | 6838 |
6839 if (li->li_tv.v_type == VAR_LIST) | |
6840 { | |
6841 subl = li->li_tv.vval.v_list; | |
6842 if (subl == NULL) | |
6843 goto fail; | |
6844 subli = subl->lv_first; | |
6845 if (subli == NULL) | |
6846 goto fail; | |
6847 lnum = get_tv_number_chk(&subli->li_tv, &error); | |
6848 if (error == TRUE) | |
6849 goto fail; | |
6850 if (lnum == 0) | |
6851 { | |
6852 --i; | |
6853 continue; | |
6854 } | |
6007 | 6855 m->pos.pos[i].lnum = lnum; |
5979 | 6856 subli = subli->li_next; |
6857 if (subli != NULL) | |
6858 { | |
6859 col = get_tv_number_chk(&subli->li_tv, &error); | |
6860 if (error == TRUE) | |
6861 goto fail; | |
6862 subli = subli->li_next; | |
6863 if (subli != NULL) | |
6864 { | |
6865 len = get_tv_number_chk(&subli->li_tv, &error); | |
6866 if (error == TRUE) | |
6867 goto fail; | |
6868 } | |
6869 } | |
6870 m->pos.pos[i].col = col; | |
6871 m->pos.pos[i].len = len; | |
6872 } | |
6873 else if (li->li_tv.v_type == VAR_NUMBER) | |
6874 { | |
6875 if (li->li_tv.vval.v_number == 0) | |
6007 | 6876 { |
6877 --i; | |
5979 | 6878 continue; |
6007 | 6879 } |
5979 | 6880 m->pos.pos[i].lnum = li->li_tv.vval.v_number; |
6881 m->pos.pos[i].col = 0; | |
6882 m->pos.pos[i].len = 0; | |
6883 } | |
6884 else | |
6885 { | |
6886 EMSG(_("List or number required")); | |
6887 goto fail; | |
6888 } | |
6889 if (toplnum == 0 || lnum < toplnum) | |
6890 toplnum = lnum; | |
6005 | 6891 if (botlnum == 0 || lnum >= botlnum) |
6892 botlnum = lnum + 1; | |
5979 | 6893 } |
6894 | |
6895 /* Calculate top and bottom lines for redrawing area */ | |
6896 if (toplnum != 0) | |
6897 { | |
6898 if (wp->w_buffer->b_mod_set) | |
6899 { | |
6900 if (wp->w_buffer->b_mod_top > toplnum) | |
6901 wp->w_buffer->b_mod_top = toplnum; | |
6902 if (wp->w_buffer->b_mod_bot < botlnum) | |
6903 wp->w_buffer->b_mod_bot = botlnum; | |
6904 } | |
6905 else | |
6906 { | |
6018 | 6907 wp->w_buffer->b_mod_set = TRUE; |
5979 | 6908 wp->w_buffer->b_mod_top = toplnum; |
6909 wp->w_buffer->b_mod_bot = botlnum; | |
6018 | 6910 wp->w_buffer->b_mod_xlines = 0; |
5979 | 6911 } |
6912 m->pos.toplnum = toplnum; | |
6913 m->pos.botlnum = botlnum; | |
6914 rtype = VALID; | |
6915 } | |
6916 } | |
6917 | |
1326 | 6918 /* Insert new match. The match list is in ascending order with regard to |
6919 * the match priorities. */ | |
6920 cur = wp->w_match_head; | |
6921 prev = cur; | |
6922 while (cur != NULL && prio >= cur->priority) | |
6923 { | |
6924 prev = cur; | |
6925 cur = cur->next; | |
6926 } | |
6927 if (cur == prev) | |
6928 wp->w_match_head = m; | |
6929 else | |
6930 prev->next = m; | |
6931 m->next = cur; | |
6932 | |
5979 | 6933 redraw_later(rtype); |
1326 | 6934 return id; |
5979 | 6935 |
6936 fail: | |
6937 vim_free(m); | |
6938 return -1; | |
1326 | 6939 } |
6940 | |
6941 /* | |
6942 * Delete match with ID 'id' in the match list of window 'wp'. | |
6943 * Print error messages if 'perr' is TRUE. | |
6944 */ | |
6945 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6946 match_delete(win_T *wp, int id, int perr) |
1326 | 6947 { |
5979 | 6948 matchitem_T *cur = wp->w_match_head; |
6949 matchitem_T *prev = cur; | |
6950 int rtype = SOME_VALID; | |
1326 | 6951 |
6952 if (id < 1) | |
6953 { | |
6954 if (perr == TRUE) | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
6955 EMSGN(_("E802: Invalid ID: %ld (must be greater than or equal to 1)"), |
1326 | 6956 id); |
6957 return -1; | |
6958 } | |
6959 while (cur != NULL && cur->id != id) | |
6960 { | |
6961 prev = cur; | |
6962 cur = cur->next; | |
6963 } | |
6964 if (cur == NULL) | |
6965 { | |
6966 if (perr == TRUE) | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
6967 EMSGN(_("E803: ID not found: %ld"), id); |
1326 | 6968 return -1; |
6969 } | |
6970 if (cur == prev) | |
6971 wp->w_match_head = cur->next; | |
6972 else | |
6973 prev->next = cur->next; | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4442
diff
changeset
|
6974 vim_regfree(cur->match.regprog); |
1326 | 6975 vim_free(cur->pattern); |
5979 | 6976 if (cur->pos.toplnum != 0) |
6977 { | |
6978 if (wp->w_buffer->b_mod_set) | |
6979 { | |
6980 if (wp->w_buffer->b_mod_top > cur->pos.toplnum) | |
6981 wp->w_buffer->b_mod_top = cur->pos.toplnum; | |
6982 if (wp->w_buffer->b_mod_bot < cur->pos.botlnum) | |
6983 wp->w_buffer->b_mod_bot = cur->pos.botlnum; | |
6984 } | |
6985 else | |
6986 { | |
6018 | 6987 wp->w_buffer->b_mod_set = TRUE; |
5979 | 6988 wp->w_buffer->b_mod_top = cur->pos.toplnum; |
6989 wp->w_buffer->b_mod_bot = cur->pos.botlnum; | |
6018 | 6990 wp->w_buffer->b_mod_xlines = 0; |
5979 | 6991 } |
6992 rtype = VALID; | |
6993 } | |
1326 | 6994 vim_free(cur); |
5979 | 6995 redraw_later(rtype); |
1326 | 6996 return 0; |
6997 } | |
6998 | |
6999 /* | |
7000 * Delete all matches in the match list of window 'wp'. | |
7001 */ | |
7002 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7003 clear_matches(win_T *wp) |
1326 | 7004 { |
7005 matchitem_T *m; | |
7006 | |
7007 while (wp->w_match_head != NULL) | |
7008 { | |
7009 m = wp->w_match_head->next; | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4442
diff
changeset
|
7010 vim_regfree(wp->w_match_head->match.regprog); |
1326 | 7011 vim_free(wp->w_match_head->pattern); |
7012 vim_free(wp->w_match_head); | |
7013 wp->w_match_head = m; | |
7014 } | |
7015 redraw_later(SOME_VALID); | |
7016 } | |
7017 | |
7018 /* | |
7019 * Get match from ID 'id' in window 'wp'. | |
7020 * Return NULL if match not found. | |
7021 */ | |
7022 matchitem_T * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7023 get_match(win_T *wp, int id) |
1326 | 7024 { |
7025 matchitem_T *cur = wp->w_match_head; | |
7026 | |
7027 while (cur != NULL && cur->id != id) | |
7028 cur = cur->next; | |
7029 return cur; | |
7030 } | |
7031 #endif | |
4379 | 7032 |
7033 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) | |
7034 int | |
4401 | 7035 get_win_number(win_T *wp, win_T *first_win) |
4379 | 7036 { |
7037 int i = 1; | |
7038 win_T *w; | |
7039 | |
4401 | 7040 for (w = first_win; w != NULL && w != wp; w = W_NEXT(w)) |
4379 | 7041 ++i; |
7042 | |
7043 if (w == NULL) | |
7044 return 0; | |
7045 else | |
7046 return i; | |
7047 } | |
4401 | 7048 |
7049 int | |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
7050 get_tab_number(tabpage_T *tp UNUSED) |
4401 | 7051 { |
7052 int i = 1; | |
7053 tabpage_T *t; | |
7054 | |
7055 for (t = first_tabpage; t != NULL && t != tp; t = t->tp_next) | |
7056 ++i; | |
7057 | |
7058 if (t == NULL) | |
7059 return 0; | |
7060 else | |
7061 return i; | |
7062 } | |
7063 #endif | |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7064 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7065 /* |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7066 * Return TRUE if "topfrp" and its children are at the right height. |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7067 */ |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7068 static int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7069 frame_check_height(frame_T *topfrp, int height) |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7070 { |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7071 frame_T *frp; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7072 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7073 if (topfrp->fr_height != height) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7074 return FALSE; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7075 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7076 if (topfrp->fr_layout == FR_ROW) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7077 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7078 if (frp->fr_height != height) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7079 return FALSE; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7080 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7081 return TRUE; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7082 } |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
7083 |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7084 /* |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7085 * Return TRUE if "topfrp" and its children are at the right width. |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7086 */ |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7087 static int |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7088 frame_check_width(frame_T *topfrp, int width) |
5004
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7089 { |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7090 frame_T *frp; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7091 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7092 if (topfrp->fr_width != width) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7093 return FALSE; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7094 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7095 if (topfrp->fr_layout == FR_COL) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7096 for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7097 if (frp->fr_width != width) |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7098 return FALSE; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7099 |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7100 return TRUE; |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7101 } |
a1b41dabc682
updated for version 7.3.1246
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
7102 |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7103 #if defined(FEAT_EVAL) || defined(PROTO) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7104 int |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7105 win_getid(typval_T *argvars) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7106 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7107 int winnr; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7108 win_T *wp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7109 |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7110 if (argvars[0].v_type == VAR_UNKNOWN) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7111 return curwin->w_id; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7112 winnr = get_tv_number(&argvars[0]); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7113 if (winnr > 0) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7114 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7115 if (argvars[1].v_type == VAR_UNKNOWN) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7116 wp = firstwin; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7117 else |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7118 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7119 tabpage_T *tp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7120 int tabnr = get_tv_number(&argvars[1]); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7121 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7122 FOR_ALL_TABPAGES(tp) |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7123 if (--tabnr == 0) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7124 break; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7125 if (tp == NULL) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7126 return -1; |
10377
dd397210a2d3
commit https://github.com/vim/vim/commit/8e639052638a9bb8c7dd6e3e10776b1218cec1a3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
7127 if (tp == curtab) |
dd397210a2d3
commit https://github.com/vim/vim/commit/8e639052638a9bb8c7dd6e3e10776b1218cec1a3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
7128 wp = firstwin; |
dd397210a2d3
commit https://github.com/vim/vim/commit/8e639052638a9bb8c7dd6e3e10776b1218cec1a3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
7129 else |
dd397210a2d3
commit https://github.com/vim/vim/commit/8e639052638a9bb8c7dd6e3e10776b1218cec1a3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
7130 wp = tp->tp_firstwin; |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7131 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7132 for ( ; wp != NULL; wp = wp->w_next) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7133 if (--winnr == 0) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7134 return wp->w_id; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7135 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7136 return 0; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7137 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7138 |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7139 int |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7140 win_gotoid(typval_T *argvars) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7141 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7142 win_T *wp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7143 tabpage_T *tp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7144 int id = get_tv_number(&argvars[0]); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7145 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7146 FOR_ALL_TAB_WINDOWS(tp, wp) |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7147 if (wp->w_id == id) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7148 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7149 goto_tabpage_win(tp, wp); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7150 return 1; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7151 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7152 return 0; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7153 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7154 |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7155 void |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7156 win_id2tabwin(typval_T *argvars, list_T *list) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7157 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7158 win_T *wp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7159 tabpage_T *tp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7160 int winnr = 1; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7161 int tabnr = 1; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7162 int id = get_tv_number(&argvars[0]); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7163 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7164 FOR_ALL_TABPAGES(tp) |
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7165 { |
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7166 FOR_ALL_WINDOWS_IN_TAB(tp, wp) |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7167 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7168 if (wp->w_id == id) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7169 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7170 list_append_number(list, tabnr); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7171 list_append_number(list, winnr); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7172 return; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7173 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7174 ++winnr; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7175 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7176 ++tabnr; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7177 winnr = 1; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7178 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7179 list_append_number(list, 0); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7180 list_append_number(list, 0); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7181 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7182 |
9858
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7183 win_T * |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7184 win_id2wp(typval_T *argvars) |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7185 { |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7186 win_T *wp; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7187 tabpage_T *tp; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7188 int id = get_tv_number(&argvars[0]); |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7189 |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7190 FOR_ALL_TAB_WINDOWS(tp, wp) |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7191 if (wp->w_id == id) |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7192 return wp; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7193 |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7194 return NULL; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7195 } |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
7196 |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7197 int |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7198 win_id2win(typval_T *argvars) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7199 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7200 win_T *wp; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7201 int nr = 1; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7202 int id = get_tv_number(&argvars[0]); |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7203 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7204 FOR_ALL_WINDOWS(wp) |
8534
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7205 { |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7206 if (wp->w_id == id) |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7207 return nr; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7208 ++nr; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7209 } |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7210 return 0; |
485d4d8a97f6
commit https://github.com/vim/vim/commit/86edef664efccbfe685906c854b9cdd04e56f2d5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
7211 } |
8536
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7212 |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7213 void |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7214 win_findbuf(typval_T *argvars, list_T *list) |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7215 { |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7216 win_T *wp; |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7217 tabpage_T *tp; |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7218 int bufnr = get_tv_number(&argvars[0]); |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7219 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
7220 FOR_ALL_TAB_WINDOWS(tp, wp) |
8536
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7221 if (wp->w_buffer->b_fnum == bufnr) |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7222 list_append_number(list, wp->w_id); |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7223 } |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7224 |
09041d2fd7d0
commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f
Christian Brabandt <cb@256bit.org>
parents:
8534
diff
changeset
|
7225 #endif |