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