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