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