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