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