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