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