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