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