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