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