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