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