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