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