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