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