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