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