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