/
window.c
7689 lines (6976 loc) · 181 KB
/
window.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read a list of people who contributed.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
#include "vim.h"
static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize, long Prenum);
static void win_init(win_T *newp, win_T *oldp, int flags);
static void win_init_some(win_T *newp, win_T *oldp);
static void frame_comp_pos(frame_T *topfrp, int *row, int *col);
static void frame_setheight(frame_T *curfrp, int height);
static void frame_setwidth(frame_T *curfrp, int width);
static void win_exchange(long);
static void win_rotate(int, int);
static void win_totop(int size, int flags);
static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height);
static void trigger_winclosed(win_T *win);
static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp);
static frame_T *win_altframe(win_T *win, tabpage_T *tp);
static tabpage_T *alt_tabpage(void);
static win_T *frame2win(frame_T *frp);
static int frame_has_win(frame_T *frp, win_T *wp);
static void win_fix_scroll(int resize);
static void win_fix_cursor(int normal);
static void frame_new_height(frame_T *topfrp, int height, int topfirst, int wfh);
static int frame_fixed_height(frame_T *frp);
static int frame_fixed_width(frame_T *frp);
static void frame_add_statusline(frame_T *frp);
static void frame_new_width(frame_T *topfrp, int width, int leftfirst, int wfw);
static void frame_add_vsep(frame_T *frp);
static int frame_minwidth(frame_T *topfrp, win_T *next_curwin);
static void frame_fix_width(win_T *wp);
static int win_alloc_firstwin(win_T *oldwin);
static void new_frame(win_T *wp);
static tabpage_T *alloc_tabpage(void);
static int leave_tabpage(buf_T *new_curbuf, int trigger_leave_autocmds);
static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_autocmds, int trigger_leave_autocmds);
static void frame_fix_height(win_T *wp);
static int frame_minheight(frame_T *topfrp, win_T *next_curwin);
static int may_open_tabpage(void);
static int win_enter_ext(win_T *wp, int flags);
static void win_free(win_T *wp, tabpage_T *tp);
static void win_append(win_T *after, win_T *wp);
static void frame_append(frame_T *after, frame_T *frp);
static void frame_insert(frame_T *before, frame_T *frp);
static void frame_remove(frame_T *frp);
static void win_goto_ver(int up, long count);
static void win_goto_hor(int left, long count);
static void frame_add_height(frame_T *frp, int n);
static void last_status_rec(frame_T *fr, int statusline);
static void make_snapshot_rec(frame_T *fr, frame_T **frp);
static void clear_snapshot(tabpage_T *tp, int idx);
static void clear_snapshot_rec(frame_T *fr);
static int check_snapshot_rec(frame_T *sn, frame_T *fr);
static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr);
static win_T *get_snapshot_curwin(int idx);
static int frame_check_height(frame_T *topfrp, int height);
static int frame_check_width(frame_T *topfrp, int width);
static win_T *win_alloc(win_T *after, int hidden);
#define NOWIN ((win_T *)-1) // non-existing window
#define ROWS_AVAIL (Rows - p_ch - tabline_height())
// flags for win_enter_ext()
#define WEE_UNDO_SYNC 0x01
#define WEE_CURWIN_INVALID 0x02
#define WEE_TRIGGER_NEW_AUTOCMDS 0x04
#define WEE_TRIGGER_ENTER_AUTOCMDS 0x08
#define WEE_TRIGGER_LEAVE_AUTOCMDS 0x10
#define WEE_ALLOW_PARSE_MESSAGES 0x20
static char *m_onlyone = N_("Already only one window");
// When non-zero splitting a window is forbidden. Used to avoid that nasty
// autocommands mess up the window structure.
static int split_disallowed = 0;
// When non-zero closing a window is forbidden. Used to avoid that nasty
// autocommands mess up the window structure.
static int close_disallowed = 0;
/*
* Disallow changing the window layout (split window, close window, move
* window). Resizing is still allowed.
* Used for autocommands that temporarily use another window and need to
* make sure the previously selected window is still there.
* Must be matched with exactly one call to window_layout_unlock()!
*/
static void
window_layout_lock(void)
{
++split_disallowed;
++close_disallowed;
}
static void
window_layout_unlock(void)
{
--split_disallowed;
--close_disallowed;
}
/*
* When the window layout cannot be changed give an error and return TRUE.
* "cmd" indicates the action being performed and is used to pick the relevant
* error message.
*/
int
window_layout_locked(enum CMD_index cmd)
{
if (split_disallowed > 0 || close_disallowed > 0)
{
if (close_disallowed == 0 && cmd == CMD_tabnew)
emsg(_(e_cannot_split_window_when_closing_buffer));
else
emsg(_(e_not_allowed_to_change_window_layout_in_this_autocmd));
return TRUE;
}
return FALSE;
}
// #define WIN_DEBUG
#ifdef WIN_DEBUG
/*
* Call this method to log the current window layout.
*/
static void
log_frame_layout(frame_T *frame)
{
ch_log(NULL, "layout %s, wi: %d, he: %d, wwi: %d, whe: %d, id: %d",
frame->fr_layout == FR_LEAF ? "LEAF"
: frame->fr_layout == FR_ROW ? "ROW" : "COL",
frame->fr_width,
frame->fr_height,
frame->fr_win == NULL ? -1 : frame->fr_win->w_width,
frame->fr_win == NULL ? -1 : frame->fr_win->w_height,
frame->fr_win == NULL ? -1 : frame->fr_win->w_id);
if (frame->fr_child != NULL)
{
ch_log(NULL, "children");
log_frame_layout(frame->fr_child);
if (frame->fr_next != NULL)
ch_log(NULL, "END of children");
}
if (frame->fr_next != NULL)
log_frame_layout(frame->fr_next);
}
#endif
/*
* Return the current window, unless in the cmdline window and "prevwin" is
* set, then return "prevwin".
*/
win_T *
prevwin_curwin(void)
{
// In cmdwin, the alternative buffer should be used.
return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin;
}
/*
* All CTRL-W window commands are handled here, called from normal_cmd().
*/
void
do_window(
int nchar,
long Prenum,
int xchar) // extra char from ":wincmd gx" or NUL
{
long Prenum1;
win_T *wp;
char_u *ptr;
linenr_T lnum = -1;
#ifdef FEAT_FIND_ID
int type = FIND_DEFINE;
int len;
#endif
char_u cbuf[40];
if (ERROR_IF_ANY_POPUP_WINDOW)
return;
#define CHECK_CMDWIN \
do { \
if (cmdwin_type != 0) \
{ \
emsg(_(e_invalid_in_cmdline_window)); \
return; \
} \
} while (0)
Prenum1 = Prenum == 0 ? 1 : Prenum;
switch (nchar)
{
// split current window in two parts, horizontally
case 'S':
case Ctrl_S:
case 's':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
// When splitting the quickfix window open a new buffer in it,
// don't replicate the quickfix buffer.
if (bt_quickfix(curbuf))
goto newwindow;
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
(void)win_split((int)Prenum, 0);
break;
// split current window in two parts, vertically
case Ctrl_V:
case 'v':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
// When splitting the quickfix window open a new buffer in it,
// don't replicate the quickfix buffer.
if (bt_quickfix(curbuf))
goto newwindow;
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
(void)win_split((int)Prenum, WSP_VERT);
break;
// split current window and edit alternate file
case Ctrl_HAT:
case '^':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
if (buflist_findnr(Prenum == 0
? curwin->w_alt_fnum : Prenum) == NULL)
{
if (Prenum == 0)
emsg(_(e_no_alternate_file));
else
semsg(_(e_buffer_nr_not_found), Prenum);
break;
}
if (!curbuf_locked() && win_split(0, 0) == OK)
(void)buflist_getfile(
Prenum == 0 ? curwin->w_alt_fnum : Prenum,
(linenr_T)0, GETF_ALT, FALSE);
break;
// open new window
case Ctrl_N:
case 'n':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
newwindow:
if (Prenum)
// window height
vim_snprintf((char *)cbuf, sizeof(cbuf) - 5, "%ld", Prenum);
else
cbuf[0] = NUL;
#if defined(FEAT_QUICKFIX)
if (nchar == 'v' || nchar == Ctrl_V)
STRCAT(cbuf, "v");
#endif
STRCAT(cbuf, "new");
do_cmdline_cmd(cbuf);
break;
// quit current window
case Ctrl_Q:
case 'q':
reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("quit", cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf);
break;
// close current window
case Ctrl_C:
case 'c':
reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("close", cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf);
break;
#if defined(FEAT_QUICKFIX)
// close preview window
case Ctrl_Z:
case 'z':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
do_cmdline_cmd((char_u *)"pclose");
break;
// cursor to preview window
case 'P':
FOR_ALL_WINDOWS(wp)
if (wp->w_p_pvw)
break;
if (wp == NULL)
emsg(_(e_there_is_no_preview_window));
else
win_goto(wp);
break;
#endif
// close all but current window
case Ctrl_O:
case 'o':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("only", cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf);
break;
// cursor to next window with wrap around
case Ctrl_W:
case 'w':
// cursor to previous window with wrap around
case 'W':
CHECK_CMDWIN;
if (ONE_WINDOW && Prenum != 1) // just one window
beep_flush();
else
{
if (Prenum) // go to specified window
{
for (wp = firstwin; --Prenum > 0; )
{
if (wp->w_next == NULL)
break;
else
wp = wp->w_next;
}
}
else
{
if (nchar == 'W') // go to previous window
{
wp = curwin->w_prev;
if (wp == NULL)
wp = lastwin; // wrap around
}
else // go to next window
{
wp = curwin->w_next;
if (wp == NULL)
wp = firstwin; // wrap around
}
}
win_goto(wp);
}
break;
// cursor to window below
case 'j':
case K_DOWN:
case Ctrl_J:
CHECK_CMDWIN;
win_goto_ver(FALSE, Prenum1);
break;
// cursor to window above
case 'k':
case K_UP:
case Ctrl_K:
CHECK_CMDWIN;
win_goto_ver(TRUE, Prenum1);
break;
// cursor to left window
case 'h':
case K_LEFT:
case Ctrl_H:
case K_BS:
CHECK_CMDWIN;
win_goto_hor(TRUE, Prenum1);
break;
// cursor to right window
case 'l':
case K_RIGHT:
case Ctrl_L:
CHECK_CMDWIN;
win_goto_hor(FALSE, Prenum1);
break;
// move window to new tab page
case 'T':
CHECK_CMDWIN;
if (one_window())
msg(_(m_onlyone));
else
{
tabpage_T *oldtab = curtab;
tabpage_T *newtab;
// First create a new tab with the window, then go back to
// the old tab and close the window there.
wp = curwin;
if (win_new_tabpage((int)Prenum) == OK
&& valid_tabpage(oldtab))
{
newtab = curtab;
goto_tabpage_tp(oldtab, TRUE, TRUE);
if (curwin == wp)
win_close(curwin, FALSE);
if (valid_tabpage(newtab))
goto_tabpage_tp(newtab, TRUE, TRUE);
}
}
break;
// cursor to top-left window
case 't':
case Ctrl_T:
win_goto(firstwin);
break;
// cursor to bottom-right window
case 'b':
case Ctrl_B:
win_goto(lastwin);
break;
// cursor to last accessed (previous) window
case 'p':
case Ctrl_P:
if (!win_valid(prevwin))
beep_flush();
else
win_goto(prevwin);
break;
// exchange current and next window
case 'x':
case Ctrl_X:
CHECK_CMDWIN;
win_exchange(Prenum);
break;
// rotate windows downwards
case Ctrl_R:
case 'r':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
win_rotate(FALSE, (int)Prenum1); // downwards
break;
// rotate windows upwards
case 'R':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
win_rotate(TRUE, (int)Prenum1); // upwards
break;
// move window to the very top/bottom/left/right
case 'K':
case 'J':
case 'H':
case 'L':
CHECK_CMDWIN;
win_totop((int)Prenum,
((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0)
| ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT));
break;
// make all windows the same width and/or height
case '=':
{
int mod = cmdmod.cmod_split & (WSP_VERT | WSP_HOR);
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_equal(NULL, FALSE,
mod == WSP_VERT ? 'v' : mod == WSP_HOR ? 'h' : 'b');
}
break;
// increase current window height
case '+':
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_setheight(curwin->w_height + (int)Prenum1);
break;
// decrease current window height
case '-':
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_setheight(curwin->w_height - (int)Prenum1);
break;
// set current window height
case Ctrl__:
case '_':
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_setheight(Prenum ? (int)Prenum : 9999);
break;
// increase current window width
case '>':
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_setwidth(curwin->w_width + (int)Prenum1);
break;
// decrease current window width
case '<':
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_setwidth(curwin->w_width - (int)Prenum1);
break;
// set current window width
case '|':
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_setwidth(Prenum != 0 ? (int)Prenum : 9999);
break;
// jump to tag and split window if tag exists (in preview window)
#if defined(FEAT_QUICKFIX)
case '}':
CHECK_CMDWIN;
if (Prenum)
g_do_tagpreview = Prenum;
else
g_do_tagpreview = p_pvh;
#endif
// FALLTHROUGH
case ']':
case Ctrl_RSB:
CHECK_CMDWIN;
// keep Visual mode, can select words to use as a tag
if (Prenum)
postponed_split = Prenum;
else
postponed_split = -1;
#ifdef FEAT_QUICKFIX
if (nchar != '}')
g_do_tagpreview = 0;
#endif
// Execute the command right here, required when "wincmd ]"
// was used in a function.
do_nv_ident(Ctrl_RSB, NUL);
break;
// edit file name under cursor in a new window
case 'f':
case 'F':
case Ctrl_F:
wingotofile:
CHECK_CMDWIN;
if (check_text_or_curbuf_locked(NULL))
break;
ptr = grab_file_name(Prenum1, &lnum);
if (ptr != NULL)
{
tabpage_T *oldtab = curtab;
win_T *oldwin = curwin;
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
setpcmark();
if (win_split(0, 0) == OK)
{
RESET_BINDING(curwin);
if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL,
ECMD_HIDE, NULL) == FAIL)
{
// Failed to open the file, close the window
// opened for it.
win_close(curwin, FALSE);
goto_tabpage_win(oldtab, oldwin);
}
else if (nchar == 'F' && lnum >= 0)
{
curwin->w_cursor.lnum = lnum;
check_cursor_lnum();
beginline(BL_SOL | BL_FIX);
}
}
vim_free(ptr);
}
break;
#ifdef FEAT_FIND_ID
// Go to the first occurrence of the identifier under cursor along path in a
// new window -- webb
case 'i': // Go to any match
case Ctrl_I:
type = FIND_ANY;
// FALLTHROUGH
case 'd': // Go to definition, using 'define'
case Ctrl_D:
CHECK_CMDWIN;
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0)
break;
// Make a copy, if the line was changed it will be freed.
ptr = vim_strnsave(ptr, len);
if (ptr == NULL)
break;
find_pattern_in_path(ptr, 0, len, TRUE,
Prenum == 0 ? TRUE : FALSE, type,
Prenum1, ACTION_SPLIT, (linenr_T)1, (linenr_T)MAXLNUM);
vim_free(ptr);
curwin->w_set_curswant = TRUE;
break;
#endif
// Quickfix window only: view the result under the cursor in a new split.
#if defined(FEAT_QUICKFIX)
case K_KENTER:
case CAR:
if (bt_quickfix(curbuf))
qf_view_result(TRUE);
break;
#endif
// CTRL-W g extended commands
case 'g':
case Ctrl_G:
CHECK_CMDWIN;
#ifdef USE_ON_FLY_SCROLL
dont_scroll = TRUE; // disallow scrolling here
#endif
++no_mapping;
++allow_keys; // no mapping for xchar, but allow key codes
if (xchar == NUL)
xchar = plain_vgetc();
LANGMAP_ADJUST(xchar, TRUE);
--no_mapping;
--allow_keys;
(void)add_to_showcmd(xchar);
switch (xchar)
{
#if defined(FEAT_QUICKFIX)
case '}':
xchar = Ctrl_RSB;
if (Prenum)
g_do_tagpreview = Prenum;
else
g_do_tagpreview = p_pvh;
#endif
// FALLTHROUGH
case ']':
case Ctrl_RSB:
// keep Visual mode, can select words to use as a tag
if (Prenum)
postponed_split = Prenum;
else
postponed_split = -1;
// Execute the command right here, required when
// "wincmd g}" was used in a function.
do_nv_ident('g', xchar);
break;
case 'f': // CTRL-W gf: "gf" in a new tab page
case 'F': // CTRL-W gF: "gF" in a new tab page
cmdmod.cmod_tab = tabpage_index(curtab) + 1;
nchar = xchar;
goto wingotofile;
case 't': // CTRL-W gt: go to next tab page
goto_tabpage((int)Prenum);
break;
case 'T': // CTRL-W gT: go to previous tab page
goto_tabpage(-(int)Prenum1);
break;
case TAB: // CTRL-W g<Tab>: go to last used tab page
if (goto_tabpage_lastused() == FAIL)
beep_flush();
break;
default:
beep_flush();
break;
}
break;
default: beep_flush();
break;
}
}
/*
* Figure out the address type for ":wincmd".
*/
void
get_wincmd_addr_type(char_u *arg, exarg_T *eap)
{
switch (*arg)
{
case 'S':
case Ctrl_S:
case 's':
case Ctrl_N:
case 'n':
case 'j':
case Ctrl_J:
case 'k':
case Ctrl_K:
case 'T':
case Ctrl_R:
case 'r':
case 'R':
case 'K':
case 'J':
case '+':
case '-':
case Ctrl__:
case '_':
case '|':
case ']':
case Ctrl_RSB:
case 'g':
case Ctrl_G:
case Ctrl_V:
case 'v':
case 'h':
case Ctrl_H:
case 'l':
case Ctrl_L:
case 'H':
case 'L':
case '>':
case '<':
#if defined(FEAT_QUICKFIX)
case '}':
#endif
case 'f':
case 'F':
case Ctrl_F:
#ifdef FEAT_FIND_ID
case 'i':
case Ctrl_I:
case 'd':
case Ctrl_D:
#endif
// window size or any count
eap->addr_type = ADDR_OTHER;
break;
case Ctrl_HAT:
case '^':
// buffer number
eap->addr_type = ADDR_BUFFERS;
break;
case Ctrl_Q:
case 'q':
case Ctrl_C:
case 'c':
case Ctrl_O:
case 'o':
case Ctrl_W:
case 'w':
case 'W':
case 'x':
case Ctrl_X:
// window number
eap->addr_type = ADDR_WINDOWS;
break;
#if defined(FEAT_QUICKFIX)
case Ctrl_Z:
case 'z':
case 'P':
#endif
case 't':
case Ctrl_T:
case 'b':
case Ctrl_B:
case 'p':
case Ctrl_P:
case '=':
case CAR:
// no count
eap->addr_type = ADDR_NONE;
break;
}
}
static void
cmd_with_count(
char *cmd,
char_u *bufp,
size_t bufsize,
long Prenum)
{
if (Prenum > 0)
vim_snprintf((char *)bufp, bufsize, "%s %ld", cmd, Prenum);
else
STRCPY(bufp, cmd);
}
/*
* If "split_disallowed" is set give an error and return FAIL.
* Otherwise return OK.
*/
static int
check_split_disallowed()
{
if (split_disallowed > 0)
{
emsg(_(e_cant_split_window_while_closing_another));
return FAIL;
}
if (curwin->w_buffer->b_locked_split)
{
emsg(_(e_cannot_split_window_when_closing_buffer));
return FAIL;
}
return OK;
}
/*
* split the current window, implements CTRL-W s and :split
*
* "size" is the height or width for the new window, 0 to use half of current
* height or width.
*
* "flags":
* WSP_ROOM: require enough room for new window
* WSP_VERT: vertical split.
* WSP_TOP: open window at the top-left of the shell (help window).
* WSP_BOT: open window at the bottom-right of the shell (quickfix window).
* WSP_HELP: creating the help window, keep layout snapshot
*
* return FAIL for failure, OK otherwise
*/
int
win_split(int size, int flags)
{
if (ERROR_IF_ANY_POPUP_WINDOW)
return FAIL;
if (check_split_disallowed() == FAIL)
return FAIL;
// When the ":tab" modifier was used open a new tab page instead.
if (may_open_tabpage() == OK)
return OK;
// Add flags from ":vertical", ":topleft" and ":botright".
flags |= cmdmod.cmod_split;
if ((flags & WSP_TOP) && (flags & WSP_BOT))
{
emsg(_(e_cant_split_topleft_and_botright_at_the_same_time));
return FAIL;
}
// When creating the help window make a snapshot of the window layout.
// Otherwise clear the snapshot, it's now invalid.
if (flags & WSP_HELP)
make_snapshot(SNAP_HELP_IDX);
else
clear_snapshot(curtab, SNAP_HELP_IDX);
return win_split_ins(size, flags, NULL, 0);
}
/*
* When "new_wp" is NULL: split the current window in two.
* When "new_wp" is not NULL: insert this window at the far
* top/left/right/bottom.
* Return FAIL for failure, OK otherwise.
*/
int
win_split_ins(
int size,
int flags,
win_T *new_wp,
int dir)
{
win_T *wp = new_wp;
win_T *oldwin;
int new_size = size;
int i;
int need_status = 0;
int do_equal = FALSE;
int needed;
int available;
int oldwin_height = 0;
int layout;
frame_T *frp, *curfrp, *frp2, *prevfrp;
int before;
int minheight;
int wmh1;
int did_set_fraction = FALSE;
if (flags & WSP_TOP)
oldwin = firstwin;
else if (flags & WSP_BOT)
oldwin = lastwin;
else
oldwin = curwin;
// add a status line when p_ls == 1 and splitting the first window
if (ONE_WINDOW && p_ls == 1 && oldwin->w_status_height == 0)
{
if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL)
{
emsg(_(e_not_enough_room));
return FAIL;
}
need_status = STATUS_HEIGHT;
}
#ifdef FEAT_GUI
// May be needed for the scrollbars that are going to change.
if (gui.in_use)
out_flush();
#endif
if (flags & WSP_VERT)
{
int wmw1;
int minwidth;
layout = FR_ROW;
/*
* Check if we are able to split the current window and compute its
* width.
*/
// Current window requires at least 1 space.
wmw1 = (p_wmw == 0 ? 1 : p_wmw);
needed = wmw1 + 1;
if (flags & WSP_ROOM)
needed += p_wiw - wmw1;
if (flags & (WSP_BOT | WSP_TOP))
{
minwidth = frame_minwidth(topframe, NOWIN);
available = topframe->fr_width;
needed += minwidth;
}
else if (p_ea)
{
minwidth = frame_minwidth(oldwin->w_frame, NOWIN);
prevfrp = oldwin->w_frame;
for (frp = oldwin->w_frame->fr_parent; frp != NULL;
frp = frp->fr_parent)
{
if (frp->fr_layout == FR_ROW)
FOR_ALL_FRAMES(frp2, frp->fr_child)
if (frp2 != prevfrp)
minwidth += frame_minwidth(frp2, NOWIN);
prevfrp = frp;
}
available = topframe->fr_width;
needed += minwidth;
}
else
{
minwidth = frame_minwidth(oldwin->w_frame, NOWIN);
available = oldwin->w_frame->fr_width;
needed += minwidth;
}
if (available < needed && new_wp == NULL)
{
emsg(_(e_not_enough_room));
return FAIL;
}
if (new_size == 0)
new_size = oldwin->w_width / 2;
if (new_size > available - minwidth - 1)
new_size = available - minwidth - 1;
if (new_size < wmw1)
new_size = wmw1;
// if it doesn't fit in the current window, need win_equal()
if (oldwin->w_width - new_size - 1 < p_wmw)
do_equal = TRUE;
// We don't like to take lines for the new window from a
// 'winfixwidth' window. Take them from a window to the left or right