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