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