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