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