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