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