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