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