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