Mercurial > vim
annotate src/buffer.c @ 9534:340106787852 v7.4.2047
commit https://github.com/vim/vim/commit/bfafb4c4a01db3f8c508716daf689e0dfe92b649
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 16 14:20:45 2016 +0200
patch 7.4.2047
Problem: Compiler warning for initializing a struct.
Solution: Initialize in another way. (Anton Lindqvist)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 16 Jul 2016 14:30:06 +0200 |
parents | bb538c090668 |
children | 123d3c102035 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
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 /* | |
11 * buffer.c: functions for dealing with the buffer structure | |
12 */ | |
13 | |
14 /* | |
15 * The buffer list is a double linked list of all buffers. | |
16 * Each buffer can be in one of these states: | |
17 * never loaded: BF_NEVERLOADED is set, only the file name is valid | |
18 * not loaded: b_ml.ml_mfp == NULL, no memfile allocated | |
19 * hidden: b_nwindows == 0, loaded but not displayed in a window | |
20 * normal: loaded and displayed in a window | |
21 * | |
22 * Instead of storing file names all over the place, each file name is | |
23 * stored in the buffer list. It can be referenced by a number. | |
24 * | |
25 * The current implementation remembers all file names ever used. | |
26 */ | |
27 | |
28 #include "vim.h" | |
29 | |
30 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_LISTCMDS) || defined(FEAT_EVAL) || defined(FEAT_PERL) | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
31 static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case); |
7 | 32 # define HAVE_BUFLIST_MATCH |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
33 static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
34 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
35 static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
36 static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer); |
7 | 37 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
38 static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st); |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
39 static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp); |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
40 static int buf_same_ino(buf_T *buf, stat_T *stp); |
7 | 41 #else |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
42 static int otherfile_buf(buf_T *buf, char_u *ffname); |
7 | 43 #endif |
44 #ifdef FEAT_TITLE | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
45 static int ti_change(char_u *str, char_u **last); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
46 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
47 static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
48 static void free_buffer(buf_T *); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
49 static void free_buffer_stuff(buf_T *buf, int free_options); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
50 static void clear_wininfo(buf_T *buf); |
7 | 51 |
52 #ifdef UNIX | |
53 # define dev_T dev_t | |
54 #else | |
55 # define dev_T unsigned | |
56 #endif | |
57 | |
58 #if defined(FEAT_SIGNS) | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
59 static void insert_sign(buf_T *buf, signlist_T *prev, signlist_T *next, int id, linenr_T lnum, int typenr); |
7 | 60 #endif |
61 | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
62 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
63 static char *msg_loclist = N_("[Location List]"); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
64 static char *msg_qflist = N_("[Quickfix List]"); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
65 #endif |
3365 | 66 #ifdef FEAT_AUTOCMD |
67 static char *e_auabort = N_("E855: Autocommands caused command to abort"); | |
68 #endif | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
69 |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
70 /* Number of times free_buffer() was called. */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
71 static int buf_free_count = 0; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
72 |
7 | 73 /* |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
74 * Open current buffer, that is: open the memfile and read the file into |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
75 * memory. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
76 * Return FAIL for failure, OK otherwise. |
7 | 77 */ |
78 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
79 open_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
80 int read_stdin, /* read file from stdin */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
81 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
82 int flags) /* extra flags for readfile() */ |
7 | 83 { |
84 int retval = OK; | |
85 #ifdef FEAT_AUTOCMD | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
86 bufref_T old_curbuf; |
7 | 87 #endif |
4139 | 88 #ifdef FEAT_SYN_HL |
89 long old_tw = curbuf->b_p_tw; | |
90 #endif | |
7 | 91 |
92 /* | |
93 * The 'readonly' flag is only set when BF_NEVERLOADED is being reset. | |
94 * When re-entering the same buffer, it should not change, because the | |
95 * user may have reset the flag by hand. | |
96 */ | |
97 if (readonlymode && curbuf->b_ffname != NULL | |
98 && (curbuf->b_flags & BF_NEVERLOADED)) | |
99 curbuf->b_p_ro = TRUE; | |
100 | |
625 | 101 if (ml_open(curbuf) == FAIL) |
7 | 102 { |
103 /* | |
104 * There MUST be a memfile, otherwise we can't do anything | |
105 * If we can't create one for the current buffer, take another buffer | |
106 */ | |
3365 | 107 close_buffer(NULL, curbuf, 0, FALSE); |
7 | 108 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) |
109 if (curbuf->b_ml.ml_mfp != NULL) | |
110 break; | |
111 /* | |
112 * if there is no memfile at all, exit | |
1698 | 113 * This is OK, since there are no changes to lose. |
7 | 114 */ |
115 if (curbuf == NULL) | |
116 { | |
117 EMSG(_("E82: Cannot allocate any buffer, exiting...")); | |
118 getout(2); | |
119 } | |
120 EMSG(_("E83: Cannot allocate buffer, using other one...")); | |
121 enter_buffer(curbuf); | |
4139 | 122 #ifdef FEAT_SYN_HL |
123 if (old_tw != curbuf->b_p_tw) | |
124 check_colorcolumn(curwin); | |
125 #endif | |
7 | 126 return FAIL; |
127 } | |
128 | |
129 #ifdef FEAT_AUTOCMD | |
130 /* The autocommands in readfile() may change the buffer, but only AFTER | |
131 * reading the file. */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
132 set_bufref(&old_curbuf, curbuf); |
7 | 133 modified_was_set = FALSE; |
134 #endif | |
135 | |
136 /* mark cursor position as being invalid */ | |
2091
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
137 curwin->w_valid = 0; |
7 | 138 |
139 if (curbuf->b_ffname != NULL | |
140 #ifdef FEAT_NETBEANS_INTG | |
141 && netbeansReadFile | |
142 #endif | |
143 ) | |
144 { | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
145 int old_msg_silent = msg_silent; |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
146 |
7 | 147 #ifdef FEAT_NETBEANS_INTG |
148 int oldFire = netbeansFireChanges; | |
149 | |
150 netbeansFireChanges = 0; | |
151 #endif | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
152 if (shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
153 msg_silent = 1; |
7 | 154 retval = readfile(curbuf->b_ffname, curbuf->b_fname, |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
155 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
156 flags | READ_NEW); |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
157 msg_silent = old_msg_silent; |
7 | 158 #ifdef FEAT_NETBEANS_INTG |
159 netbeansFireChanges = oldFire; | |
160 #endif | |
161 /* Help buffer is filtered. */ | |
162 if (curbuf->b_help) | |
163 fix_help_buffer(); | |
164 } | |
165 else if (read_stdin) | |
166 { | |
167 int save_bin = curbuf->b_p_bin; | |
168 linenr_T line_count; | |
169 | |
170 /* | |
171 * First read the text in binary mode into the buffer. | |
172 * Then read from that same buffer and append at the end. This makes | |
173 * it possible to retry when 'fileformat' or 'fileencoding' was | |
174 * guessed wrong. | |
175 */ | |
176 curbuf->b_p_bin = TRUE; | |
177 retval = readfile(NULL, NULL, (linenr_T)0, | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
178 (linenr_T)0, (linenr_T)MAXLNUM, NULL, |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
179 flags | (READ_NEW + READ_STDIN)); |
7 | 180 curbuf->b_p_bin = save_bin; |
181 if (retval == OK) | |
182 { | |
183 line_count = curbuf->b_ml.ml_line_count; | |
184 retval = readfile(NULL, NULL, (linenr_T)line_count, | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
185 (linenr_T)0, (linenr_T)MAXLNUM, eap, |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
186 flags | READ_BUFFER); |
7 | 187 if (retval == OK) |
188 { | |
189 /* Delete the binary lines. */ | |
190 while (--line_count >= 0) | |
191 ml_delete((linenr_T)1, FALSE); | |
192 } | |
193 else | |
194 { | |
195 /* Delete the converted lines. */ | |
196 while (curbuf->b_ml.ml_line_count > line_count) | |
197 ml_delete(line_count, FALSE); | |
198 } | |
199 /* Put the cursor on the first line. */ | |
200 curwin->w_cursor.lnum = 1; | |
201 curwin->w_cursor.col = 0; | |
1291 | 202 |
203 /* Set or reset 'modified' before executing autocommands, so that | |
204 * it can be changed there. */ | |
205 if (!readonlymode && !bufempty()) | |
206 changed(); | |
207 else if (retval != FAIL) | |
208 unchanged(curbuf, FALSE); | |
7 | 209 #ifdef FEAT_AUTOCMD |
210 # ifdef FEAT_EVAL | |
211 apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE, | |
212 curbuf, &retval); | |
213 # else | |
214 apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf); | |
215 # endif | |
216 #endif | |
217 } | |
218 } | |
219 | |
220 /* if first time loading this buffer, init b_chartab[] */ | |
221 if (curbuf->b_flags & BF_NEVERLOADED) | |
5438 | 222 { |
7 | 223 (void)buf_init_chartab(curbuf, FALSE); |
5440 | 224 #ifdef FEAT_CINDENT |
5438 | 225 parse_cino(curbuf); |
5440 | 226 #endif |
5438 | 227 } |
7 | 228 |
229 /* | |
230 * Set/reset the Changed flag first, autocmds may change the buffer. | |
231 * Apply the automatic commands, before processing the modelines. | |
232 * So the modelines have priority over auto commands. | |
233 */ | |
234 /* When reading stdin, the buffer contents always needs writing, so set | |
235 * the changed flag. Unless in readonly mode: "ls | gview -". | |
236 * When interrupted and 'cpoptions' contains 'i' set changed flag. */ | |
1291 | 237 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
7 | 238 #ifdef FEAT_AUTOCMD |
239 || modified_was_set /* ":set modified" used in autocmd */ | |
240 # ifdef FEAT_EVAL | |
241 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) | |
242 # endif | |
243 #endif | |
1291 | 244 ) |
7 | 245 changed(); |
1291 | 246 else if (retval != FAIL && !read_stdin) |
7 | 247 unchanged(curbuf, FALSE); |
248 save_file_ff(curbuf); /* keep this fileformat */ | |
249 | |
250 /* require "!" to overwrite the file, because it wasn't read completely */ | |
251 #ifdef FEAT_EVAL | |
252 if (aborting()) | |
253 #else | |
254 if (got_int) | |
255 #endif | |
256 curbuf->b_flags |= BF_READERR; | |
257 | |
20 | 258 #ifdef FEAT_FOLDING |
259 /* Need to update automatic folding. Do this before the autocommands, | |
260 * they may use the fold info. */ | |
261 foldUpdateAll(curwin); | |
262 #endif | |
263 | |
7 | 264 #ifdef FEAT_AUTOCMD |
265 /* need to set w_topline, unless some autocommand already did that. */ | |
266 if (!(curwin->w_valid & VALID_TOPLINE)) | |
267 { | |
268 curwin->w_topline = 1; | |
269 # ifdef FEAT_DIFF | |
270 curwin->w_topfill = 0; | |
271 # endif | |
272 } | |
273 # ifdef FEAT_EVAL | |
274 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); | |
275 # else | |
276 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
277 # endif | |
278 #endif | |
279 | |
280 if (retval != FAIL) | |
281 { | |
282 #ifdef FEAT_AUTOCMD | |
283 /* | |
284 * The autocommands may have changed the current buffer. Apply the | |
285 * modelines to the correct buffer, if it still exists and is loaded. | |
286 */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
287 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) |
7 | 288 { |
289 aco_save_T aco; | |
290 | |
291 /* Go to the buffer that was opened. */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
292 aucmd_prepbuf(&aco, old_curbuf.br_buf); |
7 | 293 #endif |
717 | 294 do_modelines(0); |
7 | 295 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); |
296 | |
297 #ifdef FEAT_AUTOCMD | |
298 # ifdef FEAT_EVAL | |
299 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, | |
300 &retval); | |
301 # else | |
302 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); | |
303 # endif | |
304 | |
305 /* restore curwin/curbuf and a few other things */ | |
306 aucmd_restbuf(&aco); | |
307 } | |
308 #endif | |
309 } | |
310 | |
311 return retval; | |
312 } | |
313 | |
314 /* | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
315 * Store "buf" in "bufref" and set the free count. |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
316 */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
317 void |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
318 set_bufref(bufref_T *bufref, buf_T *buf) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
319 { |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
320 bufref->br_buf = buf; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
321 bufref->br_buf_free_count = buf_free_count; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
322 } |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
323 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
324 /* |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
325 * Return TRUE if "bufref->br_buf" points to a valid buffer. |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
326 * Only goes through the buffer list if buf_free_count changed. |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
327 */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
328 int |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
329 bufref_valid(bufref_T *bufref) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
330 { |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
331 return bufref->br_buf_free_count == buf_free_count |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
332 ? TRUE : buf_valid(bufref->br_buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
333 } |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
334 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
335 /* |
7 | 336 * Return TRUE if "buf" points to a valid buffer (in the buffer list). |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
337 * This can be slow if there are many buffers, prefer using bufref_valid(). |
7 | 338 */ |
339 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
340 buf_valid(buf_T *buf) |
7 | 341 { |
342 buf_T *bp; | |
343 | |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
344 /* Assume that we more often have a recent buffer, start with the last |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
345 * one. */ |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
346 for (bp = lastbuf; bp != NULL; bp = bp->b_prev) |
7 | 347 if (bp == buf) |
348 return TRUE; | |
349 return FALSE; | |
350 } | |
351 | |
352 /* | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
353 * A hash table used to quickly lookup a buffer by its number. |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
354 */ |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
355 static hashtab_T buf_hashtab; |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
356 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
357 static void |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
358 buf_hashtab_add(buf_T *buf) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
359 { |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
360 sprintf((char *)buf->b_key, "%x", buf->b_fnum); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
361 if (hash_add(&buf_hashtab, buf->b_key) == FAIL) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
362 EMSG(_("E931: Buffer cannot be registered")); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
363 } |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
364 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
365 static void |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
366 buf_hashtab_remove(buf_T *buf) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
367 { |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
368 hashitem_T *hi = hash_find(&buf_hashtab, buf->b_key); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
369 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
370 if (!HASHITEM_EMPTY(hi)) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
371 hash_remove(&buf_hashtab, hi); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
372 } |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
373 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
374 /* |
7 | 375 * Close the link to a buffer. |
376 * "action" is used when there is no longer a window for the buffer. | |
377 * It can be: | |
378 * 0 buffer becomes hidden | |
379 * DOBUF_UNLOAD buffer is unloaded | |
380 * DOBUF_DELETE buffer is unloaded and removed from buffer list | |
381 * DOBUF_WIPE buffer is unloaded and really deleted | |
382 * When doing all but the first one on the current buffer, the caller should | |
383 * get a new buffer very soon! | |
384 * | |
385 * The 'bufhidden' option can force freeing and deleting. | |
3365 | 386 * |
387 * When "abort_if_last" is TRUE then do not close the buffer if autocommands | |
388 * cause there to be only one window with this buffer. e.g. when ":quit" is | |
389 * supposed to close the window but autocommands close all other windows. | |
7 | 390 */ |
391 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
392 close_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
393 win_T *win, /* if not NULL, set b_last_cursor */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
394 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
395 int action, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
396 int abort_if_last UNUSED) |
7 | 397 { |
398 #ifdef FEAT_AUTOCMD | |
399 int is_curbuf; | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
400 int nwindows; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
401 bufref_T bufref; |
7 | 402 #endif |
403 int unload_buf = (action != 0); | |
404 int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); | |
405 int wipe_buf = (action == DOBUF_WIPE); | |
406 | |
407 #ifdef FEAT_QUICKFIX | |
408 /* | |
409 * Force unloading or deleting when 'bufhidden' says so. | |
410 * The caller must take care of NOT deleting/freeing when 'bufhidden' is | |
411 * "hide" (otherwise we could never free or delete a buffer). | |
412 */ | |
413 if (buf->b_p_bh[0] == 'd') /* 'bufhidden' == "delete" */ | |
414 { | |
415 del_buf = TRUE; | |
416 unload_buf = TRUE; | |
417 } | |
418 else if (buf->b_p_bh[0] == 'w') /* 'bufhidden' == "wipe" */ | |
419 { | |
420 del_buf = TRUE; | |
421 unload_buf = TRUE; | |
422 wipe_buf = TRUE; | |
423 } | |
424 else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */ | |
425 unload_buf = TRUE; | |
426 #endif | |
427 | |
5958 | 428 if (win != NULL |
429 #ifdef FEAT_WINDOWS | |
430 && win_valid(win) /* in case autocommands closed the window */ | |
431 #endif | |
432 ) | |
7 | 433 { |
434 /* Set b_last_cursor when closing the last window for the buffer. | |
435 * Remember the last cursor position and window options of the buffer. | |
436 * This used to be only for the current window, but then options like | |
437 * 'foldmethod' may be lost with a ":only" command. */ | |
438 if (buf->b_nwindows == 1) | |
439 set_last_cursor(win); | |
440 buflist_setfpos(buf, win, | |
441 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum, | |
442 win->w_cursor.col, TRUE); | |
443 } | |
444 | |
445 #ifdef FEAT_AUTOCMD | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
446 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
447 |
7 | 448 /* When the buffer is no longer in a window, trigger BufWinLeave */ |
449 if (buf->b_nwindows == 1) | |
450 { | |
3570 | 451 buf->b_closing = TRUE; |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
452 if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
453 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
454 && !bufref_valid(&bufref)) |
3365 | 455 { |
3570 | 456 /* Autocommands deleted the buffer. */ |
457 aucmd_abort: | |
3365 | 458 EMSG(_(e_auabort)); |
7 | 459 return; |
3365 | 460 } |
3570 | 461 buf->b_closing = FALSE; |
462 if (abort_if_last && one_window()) | |
463 /* Autocommands made this the only window. */ | |
464 goto aucmd_abort; | |
7 | 465 |
466 /* When the buffer becomes hidden, but is not unloaded, trigger | |
467 * BufHidden */ | |
468 if (!unload_buf) | |
469 { | |
3570 | 470 buf->b_closing = TRUE; |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
471 if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
472 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
473 && !bufref_valid(&bufref)) |
3570 | 474 /* Autocommands deleted the buffer. */ |
475 goto aucmd_abort; | |
476 buf->b_closing = FALSE; | |
477 if (abort_if_last && one_window()) | |
478 /* Autocommands made this the only window. */ | |
479 goto aucmd_abort; | |
7 | 480 } |
481 # ifdef FEAT_EVAL | |
482 if (aborting()) /* autocmds may abort script processing */ | |
483 return; | |
484 # endif | |
485 } | |
486 nwindows = buf->b_nwindows; | |
487 #endif | |
488 | |
489 /* decrease the link count from windows (unless not in any window) */ | |
490 if (buf->b_nwindows > 0) | |
491 --buf->b_nwindows; | |
492 | |
493 /* Return when a window is displaying the buffer or when it's not | |
494 * unloaded. */ | |
495 if (buf->b_nwindows > 0 || !unload_buf) | |
496 return; | |
497 | |
498 /* Always remove the buffer when there is no file name. */ | |
499 if (buf->b_ffname == NULL) | |
500 del_buf = TRUE; | |
501 | |
502 /* | |
503 * Free all things allocated for this buffer. | |
504 * Also calls the "BufDelete" autocommands when del_buf is TRUE. | |
505 */ | |
506 #ifdef FEAT_AUTOCMD | |
507 /* Remember if we are closing the current buffer. Restore the number of | |
508 * windows, so that autocommands in buf_freeall() don't get confused. */ | |
509 is_curbuf = (buf == curbuf); | |
510 buf->b_nwindows = nwindows; | |
511 #endif | |
512 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
513 buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); |
7 | 514 |
515 #ifdef FEAT_AUTOCMD | |
516 /* Autocommands may have deleted the buffer. */ | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
517 if (!bufref_valid(&bufref)) |
7 | 518 return; |
519 # ifdef FEAT_EVAL | |
20 | 520 if (aborting()) /* autocmds may abort script processing */ |
7 | 521 return; |
522 # endif | |
523 | |
524 /* | |
525 * It's possible that autocommands change curbuf to the one being deleted. | |
526 * This might cause the previous curbuf to be deleted unexpectedly. But | |
527 * in some cases it's OK to delete the curbuf, because a new one is | |
528 * obtained anyway. Therefore only return if curbuf changed to the | |
529 * deleted buffer. | |
530 */ | |
531 if (buf == curbuf && !is_curbuf) | |
532 return; | |
9450
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
533 |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
534 if ( |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
535 #ifdef FEAT_WINDOWS |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
536 win_valid(win) && |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
537 #else |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
538 win != NULL && |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
539 #endif |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
540 win->w_buffer == buf) |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
541 win->w_buffer = NULL; /* make sure we don't use the buffer now */ |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
542 |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
543 /* Autocommands may have opened or closed windows for this buffer. |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
544 * Decrement the count for the close we do here. */ |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
545 if (buf->b_nwindows > 0) |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
546 --buf->b_nwindows; |
7 | 547 #endif |
548 | |
961 | 549 /* Change directories when the 'acd' option is set. */ |
550 DO_AUTOCHDIR | |
7 | 551 |
552 /* | |
553 * Remove the buffer from the list. | |
554 */ | |
555 if (wipe_buf) | |
556 { | |
557 #ifdef FEAT_SUN_WORKSHOP | |
558 if (usingSunWorkShop) | |
559 workshop_file_closed_lineno((char *)buf->b_ffname, | |
560 (int)buf->b_last_cursor.lnum); | |
561 #endif | |
562 vim_free(buf->b_ffname); | |
563 vim_free(buf->b_sfname); | |
564 if (buf->b_prev == NULL) | |
565 firstbuf = buf->b_next; | |
566 else | |
567 buf->b_prev->b_next = buf->b_next; | |
568 if (buf->b_next == NULL) | |
569 lastbuf = buf->b_prev; | |
570 else | |
571 buf->b_next->b_prev = buf->b_prev; | |
572 free_buffer(buf); | |
573 } | |
574 else | |
575 { | |
576 if (del_buf) | |
577 { | |
578 /* Free all internal variables and reset option values, to make | |
579 * ":bdel" compatible with Vim 5.7. */ | |
580 free_buffer_stuff(buf, TRUE); | |
581 | |
582 /* Make it look like a new buffer. */ | |
583 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; | |
584 | |
585 /* Init the options when loaded again. */ | |
586 buf->b_p_initialized = FALSE; | |
587 } | |
588 buf_clear_file(buf); | |
589 if (del_buf) | |
590 buf->b_p_bl = FALSE; | |
591 } | |
592 } | |
593 | |
594 /* | |
595 * Make buffer not contain a file. | |
596 */ | |
597 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
598 buf_clear_file(buf_T *buf) |
7 | 599 { |
600 buf->b_ml.ml_line_count = 1; | |
601 unchanged(buf, TRUE); | |
602 buf->b_shortname = FALSE; | |
603 buf->b_p_eol = TRUE; | |
604 buf->b_start_eol = TRUE; | |
605 #ifdef FEAT_MBYTE | |
606 buf->b_p_bomb = FALSE; | |
1352 | 607 buf->b_start_bomb = FALSE; |
7 | 608 #endif |
609 buf->b_ml.ml_mfp = NULL; | |
610 buf->b_ml.ml_flags = ML_EMPTY; /* empty buffer */ | |
611 #ifdef FEAT_NETBEANS_INTG | |
612 netbeans_deleted_all_lines(buf); | |
613 #endif | |
614 } | |
615 | |
616 /* | |
617 * buf_freeall() - free all things allocated for a buffer that are related to | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
618 * the file. flags: |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
619 * BFA_DEL buffer is going to be deleted |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
620 * BFA_WIPE buffer is going to be wiped out |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
621 * BFA_KEEP_UNDO do not free undo information |
7 | 622 */ |
623 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
624 buf_freeall(buf_T *buf, int flags) |
7 | 625 { |
626 #ifdef FEAT_AUTOCMD | |
627 int is_curbuf = (buf == curbuf); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
628 bufref_T bufref; |
7 | 629 |
3570 | 630 buf->b_closing = TRUE; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
631 set_bufref(&bufref, buf); |
9106
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
632 if (buf->b_ml.ml_mfp != NULL) |
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
633 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
634 if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
635 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
636 && !bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
637 /* autocommands deleted the buffer */ |
9106
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
638 return; |
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
639 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
640 if ((flags & BFA_DEL) && buf->b_p_bl) |
7 | 641 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
642 if (apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
643 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
644 && !bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
645 /* autocommands deleted the buffer */ |
7 | 646 return; |
647 } | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
648 if (flags & BFA_WIPE) |
7 | 649 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
650 if (apply_autocmds(EVENT_BUFWIPEOUT, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
651 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
652 && !bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
653 /* autocommands deleted the buffer */ |
7 | 654 return; |
655 } | |
3570 | 656 buf->b_closing = FALSE; |
7 | 657 # ifdef FEAT_EVAL |
36 | 658 if (aborting()) /* autocmds may abort script processing */ |
7 | 659 return; |
660 # endif | |
661 | |
662 /* | |
663 * It's possible that autocommands change curbuf to the one being deleted. | |
664 * This might cause curbuf to be deleted unexpectedly. But in some cases | |
665 * it's OK to delete the curbuf, because a new one is obtained anyway. | |
666 * Therefore only return if curbuf changed to the deleted buffer. | |
667 */ | |
668 if (buf == curbuf && !is_curbuf) | |
669 return; | |
670 #endif | |
671 #ifdef FEAT_DIFF | |
672 diff_buf_delete(buf); /* Can't use 'diff' for unloaded buffer. */ | |
673 #endif | |
3068 | 674 #ifdef FEAT_SYN_HL |
3182 | 675 /* Remove any ownsyntax, unless exiting. */ |
676 if (firstwin != NULL && curwin->w_buffer == buf) | |
677 reset_synblock(curwin); | |
3068 | 678 #endif |
1187 | 679 |
680 #ifdef FEAT_FOLDING | |
681 /* No folds in an empty buffer. */ | |
682 # ifdef FEAT_WINDOWS | |
683 { | |
684 win_T *win; | |
685 tabpage_T *tp; | |
686 | |
687 FOR_ALL_TAB_WINDOWS(tp, win) | |
688 if (win->w_buffer == buf) | |
689 clearFolding(win); | |
690 } | |
691 # else | |
692 if (curwin->w_buffer == buf) | |
693 clearFolding(curwin); | |
694 # endif | |
695 #endif | |
696 | |
7 | 697 #ifdef FEAT_TCL |
698 tcl_buffer_free(buf); | |
699 #endif | |
700 ml_close(buf, TRUE); /* close and delete the memline/memfile */ | |
701 buf->b_ml.ml_line_count = 0; /* no lines in buffer */ | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
702 if ((flags & BFA_KEEP_UNDO) == 0) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
703 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
704 u_blockfree(buf); /* free the memory allocated for undo */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
705 u_clearall(buf); /* reset all undo information */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
706 } |
7 | 707 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
708 syntax_clear(&buf->b_s); /* reset syntax info */ |
7 | 709 #endif |
24 | 710 buf->b_flags &= ~BF_READERR; /* a read error is no longer relevant */ |
7 | 711 } |
712 | |
713 /* | |
714 * Free a buffer structure and the things it contains related to the buffer | |
715 * itself (not the file, that must have been done already). | |
716 */ | |
717 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
718 free_buffer(buf_T *buf) |
7 | 719 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
720 ++buf_free_count; |
7 | 721 free_buffer_stuff(buf, TRUE); |
4287 | 722 #ifdef FEAT_EVAL |
723 unref_var_dict(buf->b_vars); | |
724 #endif | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
725 #ifdef FEAT_LUA |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
726 lua_buffer_free(buf); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
727 #endif |
14 | 728 #ifdef FEAT_MZSCHEME |
729 mzscheme_buffer_free(buf); | |
730 #endif | |
7 | 731 #ifdef FEAT_PERL |
732 perl_buf_free(buf); | |
733 #endif | |
734 #ifdef FEAT_PYTHON | |
735 python_buffer_free(buf); | |
736 #endif | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
737 #ifdef FEAT_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
738 python3_buffer_free(buf); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
739 #endif |
7 | 740 #ifdef FEAT_RUBY |
741 ruby_buffer_free(buf); | |
742 #endif | |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
743 #ifdef FEAT_JOB_CHANNEL |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
744 channel_buffer_free(buf); |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
745 #endif |
9515
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
746 |
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
747 buf_hashtab_remove(buf); |
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
748 |
40 | 749 #ifdef FEAT_AUTOCMD |
750 aubuflocal_remove(buf); | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
751 |
5816 | 752 if (autocmd_busy) |
753 { | |
754 /* Do not free the buffer structure while autocommands are executing, | |
755 * it's still needed. Free it when autocmd_busy is reset. */ | |
756 buf->b_next = au_pending_free_buf; | |
757 au_pending_free_buf = buf; | |
758 } | |
759 else | |
760 #endif | |
761 vim_free(buf); | |
7 | 762 } |
763 | |
764 /* | |
765 * Free stuff in the buffer for ":bdel" and when wiping out the buffer. | |
766 */ | |
767 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
768 free_buffer_stuff( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
769 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
770 int free_options) /* free options as well */ |
7 | 771 { |
772 if (free_options) | |
773 { | |
774 clear_wininfo(buf); /* including window-local options */ | |
775 free_buf_options(buf, TRUE); | |
2620 | 776 #ifdef FEAT_SPELL |
777 ga_clear(&buf->b_s.b_langp); | |
778 #endif | |
7 | 779 } |
780 #ifdef FEAT_EVAL | |
4287 | 781 vars_clear(&buf->b_vars->dv_hashtab); /* free all internal variables */ |
782 hash_init(&buf->b_vars->dv_hashtab); | |
7 | 783 #endif |
784 #ifdef FEAT_USR_CMDS | |
785 uc_clear(&buf->b_ucmds); /* clear local user commands */ | |
786 #endif | |
787 #ifdef FEAT_SIGNS | |
788 buf_delete_signs(buf); /* delete any signs */ | |
789 #endif | |
1781 | 790 #ifdef FEAT_NETBEANS_INTG |
2210 | 791 netbeans_file_killed(buf); |
1781 | 792 #endif |
7 | 793 #ifdef FEAT_LOCALMAP |
794 map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ | |
795 map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ | |
796 #endif | |
797 #ifdef FEAT_MBYTE | |
798 vim_free(buf->b_start_fenc); | |
799 buf->b_start_fenc = NULL; | |
800 #endif | |
801 } | |
802 | |
803 /* | |
804 * Free the b_wininfo list for buffer "buf". | |
805 */ | |
806 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
807 clear_wininfo(buf_T *buf) |
7 | 808 { |
809 wininfo_T *wip; | |
810 | |
811 while (buf->b_wininfo != NULL) | |
812 { | |
813 wip = buf->b_wininfo; | |
814 buf->b_wininfo = wip->wi_next; | |
815 if (wip->wi_optset) | |
816 { | |
817 clear_winopt(&wip->wi_opt); | |
818 #ifdef FEAT_FOLDING | |
819 deleteFoldRecurse(&wip->wi_folds); | |
820 #endif | |
821 } | |
822 vim_free(wip); | |
823 } | |
824 } | |
825 | |
826 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
827 /* | |
828 * Go to another buffer. Handles the result of the ATTENTION dialog. | |
829 */ | |
830 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
831 goto_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
832 exarg_T *eap, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
833 int start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
834 int dir, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
835 int count) |
7 | 836 { |
576 | 837 # if defined(FEAT_WINDOWS) && defined(HAS_SWAP_EXISTS_ACTION) |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
838 bufref_T old_curbuf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
839 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
840 set_bufref(&old_curbuf, curbuf); |
7 | 841 |
842 swap_exists_action = SEA_DIALOG; | |
843 # endif | |
844 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, | |
845 start, dir, count, eap->forceit); | |
576 | 846 # if defined(FEAT_WINDOWS) && defined(HAS_SWAP_EXISTS_ACTION) |
7 | 847 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') |
848 { | |
24 | 849 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
850 cleanup_T cs; | |
851 | |
852 /* Reset the error/interrupt/exception state here so that | |
853 * aborting() returns FALSE when closing a window. */ | |
854 enter_cleanup(&cs); | |
855 # endif | |
856 | |
857 /* Quitting means closing the split window, nothing else. */ | |
7 | 858 win_close(curwin, TRUE); |
859 swap_exists_action = SEA_NONE; | |
602 | 860 swap_exists_did_quit = TRUE; |
24 | 861 |
862 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
863 /* Restore the error/interrupt/exception state if not discarded by a | |
864 * new aborting error, interrupt, or uncaught exception. */ | |
865 leave_cleanup(&cs); | |
866 # endif | |
7 | 867 } |
868 else | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
869 handle_swap_exists(&old_curbuf); |
7 | 870 # endif |
871 } | |
872 #endif | |
873 | |
576 | 874 #if defined(HAS_SWAP_EXISTS_ACTION) || defined(PROTO) |
7 | 875 /* |
876 * Handle the situation of swap_exists_action being set. | |
877 * It is allowed for "old_curbuf" to be NULL or invalid. | |
878 */ | |
879 void | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
880 handle_swap_exists(bufref_T *old_curbuf) |
7 | 881 { |
24 | 882 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
883 cleanup_T cs; | |
884 # endif | |
4139 | 885 #ifdef FEAT_SYN_HL |
886 long old_tw = curbuf->b_p_tw; | |
887 #endif | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
888 buf_T *buf; |
20 | 889 |
7 | 890 if (swap_exists_action == SEA_QUIT) |
891 { | |
24 | 892 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
893 /* Reset the error/interrupt/exception state here so that | |
894 * aborting() returns FALSE when closing a buffer. */ | |
895 enter_cleanup(&cs); | |
896 # endif | |
897 | |
7 | 898 /* User selected Quit at ATTENTION prompt. Go back to previous |
899 * buffer. If that buffer is gone or the same as the current one, | |
900 * open a new, empty buffer. */ | |
901 swap_exists_action = SEA_NONE; /* don't want it again */ | |
602 | 902 swap_exists_did_quit = TRUE; |
3365 | 903 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
904 if (old_curbuf == NULL || !bufref_valid(old_curbuf) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
905 || old_curbuf->br_buf == curbuf) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
906 buf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED); |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
907 else |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
908 buf = old_curbuf->br_buf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
909 if (buf != NULL) |
4139 | 910 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
911 enter_buffer(buf); |
4139 | 912 #ifdef FEAT_SYN_HL |
913 if (old_tw != curbuf->b_p_tw) | |
914 check_colorcolumn(curwin); | |
915 #endif | |
916 } | |
7 | 917 /* If "old_curbuf" is NULL we are in big trouble here... */ |
24 | 918 |
919 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
920 /* Restore the error/interrupt/exception state if not discarded by a | |
921 * new aborting error, interrupt, or uncaught exception. */ | |
922 leave_cleanup(&cs); | |
923 # endif | |
7 | 924 } |
925 else if (swap_exists_action == SEA_RECOVER) | |
926 { | |
24 | 927 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
928 /* Reset the error/interrupt/exception state here so that | |
929 * aborting() returns FALSE when closing a buffer. */ | |
930 enter_cleanup(&cs); | |
931 # endif | |
932 | |
7 | 933 /* User selected Recover at ATTENTION prompt. */ |
934 msg_scroll = TRUE; | |
935 ml_recover(); | |
936 MSG_PUTS("\n"); /* don't overwrite the last message */ | |
937 cmdline_row = msg_row; | |
717 | 938 do_modelines(0); |
24 | 939 |
940 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
941 /* Restore the error/interrupt/exception state if not discarded by a | |
942 * new aborting error, interrupt, or uncaught exception. */ | |
943 leave_cleanup(&cs); | |
944 # endif | |
7 | 945 } |
946 swap_exists_action = SEA_NONE; | |
947 } | |
948 #endif | |
949 | |
950 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
951 /* | |
952 * do_bufdel() - delete or unload buffer(s) | |
953 * | |
954 * addr_count == 0: ":bdel" - delete current buffer | |
955 * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete | |
956 * buffer "end_bnr", then any other arguments. | |
957 * addr_count == 2: ":N,N bdel" - delete buffers in range | |
958 * | |
959 * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or | |
960 * DOBUF_DEL (":bdel") | |
961 * | |
962 * Returns error message or NULL | |
963 */ | |
964 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
965 do_bufdel( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
966 int command, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
967 char_u *arg, /* pointer to extra arguments */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
968 int addr_count, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
969 int start_bnr, /* first buffer number in a range */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
970 int end_bnr, /* buffer nr or last buffer nr in a range */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
971 int forceit) |
7 | 972 { |
973 int do_current = 0; /* delete current buffer? */ | |
974 int deleted = 0; /* number of buffers deleted */ | |
975 char_u *errormsg = NULL; /* return value */ | |
976 int bnr; /* buffer number */ | |
977 char_u *p; | |
978 | |
979 if (addr_count == 0) | |
980 { | |
981 (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit); | |
982 } | |
983 else | |
984 { | |
985 if (addr_count == 2) | |
986 { | |
987 if (*arg) /* both range and argument is not allowed */ | |
988 return (char_u *)_(e_trailing); | |
989 bnr = start_bnr; | |
990 } | |
991 else /* addr_count == 1 */ | |
992 bnr = end_bnr; | |
993 | |
994 for ( ;!got_int; ui_breakcheck()) | |
995 { | |
996 /* | |
997 * delete the current buffer last, otherwise when the | |
998 * current buffer is deleted, the next buffer becomes | |
999 * the current one and will be loaded, which may then | |
1000 * also be deleted, etc. | |
1001 */ | |
1002 if (bnr == curbuf->b_fnum) | |
1003 do_current = bnr; | |
1004 else if (do_buffer(command, DOBUF_FIRST, FORWARD, (int)bnr, | |
1005 forceit) == OK) | |
1006 ++deleted; | |
1007 | |
1008 /* | |
1009 * find next buffer number to delete/unload | |
1010 */ | |
1011 if (addr_count == 2) | |
1012 { | |
1013 if (++bnr > end_bnr) | |
1014 break; | |
1015 } | |
1016 else /* addr_count == 1 */ | |
1017 { | |
1018 arg = skipwhite(arg); | |
1019 if (*arg == NUL) | |
1020 break; | |
1021 if (!VIM_ISDIGIT(*arg)) | |
1022 { | |
1023 p = skiptowhite_esc(arg); | |
4236 | 1024 bnr = buflist_findpat(arg, p, command == DOBUF_WIPE, |
1025 FALSE, FALSE); | |
7 | 1026 if (bnr < 0) /* failed */ |
1027 break; | |
1028 arg = p; | |
1029 } | |
1030 else | |
1031 bnr = getdigits(&arg); | |
1032 } | |
1033 } | |
1034 if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, | |
1035 FORWARD, do_current, forceit) == OK) | |
1036 ++deleted; | |
1037 | |
1038 if (deleted == 0) | |
1039 { | |
1040 if (command == DOBUF_UNLOAD) | |
300 | 1041 STRCPY(IObuff, _("E515: No buffers were unloaded")); |
7 | 1042 else if (command == DOBUF_DEL) |
300 | 1043 STRCPY(IObuff, _("E516: No buffers were deleted")); |
7 | 1044 else |
300 | 1045 STRCPY(IObuff, _("E517: No buffers were wiped out")); |
7 | 1046 errormsg = IObuff; |
1047 } | |
1048 else if (deleted >= p_report) | |
1049 { | |
1050 if (command == DOBUF_UNLOAD) | |
1051 { | |
1052 if (deleted == 1) | |
1053 MSG(_("1 buffer unloaded")); | |
1054 else | |
1055 smsg((char_u *)_("%d buffers unloaded"), deleted); | |
1056 } | |
1057 else if (command == DOBUF_DEL) | |
1058 { | |
1059 if (deleted == 1) | |
1060 MSG(_("1 buffer deleted")); | |
1061 else | |
1062 smsg((char_u *)_("%d buffers deleted"), deleted); | |
1063 } | |
1064 else | |
1065 { | |
1066 if (deleted == 1) | |
1067 MSG(_("1 buffer wiped out")); | |
1068 else | |
1069 smsg((char_u *)_("%d buffers wiped out"), deleted); | |
1070 } | |
1071 } | |
1072 } | |
1073 | |
1074 | |
1075 return errormsg; | |
1076 } | |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1077 #endif /* FEAT_LISTCMDS */ |
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1078 |
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1079 #if defined(FEAT_LISTCMDS) || defined(FEAT_PYTHON) \ |
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1080 || defined(FEAT_PYTHON3) || defined(PROTO) |
7 | 1081 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
1082 static int empty_curbuf(int close_others, int forceit, int action); |
5586 | 1083 |
1084 /* | |
1085 * Make the current buffer empty. | |
1086 * Used when it is wiped out and it's the last buffer. | |
1087 */ | |
1088 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1089 empty_curbuf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1090 int close_others, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1091 int forceit, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1092 int action) |
5586 | 1093 { |
1094 int retval; | |
1095 buf_T *buf = curbuf; | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1096 bufref_T bufref; |
5586 | 1097 |
1098 if (action == DOBUF_UNLOAD) | |
1099 { | |
1100 EMSG(_("E90: Cannot unload last buffer")); | |
1101 return FAIL; | |
1102 } | |
1103 | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1104 set_bufref(&bufref, buf); |
5586 | 1105 #ifdef FEAT_WINDOWS |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1106 if (close_others) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1107 /* Close any other windows on this buffer, then make it empty. */ |
5586 | 1108 close_windows(buf, TRUE); |
1109 #endif | |
1110 | |
1111 setpcmark(); | |
1112 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, | |
1113 forceit ? ECMD_FORCEIT : 0, curwin); | |
1114 | |
1115 /* | |
1116 * do_ecmd() may create a new buffer, then we have to delete | |
1117 * the old one. But do_ecmd() may have done that already, check | |
1118 * if the buffer still exists. | |
1119 */ | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1120 if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows == 0) |
5586 | 1121 close_buffer(NULL, buf, action, FALSE); |
1122 if (!close_others) | |
1123 need_fileinfo = FALSE; | |
1124 return retval; | |
1125 } | |
7 | 1126 /* |
1127 * Implementation of the commands for the buffer list. | |
1128 * | |
1129 * action == DOBUF_GOTO go to specified buffer | |
1130 * action == DOBUF_SPLIT split window and go to specified buffer | |
1131 * action == DOBUF_UNLOAD unload specified buffer(s) | |
1132 * action == DOBUF_DEL delete specified buffer(s) from buffer list | |
1133 * action == DOBUF_WIPE delete specified buffer(s) really | |
1134 * | |
1135 * start == DOBUF_CURRENT go to "count" buffer from current buffer | |
1136 * start == DOBUF_FIRST go to "count" buffer from first buffer | |
1137 * start == DOBUF_LAST go to "count" buffer from last buffer | |
1138 * start == DOBUF_MOD go to "count" modified buffer from current buffer | |
1139 * | |
1140 * Return FAIL or OK. | |
1141 */ | |
1142 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1143 do_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1144 int action, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1145 int start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1146 int dir, /* FORWARD or BACKWARD */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1147 int count, /* buffer number or number of buffers */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1148 int forceit) /* TRUE for :...! */ |
7 | 1149 { |
1150 buf_T *buf; | |
1151 buf_T *bp; | |
1152 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL | |
1153 || action == DOBUF_WIPE); | |
1154 | |
1155 switch (start) | |
1156 { | |
1157 case DOBUF_FIRST: buf = firstbuf; break; | |
1158 case DOBUF_LAST: buf = lastbuf; break; | |
1159 default: buf = curbuf; break; | |
1160 } | |
1161 if (start == DOBUF_MOD) /* find next modified buffer */ | |
1162 { | |
1163 while (count-- > 0) | |
1164 { | |
1165 do | |
1166 { | |
1167 buf = buf->b_next; | |
1168 if (buf == NULL) | |
1169 buf = firstbuf; | |
1170 } | |
1171 while (buf != curbuf && !bufIsChanged(buf)); | |
1172 } | |
1173 if (!bufIsChanged(buf)) | |
1174 { | |
1175 EMSG(_("E84: No modified buffer found")); | |
1176 return FAIL; | |
1177 } | |
1178 } | |
1179 else if (start == DOBUF_FIRST && count) /* find specified buffer number */ | |
1180 { | |
1181 while (buf != NULL && buf->b_fnum != count) | |
1182 buf = buf->b_next; | |
1183 } | |
1184 else | |
1185 { | |
1186 bp = NULL; | |
1187 while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) | |
1188 { | |
1189 /* remember the buffer where we start, we come back there when all | |
1190 * buffers are unlisted. */ | |
1191 if (bp == NULL) | |
1192 bp = buf; | |
1193 if (dir == FORWARD) | |
1194 { | |
1195 buf = buf->b_next; | |
1196 if (buf == NULL) | |
1197 buf = firstbuf; | |
1198 } | |
1199 else | |
1200 { | |
1201 buf = buf->b_prev; | |
1202 if (buf == NULL) | |
1203 buf = lastbuf; | |
1204 } | |
1205 /* don't count unlisted buffers */ | |
1206 if (unload || buf->b_p_bl) | |
1207 { | |
1208 --count; | |
1209 bp = NULL; /* use this buffer as new starting point */ | |
1210 } | |
1211 if (bp == buf) | |
1212 { | |
1213 /* back where we started, didn't find anything. */ | |
1214 EMSG(_("E85: There is no listed buffer")); | |
1215 return FAIL; | |
1216 } | |
1217 } | |
1218 } | |
1219 | |
1220 if (buf == NULL) /* could not find it */ | |
1221 { | |
1222 if (start == DOBUF_FIRST) | |
1223 { | |
1224 /* don't warn when deleting */ | |
1225 if (!unload) | |
6557 | 1226 EMSGN(_(e_nobufnr), count); |
7 | 1227 } |
1228 else if (dir == FORWARD) | |
1229 EMSG(_("E87: Cannot go beyond last buffer")); | |
1230 else | |
1231 EMSG(_("E88: Cannot go before first buffer")); | |
1232 return FAIL; | |
1233 } | |
1234 | |
1235 #ifdef FEAT_GUI | |
1236 need_mouse_correct = TRUE; | |
1237 #endif | |
1238 | |
1239 #ifdef FEAT_LISTCMDS | |
1240 /* | |
1241 * delete buffer buf from memory and/or the list | |
1242 */ | |
1243 if (unload) | |
1244 { | |
1245 int forward; | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1246 # if defined(FEAT_AUTOCMD) || defined(FEAT_WINDOWS) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1247 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1248 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1249 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1250 # endif |
7 | 1251 |
1252 /* When unloading or deleting a buffer that's already unloaded and | |
1253 * unlisted: fail silently. */ | |
1254 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) | |
1255 return FAIL; | |
1256 | |
1257 if (!forceit && bufIsChanged(buf)) | |
1258 { | |
1259 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1260 if ((p_confirm || cmdmod.confirm) && p_write) | |
1261 { | |
1262 dialog_changed(buf, FALSE); | |
1263 # ifdef FEAT_AUTOCMD | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1264 if (!bufref_valid(&bufref)) |
7 | 1265 /* Autocommand deleted buffer, oops! It's not changed |
1266 * now. */ | |
1267 return FAIL; | |
1268 # endif | |
36 | 1269 /* If it's still changed fail silently, the dialog already |
1270 * mentioned why it fails. */ | |
1271 if (bufIsChanged(buf)) | |
1272 return FAIL; | |
7 | 1273 } |
36 | 1274 else |
7 | 1275 #endif |
1276 { | |
1277 EMSGN(_("E89: No write since last change for buffer %ld (add ! to override)"), | |
1278 buf->b_fnum); | |
1279 return FAIL; | |
1280 } | |
1281 } | |
1282 | |
1283 /* | |
1284 * If deleting the last (listed) buffer, make it empty. | |
1285 * The last (listed) buffer cannot be unloaded. | |
1286 */ | |
1287 for (bp = firstbuf; bp != NULL; bp = bp->b_next) | |
1288 if (bp->b_p_bl && bp != buf) | |
1289 break; | |
1290 if (bp == NULL && buf == curbuf) | |
5586 | 1291 return empty_curbuf(TRUE, forceit, action); |
7 | 1292 |
1293 #ifdef FEAT_WINDOWS | |
1294 /* | |
1295 * If the deleted buffer is the current one, close the current window | |
671 | 1296 * (unless it's the only window). Repeat this so long as we end up in |
1297 * a window with this buffer. | |
7 | 1298 */ |
671 | 1299 while (buf == curbuf |
3570 | 1300 # ifdef FEAT_AUTOCMD |
1301 && !(curwin->w_closing || curwin->w_buffer->b_closing) | |
1302 # endif | |
671 | 1303 && (firstwin != lastwin || first_tabpage->tp_next != NULL)) |
5302 | 1304 { |
1305 if (win_close(curwin, FALSE) == FAIL) | |
1306 break; | |
1307 } | |
7 | 1308 #endif |
1309 | |
1310 /* | |
1311 * If the buffer to be deleted is not the current one, delete it here. | |
1312 */ | |
1313 if (buf != curbuf) | |
1314 { | |
1315 #ifdef FEAT_WINDOWS | |
671 | 1316 close_windows(buf, FALSE); |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1317 if (buf != curbuf && bufref_valid(&bufref)) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1318 #endif |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1319 if (buf->b_nwindows <= 0) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1320 close_buffer(NULL, buf, action, FALSE); |
7 | 1321 return OK; |
1322 } | |
1323 | |
1324 /* | |
1325 * Deleting the current buffer: Need to find another buffer to go to. | |
5586 | 1326 * There should be another, otherwise it would have been handled |
1327 * above. However, autocommands may have deleted all buffers. | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9479
diff
changeset
|
1328 * First use au_new_curbuf.br_buf, if it is valid. |
7 | 1329 * Then prefer the buffer we most recently visited. |
1330 * Else try to find one that is loaded, after the current buffer, | |
1331 * then before the current buffer. | |
1332 * Finally use any buffer. | |
1333 */ | |
1334 buf = NULL; /* selected buffer */ | |
1335 bp = NULL; /* used when no loaded buffer found */ | |
1336 #ifdef FEAT_AUTOCMD | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9479
diff
changeset
|
1337 if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9479
diff
changeset
|
1338 buf = au_new_curbuf.br_buf; |
7 | 1339 # ifdef FEAT_JUMPLIST |
1340 else | |
1341 # endif | |
1342 #endif | |
1343 #ifdef FEAT_JUMPLIST | |
1344 if (curwin->w_jumplistlen > 0) | |
1345 { | |
1346 int jumpidx; | |
1347 | |
1348 jumpidx = curwin->w_jumplistidx - 1; | |
1349 if (jumpidx < 0) | |
1350 jumpidx = curwin->w_jumplistlen - 1; | |
1351 | |
1352 forward = jumpidx; | |
1353 while (jumpidx != curwin->w_jumplistidx) | |
1354 { | |
1355 buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum); | |
1356 if (buf != NULL) | |
1357 { | |
1358 if (buf == curbuf || !buf->b_p_bl) | |
1359 buf = NULL; /* skip current and unlisted bufs */ | |
1360 else if (buf->b_ml.ml_mfp == NULL) | |
1361 { | |
1362 /* skip unloaded buf, but may keep it for later */ | |
1363 if (bp == NULL) | |
1364 bp = buf; | |
1365 buf = NULL; | |
1366 } | |
1367 } | |
1368 if (buf != NULL) /* found a valid buffer: stop searching */ | |
1369 break; | |
1370 /* advance to older entry in jump list */ | |
1371 if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) | |
1372 break; | |
1373 if (--jumpidx < 0) | |
1374 jumpidx = curwin->w_jumplistlen - 1; | |
1375 if (jumpidx == forward) /* List exhausted for sure */ | |
1376 break; | |
1377 } | |
1378 } | |
1379 #endif | |
1380 | |
1381 if (buf == NULL) /* No previous buffer, Try 2'nd approach */ | |
1382 { | |
1383 forward = TRUE; | |
1384 buf = curbuf->b_next; | |
1385 for (;;) | |
1386 { | |
1387 if (buf == NULL) | |
1388 { | |
1389 if (!forward) /* tried both directions */ | |
1390 break; | |
1391 buf = curbuf->b_prev; | |
1392 forward = FALSE; | |
1393 continue; | |
1394 } | |
1395 /* in non-help buffer, try to skip help buffers, and vv */ | |
1396 if (buf->b_help == curbuf->b_help && buf->b_p_bl) | |
1397 { | |
1398 if (buf->b_ml.ml_mfp != NULL) /* found loaded buffer */ | |
1399 break; | |
1400 if (bp == NULL) /* remember unloaded buf for later */ | |
1401 bp = buf; | |
1402 } | |
1403 if (forward) | |
1404 buf = buf->b_next; | |
1405 else | |
1406 buf = buf->b_prev; | |
1407 } | |
1408 } | |
1409 if (buf == NULL) /* No loaded buffer, use unloaded one */ | |
1410 buf = bp; | |
1411 if (buf == NULL) /* No loaded buffer, find listed one */ | |
1412 { | |
1413 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
1414 if (buf->b_p_bl && buf != curbuf) | |
1415 break; | |
1416 } | |
1417 if (buf == NULL) /* Still no buffer, just take one */ | |
1418 { | |
1419 if (curbuf->b_next != NULL) | |
1420 buf = curbuf->b_next; | |
1421 else | |
1422 buf = curbuf->b_prev; | |
1423 } | |
1424 } | |
1425 | |
5586 | 1426 if (buf == NULL) |
1427 { | |
1428 /* Autocommands must have wiped out all other buffers. Only option | |
1429 * now is to make the current buffer empty. */ | |
1430 return empty_curbuf(FALSE, forceit, action); | |
1431 } | |
1432 | |
7 | 1433 /* |
1434 * make buf current buffer | |
1435 */ | |
1436 if (action == DOBUF_SPLIT) /* split window first */ | |
1437 { | |
1438 # ifdef FEAT_WINDOWS | |
1618 | 1439 /* If 'switchbuf' contains "useopen": jump to first window containing |
1440 * "buf" if one exists */ | |
1441 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) | |
825 | 1442 return OK; |
1736 | 1443 /* If 'switchbuf' contains "usetab": jump to first window in any tab |
1618 | 1444 * page containing "buf" if one exists */ |
1445 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) | |
7 | 1446 return OK; |
1447 if (win_split(0, 0) == FAIL) | |
1448 # endif | |
1449 return FAIL; | |
1450 } | |
1451 #endif | |
1452 | |
1453 /* go to current buffer - nothing to do */ | |
1454 if (buf == curbuf) | |
1455 return OK; | |
1456 | |
1457 /* | |
1458 * Check if the current buffer may be abandoned. | |
1459 */ | |
1460 if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) | |
1461 { | |
1462 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1463 if ((p_confirm || cmdmod.confirm) && p_write) | |
1464 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1465 # ifdef FEAT_AUTOCMD |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1466 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1467 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1468 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1469 # endif |
7 | 1470 dialog_changed(curbuf, FALSE); |
1471 # ifdef FEAT_AUTOCMD | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1472 if (!bufref_valid(&bufref)) |
7 | 1473 /* Autocommand deleted buffer, oops! */ |
1474 return FAIL; | |
1475 # endif | |
1476 } | |
1477 if (bufIsChanged(curbuf)) | |
1478 #endif | |
1479 { | |
1480 EMSG(_(e_nowrtmsg)); | |
1481 return FAIL; | |
1482 } | |
1483 } | |
1484 | |
1485 /* Go to the other buffer. */ | |
1486 set_curbuf(buf, action); | |
1487 | |
2583 | 1488 #if defined(FEAT_LISTCMDS) \ |
1489 && (defined(FEAT_SCROLLBIND) || defined(FEAT_CURSORBIND)) | |
7 | 1490 if (action == DOBUF_SPLIT) |
2583 | 1491 { |
1492 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ | |
1493 } | |
7 | 1494 #endif |
1495 | |
1496 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
1497 if (aborting()) /* autocmds may abort script processing */ | |
1498 return FAIL; | |
1499 #endif | |
1500 | |
1501 return OK; | |
1502 } | |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1503 #endif |
7 | 1504 |
1505 /* | |
1506 * Set current buffer to "buf". Executes autocommands and closes current | |
1507 * buffer. "action" tells how to close the current buffer: | |
1508 * DOBUF_GOTO free or hide it | |
1509 * DOBUF_SPLIT nothing | |
1510 * DOBUF_UNLOAD unload it | |
1511 * DOBUF_DEL delete it | |
1512 * DOBUF_WIPE wipe it out | |
1513 */ | |
1514 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1515 set_curbuf(buf_T *buf, int action) |
7 | 1516 { |
1517 buf_T *prevbuf; | |
1518 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL | |
1519 || action == DOBUF_WIPE); | |
4139 | 1520 #ifdef FEAT_SYN_HL |
1521 long old_tw = curbuf->b_p_tw; | |
1522 #endif | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1523 bufref_T bufref; |
7 | 1524 |
1525 setpcmark(); | |
22 | 1526 if (!cmdmod.keepalt) |
1527 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */ | |
1743 | 1528 buflist_altfpos(curwin); /* remember curpos */ |
7 | 1529 |
1530 /* Don't restart Select mode after switching to another buffer. */ | |
1531 VIsual_reselect = FALSE; | |
1532 | |
1533 /* close_windows() or apply_autocmds() may change curbuf */ | |
1534 prevbuf = curbuf; | |
9479
6149d1374ea0
commit https://github.com/vim/vim/commit/453f37dbfd6f8304a36ea84e40a9965404206186
Christian Brabandt <cb@256bit.org>
parents:
9475
diff
changeset
|
1535 set_bufref(&bufref, prevbuf); |
7 | 1536 |
1537 #ifdef FEAT_AUTOCMD | |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1538 if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) |
7 | 1539 # ifdef FEAT_EVAL |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1540 || (bufref_valid(&bufref) && !aborting())) |
7 | 1541 # else |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1542 || bufref_valid(&bufref)) |
7 | 1543 # endif |
1544 #endif | |
1545 { | |
3068 | 1546 #ifdef FEAT_SYN_HL |
1547 if (prevbuf == curwin->w_buffer) | |
1548 reset_synblock(curwin); | |
1549 #endif | |
7 | 1550 #ifdef FEAT_WINDOWS |
1551 if (unload) | |
671 | 1552 close_windows(prevbuf, FALSE); |
7 | 1553 #endif |
1554 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1555 if (bufref_valid(&bufref) && !aborting()) |
7 | 1556 #else |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1557 if (bufref_valid(&bufref)) |
7 | 1558 #endif |
815 | 1559 { |
3606 | 1560 #ifdef FEAT_WINDOWS |
3654 | 1561 win_T *previouswin = curwin; |
3606 | 1562 #endif |
815 | 1563 if (prevbuf == curbuf) |
825 | 1564 u_sync(FALSE); |
7 | 1565 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, |
1566 unload ? action : (action == DOBUF_GOTO | |
1567 && !P_HID(prevbuf) | |
3365 | 1568 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); |
3606 | 1569 #ifdef FEAT_WINDOWS |
3654 | 1570 if (curwin != previouswin && win_valid(previouswin)) |
3594 | 1571 /* autocommands changed curwin, Grr! */ |
3654 | 1572 curwin = previouswin; |
3606 | 1573 #endif |
815 | 1574 } |
7 | 1575 } |
1576 #ifdef FEAT_AUTOCMD | |
1710 | 1577 /* An autocommand may have deleted "buf", already entered it (e.g., when |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1578 * it did ":bunload") or aborted the script processing. |
3594 | 1579 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ |
1580 if ((buf_valid(buf) && buf != curbuf | |
3606 | 1581 # ifdef FEAT_EVAL |
3594 | 1582 && !aborting() |
3606 | 1583 # endif |
1584 # ifdef FEAT_WINDOWS | |
3594 | 1585 ) || curwin->w_buffer == NULL |
3606 | 1586 # endif |
3594 | 1587 ) |
7 | 1588 #endif |
4139 | 1589 { |
7 | 1590 enter_buffer(buf); |
4139 | 1591 #ifdef FEAT_SYN_HL |
1592 if (old_tw != curbuf->b_p_tw) | |
1593 check_colorcolumn(curwin); | |
1594 #endif | |
1595 } | |
7 | 1596 } |
1597 | |
1598 /* | |
1599 * Enter a new current buffer. | |
4139 | 1600 * Old curbuf must have been abandoned already! This also means "curbuf" may |
1601 * be pointing to freed memory. | |
7 | 1602 */ |
1603 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1604 enter_buffer(buf_T *buf) |
7 | 1605 { |
1606 /* Copy buffer and window local option values. Not for a help buffer. */ | |
1607 buf_copy_options(buf, BCO_ENTER | BCO_NOHELP); | |
1608 if (!buf->b_help) | |
1609 get_winopts(buf); | |
1610 #ifdef FEAT_FOLDING | |
1611 else | |
1612 /* Remove all folds in the window. */ | |
1613 clearFolding(curwin); | |
1614 foldUpdateAll(curwin); /* update folds (later). */ | |
1615 #endif | |
1616 | |
1617 /* Get the buffer in the current window. */ | |
1618 curwin->w_buffer = buf; | |
1619 curbuf = buf; | |
1620 ++curbuf->b_nwindows; | |
1621 | |
1622 #ifdef FEAT_DIFF | |
672 | 1623 if (curwin->w_p_diff) |
1624 diff_buf_add(curbuf); | |
7 | 1625 #endif |
1626 | |
3068 | 1627 #ifdef FEAT_SYN_HL |
1628 curwin->w_s = &(buf->b_s); | |
1629 #endif | |
1630 | |
7 | 1631 /* Cursor on first line by default. */ |
1632 curwin->w_cursor.lnum = 1; | |
1633 curwin->w_cursor.col = 0; | |
1634 #ifdef FEAT_VIRTUALEDIT | |
1635 curwin->w_cursor.coladd = 0; | |
1636 #endif | |
1637 curwin->w_set_curswant = TRUE; | |
1744 | 1638 #ifdef FEAT_AUTOCMD |
1639 curwin->w_topline_was_set = FALSE; | |
1640 #endif | |
7 | 1641 |
2091
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1642 /* mark cursor position as being invalid */ |
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1643 curwin->w_valid = 0; |
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1644 |
7 | 1645 /* Make sure the buffer is loaded. */ |
1646 if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */ | |
22 | 1647 { |
24 | 1648 #ifdef FEAT_AUTOCMD |
22 | 1649 /* If there is no filetype, allow for detecting one. Esp. useful for |
1650 * ":ball" used in a autocommand. If there already is a filetype we | |
1651 * might prefer to keep it. */ | |
1652 if (*curbuf->b_p_ft == NUL) | |
1653 did_filetype = FALSE; | |
24 | 1654 #endif |
22 | 1655 |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1656 open_buffer(FALSE, NULL, 0); |
22 | 1657 } |
7 | 1658 else |
1659 { | |
968 | 1660 if (!msg_silent) |
1661 need_fileinfo = TRUE; /* display file info after redraw */ | |
7 | 1662 (void)buf_check_timestamp(curbuf, FALSE); /* check if file changed */ |
1663 #ifdef FEAT_AUTOCMD | |
1664 curwin->w_topline = 1; | |
1665 # ifdef FEAT_DIFF | |
1666 curwin->w_topfill = 0; | |
1667 # endif | |
1668 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
1669 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); | |
1670 #endif | |
1671 } | |
1672 | |
1673 /* If autocommands did not change the cursor position, restore cursor lnum | |
1674 * and possibly cursor col. */ | |
1675 if (curwin->w_cursor.lnum == 1 && inindent(0)) | |
1676 buflist_getfpos(); | |
1677 | |
1678 check_arg_idx(curwin); /* check for valid arg_idx */ | |
1679 #ifdef FEAT_TITLE | |
1680 maketitle(); | |
1681 #endif | |
1682 #ifdef FEAT_AUTOCMD | |
1744 | 1683 /* when autocmds didn't change it */ |
1684 if (curwin->w_topline == 1 && !curwin->w_topline_was_set) | |
7 | 1685 #endif |
1686 scroll_cursor_halfway(FALSE); /* redisplay at correct position */ | |
1687 | |
33 | 1688 #ifdef FEAT_NETBEANS_INTG |
1689 /* Send fileOpened event because we've changed buffers. */ | |
2210 | 1690 netbeans_file_activated(curbuf); |
33 | 1691 #endif |
1692 | |
961 | 1693 /* Change directories when the 'acd' option is set. */ |
1694 DO_AUTOCHDIR | |
7 | 1695 |
1696 #ifdef FEAT_KEYMAP | |
1697 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 1698 (void)keymap_init(); |
7 | 1699 #endif |
1185 | 1700 #ifdef FEAT_SPELL |
1701 /* May need to set the spell language. Can only do this after the buffer | |
1702 * has been properly setup. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1703 if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1704 (void)did_set_spelllang(curwin); |
1185 | 1705 #endif |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1706 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1707 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1708 #endif |
1185 | 1709 |
7 | 1710 redraw_later(NOT_VALID); |
1711 } | |
1712 | |
961 | 1713 #if defined(FEAT_AUTOCHDIR) || defined(PROTO) |
1714 /* | |
1715 * Change to the directory of the current buffer. | |
8216
03af9acbefb0
commit https://github.com/vim/vim/commit/6bd364e08461159ad3c153ffba4def5b896486a1
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1716 * Don't do this while still starting up. |
961 | 1717 */ |
1718 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1719 do_autochdir(void) |
961 | 1720 { |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9450
diff
changeset
|
1721 if ((starting == 0 || test_autochdir) |
8216
03af9acbefb0
commit https://github.com/vim/vim/commit/6bd364e08461159ad3c153ffba4def5b896486a1
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1722 && curbuf->b_ffname != NULL |
03af9acbefb0
commit https://github.com/vim/vim/commit/6bd364e08461159ad3c153ffba4def5b896486a1
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1723 && vim_chdirfile(curbuf->b_ffname) == OK) |
961 | 1724 shorten_fnames(TRUE); |
1725 } | |
1726 #endif | |
1727 | |
7 | 1728 /* |
1729 * functions for dealing with the buffer list | |
1730 */ | |
1731 | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1732 static int top_file_num = 1; /* highest file number */ |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1733 |
7 | 1734 /* |
1735 * Add a file name to the buffer list. Return a pointer to the buffer. | |
1736 * If the same file name already exists return a pointer to that buffer. | |
1737 * If it does not exist, or if fname == NULL, a new entry is created. | |
1738 * If (flags & BLN_CURBUF) is TRUE, may use current buffer. | |
1739 * If (flags & BLN_LISTED) is TRUE, add new buffer to buffer list. | |
1740 * If (flags & BLN_DUMMY) is TRUE, don't count it as a real buffer. | |
9149
18bbf31015c2
commit https://github.com/vim/vim/commit/b127cfd75f59e82580df395b6e2c009774644b16
Christian Brabandt <cb@256bit.org>
parents:
9106
diff
changeset
|
1741 * If (flags & BLN_NEW) is TRUE, don't use an existing buffer. |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1742 * If (flags & BLN_NOOPT) is TRUE, don't copy options from the current buffer |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1743 * if the buffer already exists. |
7 | 1744 * This is the ONLY way to create a new buffer. |
1745 */ | |
1746 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1747 buflist_new( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1748 char_u *ffname, /* full path of fname or relative */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1749 char_u *sfname, /* short fname or NULL */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1750 linenr_T lnum, /* preferred cursor line */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1751 int flags) /* BLN_ defines */ |
7 | 1752 { |
1753 buf_T *buf; | |
1754 #ifdef UNIX | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
1755 stat_T st; |
7 | 1756 #endif |
1757 | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1758 if (top_file_num == 1) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1759 hash_init(&buf_hashtab); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1760 |
7 | 1761 fname_expand(curbuf, &ffname, &sfname); /* will allocate ffname */ |
1762 | |
1763 /* | |
1764 * If file name already exists in the list, update the entry. | |
1765 */ | |
1766 #ifdef UNIX | |
1767 /* On Unix we can use inode numbers when the file exists. Works better | |
1768 * for hard links. */ | |
1769 if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) | |
1770 st.st_dev = (dev_T)-1; | |
1771 #endif | |
9149
18bbf31015c2
commit https://github.com/vim/vim/commit/b127cfd75f59e82580df395b6e2c009774644b16
Christian Brabandt <cb@256bit.org>
parents:
9106
diff
changeset
|
1772 if (ffname != NULL && !(flags & (BLN_DUMMY | BLN_NEW)) && (buf = |
7 | 1773 #ifdef UNIX |
1774 buflist_findname_stat(ffname, &st) | |
1775 #else | |
1776 buflist_findname(ffname) | |
1777 #endif | |
1778 ) != NULL) | |
1779 { | |
1780 vim_free(ffname); | |
1781 if (lnum != 0) | |
1782 buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); | |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1783 |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1784 if ((flags & BLN_NOOPT) == 0) |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1785 /* copy the options now, if 'cpo' doesn't have 's' and not done |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1786 * already */ |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1787 buf_copy_options(buf, 0); |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1788 |
7 | 1789 if ((flags & BLN_LISTED) && !buf->b_p_bl) |
1790 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1791 #ifdef FEAT_AUTOCMD |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1792 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1793 #endif |
7 | 1794 buf->b_p_bl = TRUE; |
1795 #ifdef FEAT_AUTOCMD | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1796 set_bufref(&bufref, buf); |
7 | 1797 if (!(flags & BLN_DUMMY)) |
5816 | 1798 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1799 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1800 && !bufref_valid(&bufref)) |
5816 | 1801 return NULL; |
1802 } | |
7 | 1803 #endif |
1804 } | |
1805 return buf; | |
1806 } | |
1807 | |
1808 /* | |
1809 * If the current buffer has no name and no contents, use the current | |
1810 * buffer. Otherwise: Need to allocate a new buffer structure. | |
1811 * | |
1812 * This is the ONLY place where a new buffer structure is allocated! | |
625 | 1813 * (A spell file buffer is allocated in spell.c, but that's not a normal |
1814 * buffer.) | |
7 | 1815 */ |
1816 buf = NULL; | |
1817 if ((flags & BLN_CURBUF) | |
1818 && curbuf != NULL | |
1819 && curbuf->b_ffname == NULL | |
1820 && curbuf->b_nwindows <= 1 | |
1821 && (curbuf->b_ml.ml_mfp == NULL || bufempty())) | |
1822 { | |
1823 buf = curbuf; | |
1824 #ifdef FEAT_AUTOCMD | |
1825 /* It's like this buffer is deleted. Watch out for autocommands that | |
1826 * change curbuf! If that happens, allocate a new buffer anyway. */ | |
1827 if (curbuf->b_p_bl) | |
1828 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
1829 if (buf == curbuf) | |
1830 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); | |
1831 # ifdef FEAT_EVAL | |
36 | 1832 if (aborting()) /* autocmds may abort script processing */ |
7 | 1833 return NULL; |
1834 # endif | |
1835 #endif | |
1836 #ifdef FEAT_QUICKFIX | |
1837 # ifdef FEAT_AUTOCMD | |
1838 if (buf == curbuf) | |
1839 # endif | |
1840 { | |
1841 /* Make sure 'bufhidden' and 'buftype' are empty */ | |
1842 clear_string_option(&buf->b_p_bh); | |
1843 clear_string_option(&buf->b_p_bt); | |
1844 } | |
1845 #endif | |
1846 } | |
1847 if (buf != curbuf || curbuf == NULL) | |
1848 { | |
1849 buf = (buf_T *)alloc_clear((unsigned)sizeof(buf_T)); | |
1850 if (buf == NULL) | |
1851 { | |
1852 vim_free(ffname); | |
1853 return NULL; | |
1854 } | |
4287 | 1855 #ifdef FEAT_EVAL |
1856 /* init b: variables */ | |
1857 buf->b_vars = dict_alloc(); | |
1858 if (buf->b_vars == NULL) | |
1859 { | |
1860 vim_free(ffname); | |
1861 vim_free(buf); | |
1862 return NULL; | |
1863 } | |
1864 init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE); | |
1865 #endif | |
7 | 1866 } |
1867 | |
1868 if (ffname != NULL) | |
1869 { | |
1870 buf->b_ffname = ffname; | |
1871 buf->b_sfname = vim_strsave(sfname); | |
1872 } | |
1873 | |
1874 clear_wininfo(buf); | |
1875 buf->b_wininfo = (wininfo_T *)alloc_clear((unsigned)sizeof(wininfo_T)); | |
1876 | |
1877 if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) | |
1878 || buf->b_wininfo == NULL) | |
1879 { | |
1880 vim_free(buf->b_ffname); | |
1881 buf->b_ffname = NULL; | |
1882 vim_free(buf->b_sfname); | |
1883 buf->b_sfname = NULL; | |
1884 if (buf != curbuf) | |
1885 free_buffer(buf); | |
1886 return NULL; | |
1887 } | |
1888 | |
1889 if (buf == curbuf) | |
1890 { | |
1891 /* free all things allocated for this buffer */ | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1892 buf_freeall(buf, 0); |
7 | 1893 if (buf != curbuf) /* autocommands deleted the buffer! */ |
1894 return NULL; | |
1895 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
36 | 1896 if (aborting()) /* autocmds may abort script processing */ |
7 | 1897 return NULL; |
1898 #endif | |
1899 free_buffer_stuff(buf, FALSE); /* delete local variables et al. */ | |
3925 | 1900 |
1901 /* Init the options. */ | |
1902 buf->b_p_initialized = FALSE; | |
1903 buf_copy_options(buf, BCO_ENTER); | |
1904 | |
7 | 1905 #ifdef FEAT_KEYMAP |
1906 /* need to reload lmaps and set b:keymap_name */ | |
1907 curbuf->b_kmap_state |= KEYMAP_INIT; | |
1908 #endif | |
1909 } | |
1910 else | |
1911 { | |
1912 /* | |
1913 * put new buffer at the end of the buffer list | |
1914 */ | |
1915 buf->b_next = NULL; | |
1916 if (firstbuf == NULL) /* buffer list is empty */ | |
1917 { | |
1918 buf->b_prev = NULL; | |
1919 firstbuf = buf; | |
1920 } | |
1921 else /* append new buffer at end of list */ | |
1922 { | |
1923 lastbuf->b_next = buf; | |
1924 buf->b_prev = lastbuf; | |
1925 } | |
1926 lastbuf = buf; | |
1927 | |
1928 buf->b_fnum = top_file_num++; | |
1929 if (top_file_num < 0) /* wrap around (may cause duplicates) */ | |
1930 { | |
1931 EMSG(_("W14: Warning: List of file names overflow")); | |
1932 if (emsg_silent == 0) | |
1933 { | |
1934 out_flush(); | |
1935 ui_delay(3000L, TRUE); /* make sure it is noticed */ | |
1936 } | |
1937 top_file_num = 1; | |
1938 } | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1939 buf_hashtab_add(buf); |
7 | 1940 |
1941 /* | |
1942 * Always copy the options from the current buffer. | |
1943 */ | |
1944 buf_copy_options(buf, BCO_ALWAYS); | |
1945 } | |
1946 | |
1947 buf->b_wininfo->wi_fpos.lnum = lnum; | |
1948 buf->b_wininfo->wi_win = curwin; | |
1949 | |
126 | 1950 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1951 hash_init(&buf->b_s.b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1952 hash_init(&buf->b_s.b_keywtab_ic); |
7 | 1953 #endif |
1954 | |
1955 buf->b_fname = buf->b_sfname; | |
1956 #ifdef UNIX | |
1957 if (st.st_dev == (dev_T)-1) | |
1873 | 1958 buf->b_dev_valid = FALSE; |
7 | 1959 else |
1960 { | |
1873 | 1961 buf->b_dev_valid = TRUE; |
7 | 1962 buf->b_dev = st.st_dev; |
1963 buf->b_ino = st.st_ino; | |
1964 } | |
1965 #endif | |
1966 buf->b_u_synced = TRUE; | |
1967 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; | |
42 | 1968 if (flags & BLN_DUMMY) |
1969 buf->b_flags |= BF_DUMMY; | |
7 | 1970 buf_clear_file(buf); |
1971 clrallmarks(buf); /* clear marks */ | |
1972 fmarks_check_names(buf); /* check file marks for this file */ | |
1973 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */ | |
1974 #ifdef FEAT_AUTOCMD | |
1975 if (!(flags & BLN_DUMMY)) | |
1976 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1977 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1978 |
6639 | 1979 /* Tricky: these autocommands may change the buffer list. They could |
1980 * also split the window with re-using the one empty buffer. This may | |
1981 * result in unexpectedly losing the empty buffer. */ | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1982 set_bufref(&bufref, buf); |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1983 if (apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1984 && !bufref_valid(&bufref)) |
5816 | 1985 return NULL; |
7 | 1986 if (flags & BLN_LISTED) |
5816 | 1987 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1988 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1989 && !bufref_valid(&bufref)) |
5816 | 1990 return NULL; |
1991 } | |
7 | 1992 # ifdef FEAT_EVAL |
36 | 1993 if (aborting()) /* autocmds may abort script processing */ |
7 | 1994 return NULL; |
1995 # endif | |
1996 } | |
1997 #endif | |
1998 | |
1999 return buf; | |
2000 } | |
2001 | |
2002 /* | |
2003 * Free the memory for the options of a buffer. | |
2004 * If "free_p_ff" is TRUE also free 'fileformat', 'buftype' and | |
2005 * 'fileencoding'. | |
2006 */ | |
2007 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2008 free_buf_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2009 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2010 int free_p_ff) |
7 | 2011 { |
2012 if (free_p_ff) | |
2013 { | |
2014 #ifdef FEAT_MBYTE | |
2015 clear_string_option(&buf->b_p_fenc); | |
2016 #endif | |
2017 clear_string_option(&buf->b_p_ff); | |
2018 #ifdef FEAT_QUICKFIX | |
2019 clear_string_option(&buf->b_p_bh); | |
2020 clear_string_option(&buf->b_p_bt); | |
2021 #endif | |
2022 } | |
2023 #ifdef FEAT_FIND_ID | |
2024 clear_string_option(&buf->b_p_def); | |
2025 clear_string_option(&buf->b_p_inc); | |
2026 # ifdef FEAT_EVAL | |
2027 clear_string_option(&buf->b_p_inex); | |
2028 # endif | |
2029 #endif | |
2030 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) | |
2031 clear_string_option(&buf->b_p_inde); | |
2032 clear_string_option(&buf->b_p_indk); | |
2033 #endif | |
788 | 2034 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
2035 clear_string_option(&buf->b_p_bexpr); | |
2036 #endif | |
2360
d8e4b27cef80
Change 'cryptmethod' from a number to a string option. Make it global-local.
Bram Moolenaar <bram@vim.org>
parents:
2329
diff
changeset
|
2037 #if defined(FEAT_CRYPT) |
d8e4b27cef80
Change 'cryptmethod' from a number to a string option. Make it global-local.
Bram Moolenaar <bram@vim.org>
parents:
2329
diff
changeset
|
2038 clear_string_option(&buf->b_p_cm); |
d8e4b27cef80
Change 'cryptmethod' from a number to a string option. Make it global-local.
Bram Moolenaar <bram@vim.org>
parents:
2329
diff
changeset
|
2039 #endif |
667 | 2040 #if defined(FEAT_EVAL) |
2041 clear_string_option(&buf->b_p_fex); | |
2042 #endif | |
7 | 2043 #ifdef FEAT_CRYPT |
2044 clear_string_option(&buf->b_p_key); | |
2045 #endif | |
2046 clear_string_option(&buf->b_p_kp); | |
2047 clear_string_option(&buf->b_p_mps); | |
2048 clear_string_option(&buf->b_p_fo); | |
41 | 2049 clear_string_option(&buf->b_p_flp); |
7 | 2050 clear_string_option(&buf->b_p_isk); |
2051 #ifdef FEAT_KEYMAP | |
2052 clear_string_option(&buf->b_p_keymap); | |
2053 ga_clear(&buf->b_kmap_ga); | |
2054 #endif | |
2055 #ifdef FEAT_COMMENTS | |
2056 clear_string_option(&buf->b_p_com); | |
2057 #endif | |
2058 #ifdef FEAT_FOLDING | |
2059 clear_string_option(&buf->b_p_cms); | |
2060 #endif | |
2061 clear_string_option(&buf->b_p_nf); | |
2062 #ifdef FEAT_SYN_HL | |
2063 clear_string_option(&buf->b_p_syn); | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7572
diff
changeset
|
2064 clear_string_option(&buf->b_s.b_syn_isk); |
737 | 2065 #endif |
2066 #ifdef FEAT_SPELL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2067 clear_string_option(&buf->b_s.b_p_spc); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2068 clear_string_option(&buf->b_s.b_p_spf); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4795
diff
changeset
|
2069 vim_regfree(buf->b_s.b_cap_prog); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2070 buf->b_s.b_cap_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2071 clear_string_option(&buf->b_s.b_p_spl); |
7 | 2072 #endif |
2073 #ifdef FEAT_SEARCHPATH | |
2074 clear_string_option(&buf->b_p_sua); | |
2075 #endif | |
2076 #ifdef FEAT_AUTOCMD | |
2077 clear_string_option(&buf->b_p_ft); | |
2078 #endif | |
2079 #ifdef FEAT_CINDENT | |
2080 clear_string_option(&buf->b_p_cink); | |
2081 clear_string_option(&buf->b_p_cino); | |
2082 #endif | |
2083 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) | |
2084 clear_string_option(&buf->b_p_cinw); | |
2085 #endif | |
2086 #ifdef FEAT_INS_EXPAND | |
2087 clear_string_option(&buf->b_p_cpt); | |
2088 #endif | |
12 | 2089 #ifdef FEAT_COMPL_FUNC |
2090 clear_string_option(&buf->b_p_cfu); | |
502 | 2091 clear_string_option(&buf->b_p_ofu); |
12 | 2092 #endif |
7 | 2093 #ifdef FEAT_QUICKFIX |
2094 clear_string_option(&buf->b_p_gp); | |
2095 clear_string_option(&buf->b_p_mp); | |
2096 clear_string_option(&buf->b_p_efm); | |
2097 #endif | |
2098 clear_string_option(&buf->b_p_ep); | |
2099 clear_string_option(&buf->b_p_path); | |
2100 clear_string_option(&buf->b_p_tags); | |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
7174
diff
changeset
|
2101 clear_string_option(&buf->b_p_tc); |
7 | 2102 #ifdef FEAT_INS_EXPAND |
2103 clear_string_option(&buf->b_p_dict); | |
2104 clear_string_option(&buf->b_p_tsr); | |
2105 #endif | |
12 | 2106 #ifdef FEAT_TEXTOBJ |
2107 clear_string_option(&buf->b_p_qe); | |
2108 #endif | |
7 | 2109 buf->b_p_ar = -1; |
5446 | 2110 buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
5712 | 2111 #ifdef FEAT_LISP |
2112 clear_string_option(&buf->b_p_lw); | |
2113 #endif | |
6243 | 2114 clear_string_option(&buf->b_p_bkc); |
7 | 2115 } |
2116 | |
2117 /* | |
2118 * get alternate file n | |
2119 * set linenr to lnum or altfpos.lnum if lnum == 0 | |
2120 * also set cursor column to altfpos.col if 'startofline' is not set. | |
2121 * if (options & GETF_SETMARK) call setpcmark() | |
2122 * if (options & GETF_ALT) we are jumping to an alternate file. | |
2123 * if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping | |
2124 * | |
2125 * return FAIL for failure, OK for success | |
2126 */ | |
2127 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2128 buflist_getfile( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2129 int n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2130 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2131 int options, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2132 int forceit) |
7 | 2133 { |
2134 buf_T *buf; | |
2135 #ifdef FEAT_WINDOWS | |
2136 win_T *wp = NULL; | |
2137 #endif | |
2138 pos_T *fpos; | |
2139 colnr_T col; | |
2140 | |
2141 buf = buflist_findnr(n); | |
2142 if (buf == NULL) | |
2143 { | |
2144 if ((options & GETF_ALT) && n == 0) | |
2145 EMSG(_(e_noalt)); | |
2146 else | |
2147 EMSGN(_("E92: Buffer %ld not found"), n); | |
2148 return FAIL; | |
2149 } | |
2150 | |
2151 /* if alternate file is the current buffer, nothing to do */ | |
2152 if (buf == curbuf) | |
2153 return OK; | |
2154 | |
633 | 2155 if (text_locked()) |
631 | 2156 { |
633 | 2157 text_locked_msg(); |
7 | 2158 return FAIL; |
631 | 2159 } |
819 | 2160 #ifdef FEAT_AUTOCMD |
2161 if (curbuf_locked()) | |
2162 return FAIL; | |
2163 #endif | |
7 | 2164 |
2165 /* altfpos may be changed by getfile(), get it now */ | |
2166 if (lnum == 0) | |
2167 { | |
2168 fpos = buflist_findfpos(buf); | |
2169 lnum = fpos->lnum; | |
2170 col = fpos->col; | |
2171 } | |
2172 else | |
2173 col = 0; | |
2174 | |
2175 #ifdef FEAT_WINDOWS | |
2176 if (options & GETF_SWITCH) | |
2177 { | |
1618 | 2178 /* If 'switchbuf' contains "useopen": jump to first window containing |
2179 * "buf" if one exists */ | |
2180 if (swb_flags & SWB_USEOPEN) | |
7 | 2181 wp = buf_jump_open_win(buf); |
6843 | 2182 |
4352 | 2183 /* If 'switchbuf' contains "usetab": jump to first window in any tab |
1618 | 2184 * page containing "buf" if one exists */ |
2185 if (wp == NULL && (swb_flags & SWB_USETAB)) | |
825 | 2186 wp = buf_jump_open_tab(buf); |
6843 | 2187 |
2188 /* If 'switchbuf' contains "split", "vsplit" or "newtab" and the | |
2189 * current buffer isn't empty: open new tab or window */ | |
2190 if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB)) | |
2191 && !bufempty()) | |
7 | 2192 { |
6843 | 2193 if (swb_flags & SWB_NEWTAB) |
1618 | 2194 tabpage_new(); |
6843 | 2195 else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0) |
2196 == FAIL) | |
7 | 2197 return FAIL; |
2583 | 2198 RESET_BINDING(curwin); |
7 | 2199 } |
2200 } | |
2201 #endif | |
2202 | |
2203 ++RedrawingDisabled; | |
2204 if (getfile(buf->b_fnum, NULL, NULL, (options & GETF_SETMARK), | |
2205 lnum, forceit) <= 0) | |
2206 { | |
2207 --RedrawingDisabled; | |
2208 | |
2209 /* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */ | |
2210 if (!p_sol && col != 0) | |
2211 { | |
2212 curwin->w_cursor.col = col; | |
2213 check_cursor_col(); | |
2214 #ifdef FEAT_VIRTUALEDIT | |
2215 curwin->w_cursor.coladd = 0; | |
2216 #endif | |
2217 curwin->w_set_curswant = TRUE; | |
2218 } | |
2219 return OK; | |
2220 } | |
2221 --RedrawingDisabled; | |
2222 return FAIL; | |
2223 } | |
2224 | |
2225 /* | |
2226 * go to the last know line number for the current buffer | |
2227 */ | |
2228 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2229 buflist_getfpos(void) |
7 | 2230 { |
2231 pos_T *fpos; | |
2232 | |
2233 fpos = buflist_findfpos(curbuf); | |
2234 | |
2235 curwin->w_cursor.lnum = fpos->lnum; | |
2236 check_cursor_lnum(); | |
2237 | |
2238 if (p_sol) | |
2239 curwin->w_cursor.col = 0; | |
2240 else | |
2241 { | |
2242 curwin->w_cursor.col = fpos->col; | |
2243 check_cursor_col(); | |
2244 #ifdef FEAT_VIRTUALEDIT | |
2245 curwin->w_cursor.coladd = 0; | |
2246 #endif | |
2247 curwin->w_set_curswant = TRUE; | |
2248 } | |
2249 } | |
2250 | |
42 | 2251 #if defined(FEAT_QUICKFIX) || defined(FEAT_EVAL) || defined(PROTO) |
2252 /* | |
2253 * Find file in buffer list by name (it has to be for the current window). | |
2254 * Returns NULL if not found. | |
2255 */ | |
2256 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2257 buflist_findname_exp(char_u *fname) |
42 | 2258 { |
2259 char_u *ffname; | |
2260 buf_T *buf = NULL; | |
2261 | |
2262 /* First make the name into a full path name */ | |
2263 ffname = FullName_save(fname, | |
2264 #ifdef UNIX | |
2265 TRUE /* force expansion, get rid of symbolic links */ | |
2266 #else | |
2267 FALSE | |
2268 #endif | |
2269 ); | |
2270 if (ffname != NULL) | |
2271 { | |
2272 buf = buflist_findname(ffname); | |
2273 vim_free(ffname); | |
2274 } | |
2275 return buf; | |
2276 } | |
2277 #endif | |
2278 | |
7 | 2279 /* |
2280 * Find file in buffer list by name (it has to be for the current window). | |
2281 * "ffname" must have a full path. | |
42 | 2282 * Skips dummy buffers. |
2283 * Returns NULL if not found. | |
7 | 2284 */ |
2285 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2286 buflist_findname(char_u *ffname) |
7 | 2287 { |
2288 #ifdef UNIX | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2289 stat_T st; |
7 | 2290 |
2291 if (mch_stat((char *)ffname, &st) < 0) | |
2292 st.st_dev = (dev_T)-1; | |
2293 return buflist_findname_stat(ffname, &st); | |
2294 } | |
2295 | |
2296 /* | |
2297 * Same as buflist_findname(), but pass the stat structure to avoid getting it | |
2298 * twice for the same file. | |
42 | 2299 * Returns NULL if not found. |
7 | 2300 */ |
2301 static buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2302 buflist_findname_stat( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2303 char_u *ffname, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2304 stat_T *stp) |
7 | 2305 { |
2306 #endif | |
2307 buf_T *buf; | |
2308 | |
9485
c16e207dc465
commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
2309 /* Start at the last buffer, expect to find a match sooner. */ |
c16e207dc465
commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
2310 for (buf = lastbuf; buf != NULL; buf = buf->b_prev) |
42 | 2311 if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname |
7 | 2312 #ifdef UNIX |
2313 , stp | |
2314 #endif | |
2315 )) | |
2316 return buf; | |
2317 return NULL; | |
2318 } | |
2319 | |
4236 | 2320 #if defined(FEAT_LISTCMDS) || defined(FEAT_EVAL) || defined(FEAT_PERL) \ |
2321 || defined(PROTO) | |
7 | 2322 /* |
2323 * Find file in buffer list by a regexp pattern. | |
2324 * Return fnum of the found buffer. | |
2325 * Return < 0 for error. | |
2326 */ | |
2327 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2328 buflist_findpat( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2329 char_u *pattern, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2330 char_u *pattern_end, /* pointer to first char after pattern */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2331 int unlisted, /* find unlisted buffers */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2332 int diffmode UNUSED, /* find diff-mode buffers only */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2333 int curtab_only) /* find buffers in current tab only */ |
7 | 2334 { |
2335 buf_T *buf; | |
2336 int match = -1; | |
2337 int find_listed; | |
2338 char_u *pat; | |
2339 char_u *patend; | |
2340 int attempt; | |
2341 char_u *p; | |
2342 int toggledollar; | |
2343 | |
2344 if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) | |
2345 { | |
2346 if (*pattern == '%') | |
2347 match = curbuf->b_fnum; | |
2348 else | |
2349 match = curwin->w_alt_fnum; | |
2350 #ifdef FEAT_DIFF | |
2351 if (diffmode && !diff_mode_buf(buflist_findnr(match))) | |
2352 match = -1; | |
2353 #endif | |
2354 } | |
2355 | |
2356 /* | |
2357 * Try four ways of matching a listed buffer: | |
2358 * attempt == 0: without '^' or '$' (at any position) | |
1187 | 2359 * attempt == 1: with '^' at start (only at position 0) |
7 | 2360 * attempt == 2: with '$' at end (only match at end) |
2361 * attempt == 3: with '^' at start and '$' at end (only full match) | |
2362 * Repeat this for finding an unlisted buffer if there was no matching | |
2363 * listed buffer. | |
2364 */ | |
2365 else | |
2366 { | |
2367 pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, FALSE); | |
2368 if (pat == NULL) | |
2369 return -1; | |
2370 patend = pat + STRLEN(pat) - 1; | |
2371 toggledollar = (patend > pat && *patend == '$'); | |
2372 | |
2373 /* First try finding a listed buffer. If not found and "unlisted" | |
2374 * is TRUE, try finding an unlisted buffer. */ | |
2375 find_listed = TRUE; | |
2376 for (;;) | |
2377 { | |
2378 for (attempt = 0; attempt <= 3; ++attempt) | |
2379 { | |
6375 | 2380 regmatch_T regmatch; |
2381 | |
7 | 2382 /* may add '^' and '$' */ |
2383 if (toggledollar) | |
2384 *patend = (attempt < 2) ? NUL : '$'; /* add/remove '$' */ | |
2385 p = pat; | |
2386 if (*p == '^' && !(attempt & 1)) /* add/remove '^' */ | |
2387 ++p; | |
6375 | 2388 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); |
2389 if (regmatch.regprog == NULL) | |
7 | 2390 { |
2391 vim_free(pat); | |
2392 return -1; | |
2393 } | |
2394 | |
9485
c16e207dc465
commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
2395 for (buf = lastbuf; buf != NULL; buf = buf->b_prev) |
7 | 2396 if (buf->b_p_bl == find_listed |
2397 #ifdef FEAT_DIFF | |
2398 && (!diffmode || diff_mode_buf(buf)) | |
2399 #endif | |
6375 | 2400 && buflist_match(®match, buf, FALSE) != NULL) |
7 | 2401 { |
4236 | 2402 if (curtab_only) |
2403 { | |
2404 /* Ignore the match if the buffer is not open in | |
2405 * the current tab. */ | |
2406 #ifdef FEAT_WINDOWS | |
2407 win_T *wp; | |
2408 | |
2409 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
2410 if (wp->w_buffer == buf) | |
2411 break; | |
2412 if (wp == NULL) | |
2413 continue; | |
2414 #else | |
2415 if (curwin->w_buffer != buf) | |
2416 continue; | |
2417 #endif | |
2418 } | |
7 | 2419 if (match >= 0) /* already found a match */ |
2420 { | |
2421 match = -2; | |
2422 break; | |
2423 } | |
2424 match = buf->b_fnum; /* remember first match */ | |
2425 } | |
2426 | |
6375 | 2427 vim_regfree(regmatch.regprog); |
7 | 2428 if (match >= 0) /* found one match */ |
2429 break; | |
2430 } | |
2431 | |
2432 /* Only search for unlisted buffers if there was no match with | |
2433 * a listed buffer. */ | |
2434 if (!unlisted || !find_listed || match != -1) | |
2435 break; | |
2436 find_listed = FALSE; | |
2437 } | |
2438 | |
2439 vim_free(pat); | |
2440 } | |
2441 | |
2442 if (match == -2) | |
2443 EMSG2(_("E93: More than one match for %s"), pattern); | |
2444 else if (match < 0) | |
2445 EMSG2(_("E94: No matching buffer for %s"), pattern); | |
2446 return match; | |
2447 } | |
2448 #endif | |
2449 | |
2450 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
2451 | |
2452 /* | |
2453 * Find all buffer names that match. | |
2454 * For command line expansion of ":buf" and ":sbuf". | |
2455 * Return OK if matches found, FAIL otherwise. | |
2456 */ | |
2457 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2458 ExpandBufnames( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2459 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2460 int *num_file, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2461 char_u ***file, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2462 int options) |
7 | 2463 { |
2464 int count = 0; | |
2465 buf_T *buf; | |
2466 int round; | |
2467 char_u *p; | |
2468 int attempt; | |
170 | 2469 char_u *patc; |
7 | 2470 |
2471 *num_file = 0; /* return values in case of FAIL */ | |
2472 *file = NULL; | |
2473 | |
170 | 2474 /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ |
2475 if (*pat == '^') | |
2476 { | |
2477 patc = alloc((unsigned)STRLEN(pat) + 11); | |
2478 if (patc == NULL) | |
2479 return FAIL; | |
2480 STRCPY(patc, "\\(^\\|[\\/]\\)"); | |
2481 STRCPY(patc + 11, pat + 1); | |
2482 } | |
2483 else | |
2484 patc = pat; | |
2485 | |
7 | 2486 /* |
170 | 2487 * attempt == 0: try match with '\<', match at start of word |
267 | 2488 * attempt == 1: try match without '\<', match anywhere |
7 | 2489 */ |
267 | 2490 for (attempt = 0; attempt <= 1; ++attempt) |
7 | 2491 { |
6375 | 2492 regmatch_T regmatch; |
2493 | |
267 | 2494 if (attempt > 0 && patc == pat) |
170 | 2495 break; /* there was no anchor, no need to try again */ |
6375 | 2496 regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); |
2497 if (regmatch.regprog == NULL) | |
7 | 2498 { |
170 | 2499 if (patc != pat) |
2500 vim_free(patc); | |
2501 return FAIL; | |
7 | 2502 } |
2503 | |
2504 /* | |
2505 * round == 1: Count the matches. | |
2506 * round == 2: Build the array to keep the matches. | |
2507 */ | |
2508 for (round = 1; round <= 2; ++round) | |
2509 { | |
2510 count = 0; | |
2511 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
2512 { | |
2513 if (!buf->b_p_bl) /* skip unlisted buffers */ | |
2514 continue; | |
6375 | 2515 p = buflist_match(®match, buf, p_wic); |
7 | 2516 if (p != NULL) |
2517 { | |
2518 if (round == 1) | |
2519 ++count; | |
2520 else | |
2521 { | |
2522 if (options & WILD_HOME_REPLACE) | |
2523 p = home_replace_save(buf, p); | |
2524 else | |
2525 p = vim_strsave(p); | |
2526 (*file)[count++] = p; | |
2527 } | |
2528 } | |
2529 } | |
2530 if (count == 0) /* no match found, break here */ | |
2531 break; | |
2532 if (round == 1) | |
2533 { | |
2534 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
2535 if (*file == NULL) | |
2536 { | |
6375 | 2537 vim_regfree(regmatch.regprog); |
170 | 2538 if (patc != pat) |
2539 vim_free(patc); | |
7 | 2540 return FAIL; |
2541 } | |
2542 } | |
2543 } | |
6375 | 2544 vim_regfree(regmatch.regprog); |
7 | 2545 if (count) /* match(es) found, break here */ |
2546 break; | |
2547 } | |
2548 | |
170 | 2549 if (patc != pat) |
2550 vim_free(patc); | |
2551 | |
7 | 2552 *num_file = count; |
2553 return (count == 0 ? FAIL : OK); | |
2554 } | |
2555 | |
2556 #endif /* FEAT_CMDL_COMPL */ | |
2557 | |
2558 #ifdef HAVE_BUFLIST_MATCH | |
2559 /* | |
2560 * Check for a match on the file name for buffer "buf" with regprog "prog". | |
2561 */ | |
2562 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2563 buflist_match( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2564 regmatch_T *rmp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2565 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2566 int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ |
7 | 2567 { |
2568 char_u *match; | |
2569 | |
2570 /* First try the short file name, then the long file name. */ | |
6375 | 2571 match = fname_match(rmp, buf->b_sfname, ignore_case); |
7 | 2572 if (match == NULL) |
6375 | 2573 match = fname_match(rmp, buf->b_ffname, ignore_case); |
7 | 2574 |
2575 return match; | |
2576 } | |
2577 | |
2578 /* | |
2579 * Try matching the regexp in "prog" with file name "name". | |
2580 * Return "name" when there is a match, NULL when not. | |
2581 */ | |
2582 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2583 fname_match( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2584 regmatch_T *rmp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2585 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2586 int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ |
7 | 2587 { |
2588 char_u *match = NULL; | |
2589 char_u *p; | |
2590 | |
2591 if (name != NULL) | |
2592 { | |
6241 | 2593 /* Ignore case when 'fileignorecase' or the argument is set. */ |
6375 | 2594 rmp->rm_ic = p_fic || ignore_case; |
2595 if (vim_regexec(rmp, name, (colnr_T)0)) | |
7 | 2596 match = name; |
2597 else | |
2598 { | |
2599 /* Replace $(HOME) with '~' and try matching again. */ | |
2600 p = home_replace_save(NULL, name); | |
6375 | 2601 if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) |
7 | 2602 match = name; |
2603 vim_free(p); | |
2604 } | |
2605 } | |
2606 | |
2607 return match; | |
2608 } | |
2609 #endif | |
2610 | |
2611 /* | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2612 * Find a file in the buffer list by buffer number. |
7 | 2613 */ |
2614 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2615 buflist_findnr(int nr) |
7 | 2616 { |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2617 char_u key[VIM_SIZEOF_INT * 2 + 1]; |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2618 hashitem_T *hi; |
7 | 2619 |
2620 if (nr == 0) | |
2621 nr = curwin->w_alt_fnum; | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2622 sprintf((char *)key, "%x", nr); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2623 hi = hash_find(&buf_hashtab, key); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2624 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2625 if (!HASHITEM_EMPTY(hi)) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2626 return (buf_T *)(hi->hi_key |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2627 - ((unsigned)(curbuf->b_key - (char_u *)curbuf))); |
7 | 2628 return NULL; |
2629 } | |
2630 | |
2631 /* | |
2632 * Get name of file 'n' in the buffer list. | |
2633 * When the file has no name an empty string is returned. | |
2634 * home_replace() is used to shorten the file name (used for marks). | |
2635 * Returns a pointer to allocated memory, of NULL when failed. | |
2636 */ | |
2637 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2638 buflist_nr2name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2639 int n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2640 int fullname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2641 int helptail) /* for help buffers return tail only */ |
7 | 2642 { |
2643 buf_T *buf; | |
2644 | |
2645 buf = buflist_findnr(n); | |
2646 if (buf == NULL) | |
2647 return NULL; | |
2648 return home_replace_save(helptail ? buf : NULL, | |
2649 fullname ? buf->b_ffname : buf->b_fname); | |
2650 } | |
2651 | |
2652 /* | |
2653 * Set the "lnum" and "col" for the buffer "buf" and the current window. | |
2654 * When "copy_options" is TRUE save the local window option values. | |
2655 * When "lnum" is 0 only do the options. | |
2656 */ | |
2657 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2658 buflist_setfpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2659 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2660 win_T *win, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2661 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2662 colnr_T col, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2663 int copy_options) |
7 | 2664 { |
2665 wininfo_T *wip; | |
2666 | |
2667 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | |
2668 if (wip->wi_win == win) | |
2669 break; | |
2670 if (wip == NULL) | |
2671 { | |
2672 /* allocate a new entry */ | |
2673 wip = (wininfo_T *)alloc_clear((unsigned)sizeof(wininfo_T)); | |
2674 if (wip == NULL) | |
2675 return; | |
2676 wip->wi_win = win; | |
2677 if (lnum == 0) /* set lnum even when it's 0 */ | |
2678 lnum = 1; | |
2679 } | |
2680 else | |
2681 { | |
2682 /* remove the entry from the list */ | |
2683 if (wip->wi_prev) | |
2684 wip->wi_prev->wi_next = wip->wi_next; | |
2685 else | |
2686 buf->b_wininfo = wip->wi_next; | |
2687 if (wip->wi_next) | |
2688 wip->wi_next->wi_prev = wip->wi_prev; | |
2689 if (copy_options && wip->wi_optset) | |
2690 { | |
2691 clear_winopt(&wip->wi_opt); | |
2692 #ifdef FEAT_FOLDING | |
2693 deleteFoldRecurse(&wip->wi_folds); | |
2694 #endif | |
2695 } | |
2696 } | |
2697 if (lnum != 0) | |
2698 { | |
2699 wip->wi_fpos.lnum = lnum; | |
2700 wip->wi_fpos.col = col; | |
2701 } | |
2702 if (copy_options) | |
2703 { | |
2704 /* Save the window-specific option values. */ | |
2705 copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); | |
2706 #ifdef FEAT_FOLDING | |
2707 wip->wi_fold_manual = win->w_fold_manual; | |
2708 cloneFoldGrowArray(&win->w_folds, &wip->wi_folds); | |
2709 #endif | |
2710 wip->wi_optset = TRUE; | |
2711 } | |
2712 | |
2713 /* insert the entry in front of the list */ | |
2714 wip->wi_next = buf->b_wininfo; | |
2715 buf->b_wininfo = wip; | |
2716 wip->wi_prev = NULL; | |
2717 if (wip->wi_next) | |
2718 wip->wi_next->wi_prev = wip; | |
2719 | |
2720 return; | |
2721 } | |
2722 | |
1743 | 2723 #ifdef FEAT_DIFF |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
2724 static int wininfo_other_tab_diff(wininfo_T *wip); |
1743 | 2725 |
2726 /* | |
2727 * Return TRUE when "wip" has 'diff' set and the diff is only for another tab | |
2728 * page. That's because a diff is local to a tab page. | |
2729 */ | |
2730 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2731 wininfo_other_tab_diff(wininfo_T *wip) |
1743 | 2732 { |
2733 win_T *wp; | |
2734 | |
2735 if (wip->wi_opt.wo_diff) | |
2736 { | |
2737 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
2738 /* return FALSE when it's a window in the current tab page, thus | |
2739 * the buffer was in diff mode here */ | |
2740 if (wip->wi_win == wp) | |
2741 return FALSE; | |
2742 return TRUE; | |
2743 } | |
2744 return FALSE; | |
2745 } | |
2746 #endif | |
2747 | |
7 | 2748 /* |
2749 * Find info for the current window in buffer "buf". | |
2750 * If not found, return the info for the most recently used window. | |
1743 | 2751 * When "skip_diff_buffer" is TRUE avoid windows with 'diff' set that is in |
2752 * another tab page. | |
7 | 2753 * Returns NULL when there isn't any info. |
2754 */ | |
2755 static wininfo_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2756 find_wininfo( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2757 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2758 int skip_diff_buffer UNUSED) |
7 | 2759 { |
2760 wininfo_T *wip; | |
2761 | |
2762 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | |
1743 | 2763 if (wip->wi_win == curwin |
2764 #ifdef FEAT_DIFF | |
2765 && (!skip_diff_buffer || !wininfo_other_tab_diff(wip)) | |
2766 #endif | |
2767 ) | |
7 | 2768 break; |
1743 | 2769 |
2770 /* If no wininfo for curwin, use the first in the list (that doesn't have | |
2771 * 'diff' set and is in another tab page). */ | |
2772 if (wip == NULL) | |
2773 { | |
2774 #ifdef FEAT_DIFF | |
2775 if (skip_diff_buffer) | |
2776 { | |
2777 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | |
2778 if (!wininfo_other_tab_diff(wip)) | |
2779 break; | |
2780 } | |
2781 else | |
2782 #endif | |
2783 wip = buf->b_wininfo; | |
2784 } | |
7 | 2785 return wip; |
2786 } | |
2787 | |
2788 /* | |
2789 * Reset the local window options to the values last used in this window. | |
2790 * If the buffer wasn't used in this window before, use the values from | |
2791 * the most recently used window. If the values were never set, use the | |
2792 * global values for the window. | |
2793 */ | |
2794 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2795 get_winopts(buf_T *buf) |
7 | 2796 { |
2797 wininfo_T *wip; | |
2798 | |
2799 clear_winopt(&curwin->w_onebuf_opt); | |
2800 #ifdef FEAT_FOLDING | |
2801 clearFolding(curwin); | |
2802 #endif | |
2803 | |
1743 | 2804 wip = find_wininfo(buf, TRUE); |
7 | 2805 if (wip != NULL && wip->wi_optset) |
2806 { | |
2807 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); | |
2808 #ifdef FEAT_FOLDING | |
2809 curwin->w_fold_manual = wip->wi_fold_manual; | |
2810 curwin->w_foldinvalid = TRUE; | |
2811 cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds); | |
2812 #endif | |
2813 } | |
2814 else | |
2815 copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt); | |
2816 | |
2817 #ifdef FEAT_FOLDING | |
2818 /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ | |
2819 if (p_fdls >= 0) | |
2820 curwin->w_p_fdl = p_fdls; | |
2821 #endif | |
2799 | 2822 #ifdef FEAT_SYN_HL |
2823 check_colorcolumn(curwin); | |
2824 #endif | |
7 | 2825 } |
2826 | |
2827 /* | |
2828 * Find the position (lnum and col) for the buffer 'buf' for the current | |
2829 * window. | |
2830 * Returns a pointer to no_position if no position is found. | |
2831 */ | |
2832 pos_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2833 buflist_findfpos(buf_T *buf) |
7 | 2834 { |
2835 wininfo_T *wip; | |
1869 | 2836 static pos_T no_position = INIT_POS_T(1, 0, 0); |
7 | 2837 |
1743 | 2838 wip = find_wininfo(buf, FALSE); |
7 | 2839 if (wip != NULL) |
2840 return &(wip->wi_fpos); | |
2841 else | |
2842 return &no_position; | |
2843 } | |
2844 | |
2845 /* | |
2846 * Find the lnum for the buffer 'buf' for the current window. | |
2847 */ | |
2848 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2849 buflist_findlnum(buf_T *buf) |
7 | 2850 { |
2851 return buflist_findfpos(buf)->lnum; | |
2852 } | |
2853 | |
2854 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
2855 /* | |
2856 * List all know file names (for :files and :buffers command). | |
2857 */ | |
2858 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2859 buflist_list(exarg_T *eap) |
7 | 2860 { |
2861 buf_T *buf; | |
2862 int len; | |
2863 int i; | |
2864 | |
2865 for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) | |
2866 { | |
2867 /* skip unlisted buffers, unless ! was used */ | |
6945 | 2868 if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) |
2869 || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) | |
2870 || (vim_strchr(eap->arg, '+') | |
2871 && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf))) | |
2872 || (vim_strchr(eap->arg, 'a') | |
2873 && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0)) | |
2874 || (vim_strchr(eap->arg, 'h') | |
2875 && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0)) | |
2876 || (vim_strchr(eap->arg, '-') && buf->b_p_ma) | |
2877 || (vim_strchr(eap->arg, '=') && !buf->b_p_ro) | |
2878 || (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR)) | |
2879 || (vim_strchr(eap->arg, '%') && buf != curbuf) | |
2880 || (vim_strchr(eap->arg, '#') | |
2881 && (buf == curbuf || curwin->w_alt_fnum != buf->b_fnum))) | |
7 | 2882 continue; |
2883 msg_putchar('\n'); | |
2884 if (buf_spname(buf) != NULL) | |
3839 | 2885 vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
7 | 2886 else |
2887 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
2888 | |
302 | 2889 len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"", |
7 | 2890 buf->b_fnum, |
2891 buf->b_p_bl ? ' ' : 'u', | |
2892 buf == curbuf ? '%' : | |
2893 (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '), | |
2894 buf->b_ml.ml_mfp == NULL ? ' ' : | |
2895 (buf->b_nwindows == 0 ? 'h' : 'a'), | |
2896 !buf->b_p_ma ? '-' : (buf->b_p_ro ? '=' : ' '), | |
2897 (buf->b_flags & BF_READERR) ? 'x' | |
300 | 2898 : (bufIsChanged(buf) ? '+' : ' '), |
2899 NameBuff); | |
7572
992fe73d4ee6
commit https://github.com/vim/vim/commit/507edf63df75fe228e0f76b845b58d60266e65d8
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
2900 if (len > IOSIZE - 20) |
992fe73d4ee6
commit https://github.com/vim/vim/commit/507edf63df75fe228e0f76b845b58d60266e65d8
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
2901 len = IOSIZE - 20; |
7 | 2902 |
2903 /* put "line 999" in column 40 or after the file name */ | |
2904 i = 40 - vim_strsize(IObuff); | |
2905 do | |
2906 { | |
2907 IObuff[len++] = ' '; | |
2908 } while (--i > 0 && len < IOSIZE - 18); | |
1869 | 2909 vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), |
2910 _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum | |
272 | 2911 : (long)buflist_findlnum(buf)); |
7 | 2912 msg_outtrans(IObuff); |
2913 out_flush(); /* output one line at a time */ | |
2914 ui_breakcheck(); | |
2915 } | |
2916 } | |
2917 #endif | |
2918 | |
2919 /* | |
2920 * Get file name and line number for file 'fnum'. | |
2921 * Used by DoOneCmd() for translating '%' and '#'. | |
2922 * Used by insert_reg() and cmdline_paste() for '#' register. | |
2923 * Return FAIL if not found, OK for success. | |
2924 */ | |
2925 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2926 buflist_name_nr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2927 int fnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2928 char_u **fname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2929 linenr_T *lnum) |
7 | 2930 { |
2931 buf_T *buf; | |
2932 | |
2933 buf = buflist_findnr(fnum); | |
2934 if (buf == NULL || buf->b_fname == NULL) | |
2935 return FAIL; | |
2936 | |
2937 *fname = buf->b_fname; | |
2938 *lnum = buflist_findlnum(buf); | |
2939 | |
2940 return OK; | |
2941 } | |
2942 | |
2943 /* | |
2944 * Set the file name for "buf"' to 'ffname', short file name to 'sfname'. | |
2945 * The file name with the full path is also remembered, for when :cd is used. | |
2946 * Returns FAIL for failure (file name already in use by other buffer) | |
2947 * OK otherwise. | |
2948 */ | |
2949 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2950 setfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2951 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2952 char_u *ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2953 char_u *sfname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2954 int message) /* give message when buffer already exists */ |
7 | 2955 { |
42 | 2956 buf_T *obuf = NULL; |
7 | 2957 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2958 stat_T st; |
7 | 2959 #endif |
2960 | |
2961 if (ffname == NULL || *ffname == NUL) | |
2962 { | |
2963 /* Removing the name. */ | |
2964 vim_free(buf->b_ffname); | |
2965 vim_free(buf->b_sfname); | |
2966 buf->b_ffname = NULL; | |
2967 buf->b_sfname = NULL; | |
2968 #ifdef UNIX | |
2969 st.st_dev = (dev_T)-1; | |
2970 #endif | |
2971 } | |
2972 else | |
2973 { | |
2974 fname_expand(buf, &ffname, &sfname); /* will allocate ffname */ | |
2975 if (ffname == NULL) /* out of memory */ | |
2976 return FAIL; | |
2977 | |
2978 /* | |
2979 * if the file name is already used in another buffer: | |
2980 * - if the buffer is loaded, fail | |
2981 * - if the buffer is not loaded, delete it from the list | |
2982 */ | |
2983 #ifdef UNIX | |
2984 if (mch_stat((char *)ffname, &st) < 0) | |
2985 st.st_dev = (dev_T)-1; | |
42 | 2986 #endif |
2987 if (!(buf->b_flags & BF_DUMMY)) | |
2988 #ifdef UNIX | |
2989 obuf = buflist_findname_stat(ffname, &st); | |
7 | 2990 #else |
42 | 2991 obuf = buflist_findname(ffname); |
7 | 2992 #endif |
2993 if (obuf != NULL && obuf != buf) | |
2994 { | |
2995 if (obuf->b_ml.ml_mfp != NULL) /* it's loaded, fail */ | |
2996 { | |
2997 if (message) | |
2998 EMSG(_("E95: Buffer with this name already exists")); | |
2999 vim_free(ffname); | |
3000 return FAIL; | |
3001 } | |
3365 | 3002 /* delete from the list */ |
3003 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); | |
7 | 3004 } |
3005 sfname = vim_strsave(sfname); | |
3006 if (ffname == NULL || sfname == NULL) | |
3007 { | |
3008 vim_free(sfname); | |
3009 vim_free(ffname); | |
3010 return FAIL; | |
3011 } | |
3012 #ifdef USE_FNAME_CASE | |
3013 # ifdef USE_LONG_FNAME | |
3014 if (USE_LONG_FNAME) | |
3015 # endif | |
3016 fname_case(sfname, 0); /* set correct case for short file name */ | |
3017 #endif | |
3018 vim_free(buf->b_ffname); | |
3019 vim_free(buf->b_sfname); | |
3020 buf->b_ffname = ffname; | |
3021 buf->b_sfname = sfname; | |
3022 } | |
3023 buf->b_fname = buf->b_sfname; | |
3024 #ifdef UNIX | |
3025 if (st.st_dev == (dev_T)-1) | |
1873 | 3026 buf->b_dev_valid = FALSE; |
7 | 3027 else |
3028 { | |
1873 | 3029 buf->b_dev_valid = TRUE; |
7 | 3030 buf->b_dev = st.st_dev; |
3031 buf->b_ino = st.st_ino; | |
3032 } | |
3033 #endif | |
3034 | |
3035 buf->b_shortname = FALSE; | |
3036 | |
3037 buf_name_changed(buf); | |
3038 return OK; | |
3039 } | |
3040 | |
3041 /* | |
41 | 3042 * Crude way of changing the name of a buffer. Use with care! |
3043 * The name should be relative to the current directory. | |
3044 */ | |
3045 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3046 buf_set_name(int fnum, char_u *name) |
41 | 3047 { |
3048 buf_T *buf; | |
3049 | |
3050 buf = buflist_findnr(fnum); | |
3051 if (buf != NULL) | |
3052 { | |
3053 vim_free(buf->b_sfname); | |
3054 vim_free(buf->b_ffname); | |
844 | 3055 buf->b_ffname = vim_strsave(name); |
3056 buf->b_sfname = NULL; | |
3057 /* Allocate ffname and expand into full path. Also resolves .lnk | |
3058 * files on Win32. */ | |
3059 fname_expand(buf, &buf->b_ffname, &buf->b_sfname); | |
41 | 3060 buf->b_fname = buf->b_sfname; |
3061 } | |
3062 } | |
3063 | |
3064 /* | |
7 | 3065 * Take care of what needs to be done when the name of buffer "buf" has |
3066 * changed. | |
3067 */ | |
3068 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3069 buf_name_changed(buf_T *buf) |
7 | 3070 { |
3071 /* | |
3072 * If the file name changed, also change the name of the swapfile | |
3073 */ | |
3074 if (buf->b_ml.ml_mfp != NULL) | |
3075 ml_setname(buf); | |
3076 | |
3077 if (curwin->w_buffer == buf) | |
3078 check_arg_idx(curwin); /* check file name for arg list */ | |
3079 #ifdef FEAT_TITLE | |
3080 maketitle(); /* set window title */ | |
3081 #endif | |
3082 #ifdef FEAT_WINDOWS | |
3083 status_redraw_all(); /* status lines need to be redrawn */ | |
3084 #endif | |
3085 fmarks_check_names(buf); /* check named file marks */ | |
3086 ml_timestamp(buf); /* reset timestamp */ | |
3087 } | |
3088 | |
3089 /* | |
3090 * set alternate file name for current window | |
3091 * | |
3092 * Used by do_one_cmd(), do_write() and do_ecmd(). | |
3093 * Return the buffer. | |
3094 */ | |
3095 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3096 setaltfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3097 char_u *ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3098 char_u *sfname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3099 linenr_T lnum) |
7 | 3100 { |
3101 buf_T *buf; | |
3102 | |
3103 /* Create a buffer. 'buflisted' is not set if it's a new buffer */ | |
3104 buf = buflist_new(ffname, sfname, lnum, 0); | |
22 | 3105 if (buf != NULL && !cmdmod.keepalt) |
7 | 3106 curwin->w_alt_fnum = buf->b_fnum; |
3107 return buf; | |
3108 } | |
3109 | |
3110 /* | |
3111 * Get alternate file name for current window. | |
3112 * Return NULL if there isn't any, and give error message if requested. | |
3113 */ | |
3114 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3115 getaltfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3116 int errmsg) /* give error message */ |
7 | 3117 { |
3118 char_u *fname; | |
3119 linenr_T dummy; | |
3120 | |
3121 if (buflist_name_nr(0, &fname, &dummy) == FAIL) | |
3122 { | |
3123 if (errmsg) | |
3124 EMSG(_(e_noalt)); | |
3125 return NULL; | |
3126 } | |
3127 return fname; | |
3128 } | |
3129 | |
3130 /* | |
3131 * Add a file name to the buflist and return its number. | |
3132 * Uses same flags as buflist_new(), except BLN_DUMMY. | |
3133 * | |
3134 * used by qf_init(), main() and doarglist() | |
3135 */ | |
3136 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3137 buflist_add(char_u *fname, int flags) |
7 | 3138 { |
3139 buf_T *buf; | |
3140 | |
3141 buf = buflist_new(fname, NULL, (linenr_T)0, flags); | |
3142 if (buf != NULL) | |
3143 return buf->b_fnum; | |
3144 return 0; | |
3145 } | |
3146 | |
3147 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
3148 /* | |
3149 * Adjust slashes in file names. Called after 'shellslash' was set. | |
3150 */ | |
3151 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3152 buflist_slash_adjust(void) |
7 | 3153 { |
3154 buf_T *bp; | |
3155 | |
3156 for (bp = firstbuf; bp != NULL; bp = bp->b_next) | |
3157 { | |
3158 if (bp->b_ffname != NULL) | |
3159 slash_adjust(bp->b_ffname); | |
3160 if (bp->b_sfname != NULL) | |
3161 slash_adjust(bp->b_sfname); | |
3162 } | |
3163 } | |
3164 #endif | |
3165 | |
3166 /* | |
1743 | 3167 * Set alternate cursor position for the current buffer and window "win". |
7 | 3168 * Also save the local window option values. |
3169 */ | |
3170 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3171 buflist_altfpos(win_T *win) |
7 | 3172 { |
1743 | 3173 buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE); |
7 | 3174 } |
3175 | |
3176 /* | |
3177 * Return TRUE if 'ffname' is not the same file as current file. | |
3178 * Fname must have a full path (expanded by mch_FullName()). | |
3179 */ | |
3180 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3181 otherfile(char_u *ffname) |
7 | 3182 { |
3183 return otherfile_buf(curbuf, ffname | |
3184 #ifdef UNIX | |
3185 , NULL | |
3186 #endif | |
3187 ); | |
3188 } | |
3189 | |
3190 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3191 otherfile_buf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3192 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3193 char_u *ffname |
7 | 3194 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3195 , stat_T *stp |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3196 #endif |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3197 ) |
7 | 3198 { |
3199 /* no name is different */ | |
3200 if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) | |
3201 return TRUE; | |
3202 if (fnamecmp(ffname, buf->b_ffname) == 0) | |
3203 return FALSE; | |
3204 #ifdef UNIX | |
3205 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3206 stat_T st; |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3207 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3208 /* If no stat_T given, get it now */ |
7 | 3209 if (stp == NULL) |
3210 { | |
1873 | 3211 if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0) |
7 | 3212 st.st_dev = (dev_T)-1; |
3213 stp = &st; | |
3214 } | |
3215 /* Use dev/ino to check if the files are the same, even when the names | |
3216 * are different (possible with links). Still need to compare the | |
3217 * name above, for when the file doesn't exist yet. | |
3218 * Problem: The dev/ino changes when a file is deleted (and created | |
3219 * again) and remains the same when renamed/moved. We don't want to | |
3220 * mch_stat() each buffer each time, that would be too slow. Get the | |
3221 * dev/ino again when they appear to match, but not when they appear | |
3222 * to be different: Could skip a buffer when it's actually the same | |
3223 * file. */ | |
3224 if (buf_same_ino(buf, stp)) | |
3225 { | |
3226 buf_setino(buf); | |
3227 if (buf_same_ino(buf, stp)) | |
3228 return FALSE; | |
3229 } | |
3230 } | |
3231 #endif | |
3232 return TRUE; | |
3233 } | |
3234 | |
3235 #if defined(UNIX) || defined(PROTO) | |
3236 /* | |
3237 * Set inode and device number for a buffer. | |
3238 * Must always be called when b_fname is changed!. | |
3239 */ | |
3240 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3241 buf_setino(buf_T *buf) |
7 | 3242 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3243 stat_T st; |
7 | 3244 |
3245 if (buf->b_fname != NULL && mch_stat((char *)buf->b_fname, &st) >= 0) | |
3246 { | |
1873 | 3247 buf->b_dev_valid = TRUE; |
7 | 3248 buf->b_dev = st.st_dev; |
3249 buf->b_ino = st.st_ino; | |
3250 } | |
3251 else | |
1873 | 3252 buf->b_dev_valid = FALSE; |
7 | 3253 } |
3254 | |
3255 /* | |
3256 * Return TRUE if dev/ino in buffer "buf" matches with "stp". | |
3257 */ | |
3258 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3259 buf_same_ino( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3260 buf_T *buf, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3261 stat_T *stp) |
7 | 3262 { |
1873 | 3263 return (buf->b_dev_valid |
7 | 3264 && stp->st_dev == buf->b_dev |
3265 && stp->st_ino == buf->b_ino); | |
3266 } | |
3267 #endif | |
3268 | |
667 | 3269 /* |
3270 * Print info about the current buffer. | |
3271 */ | |
7 | 3272 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3273 fileinfo( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3274 int fullname, /* when non-zero print full path */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3275 int shorthelp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3276 int dont_truncate) |
7 | 3277 { |
3278 char_u *name; | |
3279 int n; | |
3280 char_u *p; | |
3281 char_u *buffer; | |
272 | 3282 size_t len; |
7 | 3283 |
3284 buffer = alloc(IOSIZE); | |
3285 if (buffer == NULL) | |
3286 return; | |
3287 | |
3288 if (fullname > 1) /* 2 CTRL-G: include buffer number */ | |
3289 { | |
1869 | 3290 vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); |
7 | 3291 p = buffer + STRLEN(buffer); |
3292 } | |
3293 else | |
3294 p = buffer; | |
3295 | |
3296 *p++ = '"'; | |
3297 if (buf_spname(curbuf) != NULL) | |
3835 | 3298 vim_strncpy(p, buf_spname(curbuf), IOSIZE - (p - buffer) - 1); |
7 | 3299 else |
3300 { | |
3301 if (!fullname && curbuf->b_fname != NULL) | |
3302 name = curbuf->b_fname; | |
3303 else | |
3304 name = curbuf->b_ffname; | |
3305 home_replace(shorthelp ? curbuf : NULL, name, p, | |
3306 (int)(IOSIZE - (p - buffer)), TRUE); | |
3307 } | |
3308 | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
3309 vim_snprintf_add((char *)buffer, IOSIZE, "\"%s%s%s%s%s%s", |
7 | 3310 curbufIsChanged() ? (shortmess(SHM_MOD) |
3311 ? " [+]" : _(" [Modified]")) : " ", | |
3312 (curbuf->b_flags & BF_NOTEDITED) | |
3313 #ifdef FEAT_QUICKFIX | |
3314 && !bt_dontwrite(curbuf) | |
3315 #endif | |
3316 ? _("[Not edited]") : "", | |
3317 (curbuf->b_flags & BF_NEW) | |
3318 #ifdef FEAT_QUICKFIX | |
3319 && !bt_dontwrite(curbuf) | |
3320 #endif | |
3321 ? _("[New file]") : "", | |
3322 (curbuf->b_flags & BF_READERR) ? _("[Read errors]") : "", | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
3323 curbuf->b_p_ro ? (shortmess(SHM_RO) ? _("[RO]") |
7 | 3324 : _("[readonly]")) : "", |
3325 (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK) | |
3326 || curbuf->b_p_ro) ? | |
3327 " " : ""); | |
3328 /* With 32 bit longs and more than 21,474,836 lines multiplying by 100 | |
3329 * causes an overflow, thus for large numbers divide instead. */ | |
3330 if (curwin->w_cursor.lnum > 1000000L) | |
3331 n = (int)(((long)curwin->w_cursor.lnum) / | |
3332 ((long)curbuf->b_ml.ml_line_count / 100L)); | |
3333 else | |
3334 n = (int)(((long)curwin->w_cursor.lnum * 100L) / | |
3335 (long)curbuf->b_ml.ml_line_count); | |
3336 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
3337 { | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
3338 vim_snprintf_add((char *)buffer, IOSIZE, "%s", _(no_lines_msg)); |
7 | 3339 } |
3340 #ifdef FEAT_CMDL_INFO | |
3341 else if (p_ru) | |
3342 { | |
3343 /* Current line and column are already on the screen -- webb */ | |
3344 if (curbuf->b_ml.ml_line_count == 1) | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
3345 vim_snprintf_add((char *)buffer, IOSIZE, _("1 line --%d%%--"), n); |
7 | 3346 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
3347 vim_snprintf_add((char *)buffer, IOSIZE, _("%ld lines --%d%%--"), |
7 | 3348 (long)curbuf->b_ml.ml_line_count, n); |
3349 } | |
3350 #endif | |
3351 else | |
3352 { | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
3353 vim_snprintf_add((char *)buffer, IOSIZE, |
7 | 3354 _("line %ld of %ld --%d%%-- col "), |
3355 (long)curwin->w_cursor.lnum, | |
3356 (long)curbuf->b_ml.ml_line_count, | |
3357 n); | |
3358 validate_virtcol(); | |
1869 | 3359 len = STRLEN(buffer); |
3360 col_print(buffer + len, IOSIZE - len, | |
7 | 3361 (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); |
3362 } | |
3363 | |
1869 | 3364 (void)append_arg_number(curwin, buffer, IOSIZE, !shortmess(SHM_FILE)); |
7 | 3365 |
3366 if (dont_truncate) | |
3367 { | |
3368 /* Temporarily set msg_scroll to avoid the message being truncated. | |
3369 * First call msg_start() to get the message in the right place. */ | |
3370 msg_start(); | |
3371 n = msg_scroll; | |
3372 msg_scroll = TRUE; | |
3373 msg(buffer); | |
3374 msg_scroll = n; | |
3375 } | |
3376 else | |
3377 { | |
3378 p = msg_trunc_attr(buffer, FALSE, 0); | |
3379 if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) | |
3380 /* Need to repeat the message after redrawing when: | |
3381 * - When restart_edit is set (otherwise there will be a delay | |
3382 * before redrawing). | |
3383 * - When the screen was scrolled but there is no wait-return | |
3384 * prompt. */ | |
678 | 3385 set_keep_msg(p, 0); |
7 | 3386 } |
3387 | |
3388 vim_free(buffer); | |
3389 } | |
3390 | |
3391 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3392 col_print( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3393 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3394 size_t buflen, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3395 int col, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3396 int vcol) |
7 | 3397 { |
3398 if (col == vcol) | |
1869 | 3399 vim_snprintf((char *)buf, buflen, "%d", col); |
7 | 3400 else |
1869 | 3401 vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol); |
7 | 3402 } |
3403 | |
3404 #if defined(FEAT_TITLE) || defined(PROTO) | |
3405 /* | |
3406 * put file name in title bar of window and in icon title | |
3407 */ | |
3408 | |
3409 static char_u *lasttitle = NULL; | |
3410 static char_u *lasticon = NULL; | |
3411 | |
3412 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3413 maketitle(void) |
7 | 3414 { |
3415 char_u *p; | |
3416 char_u *t_str = NULL; | |
3417 char_u *i_name; | |
3418 char_u *i_str = NULL; | |
3419 int maxlen = 0; | |
3420 int len; | |
3421 int mustset; | |
3422 char_u buf[IOSIZE]; | |
3423 int off; | |
3424 | |
3425 if (!redrawing()) | |
3426 { | |
3427 /* Postpone updating the title when 'lazyredraw' is set. */ | |
3428 need_maketitle = TRUE; | |
3429 return; | |
3430 } | |
3431 | |
3432 need_maketitle = FALSE; | |
2403
ce5a380d5144
Fix: when resetting both 'title' and 'icon' the title would be set after a
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
3433 if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL) |
7 | 3434 return; |
3435 | |
3436 if (p_title) | |
3437 { | |
3438 if (p_titlelen > 0) | |
3439 { | |
3440 maxlen = p_titlelen * Columns / 100; | |
3441 if (maxlen < 10) | |
3442 maxlen = 10; | |
3443 } | |
3444 | |
3445 t_str = buf; | |
3446 if (*p_titlestring != NUL) | |
3447 { | |
3448 #ifdef FEAT_STL_OPT | |
771 | 3449 if (stl_syntax & STL_IN_TITLE) |
3450 { | |
3451 int use_sandbox = FALSE; | |
3452 int save_called_emsg = called_emsg; | |
675 | 3453 |
3454 # ifdef FEAT_EVAL | |
771 | 3455 use_sandbox = was_set_insecurely((char_u *)"titlestring", 0); |
675 | 3456 # endif |
771 | 3457 called_emsg = FALSE; |
7 | 3458 build_stl_str_hl(curwin, t_str, sizeof(buf), |
675 | 3459 p_titlestring, use_sandbox, |
681 | 3460 0, maxlen, NULL, NULL); |
771 | 3461 if (called_emsg) |
3462 set_string_option_direct((char_u *)"titlestring", -1, | |
3463 (char_u *)"", OPT_FREE, SID_ERROR); | |
3464 called_emsg |= save_called_emsg; | |
3465 } | |
7 | 3466 else |
3467 #endif | |
3468 t_str = p_titlestring; | |
3469 } | |
3470 else | |
3471 { | |
3472 /* format: "fname + (path) (1 of 2) - VIM" */ | |
3473 | |
3780 | 3474 #define SPACE_FOR_FNAME (IOSIZE - 100) |
3475 #define SPACE_FOR_DIR (IOSIZE - 20) | |
3476 #define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */ | |
7 | 3477 if (curbuf->b_fname == NULL) |
3780 | 3478 vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME); |
7 | 3479 else |
3480 { | |
3481 p = transstr(gettail(curbuf->b_fname)); | |
3780 | 3482 vim_strncpy(buf, p, SPACE_FOR_FNAME); |
7 | 3483 vim_free(p); |
3484 } | |
3485 | |
3486 switch (bufIsChanged(curbuf) | |
3487 + (curbuf->b_p_ro * 2) | |
3488 + (!curbuf->b_p_ma * 4)) | |
3489 { | |
3490 case 1: STRCAT(buf, " +"); break; | |
3491 case 2: STRCAT(buf, " ="); break; | |
3492 case 3: STRCAT(buf, " =+"); break; | |
3493 case 4: | |
3494 case 6: STRCAT(buf, " -"); break; | |
3495 case 5: | |
3496 case 7: STRCAT(buf, " -+"); break; | |
3497 } | |
3498 | |
3499 if (curbuf->b_fname != NULL) | |
3500 { | |
3501 /* Get path of file, replace home dir with ~ */ | |
3502 off = (int)STRLEN(buf); | |
3503 buf[off++] = ' '; | |
3504 buf[off++] = '('; | |
3505 home_replace(curbuf, curbuf->b_ffname, | |
3780 | 3506 buf + off, SPACE_FOR_DIR - off, TRUE); |
7 | 3507 #ifdef BACKSLASH_IN_FILENAME |
3508 /* avoid "c:/name" to be reduced to "c" */ | |
3509 if (isalpha(buf[off]) && buf[off + 1] == ':') | |
3510 off += 2; | |
3511 #endif | |
3512 /* remove the file name */ | |
39 | 3513 p = gettail_sep(buf + off); |
7 | 3514 if (p == buf + off) |
3515 /* must be a help buffer */ | |
416 | 3516 vim_strncpy(buf + off, (char_u *)_("help"), |
3780 | 3517 (size_t)(SPACE_FOR_DIR - off - 1)); |
7 | 3518 else |
3519 *p = NUL; | |
39 | 3520 |
3780 | 3521 /* Translate unprintable chars and concatenate. Keep some |
3522 * room for the server name. When there is no room (very long | |
3523 * file name) use (...). */ | |
3524 if (off < SPACE_FOR_DIR) | |
3525 { | |
3526 p = transstr(buf + off); | |
3527 vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off)); | |
3528 vim_free(p); | |
3529 } | |
3530 else | |
3531 { | |
3532 vim_strncpy(buf + off, (char_u *)"...", | |
3533 (size_t)(SPACE_FOR_ARGNR - off)); | |
3534 } | |
7 | 3535 STRCAT(buf, ")"); |
3536 } | |
3537 | |
3780 | 3538 append_arg_number(curwin, buf, SPACE_FOR_ARGNR, FALSE); |
7 | 3539 |
3540 #if defined(FEAT_CLIENTSERVER) | |
3541 if (serverName != NULL) | |
3542 { | |
3543 STRCAT(buf, " - "); | |
2768 | 3544 vim_strcat(buf, serverName, IOSIZE); |
7 | 3545 } |
3546 else | |
3547 #endif | |
3548 STRCAT(buf, " - VIM"); | |
3549 | |
3550 if (maxlen > 0) | |
3551 { | |
3552 /* make it shorter by removing a bit in the middle */ | |
3277 | 3553 if (vim_strsize(buf) > maxlen) |
3554 trunc_string(buf, buf, maxlen, IOSIZE); | |
7 | 3555 } |
3556 } | |
3557 } | |
3558 mustset = ti_change(t_str, &lasttitle); | |
3559 | |
3560 if (p_icon) | |
3561 { | |
3562 i_str = buf; | |
3563 if (*p_iconstring != NUL) | |
3564 { | |
3565 #ifdef FEAT_STL_OPT | |
771 | 3566 if (stl_syntax & STL_IN_ICON) |
3567 { | |
3568 int use_sandbox = FALSE; | |
3569 int save_called_emsg = called_emsg; | |
675 | 3570 |
3571 # ifdef FEAT_EVAL | |
771 | 3572 use_sandbox = was_set_insecurely((char_u *)"iconstring", 0); |
675 | 3573 # endif |
771 | 3574 called_emsg = FALSE; |
7 | 3575 build_stl_str_hl(curwin, i_str, sizeof(buf), |
675 | 3576 p_iconstring, use_sandbox, |
681 | 3577 0, 0, NULL, NULL); |
771 | 3578 if (called_emsg) |
3579 set_string_option_direct((char_u *)"iconstring", -1, | |
3580 (char_u *)"", OPT_FREE, SID_ERROR); | |
3581 called_emsg |= save_called_emsg; | |
3582 } | |
7 | 3583 else |
3584 #endif | |
3585 i_str = p_iconstring; | |
3586 } | |
3587 else | |
3588 { | |
3589 if (buf_spname(curbuf) != NULL) | |
3839 | 3590 i_name = buf_spname(curbuf); |
7 | 3591 else /* use file name only in icon */ |
3592 i_name = gettail(curbuf->b_ffname); | |
3593 *i_str = NUL; | |
3594 /* Truncate name at 100 bytes. */ | |
835 | 3595 len = (int)STRLEN(i_name); |
7 | 3596 if (len > 100) |
3597 { | |
3598 len -= 100; | |
3599 #ifdef FEAT_MBYTE | |
3600 if (has_mbyte) | |
3601 len += (*mb_tail_off)(i_name, i_name + len) + 1; | |
3602 #endif | |
3603 i_name += len; | |
3604 } | |
3605 STRCPY(i_str, i_name); | |
3606 trans_characters(i_str, IOSIZE); | |
3607 } | |
3608 } | |
3609 | |
3610 mustset |= ti_change(i_str, &lasticon); | |
3611 | |
3612 if (mustset) | |
3613 resettitle(); | |
3614 } | |
3615 | |
3616 /* | |
3617 * Used for title and icon: Check if "str" differs from "*last". Set "*last" | |
3618 * from "str" if it does. | |
3619 * Return TRUE when "*last" changed. | |
3620 */ | |
3621 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3622 ti_change(char_u *str, char_u **last) |
7 | 3623 { |
3624 if ((str == NULL) != (*last == NULL) | |
3625 || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) | |
3626 { | |
3627 vim_free(*last); | |
3628 if (str == NULL) | |
3629 *last = NULL; | |
3630 else | |
3631 *last = vim_strsave(str); | |
3632 return TRUE; | |
3633 } | |
3634 return FALSE; | |
3635 } | |
3636 | |
3637 /* | |
3638 * Put current window title back (used after calling a shell) | |
3639 */ | |
3640 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3641 resettitle(void) |
7 | 3642 { |
3643 mch_settitle(lasttitle, lasticon); | |
3644 } | |
358 | 3645 |
3646 # if defined(EXITFREE) || defined(PROTO) | |
3647 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3648 free_titles(void) |
358 | 3649 { |
3650 vim_free(lasttitle); | |
3651 vim_free(lasticon); | |
3652 } | |
3653 # endif | |
3654 | |
7 | 3655 #endif /* FEAT_TITLE */ |
3656 | |
686 | 3657 #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO) |
7 | 3658 /* |
675 | 3659 * Build a string from the status line items in "fmt". |
7 | 3660 * Return length of string in screen cells. |
3661 * | |
675 | 3662 * Normally works for window "wp", except when working for 'tabline' then it |
3663 * is "curwin". | |
3664 * | |
7 | 3665 * Items are drawn interspersed with the text that surrounds it |
3666 * Specials: %-<wid>(xxx%) => group, %= => middle marker, %< => truncation | |
3667 * Item: %-<minwid>.<maxwid><itemch> All but <itemch> are optional | |
3668 * | |
3669 * If maxwidth is not zero, the string will be filled at any middle marker | |
3670 * or truncated if too long, fillchar is used for all whitespace. | |
3671 */ | |
3672 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3673 build_stl_str_hl( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3674 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3675 char_u *out, /* buffer to write into != NameBuff */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3676 size_t outlen, /* length of out[] */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3677 char_u *fmt, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3678 int use_sandbox UNUSED, /* "fmt" was set insecurely, use sandbox */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3679 int fillchar, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3680 int maxwidth, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3681 struct stl_hlrec *hltab, /* return: HL attributes (can be NULL) */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3682 struct stl_hlrec *tabtab) /* return: tab page nrs (can be NULL) */ |
7 | 3683 { |
3684 char_u *p; | |
3685 char_u *s; | |
3686 char_u *t; | |
4333 | 3687 int byteval; |
7 | 3688 #ifdef FEAT_EVAL |
3689 win_T *o_curwin; | |
3690 buf_T *o_curbuf; | |
3691 #endif | |
3692 int empty_line; | |
3693 colnr_T virtcol; | |
3694 long l; | |
3695 long n; | |
3696 int prevchar_isflag; | |
3697 int prevchar_isitem; | |
3698 int itemisflag; | |
3699 int fillable; | |
3700 char_u *str; | |
3701 long num; | |
3702 int width; | |
3703 int itemcnt; | |
3704 int curitem; | |
3705 int groupitem[STL_MAX_ITEM]; | |
3706 int groupdepth; | |
3707 struct stl_item | |
3708 { | |
3709 char_u *start; | |
3710 int minwid; | |
3711 int maxwid; | |
3712 enum | |
3713 { | |
3714 Normal, | |
3715 Empty, | |
3716 Group, | |
3717 Middle, | |
3718 Highlight, | |
681 | 3719 TabPage, |
7 | 3720 Trunc |
3721 } type; | |
3722 } item[STL_MAX_ITEM]; | |
3723 int minwid; | |
3724 int maxwid; | |
3725 int zeropad; | |
3726 char_u base; | |
3727 char_u opt; | |
3728 #define TMPLEN 70 | |
3729 char_u tmp[TMPLEN]; | |
678 | 3730 char_u *usefmt = fmt; |
681 | 3731 struct stl_hlrec *sp; |
678 | 3732 |
3733 #ifdef FEAT_EVAL | |
3734 /* | |
3735 * When the format starts with "%!" then evaluate it as an expression and | |
3736 * use the result as the actual format string. | |
3737 */ | |
3738 if (fmt[0] == '%' && fmt[1] == '!') | |
3739 { | |
3740 usefmt = eval_to_string_safe(fmt + 2, NULL, use_sandbox); | |
3741 if (usefmt == NULL) | |
943 | 3742 usefmt = fmt; |
678 | 3743 } |
3744 #endif | |
7 | 3745 |
3746 if (fillchar == 0) | |
3747 fillchar = ' '; | |
819 | 3748 #ifdef FEAT_MBYTE |
3749 /* Can't handle a multi-byte fill character yet. */ | |
3750 else if (mb_char2len(fillchar) > 1) | |
3751 fillchar = '-'; | |
3752 #endif | |
3753 | |
4333 | 3754 /* Get line & check if empty (cursorpos will show "0-1"). Note that |
3755 * p will become invalid when getting another buffer line. */ | |
3756 p = ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE); | |
3757 empty_line = (*p == NUL); | |
3758 | |
3759 /* Get the byte value now, in case we need it below. This is more | |
3760 * efficient than making a copy of the line. */ | |
3761 if (wp->w_cursor.col > (colnr_T)STRLEN(p)) | |
3762 byteval = 0; | |
3763 else | |
3764 #ifdef FEAT_MBYTE | |
3765 byteval = (*mb_ptr2char)(p + wp->w_cursor.col); | |
3766 #else | |
3767 byteval = p[wp->w_cursor.col]; | |
3768 #endif | |
7 | 3769 |
3770 groupdepth = 0; | |
3771 p = out; | |
3772 curitem = 0; | |
3773 prevchar_isflag = TRUE; | |
3774 prevchar_isitem = FALSE; | |
678 | 3775 for (s = usefmt; *s; ) |
7 | 3776 { |
2704 | 3777 if (curitem == STL_MAX_ITEM) |
3778 { | |
3779 /* There are too many items. Add the error code to the statusline | |
3780 * to give the user a hint about what went wrong. */ | |
3781 if (p + 6 < out + outlen) | |
3782 { | |
3783 mch_memmove(p, " E541", (size_t)5); | |
3784 p += 5; | |
3785 } | |
3786 break; | |
3787 } | |
3788 | |
7 | 3789 if (*s != NUL && *s != '%') |
3790 prevchar_isflag = prevchar_isitem = FALSE; | |
3791 | |
3792 /* | |
3793 * Handle up to the next '%' or the end. | |
3794 */ | |
3795 while (*s != NUL && *s != '%' && p + 1 < out + outlen) | |
3796 *p++ = *s++; | |
3797 if (*s == NUL || p + 1 >= out + outlen) | |
3798 break; | |
3799 | |
3800 /* | |
3801 * Handle one '%' item. | |
3802 */ | |
3803 s++; | |
2694 | 3804 if (*s == NUL) /* ignore trailing % */ |
3805 break; | |
7 | 3806 if (*s == '%') |
3807 { | |
3808 if (p + 1 >= out + outlen) | |
3809 break; | |
3810 *p++ = *s++; | |
3811 prevchar_isflag = prevchar_isitem = FALSE; | |
3812 continue; | |
3813 } | |
3814 if (*s == STL_MIDDLEMARK) | |
3815 { | |
3816 s++; | |
3817 if (groupdepth > 0) | |
3818 continue; | |
3819 item[curitem].type = Middle; | |
3820 item[curitem++].start = p; | |
3821 continue; | |
3822 } | |
3823 if (*s == STL_TRUNCMARK) | |
3824 { | |
3825 s++; | |
3826 item[curitem].type = Trunc; | |
3827 item[curitem++].start = p; | |
3828 continue; | |
3829 } | |
3830 if (*s == ')') | |
3831 { | |
3832 s++; | |
3833 if (groupdepth < 1) | |
3834 continue; | |
3835 groupdepth--; | |
3836 | |
3837 t = item[groupitem[groupdepth]].start; | |
3838 *p = NUL; | |
3839 l = vim_strsize(t); | |
3840 if (curitem > groupitem[groupdepth] + 1 | |
3841 && item[groupitem[groupdepth]].minwid == 0) | |
3842 { | |
3843 /* remove group if all items are empty */ | |
3844 for (n = groupitem[groupdepth] + 1; n < curitem; n++) | |
8441
768065c86a35
commit https://github.com/vim/vim/commit/af6e36ff16736106a1bc63bb4d01f51fdfeb29a2
Christian Brabandt <cb@256bit.org>
parents:
8216
diff
changeset
|
3845 if (item[n].type == Normal || item[n].type == Highlight) |
7 | 3846 break; |
3847 if (n == curitem) | |
3848 { | |
3849 p = t; | |
3850 l = 0; | |
3851 } | |
3852 } | |
3853 if (l > item[groupitem[groupdepth]].maxwid) | |
3854 { | |
3855 /* truncate, remove n bytes of text at the start */ | |
3856 #ifdef FEAT_MBYTE | |
3857 if (has_mbyte) | |
3858 { | |
3859 /* Find the first character that should be included. */ | |
3860 n = 0; | |
3861 while (l >= item[groupitem[groupdepth]].maxwid) | |
3862 { | |
3863 l -= ptr2cells(t + n); | |
474 | 3864 n += (*mb_ptr2len)(t + n); |
7 | 3865 } |
3866 } | |
3867 else | |
3868 #endif | |
835 | 3869 n = (long)(p - t) - item[groupitem[groupdepth]].maxwid + 1; |
7 | 3870 |
3871 *t = '<'; | |
1869 | 3872 mch_memmove(t + 1, t + n, (size_t)(p - (t + n))); |
7 | 3873 p = p - n + 1; |
3874 #ifdef FEAT_MBYTE | |
3875 /* Fill up space left over by half a double-wide char. */ | |
3876 while (++l < item[groupitem[groupdepth]].minwid) | |
3877 *p++ = fillchar; | |
3878 #endif | |
3879 | |
3880 /* correct the start of the items for the truncation */ | |
3881 for (l = groupitem[groupdepth] + 1; l < curitem; l++) | |
3882 { | |
3883 item[l].start -= n; | |
3884 if (item[l].start < t) | |
3885 item[l].start = t; | |
3886 } | |
3887 } | |
3888 else if (abs(item[groupitem[groupdepth]].minwid) > l) | |
3889 { | |
3890 /* fill */ | |
3891 n = item[groupitem[groupdepth]].minwid; | |
3892 if (n < 0) | |
3893 { | |
3894 /* fill by appending characters */ | |
3895 n = 0 - n; | |
3896 while (l++ < n && p + 1 < out + outlen) | |
3897 *p++ = fillchar; | |
3898 } | |
3899 else | |
3900 { | |
3901 /* fill by inserting characters */ | |
1869 | 3902 mch_memmove(t + n - l, t, (size_t)(p - t)); |
7 | 3903 l = n - l; |
3904 if (p + l >= out + outlen) | |
835 | 3905 l = (long)((out + outlen) - p - 1); |
7 | 3906 p += l; |
3907 for (n = groupitem[groupdepth] + 1; n < curitem; n++) | |
3908 item[n].start += l; | |
3909 for ( ; l > 0; l--) | |
3910 *t++ = fillchar; | |
3911 } | |
3912 } | |
3913 continue; | |
3914 } | |
3915 minwid = 0; | |
3916 maxwid = 9999; | |
3917 zeropad = FALSE; | |
3918 l = 1; | |
3919 if (*s == '0') | |
3920 { | |
3921 s++; | |
3922 zeropad = TRUE; | |
3923 } | |
3924 if (*s == '-') | |
3925 { | |
3926 s++; | |
3927 l = -1; | |
3928 } | |
3929 if (VIM_ISDIGIT(*s)) | |
3930 { | |
3931 minwid = (int)getdigits(&s); | |
3932 if (minwid < 0) /* overflow */ | |
3933 minwid = 0; | |
3934 } | |
678 | 3935 if (*s == STL_USER_HL) |
7 | 3936 { |
3937 item[curitem].type = Highlight; | |
3938 item[curitem].start = p; | |
3939 item[curitem].minwid = minwid > 9 ? 1 : minwid; | |
3940 s++; | |
3941 curitem++; | |
3942 continue; | |
3943 } | |
681 | 3944 if (*s == STL_TABPAGENR || *s == STL_TABCLOSENR) |
3945 { | |
3946 if (*s == STL_TABCLOSENR) | |
3947 { | |
3948 if (minwid == 0) | |
3949 { | |
3950 /* %X ends the close label, go back to the previously | |
3951 * define tab label nr. */ | |
3952 for (n = curitem - 1; n >= 0; --n) | |
3953 if (item[n].type == TabPage && item[n].minwid >= 0) | |
3954 { | |
3955 minwid = item[n].minwid; | |
3956 break; | |
3957 } | |
3958 } | |
3959 else | |
3960 /* close nrs are stored as negative values */ | |
3961 minwid = - minwid; | |
3962 } | |
3963 item[curitem].type = TabPage; | |
3964 item[curitem].start = p; | |
3965 item[curitem].minwid = minwid; | |
3966 s++; | |
3967 curitem++; | |
3968 continue; | |
3969 } | |
7 | 3970 if (*s == '.') |
3971 { | |
3972 s++; | |
3973 if (VIM_ISDIGIT(*s)) | |
3974 { | |
3975 maxwid = (int)getdigits(&s); | |
3976 if (maxwid <= 0) /* overflow */ | |
3977 maxwid = 50; | |
3978 } | |
3979 } | |
3980 minwid = (minwid > 50 ? 50 : minwid) * l; | |
3981 if (*s == '(') | |
3982 { | |
3983 groupitem[groupdepth++] = curitem; | |
3984 item[curitem].type = Group; | |
3985 item[curitem].start = p; | |
3986 item[curitem].minwid = minwid; | |
3987 item[curitem].maxwid = maxwid; | |
3988 s++; | |
3989 curitem++; | |
3990 continue; | |
3991 } | |
3992 if (vim_strchr(STL_ALL, *s) == NULL) | |
3993 { | |
3994 s++; | |
3995 continue; | |
3996 } | |
3997 opt = *s++; | |
3998 | |
3999 /* OK - now for the real work */ | |
4000 base = 'D'; | |
4001 itemisflag = FALSE; | |
4002 fillable = TRUE; | |
4003 num = -1; | |
4004 str = NULL; | |
4005 switch (opt) | |
4006 { | |
4007 case STL_FILEPATH: | |
4008 case STL_FULLPATH: | |
4009 case STL_FILENAME: | |
4010 fillable = FALSE; /* don't change ' ' to fillchar */ | |
4011 if (buf_spname(wp->w_buffer) != NULL) | |
3839 | 4012 vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1); |
7 | 4013 else |
4014 { | |
4015 t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname | |
667 | 4016 : wp->w_buffer->b_fname; |
7 | 4017 home_replace(wp->w_buffer, t, NameBuff, MAXPATHL, TRUE); |
4018 } | |
4019 trans_characters(NameBuff, MAXPATHL); | |
4020 if (opt != STL_FILENAME) | |
4021 str = NameBuff; | |
4022 else | |
4023 str = gettail(NameBuff); | |
4024 break; | |
4025 | |
4026 case STL_VIM_EXPR: /* '{' */ | |
4027 itemisflag = TRUE; | |
4028 t = p; | |
4029 while (*s != '}' && *s != NUL && p + 1 < out + outlen) | |
4030 *p++ = *s++; | |
4031 if (*s != '}') /* missing '}' or out of space */ | |
4032 break; | |
4033 s++; | |
4034 *p = 0; | |
4035 p = t; | |
4036 | |
4037 #ifdef FEAT_EVAL | |
1869 | 4038 vim_snprintf((char *)tmp, sizeof(tmp), "%d", curbuf->b_fnum); |
7 | 4039 set_internal_string_var((char_u *)"actual_curbuf", tmp); |
4040 | |
4041 o_curbuf = curbuf; | |
4042 o_curwin = curwin; | |
4043 curwin = wp; | |
4044 curbuf = wp->w_buffer; | |
4045 | |
675 | 4046 str = eval_to_string_safe(p, &t, use_sandbox); |
7 | 4047 |
4048 curwin = o_curwin; | |
4049 curbuf = o_curbuf; | |
145 | 4050 do_unlet((char_u *)"g:actual_curbuf", TRUE); |
7 | 4051 |
4052 if (str != NULL && *str != 0) | |
4053 { | |
4054 if (*skipdigits(str) == NUL) | |
4055 { | |
4056 num = atoi((char *)str); | |
4057 vim_free(str); | |
4058 str = NULL; | |
4059 itemisflag = FALSE; | |
4060 } | |
4061 } | |
4062 #endif | |
4063 break; | |
4064 | |
4065 case STL_LINE: | |
4066 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) | |
4067 ? 0L : (long)(wp->w_cursor.lnum); | |
4068 break; | |
4069 | |
4070 case STL_NUMLINES: | |
4071 num = wp->w_buffer->b_ml.ml_line_count; | |
4072 break; | |
4073 | |
4074 case STL_COLUMN: | |
4075 num = !(State & INSERT) && empty_line | |
4076 ? 0 : (int)wp->w_cursor.col + 1; | |
4077 break; | |
4078 | |
4079 case STL_VIRTCOL: | |
4080 case STL_VIRTCOL_ALT: | |
4081 /* In list mode virtcol needs to be recomputed */ | |
4082 virtcol = wp->w_virtcol; | |
4083 if (wp->w_p_list && lcs_tab1 == NUL) | |
4084 { | |
4085 wp->w_p_list = FALSE; | |
4086 getvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
4087 wp->w_p_list = TRUE; | |
4088 } | |
4089 ++virtcol; | |
4090 /* Don't display %V if it's the same as %c. */ | |
4091 if (opt == STL_VIRTCOL_ALT | |
4092 && (virtcol == (colnr_T)(!(State & INSERT) && empty_line | |
4093 ? 0 : (int)wp->w_cursor.col + 1))) | |
4094 break; | |
4095 num = (long)virtcol; | |
4096 break; | |
4097 | |
4098 case STL_PERCENTAGE: | |
4099 num = (int)(((long)wp->w_cursor.lnum * 100L) / | |
4100 (long)wp->w_buffer->b_ml.ml_line_count); | |
4101 break; | |
4102 | |
4103 case STL_ALTPERCENT: | |
4104 str = tmp; | |
1869 | 4105 get_rel_pos(wp, str, TMPLEN); |
7 | 4106 break; |
4107 | |
4108 case STL_ARGLISTSTAT: | |
4109 fillable = FALSE; | |
4110 tmp[0] = 0; | |
1869 | 4111 if (append_arg_number(wp, tmp, (int)sizeof(tmp), FALSE)) |
7 | 4112 str = tmp; |
4113 break; | |
4114 | |
4115 case STL_KEYMAP: | |
4116 fillable = FALSE; | |
4117 if (get_keymap_str(wp, tmp, TMPLEN)) | |
4118 str = tmp; | |
4119 break; | |
4120 case STL_PAGENUM: | |
706 | 4121 #if defined(FEAT_PRINTER) || defined(FEAT_GUI_TABLINE) |
686 | 4122 num = printer_page_num; |
7 | 4123 #else |
4124 num = 0; | |
4125 #endif | |
4126 break; | |
4127 | |
4128 case STL_BUFNO: | |
4129 num = wp->w_buffer->b_fnum; | |
4130 break; | |
4131 | |
4132 case STL_OFFSET_X: | |
4133 base = 'X'; | |
4134 case STL_OFFSET: | |
4135 #ifdef FEAT_BYTEOFF | |
4136 l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); | |
4137 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? | |
4138 0L : l + 1 + (!(State & INSERT) && empty_line ? | |
4139 0 : (int)wp->w_cursor.col); | |
4140 #endif | |
4141 break; | |
4142 | |
4143 case STL_BYTEVAL_X: | |
4144 base = 'X'; | |
4145 case STL_BYTEVAL: | |
4333 | 4146 num = byteval; |
7 | 4147 if (num == NL) |
4148 num = 0; | |
4149 else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC) | |
4150 num = NL; | |
4151 break; | |
4152 | |
4153 case STL_ROFLAG: | |
4154 case STL_ROFLAG_ALT: | |
4155 itemisflag = TRUE; | |
4156 if (wp->w_buffer->b_p_ro) | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
4157 str = (char_u *)((opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]")); |
7 | 4158 break; |
4159 | |
4160 case STL_HELPFLAG: | |
4161 case STL_HELPFLAG_ALT: | |
4162 itemisflag = TRUE; | |
4163 if (wp->w_buffer->b_help) | |
4164 str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP" | |
809 | 4165 : _("[Help]")); |
7 | 4166 break; |
4167 | |
4168 #ifdef FEAT_AUTOCMD | |
4169 case STL_FILETYPE: | |
4170 if (*wp->w_buffer->b_p_ft != NUL | |
4171 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) | |
4172 { | |
272 | 4173 vim_snprintf((char *)tmp, sizeof(tmp), "[%s]", |
4174 wp->w_buffer->b_p_ft); | |
7 | 4175 str = tmp; |
4176 } | |
4177 break; | |
4178 | |
4179 case STL_FILETYPE_ALT: | |
4180 itemisflag = TRUE; | |
4181 if (*wp->w_buffer->b_p_ft != NUL | |
4182 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 2) | |
4183 { | |
272 | 4184 vim_snprintf((char *)tmp, sizeof(tmp), ",%s", |
4185 wp->w_buffer->b_p_ft); | |
7 | 4186 for (t = tmp; *t != 0; t++) |
4187 *t = TOUPPER_LOC(*t); | |
4188 str = tmp; | |
4189 } | |
4190 break; | |
4191 #endif | |
4192 | |
4193 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
4194 case STL_PREVIEWFLAG: | |
4195 case STL_PREVIEWFLAG_ALT: | |
4196 itemisflag = TRUE; | |
4197 if (wp->w_p_pvw) | |
4198 str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV" | |
4199 : _("[Preview]")); | |
4200 break; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4201 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4202 case STL_QUICKFIX: |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4203 if (bt_quickfix(wp->w_buffer)) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4204 str = (char_u *)(wp->w_llist_ref |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4205 ? _(msg_loclist) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4206 : _(msg_qflist)); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4207 break; |
7 | 4208 #endif |
4209 | |
4210 case STL_MODIFIED: | |
4211 case STL_MODIFIED_ALT: | |
4212 itemisflag = TRUE; | |
4213 switch ((opt == STL_MODIFIED_ALT) | |
4214 + bufIsChanged(wp->w_buffer) * 2 | |
4215 + (!wp->w_buffer->b_p_ma) * 4) | |
4216 { | |
4217 case 2: str = (char_u *)"[+]"; break; | |
4218 case 3: str = (char_u *)",+"; break; | |
4219 case 4: str = (char_u *)"[-]"; break; | |
4220 case 5: str = (char_u *)",-"; break; | |
4221 case 6: str = (char_u *)"[+-]"; break; | |
4222 case 7: str = (char_u *)",+-"; break; | |
4223 } | |
4224 break; | |
678 | 4225 |
4226 case STL_HIGHLIGHT: | |
4227 t = s; | |
4228 while (*s != '#' && *s != NUL) | |
4229 ++s; | |
4230 if (*s == '#') | |
4231 { | |
4232 item[curitem].type = Highlight; | |
4233 item[curitem].start = p; | |
835 | 4234 item[curitem].minwid = -syn_namen2id(t, (int)(s - t)); |
678 | 4235 curitem++; |
4236 } | |
5407 | 4237 if (*s != NUL) |
4238 ++s; | |
678 | 4239 continue; |
7 | 4240 } |
4241 | |
4242 item[curitem].start = p; | |
4243 item[curitem].type = Normal; | |
4244 if (str != NULL && *str) | |
4245 { | |
4246 t = str; | |
4247 if (itemisflag) | |
4248 { | |
4249 if ((t[0] && t[1]) | |
4250 && ((!prevchar_isitem && *t == ',') | |
4251 || (prevchar_isflag && *t == ' '))) | |
4252 t++; | |
4253 prevchar_isflag = TRUE; | |
4254 } | |
4255 l = vim_strsize(t); | |
4256 if (l > 0) | |
4257 prevchar_isitem = TRUE; | |
4258 if (l > maxwid) | |
4259 { | |
4260 while (l >= maxwid) | |
4261 #ifdef FEAT_MBYTE | |
4262 if (has_mbyte) | |
4263 { | |
4264 l -= ptr2cells(t); | |
474 | 4265 t += (*mb_ptr2len)(t); |
7 | 4266 } |
4267 else | |
4268 #endif | |
4269 l -= byte2cells(*t++); | |
4270 if (p + 1 >= out + outlen) | |
4271 break; | |
4272 *p++ = '<'; | |
4273 } | |
4274 if (minwid > 0) | |
4275 { | |
4276 for (; l < minwid && p + 1 < out + outlen; l++) | |
4277 { | |
4278 /* Don't put a "-" in front of a digit. */ | |
4279 if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) | |
4280 *p++ = ' '; | |
4281 else | |
4282 *p++ = fillchar; | |
4283 } | |
4284 minwid = 0; | |
4285 } | |
4286 else | |
4287 minwid *= -1; | |
4288 while (*t && p + 1 < out + outlen) | |
4289 { | |
4290 *p++ = *t++; | |
4291 /* Change a space by fillchar, unless fillchar is '-' and a | |
4292 * digit follows. */ | |
4293 if (fillable && p[-1] == ' ' | |
4294 && (!VIM_ISDIGIT(*t) || fillchar != '-')) | |
4295 p[-1] = fillchar; | |
4296 } | |
4297 for (; l < minwid && p + 1 < out + outlen; l++) | |
4298 *p++ = fillchar; | |
4299 } | |
4300 else if (num >= 0) | |
4301 { | |
4302 int nbase = (base == 'D' ? 10 : (base == 'O' ? 8 : 16)); | |
4303 char_u nstr[20]; | |
4304 | |
4305 if (p + 20 >= out + outlen) | |
4306 break; /* not sufficient space */ | |
4307 prevchar_isitem = TRUE; | |
4308 t = nstr; | |
4309 if (opt == STL_VIRTCOL_ALT) | |
4310 { | |
4311 *t++ = '-'; | |
4312 minwid--; | |
4313 } | |
4314 *t++ = '%'; | |
4315 if (zeropad) | |
4316 *t++ = '0'; | |
4317 *t++ = '*'; | |
1869 | 4318 *t++ = nbase == 16 ? base : (char_u)(nbase == 8 ? 'o' : 'd'); |
7 | 4319 *t = 0; |
4320 | |
4321 for (n = num, l = 1; n >= nbase; n /= nbase) | |
4322 l++; | |
4323 if (opt == STL_VIRTCOL_ALT) | |
4324 l++; | |
4325 if (l > maxwid) | |
4326 { | |
4327 l += 2; | |
4328 n = l - maxwid; | |
4329 while (l-- > maxwid) | |
4330 num /= nbase; | |
4331 *t++ = '>'; | |
4332 *t++ = '%'; | |
4333 *t = t[-3]; | |
4334 *++t = 0; | |
272 | 4335 vim_snprintf((char *)p, outlen - (p - out), (char *)nstr, |
4336 0, num, n); | |
7 | 4337 } |
4338 else | |
272 | 4339 vim_snprintf((char *)p, outlen - (p - out), (char *)nstr, |
4340 minwid, num); | |
7 | 4341 p += STRLEN(p); |
4342 } | |
4343 else | |
4344 item[curitem].type = Empty; | |
4345 | |
4346 if (opt == STL_VIM_EXPR) | |
4347 vim_free(str); | |
4348 | |
4349 if (num >= 0 || (!itemisflag && str && *str)) | |
4350 prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ | |
4351 curitem++; | |
4352 } | |
4353 *p = NUL; | |
4354 itemcnt = curitem; | |
4355 | |
678 | 4356 #ifdef FEAT_EVAL |
4357 if (usefmt != fmt) | |
4358 vim_free(usefmt); | |
4359 #endif | |
4360 | |
7 | 4361 width = vim_strsize(out); |
4362 if (maxwidth > 0 && width > maxwidth) | |
4363 { | |
1736 | 4364 /* Result is too long, must truncate somewhere. */ |
7 | 4365 l = 0; |
4366 if (itemcnt == 0) | |
4367 s = out; | |
4368 else | |
4369 { | |
4370 for ( ; l < itemcnt; l++) | |
4371 if (item[l].type == Trunc) | |
4372 { | |
4373 /* Truncate at %< item. */ | |
4374 s = item[l].start; | |
4375 break; | |
4376 } | |
4377 if (l == itemcnt) | |
4378 { | |
4379 /* No %< item, truncate first item. */ | |
4380 s = item[0].start; | |
4381 l = 0; | |
4382 } | |
4383 } | |
4384 | |
4385 if (width - vim_strsize(s) >= maxwidth) | |
4386 { | |
4387 /* Truncation mark is beyond max length */ | |
4388 #ifdef FEAT_MBYTE | |
4389 if (has_mbyte) | |
4390 { | |
4391 s = out; | |
4392 width = 0; | |
4393 for (;;) | |
4394 { | |
4395 width += ptr2cells(s); | |
4396 if (width >= maxwidth) | |
4397 break; | |
474 | 4398 s += (*mb_ptr2len)(s); |
7 | 4399 } |
4400 /* Fill up for half a double-wide character. */ | |
4401 while (++width < maxwidth) | |
4402 *s++ = fillchar; | |
4403 } | |
4404 else | |
4405 #endif | |
4406 s = out + maxwidth - 1; | |
4407 for (l = 0; l < itemcnt; l++) | |
4408 if (item[l].start > s) | |
4409 break; | |
4410 itemcnt = l; | |
4411 *s++ = '>'; | |
4412 *s = 0; | |
4413 } | |
4414 else | |
4415 { | |
4416 #ifdef FEAT_MBYTE | |
4417 if (has_mbyte) | |
4418 { | |
4419 n = 0; | |
4420 while (width >= maxwidth) | |
4421 { | |
4422 width -= ptr2cells(s + n); | |
474 | 4423 n += (*mb_ptr2len)(s + n); |
7 | 4424 } |
4425 } | |
4426 else | |
4427 #endif | |
4428 n = width - maxwidth + 1; | |
4429 p = s + n; | |
1618 | 4430 STRMOVE(s + 1, p); |
7 | 4431 *s = '<'; |
4432 | |
4433 /* Fill up for half a double-wide character. */ | |
4434 while (++width < maxwidth) | |
4435 { | |
4436 s = s + STRLEN(s); | |
4437 *s++ = fillchar; | |
4438 *s = NUL; | |
4439 } | |
4440 | |
4441 --n; /* count the '<' */ | |
4442 for (; l < itemcnt; l++) | |
4443 { | |
4444 if (item[l].start - n >= s) | |
4445 item[l].start -= n; | |
4446 else | |
4447 item[l].start = s; | |
4448 } | |
4449 } | |
4450 width = maxwidth; | |
4451 } | |
4452 else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen) | |
4453 { | |
4454 /* Apply STL_MIDDLE if any */ | |
4455 for (l = 0; l < itemcnt; l++) | |
4456 if (item[l].type == Middle) | |
4457 break; | |
4458 if (l < itemcnt) | |
4459 { | |
4460 p = item[l].start + maxwidth - width; | |
1618 | 4461 STRMOVE(p, item[l].start); |
7 | 4462 for (s = item[l].start; s < p; s++) |
4463 *s = fillchar; | |
4464 for (l++; l < itemcnt; l++) | |
4465 item[l].start += maxwidth - width; | |
4466 width = maxwidth; | |
4467 } | |
4468 } | |
4469 | |
681 | 4470 /* Store the info about highlighting. */ |
4471 if (hltab != NULL) | |
7 | 4472 { |
681 | 4473 sp = hltab; |
7 | 4474 for (l = 0; l < itemcnt; l++) |
4475 { | |
4476 if (item[l].type == Highlight) | |
4477 { | |
681 | 4478 sp->start = item[l].start; |
4479 sp->userhl = item[l].minwid; | |
4480 sp++; | |
7 | 4481 } |
4482 } | |
681 | 4483 sp->start = NULL; |
4484 sp->userhl = 0; | |
4485 } | |
4486 | |
4487 /* Store the info about tab pages labels. */ | |
4488 if (tabtab != NULL) | |
4489 { | |
4490 sp = tabtab; | |
4491 for (l = 0; l < itemcnt; l++) | |
4492 { | |
4493 if (item[l].type == TabPage) | |
4494 { | |
4495 sp->start = item[l].start; | |
4496 sp->userhl = item[l].minwid; | |
4497 sp++; | |
4498 } | |
4499 } | |
4500 sp->start = NULL; | |
4501 sp->userhl = 0; | |
7 | 4502 } |
4503 | |
4504 return width; | |
4505 } | |
4506 #endif /* FEAT_STL_OPT */ | |
4507 | |
686 | 4508 #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \ |
4509 || defined(FEAT_GUI_TABLINE) || defined(PROTO) | |
7 | 4510 /* |
1869 | 4511 * Get relative cursor position in window into "buf[buflen]", in the form 99%, |
4512 * using "Top", "Bot" or "All" when appropriate. | |
7 | 4513 */ |
4514 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4515 get_rel_pos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4516 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4517 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4518 int buflen) |
7 | 4519 { |
4520 long above; /* number of lines above window */ | |
4521 long below; /* number of lines below window */ | |
4522 | |
6466 | 4523 if (buflen < 3) /* need at least 3 chars for writing */ |
4524 return; | |
7 | 4525 above = wp->w_topline - 1; |
4526 #ifdef FEAT_DIFF | |
4527 above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; | |
6975 | 4528 if (wp->w_topline == 1 && wp->w_topfill >= 1) |
4529 above = 0; /* All buffer lines are displayed and there is an | |
4530 * indication of filler lines, that can be considered | |
4531 * seeing all lines. */ | |
7 | 4532 #endif |
4533 below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; | |
4534 if (below <= 0) | |
1869 | 4535 vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")), |
4536 (size_t)(buflen - 1)); | |
7 | 4537 else if (above <= 0) |
1869 | 4538 vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1)); |
7 | 4539 else |
1869 | 4540 vim_snprintf((char *)buf, (size_t)buflen, "%2d%%", above > 1000000L |
7 | 4541 ? (int)(above / ((above + below) / 100L)) |
4542 : (int)(above * 100L / (above + below))); | |
4543 } | |
4544 #endif | |
4545 | |
4546 /* | |
1869 | 4547 * Append (file 2 of 8) to "buf[buflen]", if editing more than one file. |
7 | 4548 * Return TRUE if it was appended. |
4549 */ | |
1869 | 4550 static int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4551 append_arg_number( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4552 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4553 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4554 int buflen, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4555 int add_file) /* Add "file" before the arg number */ |
7 | 4556 { |
4557 char_u *p; | |
4558 | |
4559 if (ARGCOUNT <= 1) /* nothing to do */ | |
4560 return FALSE; | |
4561 | |
1869 | 4562 p = buf + STRLEN(buf); /* go to the end of the buffer */ |
4563 if (p - buf + 35 >= buflen) /* getting too long */ | |
7 | 4564 return FALSE; |
4565 *p++ = ' '; | |
4566 *p++ = '('; | |
4567 if (add_file) | |
4568 { | |
4569 STRCPY(p, "file "); | |
4570 p += 5; | |
4571 } | |
1869 | 4572 vim_snprintf((char *)p, (size_t)(buflen - (p - buf)), |
4573 wp->w_arg_idx_invalid ? "(%d) of %d)" | |
7 | 4574 : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT); |
4575 return TRUE; | |
4576 } | |
4577 | |
4578 /* | |
4579 * If fname is not a full path, make it a full path. | |
4580 * Returns pointer to allocated memory (NULL for failure). | |
4581 */ | |
4582 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4583 fix_fname(char_u *fname) |
7 | 4584 { |
4585 /* | |
4586 * Force expanding the path always for Unix, because symbolic links may | |
4587 * mess up the full path name, even though it starts with a '/'. | |
4588 * Also expand when there is ".." in the file name, try to remove it, | |
4589 * because "c:/src/../README" is equal to "c:/README". | |
1420 | 4590 * Similarly "c:/src//file" is equal to "c:/src/file". |
7 | 4591 * For MS-Windows also expand names like "longna~1" to "longname". |
4592 */ | |
1082 | 4593 #ifdef UNIX |
7 | 4594 return FullName_save(fname, TRUE); |
4595 #else | |
1420 | 4596 if (!vim_isAbsName(fname) |
4597 || strstr((char *)fname, "..") != NULL | |
4598 || strstr((char *)fname, "//") != NULL | |
4599 # ifdef BACKSLASH_IN_FILENAME | |
4600 || strstr((char *)fname, "\\\\") != NULL | |
4601 # endif | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4602 # if defined(MSWIN) |
7 | 4603 || vim_strchr(fname, '~') != NULL |
1420 | 4604 # endif |
7 | 4605 ) |
4606 return FullName_save(fname, FALSE); | |
4607 | |
4608 fname = vim_strsave(fname); | |
4609 | |
1420 | 4610 # ifdef USE_FNAME_CASE |
4611 # ifdef USE_LONG_FNAME | |
7 | 4612 if (USE_LONG_FNAME) |
1420 | 4613 # endif |
7 | 4614 { |
4615 if (fname != NULL) | |
4616 fname_case(fname, 0); /* set correct case for file name */ | |
4617 } | |
1420 | 4618 # endif |
7 | 4619 |
4620 return fname; | |
4621 #endif | |
4622 } | |
4623 | |
4624 /* | |
4625 * Make "ffname" a full file name, set "sfname" to "ffname" if not NULL. | |
4626 * "ffname" becomes a pointer to allocated memory (or NULL). | |
4627 */ | |
4628 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4629 fname_expand( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4630 buf_T *buf UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4631 char_u **ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4632 char_u **sfname) |
7 | 4633 { |
4634 if (*ffname == NULL) /* if no file name given, nothing to do */ | |
4635 return; | |
4636 if (*sfname == NULL) /* if no short file name given, use ffname */ | |
4637 *sfname = *ffname; | |
4638 *ffname = fix_fname(*ffname); /* expand to full path */ | |
4639 | |
4640 #ifdef FEAT_SHORTCUT | |
4641 if (!buf->b_p_bin) | |
4642 { | |
844 | 4643 char_u *rfname; |
7 | 4644 |
4645 /* If the file name is a shortcut file, use the file it links to. */ | |
4646 rfname = mch_resolve_shortcut(*ffname); | |
844 | 4647 if (rfname != NULL) |
7 | 4648 { |
4649 vim_free(*ffname); | |
4650 *ffname = rfname; | |
4651 *sfname = rfname; | |
4652 } | |
4653 } | |
4654 #endif | |
4655 } | |
4656 | |
4657 /* | |
4658 * Get the file name for an argument list entry. | |
4659 */ | |
4660 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4661 alist_name(aentry_T *aep) |
7 | 4662 { |
4663 buf_T *bp; | |
4664 | |
4665 /* Use the name from the associated buffer if it exists. */ | |
4666 bp = buflist_findnr(aep->ae_fnum); | |
1036 | 4667 if (bp == NULL || bp->b_fname == NULL) |
7 | 4668 return aep->ae_fname; |
4669 return bp->b_fname; | |
4670 } | |
4671 | |
4672 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
4673 /* | |
4674 * do_arg_all(): Open up to 'count' windows, one for each argument. | |
4675 */ | |
4676 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4677 do_arg_all( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4678 int count, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4679 int forceit, /* hide buffers in current windows */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4680 int keep_tabs) /* keep current tabs, for ":tab drop file" */ |
7 | 4681 { |
4682 int i; | |
4683 win_T *wp, *wpnext; | |
3380 | 4684 char_u *opened; /* Array of weight for which args are open: |
4685 * 0: not opened | |
4686 * 1: opened in other tab | |
4687 * 2: opened in curtab | |
4688 * 3: opened in curtab and curwin | |
4689 */ | |
1411 | 4690 int opened_len; /* length of opened[] */ |
7 | 4691 int use_firstwin = FALSE; /* use first window for arglist */ |
4692 int split_ret = OK; | |
4693 int p_ea_save; | |
4694 alist_T *alist; /* argument list to be used */ | |
4695 buf_T *buf; | |
698 | 4696 tabpage_T *tpnext; |
4697 int had_tab = cmdmod.tab; | |
3380 | 4698 win_T *old_curwin, *last_curwin; |
4699 tabpage_T *old_curtab, *last_curtab; | |
726 | 4700 win_T *new_curwin = NULL; |
4701 tabpage_T *new_curtab = NULL; | |
7 | 4702 |
4703 if (ARGCOUNT <= 0) | |
4704 { | |
4705 /* Don't give an error message. We don't want it when the ":all" | |
4706 * command is in the .vimrc. */ | |
4707 return; | |
4708 } | |
4709 setpcmark(); | |
4710 | |
4711 opened_len = ARGCOUNT; | |
4712 opened = alloc_clear((unsigned)opened_len); | |
4713 if (opened == NULL) | |
4714 return; | |
4715 | |
3380 | 4716 /* Autocommands may do anything to the argument list. Make sure it's not |
4717 * freed while we are working here by "locking" it. We still have to | |
4718 * watch out for its size to be changed. */ | |
4719 alist = curwin->w_alist; | |
4720 ++alist->al_refcount; | |
4721 | |
4722 old_curwin = curwin; | |
4723 old_curtab = curtab; | |
4724 | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
4725 # ifdef FEAT_GUI |
7 | 4726 need_mouse_correct = TRUE; |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
4727 # endif |
7 | 4728 |
4729 /* | |
4730 * Try closing all windows that are not in the argument list. | |
4731 * Also close windows that are not full width; | |
4732 * When 'hidden' or "forceit" set the buffer becomes hidden. | |
4733 * Windows that have a changed buffer and can't be hidden won't be closed. | |
698 | 4734 * When the ":tab" modifier was used do this for all tab pages. |
7 | 4735 */ |
698 | 4736 if (had_tab > 0) |
4354 | 4737 goto_tabpage_tp(first_tabpage, TRUE, TRUE); |
698 | 4738 for (;;) |
7 | 4739 { |
698 | 4740 tpnext = curtab->tp_next; |
4741 for (wp = firstwin; wp != NULL; wp = wpnext) | |
7 | 4742 { |
698 | 4743 wpnext = wp->w_next; |
4744 buf = wp->w_buffer; | |
4745 if (buf->b_ffname == NULL | |
3380 | 4746 || (!keep_tabs && buf->b_nwindows > 1) |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
4747 || wp->w_width != Columns) |
3380 | 4748 i = opened_len; |
698 | 4749 else |
7 | 4750 { |
698 | 4751 /* check if the buffer in this window is in the arglist */ |
3380 | 4752 for (i = 0; i < opened_len; ++i) |
7 | 4753 { |
3380 | 4754 if (i < alist->al_ga.ga_len |
4755 && (AARGLIST(alist)[i].ae_fnum == buf->b_fnum | |
4756 || fullpathcmp(alist_name(&AARGLIST(alist)[i]), | |
4757 buf->b_ffname, TRUE) & FPC_SAME)) | |
7 | 4758 { |
3380 | 4759 int weight = 1; |
4760 | |
4761 if (old_curtab == curtab) | |
726 | 4762 { |
3380 | 4763 ++weight; |
4764 if (old_curwin == wp) | |
4765 ++weight; | |
4766 } | |
4767 | |
4768 if (weight > (int)opened[i]) | |
4769 { | |
4770 opened[i] = (char_u)weight; | |
726 | 4771 if (i == 0) |
4772 { | |
3380 | 4773 if (new_curwin != NULL) |
4774 new_curwin->w_arg_idx = opened_len; | |
726 | 4775 new_curwin = wp; |
4776 new_curtab = curtab; | |
4777 } | |
4778 } | |
3380 | 4779 else if (keep_tabs) |
4780 i = opened_len; | |
4781 | |
4782 if (wp->w_alist != alist) | |
698 | 4783 { |
4784 /* Use the current argument list for all windows | |
4785 * containing a file from it. */ | |
4786 alist_unlink(wp->w_alist); | |
3380 | 4787 wp->w_alist = alist; |
698 | 4788 ++wp->w_alist->al_refcount; |
4789 } | |
4790 break; | |
7 | 4791 } |
698 | 4792 } |
4793 } | |
4794 wp->w_arg_idx = i; | |
4795 | |
3380 | 4796 if (i == opened_len && !keep_tabs)/* close this window */ |
698 | 4797 { |
4798 if (P_HID(buf) || forceit || buf->b_nwindows > 1 | |
726 | 4799 || !bufIsChanged(buf)) |
698 | 4800 { |
4801 /* If the buffer was changed, and we would like to hide it, | |
4802 * try autowriting. */ | |
726 | 4803 if (!P_HID(buf) && buf->b_nwindows <= 1 |
4804 && bufIsChanged(buf)) | |
698 | 4805 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
4806 #ifdef FEAT_AUTOCMD |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
4807 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
4808 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
4809 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
4810 #endif |
698 | 4811 (void)autowrite(buf, FALSE); |
4812 #ifdef FEAT_AUTOCMD | |
4813 /* check if autocommands removed the window */ | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
4814 if (!win_valid(wp) || !bufref_valid(&bufref)) |
698 | 4815 { |
4816 wpnext = firstwin; /* start all over... */ | |
4817 continue; | |
4818 } | |
4819 #endif | |
4820 } | |
4821 #ifdef FEAT_WINDOWS | |
726 | 4822 /* don't close last window */ |
3380 | 4823 if (firstwin == lastwin |
4824 && (first_tabpage->tp_next == NULL || !had_tab)) | |
698 | 4825 #endif |
4826 use_firstwin = TRUE; | |
4827 #ifdef FEAT_WINDOWS | |
4828 else | |
4829 { | |
4830 win_close(wp, !P_HID(buf) && !bufIsChanged(buf)); | |
4831 # ifdef FEAT_AUTOCMD | |
4832 /* check if autocommands removed the next window */ | |
4833 if (!win_valid(wpnext)) | |
4834 wpnext = firstwin; /* start all over... */ | |
4835 # endif | |
4836 } | |
4837 #endif | |
7 | 4838 } |
4839 } | |
4840 } | |
698 | 4841 |
4842 /* Without the ":tab" modifier only do the current tab page. */ | |
4843 if (had_tab == 0 || tpnext == NULL) | |
4844 break; | |
4845 | |
7 | 4846 # ifdef FEAT_AUTOCMD |
698 | 4847 /* check if autocommands removed the next tab page */ |
4848 if (!valid_tabpage(tpnext)) | |
4849 tpnext = first_tabpage; /* start all over...*/ | |
7 | 4850 # endif |
4354 | 4851 goto_tabpage_tp(tpnext, TRUE, TRUE); |
7 | 4852 } |
4853 | |
4854 /* | |
4855 * Open a window for files in the argument list that don't have one. | |
4856 * ARGCOUNT may change while doing this, because of autocommands. | |
4857 */ | |
3380 | 4858 if (count > opened_len || count <= 0) |
4859 count = opened_len; | |
7 | 4860 |
4861 #ifdef FEAT_AUTOCMD | |
4862 /* Don't execute Win/Buf Enter/Leave autocommands here. */ | |
4863 ++autocmd_no_enter; | |
4864 ++autocmd_no_leave; | |
4865 #endif | |
3380 | 4866 last_curwin = curwin; |
4867 last_curtab = curtab; | |
7 | 4868 win_enter(lastwin, FALSE); |
819 | 4869 #ifdef FEAT_WINDOWS |
4870 /* ":drop all" should re-use an empty window to avoid "--remote-tab" | |
4871 * leaving an empty tab page when executed locally. */ | |
4872 if (keep_tabs && bufempty() && curbuf->b_nwindows == 1 | |
4873 && curbuf->b_ffname == NULL && !curbuf->b_changed) | |
4874 use_firstwin = TRUE; | |
4875 #endif | |
4876 | |
3380 | 4877 for (i = 0; i < count && i < opened_len && !got_int; ++i) |
7 | 4878 { |
4879 if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1) | |
4880 arg_had_last = TRUE; | |
3380 | 4881 if (opened[i] > 0) |
7 | 4882 { |
4883 /* Move the already present window to below the current window */ | |
4884 if (curwin->w_arg_idx != i) | |
4885 { | |
4886 for (wpnext = firstwin; wpnext != NULL; wpnext = wpnext->w_next) | |
4887 { | |
4888 if (wpnext->w_arg_idx == i) | |
4889 { | |
3380 | 4890 if (keep_tabs) |
4891 { | |
4892 new_curwin = wpnext; | |
4893 new_curtab = curtab; | |
4894 } | |
4895 else | |
4896 win_move_after(wpnext, curwin); | |
7 | 4897 break; |
4898 } | |
4899 } | |
4900 } | |
4901 } | |
4902 else if (split_ret == OK) | |
4903 { | |
4904 if (!use_firstwin) /* split current window */ | |
4905 { | |
4906 p_ea_save = p_ea; | |
4907 p_ea = TRUE; /* use space from all windows */ | |
4908 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); | |
4909 p_ea = p_ea_save; | |
4910 if (split_ret == FAIL) | |
4911 continue; | |
4912 } | |
4913 #ifdef FEAT_AUTOCMD | |
4914 else /* first window: do autocmd for leaving this buffer */ | |
4915 --autocmd_no_leave; | |
4916 #endif | |
4917 | |
4918 /* | |
726 | 4919 * edit file "i" |
7 | 4920 */ |
4921 curwin->w_arg_idx = i; | |
726 | 4922 if (i == 0) |
4923 { | |
4924 new_curwin = curwin; | |
4925 new_curtab = curtab; | |
4926 } | |
7 | 4927 (void)do_ecmd(0, alist_name(&AARGLIST(alist)[i]), NULL, NULL, |
4928 ECMD_ONE, | |
4929 ((P_HID(curwin->w_buffer) | |
4930 || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0) | |
1743 | 4931 + ECMD_OLDBUF, curwin); |
7 | 4932 #ifdef FEAT_AUTOCMD |
4933 if (use_firstwin) | |
4934 ++autocmd_no_leave; | |
4935 #endif | |
4936 use_firstwin = FALSE; | |
4937 } | |
4938 ui_breakcheck(); | |
698 | 4939 |
4940 /* When ":tab" was used open a new tab for a new window repeatedly. */ | |
4941 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) | |
4942 cmdmod.tab = 9999; | |
7 | 4943 } |
4944 | |
4945 /* Remove the "lock" on the argument list. */ | |
4946 alist_unlink(alist); | |
4947 | |
4948 #ifdef FEAT_AUTOCMD | |
4949 --autocmd_no_enter; | |
4950 #endif | |
3380 | 4951 /* restore last referenced tabpage's curwin */ |
4952 if (last_curtab != new_curtab) | |
4953 { | |
4954 if (valid_tabpage(last_curtab)) | |
4354 | 4955 goto_tabpage_tp(last_curtab, TRUE, TRUE); |
3380 | 4956 if (win_valid(last_curwin)) |
4957 win_enter(last_curwin, FALSE); | |
4958 } | |
726 | 4959 /* to window with first arg */ |
4960 if (valid_tabpage(new_curtab)) | |
4354 | 4961 goto_tabpage_tp(new_curtab, TRUE, TRUE); |
726 | 4962 if (win_valid(new_curwin)) |
4963 win_enter(new_curwin, FALSE); | |
4964 | |
7 | 4965 #ifdef FEAT_AUTOCMD |
4966 --autocmd_no_leave; | |
4967 #endif | |
4968 vim_free(opened); | |
4969 } | |
4970 | |
4971 # if defined(FEAT_LISTCMDS) || defined(PROTO) | |
4972 /* | |
4973 * Open a window for a number of buffers. | |
4974 */ | |
4975 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4976 ex_buffer_all(exarg_T *eap) |
7 | 4977 { |
4978 buf_T *buf; | |
4979 win_T *wp, *wpnext; | |
4980 int split_ret = OK; | |
4981 int p_ea_save; | |
4982 int open_wins = 0; | |
4983 int r; | |
4984 int count; /* Maximum number of windows to open. */ | |
4985 int all; /* When TRUE also load inactive buffers. */ | |
698 | 4986 #ifdef FEAT_WINDOWS |
4987 int had_tab = cmdmod.tab; | |
4988 tabpage_T *tpnext; | |
4989 #endif | |
7 | 4990 |
4991 if (eap->addr_count == 0) /* make as many windows as possible */ | |
4992 count = 9999; | |
4993 else | |
4994 count = eap->line2; /* make as many windows as specified */ | |
4995 if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) | |
4996 all = FALSE; | |
4997 else | |
4998 all = TRUE; | |
4999 | |
5000 setpcmark(); | |
5001 | |
5002 #ifdef FEAT_GUI | |
5003 need_mouse_correct = TRUE; | |
5004 #endif | |
5005 | |
5006 /* | |
5007 * Close superfluous windows (two windows for the same buffer). | |
5008 * Also close windows that are not full-width. | |
5009 */ | |
698 | 5010 #ifdef FEAT_WINDOWS |
5011 if (had_tab > 0) | |
4354 | 5012 goto_tabpage_tp(first_tabpage, TRUE, TRUE); |
698 | 5013 for (;;) |
7 | 5014 { |
698 | 5015 #endif |
5016 tpnext = curtab->tp_next; | |
5017 for (wp = firstwin; wp != NULL; wp = wpnext) | |
7 | 5018 { |
698 | 5019 wpnext = wp->w_next; |
706 | 5020 if ((wp->w_buffer->b_nwindows > 1 |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
5021 #ifdef FEAT_WINDOWS |
698 | 5022 || ((cmdmod.split & WSP_VERT) |
5023 ? wp->w_height + wp->w_status_height < Rows - p_ch | |
706 | 5024 - tabline_height() |
698 | 5025 : wp->w_width != Columns) |
701 | 5026 || (had_tab > 0 && wp != firstwin) |
5027 #endif | |
3570 | 5028 ) && firstwin != lastwin |
5029 #ifdef FEAT_AUTOCMD | |
5030 && !(wp->w_closing || wp->w_buffer->b_closing) | |
5031 #endif | |
5032 ) | |
698 | 5033 { |
5034 win_close(wp, FALSE); | |
7 | 5035 #ifdef FEAT_AUTOCMD |
698 | 5036 wpnext = firstwin; /* just in case an autocommand does |
5037 something strange with windows */ | |
701 | 5038 tpnext = first_tabpage; /* start all over...*/ |
698 | 5039 open_wins = 0; |
5040 #endif | |
5041 } | |
5042 else | |
5043 ++open_wins; | |
7 | 5044 } |
698 | 5045 |
5046 #ifdef FEAT_WINDOWS | |
5047 /* Without the ":tab" modifier only do the current tab page. */ | |
5048 if (had_tab == 0 || tpnext == NULL) | |
5049 break; | |
4354 | 5050 goto_tabpage_tp(tpnext, TRUE, TRUE); |
7 | 5051 } |
698 | 5052 #endif |
7 | 5053 |
5054 /* | |
5055 * Go through the buffer list. When a buffer doesn't have a window yet, | |
5056 * open one. Otherwise move the window to the right position. | |
5057 * Watch out for autocommands that delete buffers or windows! | |
5058 */ | |
5059 #ifdef FEAT_AUTOCMD | |
5060 /* Don't execute Win/Buf Enter/Leave autocommands here. */ | |
5061 ++autocmd_no_enter; | |
5062 #endif | |
5063 win_enter(lastwin, FALSE); | |
5064 #ifdef FEAT_AUTOCMD | |
5065 ++autocmd_no_leave; | |
5066 #endif | |
5067 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) | |
5068 { | |
5069 /* Check if this buffer needs a window */ | |
5070 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) | |
5071 continue; | |
5072 | |
701 | 5073 #ifdef FEAT_WINDOWS |
5074 if (had_tab != 0) | |
5075 { | |
5076 /* With the ":tab" modifier don't move the window. */ | |
5077 if (buf->b_nwindows > 0) | |
5078 wp = lastwin; /* buffer has a window, skip it */ | |
5079 else | |
5080 wp = NULL; | |
5081 } | |
5082 else | |
5083 #endif | |
5084 { | |
5085 /* Check if this buffer already has a window */ | |
5086 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
5087 if (wp->w_buffer == buf) | |
5088 break; | |
5089 /* If the buffer already has a window, move it */ | |
5090 if (wp != NULL) | |
5091 win_move_after(wp, curwin); | |
5092 } | |
5093 | |
5094 if (wp == NULL && split_ret == OK) | |
7 | 5095 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5096 #ifdef FEAT_AUTOCMD |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5097 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5098 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5099 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5100 #endif |
7 | 5101 /* Split the window and put the buffer in it */ |
5102 p_ea_save = p_ea; | |
5103 p_ea = TRUE; /* use space from all windows */ | |
5104 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); | |
5105 ++open_wins; | |
5106 p_ea = p_ea_save; | |
5107 if (split_ret == FAIL) | |
5108 continue; | |
5109 | |
5110 /* Open the buffer in this window. */ | |
576 | 5111 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 5112 swap_exists_action = SEA_DIALOG; |
5113 #endif | |
5114 set_curbuf(buf, DOBUF_GOTO); | |
5115 #ifdef FEAT_AUTOCMD | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5116 if (!bufref_valid(&bufref)) |
20 | 5117 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5118 /* autocommands deleted the buffer!!! */ |
576 | 5119 #if defined(HAS_SWAP_EXISTS_ACTION) |
20 | 5120 swap_exists_action = SEA_NONE; |
7 | 5121 # endif |
5122 break; | |
5123 } | |
5124 #endif | |
576 | 5125 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 5126 if (swap_exists_action == SEA_QUIT) |
5127 { | |
24 | 5128 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
5129 cleanup_T cs; | |
5130 | |
5131 /* Reset the error/interrupt/exception state here so that | |
5132 * aborting() returns FALSE when closing a window. */ | |
5133 enter_cleanup(&cs); | |
5134 # endif | |
5135 | |
5136 /* User selected Quit at ATTENTION prompt; close this window. */ | |
7 | 5137 win_close(curwin, TRUE); |
5138 --open_wins; | |
5139 swap_exists_action = SEA_NONE; | |
602 | 5140 swap_exists_did_quit = TRUE; |
24 | 5141 |
5142 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
5143 /* Restore the error/interrupt/exception state if not | |
5144 * discarded by a new aborting error, interrupt, or uncaught | |
5145 * exception. */ | |
5146 leave_cleanup(&cs); | |
5147 # endif | |
7 | 5148 } |
5149 else | |
5150 handle_swap_exists(NULL); | |
5151 #endif | |
5152 } | |
5153 | |
5154 ui_breakcheck(); | |
5155 if (got_int) | |
5156 { | |
5157 (void)vgetc(); /* only break the file loading, not the rest */ | |
5158 break; | |
5159 } | |
20 | 5160 #ifdef FEAT_EVAL |
5161 /* Autocommands deleted the buffer or aborted script processing!!! */ | |
5162 if (aborting()) | |
5163 break; | |
5164 #endif | |
698 | 5165 #ifdef FEAT_WINDOWS |
5166 /* When ":tab" was used open a new tab for a new window repeatedly. */ | |
5167 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) | |
5168 cmdmod.tab = 9999; | |
5169 #endif | |
7 | 5170 } |
5171 #ifdef FEAT_AUTOCMD | |
5172 --autocmd_no_enter; | |
5173 #endif | |
5174 win_enter(firstwin, FALSE); /* back to first window */ | |
5175 #ifdef FEAT_AUTOCMD | |
5176 --autocmd_no_leave; | |
5177 #endif | |
5178 | |
5179 /* | |
5180 * Close superfluous windows. | |
5181 */ | |
5182 for (wp = lastwin; open_wins > count; ) | |
5183 { | |
5184 r = (P_HID(wp->w_buffer) || !bufIsChanged(wp->w_buffer) | |
5185 || autowrite(wp->w_buffer, FALSE) == OK); | |
5186 #ifdef FEAT_AUTOCMD | |
5187 if (!win_valid(wp)) | |
5188 { | |
5189 /* BufWrite Autocommands made the window invalid, start over */ | |
5190 wp = lastwin; | |
5191 } | |
5192 else | |
5193 #endif | |
5194 if (r) | |
5195 { | |
5196 win_close(wp, !P_HID(wp->w_buffer)); | |
5197 --open_wins; | |
5198 wp = lastwin; | |
5199 } | |
5200 else | |
5201 { | |
5202 wp = wp->w_prev; | |
5203 if (wp == NULL) | |
5204 break; | |
5205 } | |
5206 } | |
5207 } | |
5208 # endif /* FEAT_LISTCMDS */ | |
5209 | |
5210 #endif /* FEAT_WINDOWS */ | |
5211 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
5212 static int chk_modeline(linenr_T, int); |
717 | 5213 |
7 | 5214 /* |
5215 * do_modelines() - process mode lines for the current file | |
5216 * | |
717 | 5217 * "flags" can be: |
5218 * OPT_WINONLY only set options local to window | |
5219 * OPT_NOWIN don't set options local to window | |
5220 * | |
7 | 5221 * Returns immediately if the "ml" option isn't set. |
5222 */ | |
5223 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5224 do_modelines(int flags) |
7 | 5225 { |
23 | 5226 linenr_T lnum; |
5227 int nmlines; | |
5228 static int entered = 0; | |
7 | 5229 |
5230 if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0) | |
5231 return; | |
5232 | |
5233 /* Disallow recursive entry here. Can happen when executing a modeline | |
5234 * triggers an autocommand, which reloads modelines with a ":do". */ | |
5235 if (entered) | |
5236 return; | |
5237 | |
5238 ++entered; | |
5239 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines; | |
5240 ++lnum) | |
717 | 5241 if (chk_modeline(lnum, flags) == FAIL) |
7 | 5242 nmlines = 0; |
5243 | |
5244 for (lnum = curbuf->b_ml.ml_line_count; lnum > 0 && lnum > nmlines | |
5245 && lnum > curbuf->b_ml.ml_line_count - nmlines; --lnum) | |
717 | 5246 if (chk_modeline(lnum, flags) == FAIL) |
7 | 5247 nmlines = 0; |
5248 --entered; | |
5249 } | |
5250 | |
5251 #include "version.h" /* for version number */ | |
5252 | |
5253 /* | |
5254 * chk_modeline() - check a single line for a mode string | |
5255 * Return FAIL if an error encountered. | |
5256 */ | |
5257 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5258 chk_modeline( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5259 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5260 int flags) /* Same as for do_modelines(). */ |
7 | 5261 { |
5262 char_u *s; | |
5263 char_u *e; | |
5264 char_u *linecopy; /* local copy of any modeline found */ | |
5265 int prev; | |
5266 int vers; | |
5267 int end; | |
5268 int retval = OK; | |
5269 char_u *save_sourcing_name; | |
5270 linenr_T save_sourcing_lnum; | |
5271 #ifdef FEAT_EVAL | |
5272 scid_T save_SID; | |
5273 #endif | |
5274 | |
5275 prev = -1; | |
5276 for (s = ml_get(lnum); *s != NUL; ++s) | |
5277 { | |
5278 if (prev == -1 || vim_isspace(prev)) | |
5279 { | |
5280 if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) | |
5281 || STRNCMP(s, "vi:", (size_t)3) == 0) | |
5282 break; | |
5010
b614332f7df2
updated for version 7.3.1249
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
5283 /* Accept both "vim" and "Vim". */ |
b614332f7df2
updated for version 7.3.1249
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
5284 if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') |
7 | 5285 { |
5286 if (s[3] == '<' || s[3] == '=' || s[3] == '>') | |
5287 e = s + 4; | |
5288 else | |
5289 e = s + 3; | |
5290 vers = getdigits(&e); | |
5291 if (*e == ':' | |
5043
53c1b30632df
updated for version 7.3.1265
Bram Moolenaar <bram@vim.org>
parents:
5010
diff
changeset
|
5292 && (s[0] != 'V' |
53c1b30632df
updated for version 7.3.1265
Bram Moolenaar <bram@vim.org>
parents:
5010
diff
changeset
|
5293 || STRNCMP(skipwhite(e + 1), "set", 3) == 0) |
7 | 5294 && (s[3] == ':' |
5295 || (VIM_VERSION_100 >= vers && isdigit(s[3])) | |
5296 || (VIM_VERSION_100 < vers && s[3] == '<') | |
5297 || (VIM_VERSION_100 > vers && s[3] == '>') | |
5298 || (VIM_VERSION_100 == vers && s[3] == '='))) | |
5299 break; | |
5300 } | |
5301 } | |
5302 prev = *s; | |
5303 } | |
5304 | |
5305 if (*s) | |
5306 { | |
5307 do /* skip over "ex:", "vi:" or "vim:" */ | |
5308 ++s; | |
5309 while (s[-1] != ':'); | |
5310 | |
5311 s = linecopy = vim_strsave(s); /* copy the line, it will change */ | |
5312 if (linecopy == NULL) | |
5313 return FAIL; | |
5314 | |
5315 save_sourcing_lnum = sourcing_lnum; | |
5316 save_sourcing_name = sourcing_name; | |
5317 sourcing_lnum = lnum; /* prepare for emsg() */ | |
5318 sourcing_name = (char_u *)"modelines"; | |
5319 | |
5320 end = FALSE; | |
5321 while (end == FALSE) | |
5322 { | |
5323 s = skipwhite(s); | |
5324 if (*s == NUL) | |
5325 break; | |
5326 | |
5327 /* | |
5328 * Find end of set command: ':' or end of line. | |
5329 * Skip over "\:", replacing it with ":". | |
5330 */ | |
5331 for (e = s; *e != ':' && *e != NUL; ++e) | |
5332 if (e[0] == '\\' && e[1] == ':') | |
1618 | 5333 STRMOVE(e, e + 1); |
7 | 5334 if (*e == NUL) |
5335 end = TRUE; | |
5336 | |
5337 /* | |
5338 * If there is a "set" command, require a terminating ':' and | |
5339 * ignore the stuff after the ':'. | |
5340 * "vi:set opt opt opt: foo" -- foo not interpreted | |
5341 * "vi:opt opt opt: foo" -- foo interpreted | |
5342 * Accept "se" for compatibility with Elvis. | |
5343 */ | |
5344 if (STRNCMP(s, "set ", (size_t)4) == 0 | |
5345 || STRNCMP(s, "se ", (size_t)3) == 0) | |
5346 { | |
5347 if (*e != ':') /* no terminating ':'? */ | |
5348 break; | |
5349 end = TRUE; | |
5350 s = vim_strchr(s, ' ') + 1; | |
5351 } | |
5352 *e = NUL; /* truncate the set command */ | |
5353 | |
5354 if (*s != NUL) /* skip over an empty "::" */ | |
5355 { | |
5356 #ifdef FEAT_EVAL | |
5357 save_SID = current_SID; | |
5358 current_SID = SID_MODELINE; | |
5359 #endif | |
717 | 5360 retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); |
7 | 5361 #ifdef FEAT_EVAL |
5362 current_SID = save_SID; | |
5363 #endif | |
5364 if (retval == FAIL) /* stop if error found */ | |
5365 break; | |
5366 } | |
5367 s = e + 1; /* advance to next part */ | |
5368 } | |
5369 | |
5370 sourcing_lnum = save_sourcing_lnum; | |
5371 sourcing_name = save_sourcing_name; | |
5372 | |
5373 vim_free(linecopy); | |
5374 } | |
5375 return retval; | |
5376 } | |
5377 | |
1559 | 5378 #if defined(FEAT_VIMINFO) || defined(PROTO) |
7 | 5379 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5380 read_viminfo_bufferlist( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5381 vir_T *virp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5382 int writing) |
7 | 5383 { |
5384 char_u *tab; | |
5385 linenr_T lnum; | |
5386 colnr_T col; | |
5387 buf_T *buf; | |
5388 char_u *sfname; | |
5389 char_u *xline; | |
5390 | |
5391 /* Handle long line and escaped characters. */ | |
5392 xline = viminfo_readstring(virp, 1, FALSE); | |
5393 | |
5394 /* don't read in if there are files on the command-line or if writing: */ | |
5395 if (xline != NULL && !writing && ARGCOUNT == 0 | |
5396 && find_viminfo_parameter('%') != NULL) | |
5397 { | |
5398 /* Format is: <fname> Tab <lnum> Tab <col>. | |
5399 * Watch out for a Tab in the file name, work from the end. */ | |
5400 lnum = 0; | |
5401 col = 0; | |
5402 tab = vim_strrchr(xline, '\t'); | |
5403 if (tab != NULL) | |
5404 { | |
5405 *tab++ = '\0'; | |
1869 | 5406 col = (colnr_T)atoi((char *)tab); |
7 | 5407 tab = vim_strrchr(xline, '\t'); |
5408 if (tab != NULL) | |
5409 { | |
5410 *tab++ = '\0'; | |
5411 lnum = atol((char *)tab); | |
5412 } | |
5413 } | |
5414 | |
5415 /* Expand "~/" in the file name at "line + 1" to a full path. | |
5416 * Then try shortening it by comparing with the current directory */ | |
5417 expand_env(xline, NameBuff, MAXPATHL); | |
1411 | 5418 sfname = shorten_fname1(NameBuff); |
7 | 5419 |
5420 buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED); | |
5421 if (buf != NULL) /* just in case... */ | |
5422 { | |
5423 buf->b_last_cursor.lnum = lnum; | |
5424 buf->b_last_cursor.col = col; | |
5425 buflist_setfpos(buf, curwin, lnum, col, FALSE); | |
5426 } | |
5427 } | |
5428 vim_free(xline); | |
5429 | |
5430 return viminfo_readline(virp); | |
5431 } | |
5432 | |
5433 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5434 write_viminfo_bufferlist(FILE *fp) |
7 | 5435 { |
5436 buf_T *buf; | |
5437 #ifdef FEAT_WINDOWS | |
5438 win_T *win; | |
671 | 5439 tabpage_T *tp; |
7 | 5440 #endif |
5441 char_u *line; | |
23 | 5442 int max_buffers; |
7 | 5443 |
5444 if (find_viminfo_parameter('%') == NULL) | |
5445 return; | |
5446 | |
23 | 5447 /* Without a number -1 is returned: do all buffers. */ |
5448 max_buffers = get_viminfo_parameter('%'); | |
5449 | |
7 | 5450 /* Allocate room for the file name, lnum and col. */ |
1869 | 5451 #define LINE_BUF_LEN (MAXPATHL + 40) |
5452 line = alloc(LINE_BUF_LEN); | |
7 | 5453 if (line == NULL) |
5454 return; | |
5455 | |
5456 #ifdef FEAT_WINDOWS | |
671 | 5457 FOR_ALL_TAB_WINDOWS(tp, win) |
7 | 5458 set_last_cursor(win); |
5459 #else | |
5460 set_last_cursor(curwin); | |
5461 #endif | |
5462 | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
5463 fputs(_("\n# Buffer list:\n"), fp); |
7 | 5464 for (buf = firstbuf; buf != NULL ; buf = buf->b_next) |
5465 { | |
5466 if (buf->b_fname == NULL | |
5467 || !buf->b_p_bl | |
5468 #ifdef FEAT_QUICKFIX | |
5469 || bt_quickfix(buf) | |
5470 #endif | |
5471 || removable(buf->b_ffname)) | |
5472 continue; | |
5473 | |
23 | 5474 if (max_buffers-- == 0) |
5475 break; | |
7 | 5476 putc('%', fp); |
5477 home_replace(NULL, buf->b_ffname, line, MAXPATHL, TRUE); | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
5478 vim_snprintf_add((char *)line, LINE_BUF_LEN, "\t%ld\t%d", |
7 | 5479 (long)buf->b_last_cursor.lnum, |
5480 buf->b_last_cursor.col); | |
5481 viminfo_writestring(fp, line); | |
5482 } | |
5483 vim_free(line); | |
5484 } | |
5485 #endif | |
5486 | |
5487 | |
5488 /* | |
5489 * Return special buffer name. | |
5490 * Returns NULL when the buffer has a normal file name. | |
5491 */ | |
3839 | 5492 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5493 buf_spname(buf_T *buf) |
7 | 5494 { |
5495 #if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
5496 if (bt_quickfix(buf)) | |
643 | 5497 { |
5208
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5498 win_T *win; |
1559 | 5499 tabpage_T *tp; |
643 | 5500 |
5501 /* | |
5502 * For location list window, w_llist_ref points to the location list. | |
5503 * For quickfix window, w_llist_ref is NULL. | |
5504 */ | |
5208
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5505 if (find_win_for_buf(buf, &win, &tp) == OK && win->w_llist_ref != NULL) |
3839 | 5506 return (char_u *)_(msg_loclist); |
643 | 5507 else |
3839 | 5508 return (char_u *)_(msg_qflist); |
643 | 5509 } |
7 | 5510 #endif |
5511 #ifdef FEAT_QUICKFIX | |
5512 /* There is no _file_ when 'buftype' is "nofile", b_sfname | |
5513 * contains the name as specified by the user */ | |
5514 if (bt_nofile(buf)) | |
5515 { | |
5516 if (buf->b_sfname != NULL) | |
3839 | 5517 return buf->b_sfname; |
5518 return (char_u *)_("[Scratch]"); | |
7 | 5519 } |
5520 #endif | |
5521 if (buf->b_fname == NULL) | |
3839 | 5522 return (char_u *)_("[No Name]"); |
7 | 5523 return NULL; |
5524 } | |
5525 | |
5208
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5526 #if (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5527 || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \ |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5528 || defined(PROTO) |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5529 /* |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5530 * Find a window for buffer "buf". |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5531 * If found OK is returned and "wp" and "tp" are set to the window and tabpage. |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5532 * If not found FAIL is returned. |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5533 */ |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5534 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5535 find_win_for_buf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5536 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5537 win_T **wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5538 tabpage_T **tp) |
5208
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5539 { |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5540 FOR_ALL_TAB_WINDOWS(*tp, *wp) |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5541 if ((*wp)->w_buffer == buf) |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5542 goto win_found; |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5543 return FAIL; |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5544 win_found: |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5545 return OK; |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5546 } |
bc4fb0317465
updated for version 7.4a.030
Bram Moolenaar <bram@vim.org>
parents:
5043
diff
changeset
|
5547 #endif |
7 | 5548 |
5549 #if defined(FEAT_SIGNS) || defined(PROTO) | |
5550 /* | |
5551 * Insert the sign into the signlist. | |
5552 */ | |
5553 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5554 insert_sign( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5555 buf_T *buf, /* buffer to store sign in */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5556 signlist_T *prev, /* previous sign entry */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5557 signlist_T *next, /* next sign entry */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5558 int id, /* sign ID */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5559 linenr_T lnum, /* line number which gets the mark */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5560 int typenr) /* typenr of sign we are adding */ |
7 | 5561 { |
5562 signlist_T *newsign; | |
5563 | |
5564 newsign = (signlist_T *)lalloc((long_u)sizeof(signlist_T), FALSE); | |
5565 if (newsign != NULL) | |
5566 { | |
5567 newsign->id = id; | |
5568 newsign->lnum = lnum; | |
5569 newsign->typenr = typenr; | |
5570 newsign->next = next; | |
5571 #ifdef FEAT_NETBEANS_INTG | |
5572 newsign->prev = prev; | |
5573 if (next != NULL) | |
5574 next->prev = newsign; | |
5575 #endif | |
5576 | |
5577 if (prev == NULL) | |
5578 { | |
5579 /* When adding first sign need to redraw the windows to create the | |
5580 * column for signs. */ | |
5581 if (buf->b_signlist == NULL) | |
5582 { | |
5583 redraw_buf_later(buf, NOT_VALID); | |
5584 changed_cline_bef_curs(); | |
5585 } | |
5586 | |
5587 /* first sign in signlist */ | |
5588 buf->b_signlist = newsign; | |
6689 | 5589 #ifdef FEAT_NETBEANS_INTG |
5590 if (netbeans_active()) | |
5591 buf->b_has_sign_column = TRUE; | |
5592 #endif | |
7 | 5593 } |
5594 else | |
5595 prev->next = newsign; | |
5596 } | |
5597 } | |
5598 | |
5599 /* | |
5600 * Add the sign into the signlist. Find the right spot to do it though. | |
5601 */ | |
5602 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5603 buf_addsign( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5604 buf_T *buf, /* buffer to store sign in */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5605 int id, /* sign ID */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5606 linenr_T lnum, /* line number which gets the mark */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5607 int typenr) /* typenr of sign we are adding */ |
7 | 5608 { |
5609 signlist_T *sign; /* a sign in the signlist */ | |
5610 signlist_T *prev; /* the previous sign */ | |
5611 | |
5612 prev = NULL; | |
5613 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5614 { | |
5615 if (lnum == sign->lnum && id == sign->id) | |
5616 { | |
5617 sign->typenr = typenr; | |
5618 return; | |
5619 } | |
5620 else if ( | |
5621 #ifndef FEAT_NETBEANS_INTG /* keep signs sorted by lnum */ | |
5622 id < 0 && | |
5623 #endif | |
5624 lnum < sign->lnum) | |
5625 { | |
5626 #ifdef FEAT_NETBEANS_INTG /* insert new sign at head of list for this lnum */ | |
5627 /* XXX - GRP: Is this because of sign slide problem? Or is it | |
5628 * really needed? Or is it because we allow multiple signs per | |
5629 * line? If so, should I add that feature to FEAT_SIGNS? | |
5630 */ | |
5631 while (prev != NULL && prev->lnum == lnum) | |
5632 prev = prev->prev; | |
5633 if (prev == NULL) | |
5634 sign = buf->b_signlist; | |
5635 else | |
5636 sign = prev->next; | |
5637 #endif | |
5638 insert_sign(buf, prev, sign, id, lnum, typenr); | |
5639 return; | |
5640 } | |
5641 prev = sign; | |
5642 } | |
5643 #ifdef FEAT_NETBEANS_INTG /* insert new sign at head of list for this lnum */ | |
5644 /* XXX - GRP: See previous comment */ | |
5645 while (prev != NULL && prev->lnum == lnum) | |
5646 prev = prev->prev; | |
5647 if (prev == NULL) | |
5648 sign = buf->b_signlist; | |
5649 else | |
5650 sign = prev->next; | |
5651 #endif | |
5652 insert_sign(buf, prev, sign, id, lnum, typenr); | |
5653 | |
5654 return; | |
5655 } | |
5656 | |
5869 | 5657 /* |
5658 * For an existing, placed sign "markId" change the type to "typenr". | |
5659 * Returns the line number of the sign, or zero if the sign is not found. | |
5660 */ | |
1869 | 5661 linenr_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5662 buf_change_sign_type( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5663 buf_T *buf, /* buffer to store sign in */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5664 int markId, /* sign ID */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5665 int typenr) /* typenr of sign we are adding */ |
7 | 5666 { |
5667 signlist_T *sign; /* a sign in the signlist */ | |
5668 | |
5669 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5670 { | |
5671 if (sign->id == markId) | |
5672 { | |
5673 sign->typenr = typenr; | |
5674 return sign->lnum; | |
5675 } | |
5676 } | |
5677 | |
1869 | 5678 return (linenr_T)0; |
7 | 5679 } |
5680 | |
1869 | 5681 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5682 buf_getsigntype( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5683 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5684 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5685 int type) /* SIGN_ICON, SIGN_TEXT, SIGN_ANY, SIGN_LINEHL */ |
7 | 5686 { |
5687 signlist_T *sign; /* a sign in a b_signlist */ | |
5688 | |
5689 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5690 if (sign->lnum == lnum | |
5691 && (type == SIGN_ANY | |
5692 # ifdef FEAT_SIGN_ICONS | |
5693 || (type == SIGN_ICON | |
5694 && sign_get_image(sign->typenr) != NULL) | |
5695 # endif | |
5696 || (type == SIGN_TEXT | |
5697 && sign_get_text(sign->typenr) != NULL) | |
5698 || (type == SIGN_LINEHL | |
5699 && sign_get_attr(sign->typenr, TRUE) != 0))) | |
5700 return sign->typenr; | |
5701 return 0; | |
5702 } | |
5703 | |
5704 | |
5705 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5706 buf_delsign( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5707 buf_T *buf, /* buffer sign is stored in */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5708 int id) /* sign id */ |
7 | 5709 { |
5710 signlist_T **lastp; /* pointer to pointer to current sign */ | |
5711 signlist_T *sign; /* a sign in a b_signlist */ | |
5712 signlist_T *next; /* the next sign in a b_signlist */ | |
5713 linenr_T lnum; /* line number whose sign was deleted */ | |
5714 | |
5715 lastp = &buf->b_signlist; | |
5716 lnum = 0; | |
5717 for (sign = buf->b_signlist; sign != NULL; sign = next) | |
5718 { | |
5719 next = sign->next; | |
5720 if (sign->id == id) | |
5721 { | |
5722 *lastp = next; | |
5723 #ifdef FEAT_NETBEANS_INTG | |
5724 if (next != NULL) | |
5725 next->prev = sign->prev; | |
5726 #endif | |
5727 lnum = sign->lnum; | |
5728 vim_free(sign); | |
5729 break; | |
5730 } | |
5731 else | |
5732 lastp = &sign->next; | |
5733 } | |
5734 | |
5735 /* When deleted the last sign need to redraw the windows to remove the | |
5736 * sign column. */ | |
5737 if (buf->b_signlist == NULL) | |
5738 { | |
5739 redraw_buf_later(buf, NOT_VALID); | |
5740 changed_cline_bef_curs(); | |
5741 } | |
5742 | |
5743 return lnum; | |
5744 } | |
5745 | |
5746 | |
5747 /* | |
5748 * Find the line number of the sign with the requested id. If the sign does | |
5749 * not exist, return 0 as the line number. This will still let the correct file | |
5750 * get loaded. | |
5751 */ | |
5752 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5753 buf_findsign( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5754 buf_T *buf, /* buffer to store sign in */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5755 int id) /* sign ID */ |
7 | 5756 { |
5757 signlist_T *sign; /* a sign in the signlist */ | |
5758 | |
5759 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5760 if (sign->id == id) | |
5761 return sign->lnum; | |
5762 | |
5763 return 0; | |
5764 } | |
5765 | |
5766 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5767 buf_findsign_id( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5768 buf_T *buf, /* buffer whose sign we are searching for */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5769 linenr_T lnum) /* line number of sign */ |
7 | 5770 { |
5771 signlist_T *sign; /* a sign in the signlist */ | |
5772 | |
5773 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5774 if (sign->lnum == lnum) | |
5775 return sign->id; | |
5776 | |
5777 return 0; | |
5778 } | |
5779 | |
5780 | |
5781 # if defined(FEAT_NETBEANS_INTG) || defined(PROTO) | |
5782 /* see if a given type of sign exists on a specific line */ | |
5783 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5784 buf_findsigntype_id( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5785 buf_T *buf, /* buffer whose sign we are searching for */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5786 linenr_T lnum, /* line number of sign */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5787 int typenr) /* sign type number */ |
7 | 5788 { |
5789 signlist_T *sign; /* a sign in the signlist */ | |
5790 | |
5791 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5792 if (sign->lnum == lnum && sign->typenr == typenr) | |
5793 return sign->id; | |
5794 | |
5795 return 0; | |
5796 } | |
5797 | |
5798 | |
5799 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
5800 /* return the number of icons on the given line */ | |
5801 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5802 buf_signcount(buf_T *buf, linenr_T lnum) |
7 | 5803 { |
5804 signlist_T *sign; /* a sign in the signlist */ | |
5805 int count = 0; | |
5806 | |
5807 for (sign = buf->b_signlist; sign != NULL; sign = sign->next) | |
5808 if (sign->lnum == lnum) | |
5809 if (sign_get_image(sign->typenr) != NULL) | |
5810 count++; | |
5811 | |
5812 return count; | |
5813 } | |
5814 # endif /* FEAT_SIGN_ICONS */ | |
5815 # endif /* FEAT_NETBEANS_INTG */ | |
5816 | |
5817 | |
5818 /* | |
5819 * Delete signs in buffer "buf". | |
5820 */ | |
3672 | 5821 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5822 buf_delete_signs(buf_T *buf) |
7 | 5823 { |
5824 signlist_T *next; | |
5825 | |
5869 | 5826 /* When deleting the last sign need to redraw the windows to remove the |
6060 | 5827 * sign column. Not when curwin is NULL (this means we're exiting). */ |
5828 if (buf->b_signlist != NULL && curwin != NULL) | |
5869 | 5829 { |
5830 redraw_buf_later(buf, NOT_VALID); | |
5831 changed_cline_bef_curs(); | |
5832 } | |
5833 | |
7 | 5834 while (buf->b_signlist != NULL) |
5835 { | |
5836 next = buf->b_signlist->next; | |
5837 vim_free(buf->b_signlist); | |
5838 buf->b_signlist = next; | |
5839 } | |
5840 } | |
5841 | |
5842 /* | |
5843 * Delete all signs in all buffers. | |
5844 */ | |
5845 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5846 buf_delete_all_signs(void) |
7 | 5847 { |
5848 buf_T *buf; /* buffer we are checking for signs */ | |
5849 | |
5850 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
5851 if (buf->b_signlist != NULL) | |
5852 buf_delete_signs(buf); | |
5853 } | |
5854 | |
5855 /* | |
5856 * List placed signs for "rbuf". If "rbuf" is NULL do it for all buffers. | |
5857 */ | |
5858 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5859 sign_list_placed(buf_T *rbuf) |
7 | 5860 { |
5861 buf_T *buf; | |
5862 signlist_T *p; | |
5863 char lbuf[BUFSIZ]; | |
5864 | |
5865 MSG_PUTS_TITLE(_("\n--- Signs ---")); | |
5866 msg_putchar('\n'); | |
5867 if (rbuf == NULL) | |
5868 buf = firstbuf; | |
5869 else | |
5870 buf = rbuf; | |
3411 | 5871 while (buf != NULL && !got_int) |
7 | 5872 { |
5873 if (buf->b_signlist != NULL) | |
5874 { | |
272 | 5875 vim_snprintf(lbuf, BUFSIZ, _("Signs for %s:"), buf->b_fname); |
7 | 5876 MSG_PUTS_ATTR(lbuf, hl_attr(HLF_D)); |
5877 msg_putchar('\n'); | |
5878 } | |
3411 | 5879 for (p = buf->b_signlist; p != NULL && !got_int; p = p->next) |
7 | 5880 { |
272 | 5881 vim_snprintf(lbuf, BUFSIZ, _(" line=%ld id=%d name=%s"), |
7 | 5882 (long)p->lnum, p->id, sign_typenr2name(p->typenr)); |
5883 MSG_PUTS(lbuf); | |
5884 msg_putchar('\n'); | |
5885 } | |
5886 if (rbuf != NULL) | |
5887 break; | |
5888 buf = buf->b_next; | |
5889 } | |
5890 } | |
5891 | |
5892 /* | |
5893 * Adjust a placed sign for inserted/deleted lines. | |
5894 */ | |
5895 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5896 sign_mark_adjust( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5897 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5898 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5899 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5900 long amount_after) |
7 | 5901 { |
5902 signlist_T *sign; /* a sign in a b_signlist */ | |
5903 | |
5904 for (sign = curbuf->b_signlist; sign != NULL; sign = sign->next) | |
5905 { | |
5906 if (sign->lnum >= line1 && sign->lnum <= line2) | |
5907 { | |
5908 if (amount == MAXLNUM) | |
5909 sign->lnum = line1; | |
5910 else | |
5911 sign->lnum += amount; | |
5912 } | |
5913 else if (sign->lnum > line2) | |
5914 sign->lnum += amount_after; | |
5915 } | |
5916 } | |
5917 #endif /* FEAT_SIGNS */ | |
5918 | |
5919 /* | |
5920 * Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed. | |
5921 */ | |
5922 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5923 set_buflisted(int on) |
7 | 5924 { |
5925 if (on != curbuf->b_p_bl) | |
5926 { | |
5927 curbuf->b_p_bl = on; | |
5928 #ifdef FEAT_AUTOCMD | |
5929 if (on) | |
5930 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); | |
5931 else | |
5932 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
5933 #endif | |
5934 } | |
5935 } | |
5936 | |
5937 /* | |
5938 * Read the file for "buf" again and check if the contents changed. | |
5939 * Return TRUE if it changed or this could not be checked. | |
5940 */ | |
5941 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5942 buf_contents_changed(buf_T *buf) |
7 | 5943 { |
5944 buf_T *newbuf; | |
5945 int differ = TRUE; | |
5946 linenr_T lnum; | |
5947 aco_save_T aco; | |
5948 exarg_T ea; | |
5949 | |
5950 /* Allocate a buffer without putting it in the buffer list. */ | |
5951 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); | |
5952 if (newbuf == NULL) | |
5953 return TRUE; | |
5954 | |
5955 /* Force the 'fileencoding' and 'fileformat' to be equal. */ | |
5956 if (prep_exarg(&ea, buf) == FAIL) | |
5957 { | |
5958 wipe_buffer(newbuf, FALSE); | |
5959 return TRUE; | |
5960 } | |
5961 | |
5962 /* set curwin/curbuf to buf and save a few things */ | |
5963 aucmd_prepbuf(&aco, newbuf); | |
5964 | |
625 | 5965 if (ml_open(curbuf) == OK |
7 | 5966 && readfile(buf->b_ffname, buf->b_fname, |
5967 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, | |
5968 &ea, READ_NEW | READ_DUMMY) == OK) | |
5969 { | |
5970 /* compare the two files line by line */ | |
5971 if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) | |
5972 { | |
5973 differ = FALSE; | |
5974 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
5975 if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0) | |
5976 { | |
5977 differ = TRUE; | |
5978 break; | |
5979 } | |
5980 } | |
5981 } | |
5982 vim_free(ea.cmd); | |
5983 | |
5984 /* restore curwin/curbuf and a few other things */ | |
5985 aucmd_restbuf(&aco); | |
5986 | |
5987 if (curbuf != newbuf) /* safety check */ | |
5988 wipe_buffer(newbuf, FALSE); | |
5989 | |
5990 return differ; | |
5991 } | |
5992 | |
5993 /* | |
5994 * Wipe out a buffer and decrement the last buffer number if it was used for | |
5995 * this buffer. Call this to wipe out a temp buffer that does not contain any | |
5996 * marks. | |
5997 */ | |
5998 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5999 wipe_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6000 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6001 int aucmd UNUSED) /* When TRUE trigger autocommands. */ |
7 | 6002 { |
6003 if (buf->b_fnum == top_file_num - 1) | |
6004 --top_file_num; | |
6005 | |
6006 #ifdef FEAT_AUTOCMD | |
6007 if (!aucmd) /* Don't trigger BufDelete autocommands here. */ | |
1410 | 6008 block_autocmds(); |
7 | 6009 #endif |
3365 | 6010 close_buffer(NULL, buf, DOBUF_WIPE, FALSE); |
7 | 6011 #ifdef FEAT_AUTOCMD |
6012 if (!aucmd) | |
1410 | 6013 unblock_autocmds(); |
7 | 6014 #endif |
6015 } |