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