Mercurial > vim
annotate src/quickfix.c @ 5062:761cef8f5d1d v7.3.1274
updated for version 7.3.1274
Problem: When selecting an entry from a location list it may pick an
arbitrary window or open a new one.
Solution: Prefer using a window related to the location list. (Lech Lorens)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sun, 30 Jun 2013 13:57:45 +0200 |
parents | 30910831e5b0 |
children | 14e7a115d54d |
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 * quickfix.c: functions for quickfix mode, using a file with error messages | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 #if defined(FEAT_QUICKFIX) || defined(PROTO) | |
17 | |
18 struct dir_stack_T | |
19 { | |
20 struct dir_stack_T *next; | |
21 char_u *dirname; | |
22 }; | |
23 | |
24 static struct dir_stack_T *dir_stack = NULL; | |
25 | |
26 /* | |
230 | 27 * For each error the next struct is allocated and linked in a list. |
7 | 28 */ |
230 | 29 typedef struct qfline_S qfline_T; |
30 struct qfline_S | |
7 | 31 { |
230 | 32 qfline_T *qf_next; /* pointer to next error in the list */ |
33 qfline_T *qf_prev; /* pointer to previous error in the list */ | |
34 linenr_T qf_lnum; /* line number where the error occurred */ | |
35 int qf_fnum; /* file number for the line */ | |
36 int qf_col; /* column where the error occurred */ | |
37 int qf_nr; /* error number */ | |
38 char_u *qf_pattern; /* search pattern for the error */ | |
39 char_u *qf_text; /* description of the error */ | |
40 char_u qf_viscol; /* set to TRUE if qf_col is screen column */ | |
41 char_u qf_cleared; /* set to TRUE if line has been deleted */ | |
42 char_u qf_type; /* type of the error (mostly 'E'); 1 for | |
7 | 43 :helpgrep */ |
230 | 44 char_u qf_valid; /* valid error message detected */ |
7 | 45 }; |
46 | |
47 /* | |
48 * There is a stack of error lists. | |
49 */ | |
50 #define LISTCOUNT 10 | |
51 | |
644 | 52 typedef struct qf_list_S |
7 | 53 { |
230 | 54 qfline_T *qf_start; /* pointer to the first error */ |
55 qfline_T *qf_ptr; /* pointer to the current error */ | |
56 int qf_count; /* number of errors (0 means no error list) */ | |
57 int qf_index; /* current index in the error list */ | |
58 int qf_nonevalid; /* TRUE if not a single valid entry found */ | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
59 char_u *qf_title; /* title derived from the command that created |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
60 * the error list */ |
644 | 61 } qf_list_T; |
62 | |
63 struct qf_info_S | |
64 { | |
65 /* | |
66 * Count of references to this list. Used only for location lists. | |
67 * When a location list window reference this list, qf_refcount | |
68 * will be 2. Otherwise, qf_refcount will be 1. When qf_refcount | |
69 * reaches 0, the list is freed. | |
70 */ | |
71 int qf_refcount; | |
72 int qf_listcount; /* current number of lists */ | |
73 int qf_curlist; /* current error list */ | |
74 qf_list_T qf_lists[LISTCOUNT]; | |
75 }; | |
76 | |
77 static qf_info_T ql_info; /* global quickfix list */ | |
7 | 78 |
230 | 79 #define FMT_PATTERNS 10 /* maximum number of % recognized */ |
7 | 80 |
81 /* | |
82 * Structure used to hold the info of one part of 'errorformat' | |
83 */ | |
789 | 84 typedef struct efm_S efm_T; |
85 struct efm_S | |
7 | 86 { |
87 regprog_T *prog; /* pre-formatted part of 'errorformat' */ | |
789 | 88 efm_T *next; /* pointer to next (NULL if last) */ |
7 | 89 char_u addr[FMT_PATTERNS]; /* indices of used % patterns */ |
90 char_u prefix; /* prefix of this format line: */ | |
91 /* 'D' enter directory */ | |
92 /* 'X' leave directory */ | |
93 /* 'A' start of multi-line message */ | |
94 /* 'E' error message */ | |
95 /* 'W' warning message */ | |
96 /* 'I' informational message */ | |
97 /* 'C' continuation line */ | |
98 /* 'Z' end of multi-line message */ | |
99 /* 'G' general, unspecific message */ | |
100 /* 'P' push file (partial) message */ | |
101 /* 'Q' pop/quit file (partial) message */ | |
102 /* 'O' overread (partial) message */ | |
103 char_u flags; /* additional flags given in prefix */ | |
104 /* '-' do not include this line */ | |
625 | 105 /* '+' include whole line in message */ |
789 | 106 int conthere; /* %> used */ |
7 | 107 }; |
108 | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
109 static int qf_init_ext __ARGS((qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast, char_u *qf_title)); |
3965 | 110 static void qf_new_list __ARGS((qf_info_T *qi, char_u *qf_title)); |
1571 | 111 static void ll_free_all __ARGS((qf_info_T **pqi)); |
1065 | 112 static int qf_add_entry __ARGS((qf_info_T *qi, qfline_T **prevp, char_u *dir, char_u *fname, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid)); |
1571 | 113 static qf_info_T *ll_new_list __ARGS((void)); |
644 | 114 static void qf_msg __ARGS((qf_info_T *qi)); |
115 static void qf_free __ARGS((qf_info_T *qi, int idx)); | |
7 | 116 static char_u *qf_types __ARGS((int, int)); |
117 static int qf_get_fnum __ARGS((char_u *, char_u *)); | |
118 static char_u *qf_push_dir __ARGS((char_u *, struct dir_stack_T **)); | |
119 static char_u *qf_pop_dir __ARGS((struct dir_stack_T **)); | |
120 static char_u *qf_guess_filepath __ARGS((char_u *)); | |
121 static void qf_fmt_text __ARGS((char_u *text, char_u *buf, int bufsize)); | |
122 static void qf_clean_dir_stack __ARGS((struct dir_stack_T **)); | |
123 #ifdef FEAT_WINDOWS | |
644 | 124 static int qf_win_pos_update __ARGS((qf_info_T *qi, int old_qf_index)); |
859 | 125 static int is_qf_win __ARGS((win_T *win, qf_info_T *qi)); |
644 | 126 static win_T *qf_find_win __ARGS((qf_info_T *qi)); |
127 static buf_T *qf_find_buf __ARGS((qf_info_T *qi)); | |
128 static void qf_update_buffer __ARGS((qf_info_T *qi)); | |
3016 | 129 static void qf_set_title __ARGS((qf_info_T *qi)); |
644 | 130 static void qf_fill_buffer __ARGS((qf_info_T *qi)); |
7 | 131 #endif |
132 static char_u *get_mef_name __ARGS((void)); | |
3490 | 133 static void restore_start_dir __ARGS((char_u *dirname_start)); |
134 static buf_T *load_dummy_buffer __ARGS((char_u *fname, char_u *dirname_start, char_u *resulting_dir)); | |
135 static void wipe_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start)); | |
136 static void unload_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start)); | |
665 | 137 static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *)); |
7 | 138 |
644 | 139 /* Quickfix window check helper macro */ |
140 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL) | |
141 /* Location list window check helper macro */ | |
142 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) | |
143 /* | |
144 * Return location list for window 'wp' | |
145 * For location list window, return the referenced location list | |
146 */ | |
147 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist) | |
148 | |
7 | 149 /* |
41 | 150 * Read the errorfile "efile" into memory, line by line, building the error |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
151 * list. Set the error list's title to qf_title. |
7 | 152 * Return -1 for error, number of errors for success. |
153 */ | |
154 int | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
155 qf_init(wp, efile, errorformat, newlist, qf_title) |
644 | 156 win_T *wp; |
7 | 157 char_u *efile; |
158 char_u *errorformat; | |
159 int newlist; /* TRUE: start a new error list */ | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
160 char_u *qf_title; |
7 | 161 { |
644 | 162 qf_info_T *qi = &ql_info; |
163 | |
41 | 164 if (efile == NULL) |
165 return FAIL; | |
644 | 166 |
167 if (wp != NULL) | |
665 | 168 { |
169 qi = ll_get_or_alloc_list(wp); | |
170 if (qi == NULL) | |
171 return FAIL; | |
172 } | |
644 | 173 |
174 return qf_init_ext(qi, efile, curbuf, NULL, errorformat, newlist, | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
175 (linenr_T)0, (linenr_T)0, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
176 qf_title); |
41 | 177 } |
178 | |
179 /* | |
180 * Read the errorfile "efile" into memory, line by line, building the error | |
181 * list. | |
182 * Alternative: when "efile" is null read errors from buffer "buf". | |
183 * Always use 'errorformat' from "buf" if there is a local value. | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
184 * Then "lnumfirst" and "lnumlast" specify the range of lines to use. |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
185 * Set the title of the list to "qf_title". |
41 | 186 * Return -1 for error, number of errors for success. |
187 */ | |
188 static int | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
189 qf_init_ext(qi, efile, buf, tv, errorformat, newlist, lnumfirst, lnumlast, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
190 qf_title) |
644 | 191 qf_info_T *qi; |
41 | 192 char_u *efile; |
193 buf_T *buf; | |
446 | 194 typval_T *tv; |
41 | 195 char_u *errorformat; |
196 int newlist; /* TRUE: start a new error list */ | |
197 linenr_T lnumfirst; /* first line number to use */ | |
198 linenr_T lnumlast; /* last line number to use */ | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
199 char_u *qf_title; |
41 | 200 { |
7 | 201 char_u *namebuf; |
202 char_u *errmsg; | |
230 | 203 char_u *pattern; |
7 | 204 char_u *fmtstr = NULL; |
205 int col = 0; | |
170 | 206 char_u use_viscol = FALSE; |
7 | 207 int type = 0; |
208 int valid; | |
41 | 209 linenr_T buflnum = lnumfirst; |
7 | 210 long lnum = 0L; |
211 int enr = 0; | |
41 | 212 FILE *fd = NULL; |
230 | 213 qfline_T *qfprev = NULL; /* init to make SASC shut up */ |
7 | 214 char_u *efmp; |
789 | 215 efm_T *fmt_first = NULL; |
216 efm_T *fmt_last = NULL; | |
217 efm_T *fmt_ptr; | |
218 efm_T *fmt_start = NULL; | |
7 | 219 char_u *efm; |
220 char_u *ptr; | |
221 char_u *srcptr; | |
222 int len; | |
223 int i; | |
224 int round; | |
225 int idx = 0; | |
226 int multiline = FALSE; | |
227 int multiignore = FALSE; | |
228 int multiscan = FALSE; | |
229 int retval = -1; /* default: return error flag */ | |
230 char_u *directory = NULL; | |
231 char_u *currfile = NULL; | |
232 char_u *tail = NULL; | |
446 | 233 char_u *p_str = NULL; |
234 listitem_T *p_li = NULL; | |
7 | 235 struct dir_stack_T *file_stack = NULL; |
236 regmatch_T regmatch; | |
237 static struct fmtpattern | |
238 { | |
239 char_u convchar; | |
240 char *pattern; | |
241 } fmt_pat[FMT_PATTERNS] = | |
242 { | |
502 | 243 {'f', ".\\+"}, /* only used when at end */ |
7 | 244 {'n', "\\d\\+"}, |
245 {'l', "\\d\\+"}, | |
246 {'c', "\\d\\+"}, | |
247 {'t', "."}, | |
248 {'m', ".\\+"}, | |
249 {'r', ".*"}, | |
3555 | 250 {'p', "[- .]*"}, |
230 | 251 {'v', "\\d\\+"}, |
252 {'s', ".\\+"} | |
7 | 253 }; |
254 | |
255 namebuf = alloc(CMDBUFFSIZE + 1); | |
256 errmsg = alloc(CMDBUFFSIZE + 1); | |
230 | 257 pattern = alloc(CMDBUFFSIZE + 1); |
258 if (namebuf == NULL || errmsg == NULL || pattern == NULL) | |
7 | 259 goto qf_init_end; |
260 | |
41 | 261 if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) |
7 | 262 { |
263 EMSG2(_(e_openerrf), efile); | |
264 goto qf_init_end; | |
265 } | |
266 | |
644 | 267 if (newlist || qi->qf_curlist == qi->qf_listcount) |
7 | 268 /* make place for a new list */ |
3965 | 269 qf_new_list(qi, qf_title); |
644 | 270 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
7 | 271 /* Adding to existing list, find last entry. */ |
644 | 272 for (qfprev = qi->qf_lists[qi->qf_curlist].qf_start; |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
273 qfprev->qf_next != qfprev; qfprev = qfprev->qf_next) |
7 | 274 ; |
275 | |
276 /* | |
277 * Each part of the format string is copied and modified from errorformat to | |
278 * regex prog. Only a few % characters are allowed. | |
279 */ | |
280 /* Use the local value of 'errorformat' if it's set. */ | |
446 | 281 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) |
41 | 282 efm = buf->b_p_efm; |
7 | 283 else |
284 efm = errorformat; | |
285 /* | |
286 * Get some space to modify the format string into. | |
287 */ | |
288 i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2); | |
289 for (round = FMT_PATTERNS; round > 0; ) | |
290 i += (int)STRLEN(fmt_pat[--round].pattern); | |
291 #ifdef COLON_IN_FILENAME | |
292 i += 12; /* "%f" can become twelve chars longer */ | |
293 #else | |
294 i += 2; /* "%f" can become two chars longer */ | |
295 #endif | |
296 if ((fmtstr = alloc(i)) == NULL) | |
297 goto error2; | |
298 | |
789 | 299 while (efm[0] != NUL) |
7 | 300 { |
301 /* | |
302 * Allocate a new eformat structure and put it at the end of the list | |
303 */ | |
789 | 304 fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T)); |
7 | 305 if (fmt_ptr == NULL) |
306 goto error2; | |
307 if (fmt_first == NULL) /* first one */ | |
308 fmt_first = fmt_ptr; | |
309 else | |
310 fmt_last->next = fmt_ptr; | |
311 fmt_last = fmt_ptr; | |
312 | |
313 /* | |
314 * Isolate one part in the 'errorformat' option | |
315 */ | |
316 for (len = 0; efm[len] != NUL && efm[len] != ','; ++len) | |
317 if (efm[len] == '\\' && efm[len + 1] != NUL) | |
318 ++len; | |
319 | |
320 /* | |
321 * Build regexp pattern from current 'errorformat' option | |
322 */ | |
323 ptr = fmtstr; | |
324 *ptr++ = '^'; | |
789 | 325 round = 0; |
7 | 326 for (efmp = efm; efmp < efm + len; ++efmp) |
327 { | |
328 if (*efmp == '%') | |
329 { | |
330 ++efmp; | |
331 for (idx = 0; idx < FMT_PATTERNS; ++idx) | |
332 if (fmt_pat[idx].convchar == *efmp) | |
333 break; | |
334 if (idx < FMT_PATTERNS) | |
335 { | |
336 if (fmt_ptr->addr[idx]) | |
337 { | |
338 sprintf((char *)errmsg, | |
339 _("E372: Too many %%%c in format string"), *efmp); | |
340 EMSG(errmsg); | |
341 goto error2; | |
342 } | |
343 if ((idx | |
344 && idx < 6 | |
345 && vim_strchr((char_u *)"DXOPQ", | |
346 fmt_ptr->prefix) != NULL) | |
347 || (idx == 6 | |
348 && vim_strchr((char_u *)"OPQ", | |
349 fmt_ptr->prefix) == NULL)) | |
350 { | |
351 sprintf((char *)errmsg, | |
352 _("E373: Unexpected %%%c in format string"), *efmp); | |
353 EMSG(errmsg); | |
354 goto error2; | |
355 } | |
356 fmt_ptr->addr[idx] = (char_u)++round; | |
357 *ptr++ = '\\'; | |
358 *ptr++ = '('; | |
359 #ifdef BACKSLASH_IN_FILENAME | |
360 if (*efmp == 'f') | |
361 { | |
362 /* Also match "c:" in the file name, even when | |
363 * checking for a colon next: "%f:". | |
364 * "\%(\a:\)\=" */ | |
365 STRCPY(ptr, "\\%(\\a:\\)\\="); | |
366 ptr += 10; | |
367 } | |
368 #endif | |
502 | 369 if (*efmp == 'f' && efmp[1] != NUL) |
7 | 370 { |
502 | 371 if (efmp[1] != '\\' && efmp[1] != '%') |
372 { | |
373 /* A file name may contain spaces, but this isn't | |
374 * in "\f". For "%f:%l:%m" there may be a ":" in | |
375 * the file name. Use ".\{-1,}x" instead (x is | |
376 * the next character), the requirement that :999: | |
377 * follows should work. */ | |
378 STRCPY(ptr, ".\\{-1,}"); | |
379 ptr += 7; | |
380 } | |
381 else | |
382 { | |
383 /* File name followed by '\\' or '%': include as | |
384 * many file name chars as possible. */ | |
385 STRCPY(ptr, "\\f\\+"); | |
386 ptr += 4; | |
387 } | |
7 | 388 } |
389 else | |
390 { | |
391 srcptr = (char_u *)fmt_pat[idx].pattern; | |
392 while ((*ptr = *srcptr++) != NUL) | |
393 ++ptr; | |
394 } | |
395 *ptr++ = '\\'; | |
396 *ptr++ = ')'; | |
397 } | |
398 else if (*efmp == '*') | |
399 { | |
400 if (*++efmp == '[' || *efmp == '\\') | |
401 { | |
402 if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */ | |
403 { | |
404 if (efmp[1] == '^') | |
405 *ptr++ = *++efmp; | |
406 if (efmp < efm + len) | |
407 { | |
408 *ptr++ = *++efmp; /* could be ']' */ | |
409 while (efmp < efm + len | |
410 && (*ptr++ = *++efmp) != ']') | |
411 /* skip */; | |
412 if (efmp == efm + len) | |
413 { | |
414 EMSG(_("E374: Missing ] in format string")); | |
415 goto error2; | |
416 } | |
417 } | |
418 } | |
419 else if (efmp < efm + len) /* %*\D, %*\s etc. */ | |
420 *ptr++ = *++efmp; | |
421 *ptr++ = '\\'; | |
422 *ptr++ = '+'; | |
423 } | |
424 else | |
425 { | |
426 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */ | |
427 sprintf((char *)errmsg, | |
428 _("E375: Unsupported %%%c in format string"), *efmp); | |
429 EMSG(errmsg); | |
430 goto error2; | |
431 } | |
432 } | |
433 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) | |
434 *ptr++ = *efmp; /* regexp magic characters */ | |
435 else if (*efmp == '#') | |
436 *ptr++ = '*'; | |
789 | 437 else if (*efmp == '>') |
438 fmt_ptr->conthere = TRUE; | |
7 | 439 else if (efmp == efm + 1) /* analyse prefix */ |
440 { | |
441 if (vim_strchr((char_u *)"+-", *efmp) != NULL) | |
442 fmt_ptr->flags = *efmp++; | |
443 if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL) | |
444 fmt_ptr->prefix = *efmp; | |
445 else | |
446 { | |
447 sprintf((char *)errmsg, | |
448 _("E376: Invalid %%%c in format string prefix"), *efmp); | |
449 EMSG(errmsg); | |
450 goto error2; | |
451 } | |
452 } | |
453 else | |
454 { | |
455 sprintf((char *)errmsg, | |
456 _("E377: Invalid %%%c in format string"), *efmp); | |
457 EMSG(errmsg); | |
458 goto error2; | |
459 } | |
460 } | |
461 else /* copy normal character */ | |
462 { | |
463 if (*efmp == '\\' && efmp + 1 < efm + len) | |
464 ++efmp; | |
465 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL) | |
466 *ptr++ = '\\'; /* escape regexp atoms */ | |
467 if (*efmp) | |
468 *ptr++ = *efmp; | |
469 } | |
470 } | |
471 *ptr++ = '$'; | |
472 *ptr = NUL; | |
473 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) | |
474 goto error2; | |
475 /* | |
476 * Advance to next part | |
477 */ | |
478 efm = skip_to_option_part(efm + len); /* skip comma and spaces */ | |
479 } | |
480 if (fmt_first == NULL) /* nothing found */ | |
481 { | |
482 EMSG(_("E378: 'errorformat' contains no pattern")); | |
483 goto error2; | |
484 } | |
485 | |
486 /* | |
487 * got_int is reset here, because it was probably set when killing the | |
488 * ":make" command, but we still want to read the errorfile then. | |
489 */ | |
490 got_int = FALSE; | |
491 | |
492 /* Always ignore case when looking for a matching error. */ | |
493 regmatch.rm_ic = TRUE; | |
494 | |
446 | 495 if (tv != NULL) |
496 { | |
497 if (tv->v_type == VAR_STRING) | |
498 p_str = tv->vval.v_string; | |
499 else if (tv->v_type == VAR_LIST) | |
500 p_li = tv->vval.v_list->lv_first; | |
501 } | |
502 | |
7 | 503 /* |
504 * Read the lines in the error file one by one. | |
505 * Try to recognize one of the error formats in each line. | |
506 */ | |
41 | 507 while (!got_int) |
7 | 508 { |
41 | 509 /* Get the next line. */ |
510 if (fd == NULL) | |
511 { | |
446 | 512 if (tv != NULL) |
513 { | |
514 if (tv->v_type == VAR_STRING) | |
515 { | |
516 /* Get the next line from the supplied string */ | |
517 char_u *p; | |
518 | |
519 if (!*p_str) /* Reached the end of the string */ | |
520 break; | |
521 | |
522 p = vim_strchr(p_str, '\n'); | |
523 if (p) | |
835 | 524 len = (int)(p - p_str + 1); |
446 | 525 else |
835 | 526 len = (int)STRLEN(p_str); |
446 | 527 |
528 if (len > CMDBUFFSIZE - 2) | |
529 vim_strncpy(IObuff, p_str, CMDBUFFSIZE - 2); | |
530 else | |
531 vim_strncpy(IObuff, p_str, len); | |
532 | |
533 p_str += len; | |
534 } | |
535 else if (tv->v_type == VAR_LIST) | |
536 { | |
537 /* Get the next line from the supplied list */ | |
538 while (p_li && p_li->li_tv.v_type != VAR_STRING) | |
539 p_li = p_li->li_next; /* Skip non-string items */ | |
540 | |
541 if (!p_li) /* End of the list */ | |
542 break; | |
543 | |
835 | 544 len = (int)STRLEN(p_li->li_tv.vval.v_string); |
446 | 545 if (len > CMDBUFFSIZE - 2) |
546 len = CMDBUFFSIZE - 2; | |
547 | |
548 vim_strncpy(IObuff, p_li->li_tv.vval.v_string, len); | |
549 | |
550 p_li = p_li->li_next; /* next item */ | |
551 } | |
552 } | |
553 else | |
554 { | |
555 /* Get the next line from the supplied buffer */ | |
556 if (buflnum > lnumlast) | |
557 break; | |
558 vim_strncpy(IObuff, ml_get_buf(buf, buflnum++, FALSE), | |
559 CMDBUFFSIZE - 2); | |
560 } | |
41 | 561 } |
562 else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL) | |
563 break; | |
564 | |
7 | 565 IObuff[CMDBUFFSIZE - 2] = NUL; /* for very long lines */ |
3002 | 566 #ifdef FEAT_MBYTE |
567 remove_bom(IObuff); | |
568 #endif | |
569 | |
7 | 570 if ((efmp = vim_strrchr(IObuff, '\n')) != NULL) |
571 *efmp = NUL; | |
572 #ifdef USE_CRNL | |
573 if ((efmp = vim_strrchr(IObuff, '\r')) != NULL) | |
574 *efmp = NUL; | |
575 #endif | |
576 | |
789 | 577 /* If there was no %> item start at the first pattern */ |
578 if (fmt_start == NULL) | |
579 fmt_ptr = fmt_first; | |
580 else | |
581 { | |
582 fmt_ptr = fmt_start; | |
583 fmt_start = NULL; | |
584 } | |
585 | |
7 | 586 /* |
587 * Try to match each part of 'errorformat' until we find a complete | |
588 * match or no match. | |
589 */ | |
590 valid = TRUE; | |
591 restofline: | |
789 | 592 for ( ; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) |
7 | 593 { |
594 idx = fmt_ptr->prefix; | |
595 if (multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL) | |
596 continue; | |
597 namebuf[0] = NUL; | |
230 | 598 pattern[0] = NUL; |
7 | 599 if (!multiscan) |
600 errmsg[0] = NUL; | |
601 lnum = 0; | |
602 col = 0; | |
170 | 603 use_viscol = FALSE; |
7 | 604 enr = -1; |
605 type = 0; | |
606 tail = NULL; | |
607 | |
608 regmatch.regprog = fmt_ptr->prog; | |
609 if (vim_regexec(®match, IObuff, (colnr_T)0)) | |
610 { | |
611 if ((idx == 'C' || idx == 'Z') && !multiline) | |
612 continue; | |
613 if (vim_strchr((char_u *)"EWI", idx) != NULL) | |
614 type = idx; | |
615 else | |
616 type = 0; | |
617 /* | |
895 | 618 * Extract error message data from matched line. |
619 * We check for an actual submatch, because "\[" and "\]" in | |
620 * the 'errorformat' may cause the wrong submatch to be used. | |
7 | 621 */ |
622 if ((i = (int)fmt_ptr->addr[0]) > 0) /* %f */ | |
623 { | |
895 | 624 int c; |
625 | |
626 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) | |
627 continue; | |
277 | 628 |
629 /* Expand ~/file and $HOME/file to full path. */ | |
895 | 630 c = *regmatch.endp[i]; |
277 | 631 *regmatch.endp[i] = NUL; |
632 expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE); | |
633 *regmatch.endp[i] = c; | |
634 | |
7 | 635 if (vim_strchr((char_u *)"OPQ", idx) != NULL |
277 | 636 && mch_getperm(namebuf) == -1) |
7 | 637 continue; |
638 } | |
639 if ((i = (int)fmt_ptr->addr[1]) > 0) /* %n */ | |
895 | 640 { |
641 if (regmatch.startp[i] == NULL) | |
642 continue; | |
7 | 643 enr = (int)atol((char *)regmatch.startp[i]); |
895 | 644 } |
7 | 645 if ((i = (int)fmt_ptr->addr[2]) > 0) /* %l */ |
895 | 646 { |
647 if (regmatch.startp[i] == NULL) | |
648 continue; | |
7 | 649 lnum = atol((char *)regmatch.startp[i]); |
895 | 650 } |
7 | 651 if ((i = (int)fmt_ptr->addr[3]) > 0) /* %c */ |
895 | 652 { |
653 if (regmatch.startp[i] == NULL) | |
654 continue; | |
7 | 655 col = (int)atol((char *)regmatch.startp[i]); |
895 | 656 } |
7 | 657 if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */ |
895 | 658 { |
659 if (regmatch.startp[i] == NULL) | |
660 continue; | |
7 | 661 type = *regmatch.startp[i]; |
895 | 662 } |
625 | 663 if (fmt_ptr->flags == '+' && !multiscan) /* %+ */ |
7 | 664 STRCPY(errmsg, IObuff); |
665 else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */ | |
666 { | |
895 | 667 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
668 continue; | |
7 | 669 len = (int)(regmatch.endp[i] - regmatch.startp[i]); |
418 | 670 vim_strncpy(errmsg, regmatch.startp[i], len); |
7 | 671 } |
672 if ((i = (int)fmt_ptr->addr[6]) > 0) /* %r */ | |
895 | 673 { |
674 if (regmatch.startp[i] == NULL) | |
675 continue; | |
7 | 676 tail = regmatch.startp[i]; |
895 | 677 } |
7 | 678 if ((i = (int)fmt_ptr->addr[7]) > 0) /* %p */ |
679 { | |
3555 | 680 char_u *match_ptr; |
681 | |
895 | 682 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
683 continue; | |
3555 | 684 col = 0; |
685 for (match_ptr = regmatch.startp[i]; | |
686 match_ptr != regmatch.endp[i]; ++match_ptr) | |
687 { | |
688 ++col; | |
689 if (*match_ptr == TAB) | |
690 { | |
691 col += 7; | |
692 col -= col % 8; | |
693 } | |
694 } | |
695 ++col; | |
696 use_viscol = TRUE; | |
7 | 697 } |
698 if ((i = (int)fmt_ptr->addr[8]) > 0) /* %v */ | |
699 { | |
895 | 700 if (regmatch.startp[i] == NULL) |
701 continue; | |
7 | 702 col = (int)atol((char *)regmatch.startp[i]); |
170 | 703 use_viscol = TRUE; |
7 | 704 } |
230 | 705 if ((i = (int)fmt_ptr->addr[9]) > 0) /* %s */ |
706 { | |
895 | 707 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
708 continue; | |
230 | 709 len = (int)(regmatch.endp[i] - regmatch.startp[i]); |
710 if (len > CMDBUFFSIZE - 5) | |
711 len = CMDBUFFSIZE - 5; | |
712 STRCPY(pattern, "^\\V"); | |
713 STRNCAT(pattern, regmatch.startp[i], len); | |
714 pattern[len + 3] = '\\'; | |
715 pattern[len + 4] = '$'; | |
716 pattern[len + 5] = NUL; | |
717 } | |
7 | 718 break; |
719 } | |
720 } | |
721 multiscan = FALSE; | |
789 | 722 |
625 | 723 if (fmt_ptr == NULL || idx == 'D' || idx == 'X') |
7 | 724 { |
625 | 725 if (fmt_ptr != NULL) |
7 | 726 { |
727 if (idx == 'D') /* enter directory */ | |
728 { | |
729 if (*namebuf == NUL) | |
730 { | |
731 EMSG(_("E379: Missing or empty directory name")); | |
732 goto error2; | |
733 } | |
734 if ((directory = qf_push_dir(namebuf, &dir_stack)) == NULL) | |
735 goto error2; | |
736 } | |
737 else if (idx == 'X') /* leave directory */ | |
738 directory = qf_pop_dir(&dir_stack); | |
739 } | |
740 namebuf[0] = NUL; /* no match found, remove file name */ | |
741 lnum = 0; /* don't jump to this line */ | |
742 valid = FALSE; | |
743 STRCPY(errmsg, IObuff); /* copy whole line to error message */ | |
625 | 744 if (fmt_ptr == NULL) |
7 | 745 multiline = multiignore = FALSE; |
746 } | |
625 | 747 else if (fmt_ptr != NULL) |
7 | 748 { |
789 | 749 /* honor %> item */ |
750 if (fmt_ptr->conthere) | |
751 fmt_start = fmt_ptr; | |
752 | |
7 | 753 if (vim_strchr((char_u *)"AEWI", idx) != NULL) |
754 multiline = TRUE; /* start of a multi-line message */ | |
755 else if (vim_strchr((char_u *)"CZ", idx) != NULL) | |
756 { /* continuation of multi-line msg */ | |
757 if (qfprev == NULL) | |
758 goto error2; | |
759 if (*errmsg && !multiignore) | |
760 { | |
761 len = (int)STRLEN(qfprev->qf_text); | |
762 if ((ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2))) | |
763 == NULL) | |
764 goto error2; | |
765 STRCPY(ptr, qfprev->qf_text); | |
766 vim_free(qfprev->qf_text); | |
767 qfprev->qf_text = ptr; | |
768 *(ptr += len) = '\n'; | |
769 STRCPY(++ptr, errmsg); | |
770 } | |
771 if (qfprev->qf_nr == -1) | |
772 qfprev->qf_nr = enr; | |
773 if (vim_isprintc(type) && !qfprev->qf_type) | |
774 qfprev->qf_type = type; /* only printable chars allowed */ | |
775 if (!qfprev->qf_lnum) | |
776 qfprev->qf_lnum = lnum; | |
777 if (!qfprev->qf_col) | |
778 qfprev->qf_col = col; | |
170 | 779 qfprev->qf_viscol = use_viscol; |
7 | 780 if (!qfprev->qf_fnum) |
781 qfprev->qf_fnum = qf_get_fnum(directory, | |
782 *namebuf || directory ? namebuf | |
783 : currfile && valid ? currfile : 0); | |
784 if (idx == 'Z') | |
785 multiline = multiignore = FALSE; | |
786 line_breakcheck(); | |
787 continue; | |
788 } | |
789 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) | |
790 { | |
791 /* global file names */ | |
792 valid = FALSE; | |
793 if (*namebuf == NUL || mch_getperm(namebuf) >= 0) | |
794 { | |
795 if (*namebuf && idx == 'P') | |
796 currfile = qf_push_dir(namebuf, &file_stack); | |
797 else if (idx == 'Q') | |
798 currfile = qf_pop_dir(&file_stack); | |
799 *namebuf = NUL; | |
800 if (tail && *tail) | |
801 { | |
1668 | 802 STRMOVE(IObuff, skipwhite(tail)); |
7 | 803 multiscan = TRUE; |
804 goto restofline; | |
805 } | |
806 } | |
807 } | |
808 if (fmt_ptr->flags == '-') /* generally exclude this line */ | |
809 { | |
810 if (multiline) | |
811 multiignore = TRUE; /* also exclude continuation lines */ | |
812 continue; | |
813 } | |
814 } | |
815 | |
644 | 816 if (qf_add_entry(qi, &qfprev, |
7 | 817 directory, |
129 | 818 (*namebuf || directory) |
7 | 819 ? namebuf |
129 | 820 : ((currfile && valid) ? currfile : (char_u *)NULL), |
1065 | 821 0, |
7 | 822 errmsg, |
823 lnum, | |
824 col, | |
170 | 825 use_viscol, |
230 | 826 pattern, |
7 | 827 enr, |
828 type, | |
829 valid) == FAIL) | |
830 goto error2; | |
831 line_breakcheck(); | |
832 } | |
41 | 833 if (fd == NULL || !ferror(fd)) |
7 | 834 { |
644 | 835 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) |
7 | 836 { |
644 | 837 /* no valid entry found */ |
838 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
839 qi->qf_lists[qi->qf_curlist].qf_start; | |
840 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
841 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; | |
7 | 842 } |
843 else | |
844 { | |
644 | 845 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
846 if (qi->qf_lists[qi->qf_curlist].qf_ptr == NULL) | |
847 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
848 qi->qf_lists[qi->qf_curlist].qf_start; | |
7 | 849 } |
644 | 850 /* return number of matches */ |
851 retval = qi->qf_lists[qi->qf_curlist].qf_count; | |
7 | 852 goto qf_init_ok; |
853 } | |
854 EMSG(_(e_readerrf)); | |
855 error2: | |
644 | 856 qf_free(qi, qi->qf_curlist); |
857 qi->qf_listcount--; | |
858 if (qi->qf_curlist > 0) | |
859 --qi->qf_curlist; | |
7 | 860 qf_init_ok: |
41 | 861 if (fd != NULL) |
862 fclose(fd); | |
7 | 863 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) |
864 { | |
865 fmt_first = fmt_ptr->next; | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
866 vim_regfree(fmt_ptr->prog); |
7 | 867 vim_free(fmt_ptr); |
868 } | |
869 qf_clean_dir_stack(&dir_stack); | |
870 qf_clean_dir_stack(&file_stack); | |
871 qf_init_end: | |
872 vim_free(namebuf); | |
873 vim_free(errmsg); | |
230 | 874 vim_free(pattern); |
7 | 875 vim_free(fmtstr); |
876 | |
877 #ifdef FEAT_WINDOWS | |
644 | 878 qf_update_buffer(qi); |
7 | 879 #endif |
880 | |
881 return retval; | |
882 } | |
883 | |
884 /* | |
885 * Prepare for adding a new quickfix list. | |
886 */ | |
887 static void | |
3965 | 888 qf_new_list(qi, qf_title) |
644 | 889 qf_info_T *qi; |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
890 char_u *qf_title; |
7 | 891 { |
892 int i; | |
893 | |
894 /* | |
895 * If the current entry is not the last entry, delete entries below | |
896 * the current entry. This makes it possible to browse in a tree-like | |
897 * way with ":grep'. | |
898 */ | |
644 | 899 while (qi->qf_listcount > qi->qf_curlist + 1) |
900 qf_free(qi, --qi->qf_listcount); | |
7 | 901 |
902 /* | |
903 * When the stack is full, remove to oldest entry | |
904 * Otherwise, add a new entry. | |
905 */ | |
644 | 906 if (qi->qf_listcount == LISTCOUNT) |
7 | 907 { |
644 | 908 qf_free(qi, 0); |
7 | 909 for (i = 1; i < LISTCOUNT; ++i) |
644 | 910 qi->qf_lists[i - 1] = qi->qf_lists[i]; |
911 qi->qf_curlist = LISTCOUNT - 1; | |
7 | 912 } |
913 else | |
644 | 914 qi->qf_curlist = qi->qf_listcount++; |
3259 | 915 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T))); |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
916 if (qf_title != NULL) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
917 { |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2411
diff
changeset
|
918 char_u *p = alloc((int)STRLEN(qf_title) + 2); |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
919 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
920 qi->qf_lists[qi->qf_curlist].qf_title = p; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
921 if (p != NULL) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
922 sprintf((char *)p, ":%s", (char *)qf_title); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
923 } |
7 | 924 } |
925 | |
644 | 926 /* |
927 * Free a location list | |
928 */ | |
929 static void | |
930 ll_free_all(pqi) | |
931 qf_info_T **pqi; | |
359 | 932 { |
933 int i; | |
644 | 934 qf_info_T *qi; |
935 | |
936 qi = *pqi; | |
937 if (qi == NULL) | |
938 return; | |
939 *pqi = NULL; /* Remove reference to this list */ | |
940 | |
941 qi->qf_refcount--; | |
942 if (qi->qf_refcount < 1) | |
943 { | |
944 /* No references to this location list */ | |
945 for (i = 0; i < qi->qf_listcount; ++i) | |
946 qf_free(qi, i); | |
947 vim_free(qi); | |
948 } | |
359 | 949 } |
644 | 950 |
951 void | |
952 qf_free_all(wp) | |
953 win_T *wp; | |
954 { | |
955 int i; | |
956 qf_info_T *qi = &ql_info; | |
957 | |
958 if (wp != NULL) | |
959 { | |
960 /* location list */ | |
961 ll_free_all(&wp->w_llist); | |
962 ll_free_all(&wp->w_llist_ref); | |
963 } | |
964 else | |
965 /* quickfix list */ | |
966 for (i = 0; i < qi->qf_listcount; ++i) | |
967 qf_free(qi, i); | |
968 } | |
359 | 969 |
7 | 970 /* |
971 * Add an entry to the end of the list of errors. | |
972 * Returns OK or FAIL. | |
973 */ | |
974 static int | |
1065 | 975 qf_add_entry(qi, prevp, dir, fname, bufnum, mesg, lnum, col, vis_col, pattern, |
976 nr, type, valid) | |
644 | 977 qf_info_T *qi; /* quickfix list */ |
230 | 978 qfline_T **prevp; /* pointer to previously added entry or NULL */ |
7 | 979 char_u *dir; /* optional directory name */ |
980 char_u *fname; /* file name or NULL */ | |
1065 | 981 int bufnum; /* buffer number or zero */ |
7 | 982 char_u *mesg; /* message */ |
983 long lnum; /* line number */ | |
984 int col; /* column */ | |
170 | 985 int vis_col; /* using visual column */ |
230 | 986 char_u *pattern; /* search pattern */ |
7 | 987 int nr; /* error number */ |
988 int type; /* type character */ | |
989 int valid; /* valid entry */ | |
990 { | |
230 | 991 qfline_T *qfp; |
7 | 992 |
230 | 993 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) |
7 | 994 return FAIL; |
1065 | 995 if (bufnum != 0) |
996 qfp->qf_fnum = bufnum; | |
997 else | |
998 qfp->qf_fnum = qf_get_fnum(dir, fname); | |
7 | 999 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) |
1000 { | |
1001 vim_free(qfp); | |
1002 return FAIL; | |
1003 } | |
1004 qfp->qf_lnum = lnum; | |
1005 qfp->qf_col = col; | |
170 | 1006 qfp->qf_viscol = vis_col; |
230 | 1007 if (pattern == NULL || *pattern == NUL) |
1008 qfp->qf_pattern = NULL; | |
1009 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL) | |
1010 { | |
1011 vim_free(qfp->qf_text); | |
1012 vim_free(qfp); | |
1013 return FAIL; | |
1014 } | |
7 | 1015 qfp->qf_nr = nr; |
1016 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ | |
1017 type = 0; | |
1018 qfp->qf_type = type; | |
1019 qfp->qf_valid = valid; | |
1020 | |
644 | 1021 if (qi->qf_lists[qi->qf_curlist].qf_count == 0) |
1022 /* first element in the list */ | |
7 | 1023 { |
644 | 1024 qi->qf_lists[qi->qf_curlist].qf_start = qfp; |
7 | 1025 qfp->qf_prev = qfp; /* first element points to itself */ |
1026 } | |
1027 else | |
1028 { | |
1029 qfp->qf_prev = *prevp; | |
1030 (*prevp)->qf_next = qfp; | |
1031 } | |
1032 qfp->qf_next = qfp; /* last element points to itself */ | |
1033 qfp->qf_cleared = FALSE; | |
1034 *prevp = qfp; | |
644 | 1035 ++qi->qf_lists[qi->qf_curlist].qf_count; |
1036 if (qi->qf_lists[qi->qf_curlist].qf_index == 0 && qfp->qf_valid) | |
1037 /* first valid entry */ | |
7 | 1038 { |
644 | 1039 qi->qf_lists[qi->qf_curlist].qf_index = |
1040 qi->qf_lists[qi->qf_curlist].qf_count; | |
1041 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; | |
7 | 1042 } |
1043 | |
1044 return OK; | |
1045 } | |
1046 | |
1047 /* | |
659 | 1048 * Allocate a new location list |
644 | 1049 */ |
659 | 1050 static qf_info_T * |
1051 ll_new_list() | |
644 | 1052 { |
659 | 1053 qf_info_T *qi; |
1054 | |
1055 qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T)); | |
1056 if (qi != NULL) | |
1057 { | |
1058 vim_memset(qi, 0, (size_t)(sizeof(qf_info_T))); | |
1059 qi->qf_refcount++; | |
1060 } | |
1061 | |
1062 return qi; | |
644 | 1063 } |
1064 | |
1065 /* | |
1066 * Return the location list for window 'wp'. | |
1067 * If not present, allocate a location list | |
1068 */ | |
1069 static qf_info_T * | |
1070 ll_get_or_alloc_list(wp) | |
1071 win_T *wp; | |
1072 { | |
1073 if (IS_LL_WINDOW(wp)) | |
1074 /* For a location list window, use the referenced location list */ | |
1075 return wp->w_llist_ref; | |
1076 | |
1077 /* | |
1078 * For a non-location list window, w_llist_ref should not point to a | |
1079 * location list. | |
1080 */ | |
1081 ll_free_all(&wp->w_llist_ref); | |
1082 | |
1083 if (wp->w_llist == NULL) | |
659 | 1084 wp->w_llist = ll_new_list(); /* new location list */ |
644 | 1085 return wp->w_llist; |
1086 } | |
1087 | |
1088 /* | |
1089 * Copy the location list from window "from" to window "to". | |
1090 */ | |
1091 void | |
1092 copy_loclist(from, to) | |
1093 win_T *from; | |
1094 win_T *to; | |
1095 { | |
1096 qf_info_T *qi; | |
1097 int idx; | |
1098 int i; | |
1099 | |
1100 /* | |
1101 * When copying from a location list window, copy the referenced | |
1102 * location list. For other windows, copy the location list for | |
1103 * that window. | |
1104 */ | |
1105 if (IS_LL_WINDOW(from)) | |
1106 qi = from->w_llist_ref; | |
1107 else | |
1108 qi = from->w_llist; | |
1109 | |
1110 if (qi == NULL) /* no location list to copy */ | |
1111 return; | |
1112 | |
659 | 1113 /* allocate a new location list */ |
1114 if ((to->w_llist = ll_new_list()) == NULL) | |
644 | 1115 return; |
1116 | |
1117 to->w_llist->qf_listcount = qi->qf_listcount; | |
1118 | |
1119 /* Copy the location lists one at a time */ | |
1120 for (idx = 0; idx < qi->qf_listcount; idx++) | |
1121 { | |
1122 qf_list_T *from_qfl; | |
1123 qf_list_T *to_qfl; | |
1124 | |
1125 to->w_llist->qf_curlist = idx; | |
1126 | |
1127 from_qfl = &qi->qf_lists[idx]; | |
1128 to_qfl = &to->w_llist->qf_lists[idx]; | |
1129 | |
1130 /* Some of the fields are populated by qf_add_entry() */ | |
1131 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; | |
1132 to_qfl->qf_count = 0; | |
1133 to_qfl->qf_index = 0; | |
1134 to_qfl->qf_start = NULL; | |
1135 to_qfl->qf_ptr = NULL; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1136 if (from_qfl->qf_title != NULL) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1137 to_qfl->qf_title = vim_strsave(from_qfl->qf_title); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1138 else |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1139 to_qfl->qf_title = NULL; |
644 | 1140 |
1141 if (from_qfl->qf_count) | |
1142 { | |
1143 qfline_T *from_qfp; | |
1144 qfline_T *prevp = NULL; | |
1145 | |
1146 /* copy all the location entries in this list */ | |
1147 for (i = 0, from_qfp = from_qfl->qf_start; i < from_qfl->qf_count; | |
1148 ++i, from_qfp = from_qfp->qf_next) | |
1149 { | |
1150 if (qf_add_entry(to->w_llist, &prevp, | |
1151 NULL, | |
1152 NULL, | |
1065 | 1153 0, |
644 | 1154 from_qfp->qf_text, |
1155 from_qfp->qf_lnum, | |
1156 from_qfp->qf_col, | |
1157 from_qfp->qf_viscol, | |
1158 from_qfp->qf_pattern, | |
1159 from_qfp->qf_nr, | |
1160 0, | |
1161 from_qfp->qf_valid) == FAIL) | |
1162 { | |
1163 qf_free_all(to); | |
1164 return; | |
1165 } | |
1166 /* | |
1167 * qf_add_entry() will not set the qf_num field, as the | |
1168 * directory and file names are not supplied. So the qf_fnum | |
1169 * field is copied here. | |
1170 */ | |
1171 prevp->qf_fnum = from_qfp->qf_fnum; /* file number */ | |
1172 prevp->qf_type = from_qfp->qf_type; /* error type */ | |
1173 if (from_qfl->qf_ptr == from_qfp) | |
1174 to_qfl->qf_ptr = prevp; /* current location */ | |
1175 } | |
1176 } | |
1177 | |
1178 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */ | |
1179 | |
1180 /* When no valid entries are present in the list, qf_ptr points to | |
1181 * the first item in the list */ | |
2795 | 1182 if (to_qfl->qf_nonevalid) |
5060
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1183 { |
644 | 1184 to_qfl->qf_ptr = to_qfl->qf_start; |
5060
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1185 to_qfl->qf_index = 1; |
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1186 } |
644 | 1187 } |
1188 | |
1189 to->w_llist->qf_curlist = qi->qf_curlist; /* current list */ | |
1190 } | |
1191 | |
1192 /* | |
7 | 1193 * get buffer number for file "dir.name" |
1194 */ | |
1195 static int | |
1196 qf_get_fnum(directory, fname) | |
1197 char_u *directory; | |
1198 char_u *fname; | |
1199 { | |
1200 if (fname == NULL || *fname == NUL) /* no file name */ | |
1201 return 0; | |
1202 { | |
1203 char_u *ptr; | |
1204 int fnum; | |
1205 | |
2823 | 1206 #ifdef VMS |
7 | 1207 vms_remove_version(fname); |
2823 | 1208 #endif |
1209 #ifdef BACKSLASH_IN_FILENAME | |
7 | 1210 if (directory != NULL) |
1211 slash_adjust(directory); | |
1212 slash_adjust(fname); | |
2823 | 1213 #endif |
7 | 1214 if (directory != NULL && !vim_isAbsName(fname) |
1215 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL) | |
1216 { | |
1217 /* | |
1218 * Here we check if the file really exists. | |
1219 * This should normally be true, but if make works without | |
1220 * "leaving directory"-messages we might have missed a | |
1221 * directory change. | |
1222 */ | |
1223 if (mch_getperm(ptr) < 0) | |
1224 { | |
1225 vim_free(ptr); | |
1226 directory = qf_guess_filepath(fname); | |
1227 if (directory) | |
1228 ptr = concat_fnames(directory, fname, TRUE); | |
1229 else | |
1230 ptr = vim_strsave(fname); | |
1231 } | |
1232 /* Use concatenated directory name and file name */ | |
1233 fnum = buflist_add(ptr, 0); | |
1234 vim_free(ptr); | |
1235 return fnum; | |
1236 } | |
1237 return buflist_add(fname, 0); | |
1238 } | |
1239 } | |
1240 | |
1241 /* | |
1242 * push dirbuf onto the directory stack and return pointer to actual dir or | |
1243 * NULL on error | |
1244 */ | |
1245 static char_u * | |
1246 qf_push_dir(dirbuf, stackptr) | |
1247 char_u *dirbuf; | |
1248 struct dir_stack_T **stackptr; | |
1249 { | |
1250 struct dir_stack_T *ds_new; | |
1251 struct dir_stack_T *ds_ptr; | |
1252 | |
1253 /* allocate new stack element and hook it in */ | |
1254 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); | |
1255 if (ds_new == NULL) | |
1256 return NULL; | |
1257 | |
1258 ds_new->next = *stackptr; | |
1259 *stackptr = ds_new; | |
1260 | |
1261 /* store directory on the stack */ | |
1262 if (vim_isAbsName(dirbuf) | |
1263 || (*stackptr)->next == NULL | |
1264 || (*stackptr && dir_stack != *stackptr)) | |
1265 (*stackptr)->dirname = vim_strsave(dirbuf); | |
1266 else | |
1267 { | |
1268 /* Okay we don't have an absolute path. | |
1269 * dirbuf must be a subdir of one of the directories on the stack. | |
1270 * Let's search... | |
1271 */ | |
1272 ds_new = (*stackptr)->next; | |
1273 (*stackptr)->dirname = NULL; | |
1274 while (ds_new) | |
1275 { | |
1276 vim_free((*stackptr)->dirname); | |
1277 (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, | |
1278 TRUE); | |
1279 if (mch_isdir((*stackptr)->dirname) == TRUE) | |
1280 break; | |
1281 | |
1282 ds_new = ds_new->next; | |
1283 } | |
1284 | |
1285 /* clean up all dirs we already left */ | |
1286 while ((*stackptr)->next != ds_new) | |
1287 { | |
1288 ds_ptr = (*stackptr)->next; | |
1289 (*stackptr)->next = (*stackptr)->next->next; | |
1290 vim_free(ds_ptr->dirname); | |
1291 vim_free(ds_ptr); | |
1292 } | |
1293 | |
1294 /* Nothing found -> it must be on top level */ | |
1295 if (ds_new == NULL) | |
1296 { | |
1297 vim_free((*stackptr)->dirname); | |
1298 (*stackptr)->dirname = vim_strsave(dirbuf); | |
1299 } | |
1300 } | |
1301 | |
1302 if ((*stackptr)->dirname != NULL) | |
1303 return (*stackptr)->dirname; | |
1304 else | |
1305 { | |
1306 ds_ptr = *stackptr; | |
1307 *stackptr = (*stackptr)->next; | |
1308 vim_free(ds_ptr); | |
1309 return NULL; | |
1310 } | |
1311 } | |
1312 | |
1313 | |
1314 /* | |
1315 * pop dirbuf from the directory stack and return previous directory or NULL if | |
1316 * stack is empty | |
1317 */ | |
1318 static char_u * | |
1319 qf_pop_dir(stackptr) | |
1320 struct dir_stack_T **stackptr; | |
1321 { | |
1322 struct dir_stack_T *ds_ptr; | |
1323 | |
1324 /* TODO: Should we check if dirbuf is the directory on top of the stack? | |
1325 * What to do if it isn't? */ | |
1326 | |
1327 /* pop top element and free it */ | |
1328 if (*stackptr != NULL) | |
1329 { | |
1330 ds_ptr = *stackptr; | |
1331 *stackptr = (*stackptr)->next; | |
1332 vim_free(ds_ptr->dirname); | |
1333 vim_free(ds_ptr); | |
1334 } | |
1335 | |
1336 /* return NEW top element as current dir or NULL if stack is empty*/ | |
1337 return *stackptr ? (*stackptr)->dirname : NULL; | |
1338 } | |
1339 | |
1340 /* | |
1341 * clean up directory stack | |
1342 */ | |
1343 static void | |
1344 qf_clean_dir_stack(stackptr) | |
1345 struct dir_stack_T **stackptr; | |
1346 { | |
1347 struct dir_stack_T *ds_ptr; | |
1348 | |
1349 while ((ds_ptr = *stackptr) != NULL) | |
1350 { | |
1351 *stackptr = (*stackptr)->next; | |
1352 vim_free(ds_ptr->dirname); | |
1353 vim_free(ds_ptr); | |
1354 } | |
1355 } | |
1356 | |
1357 /* | |
1358 * Check in which directory of the directory stack the given file can be | |
1359 * found. | |
1360 * Returns a pointer to the directory name or NULL if not found | |
1361 * Cleans up intermediate directory entries. | |
1362 * | |
1363 * TODO: How to solve the following problem? | |
1364 * If we have the this directory tree: | |
1365 * ./ | |
1366 * ./aa | |
1367 * ./aa/bb | |
1368 * ./bb | |
1369 * ./bb/x.c | |
1370 * and make says: | |
1371 * making all in aa | |
1372 * making all in bb | |
1373 * x.c:9: Error | |
1374 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb. | |
1375 * qf_guess_filepath will return NULL. | |
1376 */ | |
1377 static char_u * | |
1378 qf_guess_filepath(filename) | |
1379 char_u *filename; | |
1380 { | |
1381 struct dir_stack_T *ds_ptr; | |
1382 struct dir_stack_T *ds_tmp; | |
1383 char_u *fullname; | |
1384 | |
1385 /* no dirs on the stack - there's nothing we can do */ | |
1386 if (dir_stack == NULL) | |
1387 return NULL; | |
1388 | |
1389 ds_ptr = dir_stack->next; | |
1390 fullname = NULL; | |
1391 while (ds_ptr) | |
1392 { | |
1393 vim_free(fullname); | |
1394 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); | |
1395 | |
1396 /* If concat_fnames failed, just go on. The worst thing that can happen | |
1397 * is that we delete the entire stack. | |
1398 */ | |
1399 if ((fullname != NULL) && (mch_getperm(fullname) >= 0)) | |
1400 break; | |
1401 | |
1402 ds_ptr = ds_ptr->next; | |
1403 } | |
1404 | |
1405 vim_free(fullname); | |
1406 | |
1407 /* clean up all dirs we already left */ | |
1408 while (dir_stack->next != ds_ptr) | |
1409 { | |
1410 ds_tmp = dir_stack->next; | |
1411 dir_stack->next = dir_stack->next->next; | |
1412 vim_free(ds_tmp->dirname); | |
1413 vim_free(ds_tmp); | |
1414 } | |
1415 | |
1416 return ds_ptr==NULL? NULL: ds_ptr->dirname; | |
1417 | |
1418 } | |
1419 | |
1420 /* | |
1421 * jump to a quickfix line | |
1422 * if dir == FORWARD go "errornr" valid entries forward | |
1423 * if dir == BACKWARD go "errornr" valid entries backward | |
1424 * if dir == FORWARD_FILE go "errornr" valid entries files backward | |
1425 * if dir == BACKWARD_FILE go "errornr" valid entries files backward | |
1426 * else if "errornr" is zero, redisplay the same line | |
1427 * else go to entry "errornr" | |
1428 */ | |
1429 void | |
659 | 1430 qf_jump(qi, dir, errornr, forceit) |
1431 qf_info_T *qi; | |
7 | 1432 int dir; |
1433 int errornr; | |
1434 int forceit; | |
1435 { | |
644 | 1436 qf_info_T *ll_ref; |
230 | 1437 qfline_T *qf_ptr; |
1438 qfline_T *old_qf_ptr; | |
7 | 1439 int qf_index; |
1440 int old_qf_fnum; | |
1441 int old_qf_index; | |
1442 int prev_index; | |
1443 static char_u *e_no_more_items = (char_u *)N_("E553: No more items"); | |
1444 char_u *err = e_no_more_items; | |
1445 linenr_T i; | |
1446 buf_T *old_curbuf; | |
1447 linenr_T old_lnum; | |
1448 colnr_T screen_col; | |
1449 colnr_T char_col; | |
1450 char_u *line; | |
1451 #ifdef FEAT_WINDOWS | |
639 | 1452 char_u *old_swb = p_swb; |
1621 | 1453 unsigned old_swb_flags = swb_flags; |
7 | 1454 int opened_window = FALSE; |
1455 win_T *win; | |
1456 win_T *altwin; | |
1822 | 1457 int flags; |
7 | 1458 #endif |
1743 | 1459 win_T *oldwin = curwin; |
7 | 1460 int print_message = TRUE; |
1461 int len; | |
1462 #ifdef FEAT_FOLDING | |
1463 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
1464 #endif | |
9 | 1465 int ok = OK; |
644 | 1466 int usable_win; |
1467 | |
659 | 1468 if (qi == NULL) |
1469 qi = &ql_info; | |
644 | 1470 |
1471 if (qi->qf_curlist >= qi->qf_listcount | |
1472 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | |
7 | 1473 { |
1474 EMSG(_(e_quickfix)); | |
1475 return; | |
1476 } | |
1477 | |
644 | 1478 qf_ptr = qi->qf_lists[qi->qf_curlist].qf_ptr; |
7 | 1479 old_qf_ptr = qf_ptr; |
644 | 1480 qf_index = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 1481 old_qf_index = qf_index; |
1482 if (dir == FORWARD || dir == FORWARD_FILE) /* next valid entry */ | |
1483 { | |
1484 while (errornr--) | |
1485 { | |
1486 old_qf_ptr = qf_ptr; | |
1487 prev_index = qf_index; | |
1488 old_qf_fnum = qf_ptr->qf_fnum; | |
1489 do | |
1490 { | |
644 | 1491 if (qf_index == qi->qf_lists[qi->qf_curlist].qf_count |
7 | 1492 || qf_ptr->qf_next == NULL) |
1493 { | |
1494 qf_ptr = old_qf_ptr; | |
1495 qf_index = prev_index; | |
1496 if (err != NULL) | |
1497 { | |
1498 EMSG(_(err)); | |
1499 goto theend; | |
1500 } | |
1501 errornr = 0; | |
1502 break; | |
1503 } | |
1504 ++qf_index; | |
1505 qf_ptr = qf_ptr->qf_next; | |
644 | 1506 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid |
1507 && !qf_ptr->qf_valid) | |
7 | 1508 || (dir == FORWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); |
1509 err = NULL; | |
1510 } | |
1511 } | |
1512 else if (dir == BACKWARD || dir == BACKWARD_FILE) /* prev. valid entry */ | |
1513 { | |
1514 while (errornr--) | |
1515 { | |
1516 old_qf_ptr = qf_ptr; | |
1517 prev_index = qf_index; | |
1518 old_qf_fnum = qf_ptr->qf_fnum; | |
1519 do | |
1520 { | |
1521 if (qf_index == 1 || qf_ptr->qf_prev == NULL) | |
1522 { | |
1523 qf_ptr = old_qf_ptr; | |
1524 qf_index = prev_index; | |
1525 if (err != NULL) | |
1526 { | |
1527 EMSG(_(err)); | |
1528 goto theend; | |
1529 } | |
1530 errornr = 0; | |
1531 break; | |
1532 } | |
1533 --qf_index; | |
1534 qf_ptr = qf_ptr->qf_prev; | |
644 | 1535 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid |
1536 && !qf_ptr->qf_valid) | |
7 | 1537 || (dir == BACKWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); |
1538 err = NULL; | |
1539 } | |
1540 } | |
1541 else if (errornr != 0) /* go to specified number */ | |
1542 { | |
1543 while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL) | |
1544 { | |
1545 --qf_index; | |
1546 qf_ptr = qf_ptr->qf_prev; | |
1547 } | |
644 | 1548 while (errornr > qf_index && qf_index < |
1549 qi->qf_lists[qi->qf_curlist].qf_count | |
7 | 1550 && qf_ptr->qf_next != NULL) |
1551 { | |
1552 ++qf_index; | |
1553 qf_ptr = qf_ptr->qf_next; | |
1554 } | |
1555 } | |
1556 | |
1557 #ifdef FEAT_WINDOWS | |
644 | 1558 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; |
1559 if (qf_win_pos_update(qi, old_qf_index)) | |
7 | 1560 /* No need to print the error message if it's visible in the error |
1561 * window */ | |
1562 print_message = FALSE; | |
1563 | |
1564 /* | |
9 | 1565 * For ":helpgrep" find a help window or open one. |
1566 */ | |
682 | 1567 if (qf_ptr->qf_type == 1 && (!curwin->w_buffer->b_help || cmdmod.tab != 0)) |
9 | 1568 { |
1569 win_T *wp; | |
1570 | |
682 | 1571 if (cmdmod.tab != 0) |
1572 wp = NULL; | |
1573 else | |
1574 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
1575 if (wp->w_buffer != NULL && wp->w_buffer->b_help) | |
1576 break; | |
9 | 1577 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
1578 win_enter(wp, TRUE); | |
1579 else | |
1580 { | |
1581 /* | |
1582 * Split off help window; put it at far top if no position | |
1583 * specified, the current window is vertically split and narrow. | |
1584 */ | |
1822 | 1585 flags = WSP_HELP; |
9 | 1586 # ifdef FEAT_VERTSPLIT |
1587 if (cmdmod.split == 0 && curwin->w_width != Columns | |
1588 && curwin->w_width < 80) | |
1822 | 1589 flags |= WSP_TOP; |
9 | 1590 # endif |
1822 | 1591 if (qi != &ql_info) |
1592 flags |= WSP_NEWLOC; /* don't copy the location list */ | |
1593 | |
1594 if (win_split(0, flags) == FAIL) | |
9 | 1595 goto theend; |
26 | 1596 opened_window = TRUE; /* close it when fail */ |
9 | 1597 |
1598 if (curwin->w_height < p_hh) | |
1599 win_setheight((int)p_hh); | |
659 | 1600 |
1601 if (qi != &ql_info) /* not a quickfix list */ | |
1602 { | |
1603 /* The new window should use the supplied location list */ | |
1604 curwin->w_llist = qi; | |
1605 qi->qf_refcount++; | |
1606 } | |
9 | 1607 } |
1608 | |
1609 if (!p_im) | |
1610 restart_edit = 0; /* don't want insert mode in help file */ | |
1611 } | |
1612 | |
1613 /* | |
7 | 1614 * If currently in the quickfix window, find another window to show the |
1615 * file in. | |
1616 */ | |
26 | 1617 if (bt_quickfix(curbuf) && !opened_window) |
7 | 1618 { |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1619 win_T *usable_win_ptr = NULL; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1620 |
7 | 1621 /* |
1622 * If there is no file specified, we don't know where to go. | |
1623 * But do advance, otherwise ":cn" gets stuck. | |
1624 */ | |
1625 if (qf_ptr->qf_fnum == 0) | |
1626 goto theend; | |
1627 | |
644 | 1628 usable_win = 0; |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1629 |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1630 ll_ref = curwin->w_llist_ref; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1631 if (ll_ref != NULL) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1632 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1633 /* Find a window using the same location list that is not a |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1634 * quickfix window. */ |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1635 FOR_ALL_WINDOWS(usable_win_ptr) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1636 if (usable_win_ptr->w_llist == ll_ref |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1637 && usable_win_ptr->w_buffer->b_p_bt[0] != 'q') |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1638 break; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1639 } |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1640 |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1641 if (!usable_win) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1642 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1643 /* Locate a window showing a normal buffer */ |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1644 FOR_ALL_WINDOWS(win) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1645 if (win->w_buffer->b_p_bt[0] == NUL) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1646 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1647 usable_win = 1; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1648 break; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1649 } |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1650 } |
644 | 1651 |
7 | 1652 /* |
1621 | 1653 * If no usable window is found and 'switchbuf' contains "usetab" |
1020 | 1654 * then search in other tabs. |
7 | 1655 */ |
1621 | 1656 if (!usable_win && (swb_flags & SWB_USETAB)) |
1020 | 1657 { |
1658 tabpage_T *tp; | |
1659 win_T *wp; | |
1660 | |
1661 FOR_ALL_TAB_WINDOWS(tp, wp) | |
1662 { | |
1663 if (wp->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1664 { | |
1665 goto_tabpage_win(tp, wp); | |
1666 usable_win = 1; | |
1819 | 1667 goto win_found; |
1020 | 1668 } |
1669 } | |
1670 } | |
1819 | 1671 win_found: |
1020 | 1672 |
1673 /* | |
1396 | 1674 * If there is only one window and it is the quickfix window, create a |
1675 * new one above the quickfix window. | |
1020 | 1676 */ |
1677 if (((firstwin == lastwin) && bt_quickfix(curbuf)) || !usable_win) | |
7 | 1678 { |
1822 | 1679 flags = WSP_ABOVE; |
1680 if (ll_ref != NULL) | |
1681 flags |= WSP_NEWLOC; | |
1682 if (win_split(0, flags) == FAIL) | |
7 | 1683 goto failed; /* not enough room for window */ |
1684 opened_window = TRUE; /* close it when fail */ | |
1685 p_swb = empty_option; /* don't split again */ | |
1621 | 1686 swb_flags = 0; |
2583 | 1687 RESET_BINDING(curwin); |
644 | 1688 if (ll_ref != NULL) |
1689 { | |
1690 /* The new window should use the location list from the | |
1691 * location list window */ | |
1692 curwin->w_llist = ll_ref; | |
1693 ll_ref->qf_refcount++; | |
1694 } | |
7 | 1695 } |
1696 else | |
1697 { | |
644 | 1698 if (curwin->w_llist_ref != NULL) |
1699 { | |
1700 /* In a location window */ | |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1701 win = usable_win_ptr; |
644 | 1702 if (win == NULL) |
1703 { | |
1704 /* Find the window showing the selected file */ | |
1705 FOR_ALL_WINDOWS(win) | |
1706 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1707 break; | |
1708 if (win == NULL) | |
1709 { | |
1710 /* Find a previous usable window */ | |
1711 win = curwin; | |
1712 do | |
1713 { | |
1714 if (win->w_buffer->b_p_bt[0] == NUL) | |
1715 break; | |
1716 if (win->w_prev == NULL) | |
1717 win = lastwin; /* wrap around the top */ | |
1718 else | |
1719 win = win->w_prev; /* go to previous window */ | |
1720 } while (win != curwin); | |
1721 } | |
1722 } | |
1723 win_goto(win); | |
1724 | |
1725 /* If the location list for the window is not set, then set it | |
1726 * to the location list from the location window */ | |
1727 if (win->w_llist == NULL) | |
1728 { | |
1729 win->w_llist = ll_ref; | |
1730 ll_ref->qf_refcount++; | |
1731 } | |
1732 } | |
1733 else | |
1734 { | |
1735 | |
7 | 1736 /* |
1737 * Try to find a window that shows the right buffer. | |
1738 * Default to the window just above the quickfix buffer. | |
1739 */ | |
1740 win = curwin; | |
1741 altwin = NULL; | |
1742 for (;;) | |
1743 { | |
1744 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1745 break; | |
1746 if (win->w_prev == NULL) | |
1747 win = lastwin; /* wrap around the top */ | |
1748 else | |
1749 win = win->w_prev; /* go to previous window */ | |
1750 | |
644 | 1751 if (IS_QF_WINDOW(win)) |
7 | 1752 { |
1753 /* Didn't find it, go to the window before the quickfix | |
1754 * window. */ | |
1755 if (altwin != NULL) | |
1756 win = altwin; | |
1757 else if (curwin->w_prev != NULL) | |
1758 win = curwin->w_prev; | |
1759 else | |
1760 win = curwin->w_next; | |
1761 break; | |
1762 } | |
1763 | |
1764 /* Remember a usable window. */ | |
1765 if (altwin == NULL && !win->w_p_pvw | |
1766 && win->w_buffer->b_p_bt[0] == NUL) | |
1767 altwin = win; | |
1768 } | |
1769 | |
1770 win_goto(win); | |
644 | 1771 } |
7 | 1772 } |
1773 } | |
1774 #endif | |
1775 | |
1776 /* | |
1777 * If there is a file name, | |
1778 * read the wanted file if needed, and check autowrite etc. | |
1779 */ | |
1780 old_curbuf = curbuf; | |
1781 old_lnum = curwin->w_cursor.lnum; | |
9 | 1782 |
1783 if (qf_ptr->qf_fnum != 0) | |
1784 { | |
1785 if (qf_ptr->qf_type == 1) | |
1786 { | |
1787 /* Open help file (do_ecmd() will set b_help flag, readfile() will | |
1788 * set b_p_ro flag). */ | |
1789 if (!can_abandon(curbuf, forceit)) | |
1790 { | |
1791 EMSG(_(e_nowrtmsg)); | |
1792 ok = FALSE; | |
1793 } | |
1794 else | |
1795 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, | |
1743 | 1796 ECMD_HIDE + ECMD_SET_HELP, |
1797 oldwin == curwin ? curwin : NULL); | |
9 | 1798 } |
1799 else | |
1800 ok = buflist_getfile(qf_ptr->qf_fnum, | |
1801 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); | |
1802 } | |
1803 | |
1804 if (ok == OK) | |
7 | 1805 { |
1806 /* When not switched to another buffer, still need to set pc mark */ | |
1807 if (curbuf == old_curbuf) | |
1808 setpcmark(); | |
1809 | |
230 | 1810 if (qf_ptr->qf_pattern == NULL) |
7 | 1811 { |
230 | 1812 /* |
1813 * Go to line with error, unless qf_lnum is 0. | |
1814 */ | |
1815 i = qf_ptr->qf_lnum; | |
1816 if (i > 0) | |
1817 { | |
1818 if (i > curbuf->b_ml.ml_line_count) | |
1819 i = curbuf->b_ml.ml_line_count; | |
1820 curwin->w_cursor.lnum = i; | |
1821 } | |
1822 if (qf_ptr->qf_col > 0) | |
7 | 1823 { |
230 | 1824 curwin->w_cursor.col = qf_ptr->qf_col - 1; |
1825 if (qf_ptr->qf_viscol == TRUE) | |
7 | 1826 { |
230 | 1827 /* |
1828 * Check each character from the beginning of the error | |
1829 * line up to the error column. For each tab character | |
1830 * found, reduce the error column value by the length of | |
1831 * a tab character. | |
1832 */ | |
1833 line = ml_get_curline(); | |
1834 screen_col = 0; | |
1835 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col) | |
7 | 1836 { |
230 | 1837 if (*line == NUL) |
1838 break; | |
1839 if (*line++ == '\t') | |
1840 { | |
1841 curwin->w_cursor.col -= 7 - (screen_col % 8); | |
1842 screen_col += 8 - (screen_col % 8); | |
1843 } | |
1844 else | |
1845 ++screen_col; | |
7 | 1846 } |
1847 } | |
230 | 1848 check_cursor(); |
7 | 1849 } |
230 | 1850 else |
1851 beginline(BL_WHITE | BL_FIX); | |
7 | 1852 } |
1853 else | |
230 | 1854 { |
1855 pos_T save_cursor; | |
1856 | |
1857 /* Move the cursor to the first line in the buffer */ | |
1858 save_cursor = curwin->w_cursor; | |
1859 curwin->w_cursor.lnum = 0; | |
1521 | 1860 if (!do_search(NULL, '/', qf_ptr->qf_pattern, (long)1, |
1861 SEARCH_KEEP, NULL)) | |
230 | 1862 curwin->w_cursor = save_cursor; |
1863 } | |
7 | 1864 |
1865 #ifdef FEAT_FOLDING | |
1866 if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped) | |
1867 foldOpenCursor(); | |
1868 #endif | |
1869 if (print_message) | |
1870 { | |
3267 | 1871 /* Update the screen before showing the message, unless the screen |
1872 * scrolled up. */ | |
1873 if (!msg_scrolled) | |
1874 update_topline_redraw(); | |
7 | 1875 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, |
644 | 1876 qi->qf_lists[qi->qf_curlist].qf_count, |
7 | 1877 qf_ptr->qf_cleared ? _(" (line deleted)") : "", |
1878 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); | |
1879 /* Add the message, skipping leading whitespace and newlines. */ | |
1880 len = (int)STRLEN(IObuff); | |
1881 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); | |
1882 | |
1883 /* Output the message. Overwrite to avoid scrolling when the 'O' | |
1884 * flag is present in 'shortmess'; But when not jumping, print the | |
1885 * whole message. */ | |
1886 i = msg_scroll; | |
1887 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) | |
1888 msg_scroll = TRUE; | |
1889 else if (!msg_scrolled && shortmess(SHM_OVERALL)) | |
1890 msg_scroll = FALSE; | |
1891 msg_attr_keep(IObuff, 0, TRUE); | |
1892 msg_scroll = i; | |
1893 } | |
1894 } | |
1895 else | |
1896 { | |
1897 #ifdef FEAT_WINDOWS | |
1898 if (opened_window) | |
1899 win_close(curwin, TRUE); /* Close opened window */ | |
1900 #endif | |
1901 if (qf_ptr->qf_fnum != 0) | |
1902 { | |
1903 /* | |
1904 * Couldn't open file, so put index back where it was. This could | |
1905 * happen if the file was readonly and we changed something. | |
1906 */ | |
1907 #ifdef FEAT_WINDOWS | |
1908 failed: | |
1909 #endif | |
1910 qf_ptr = old_qf_ptr; | |
1911 qf_index = old_qf_index; | |
1912 } | |
1913 } | |
1914 theend: | |
644 | 1915 qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr; |
1916 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; | |
7 | 1917 #ifdef FEAT_WINDOWS |
1918 if (p_swb != old_swb && opened_window) | |
1919 { | |
1920 /* Restore old 'switchbuf' value, but not when an autocommand or | |
1921 * modeline has changed the value. */ | |
1922 if (p_swb == empty_option) | |
1621 | 1923 { |
7 | 1924 p_swb = old_swb; |
1621 | 1925 swb_flags = old_swb_flags; |
1926 } | |
7 | 1927 else |
1928 free_string_option(old_swb); | |
1929 } | |
1930 #endif | |
1931 } | |
1932 | |
1933 /* | |
1934 * ":clist": list all errors | |
644 | 1935 * ":llist": list all locations |
7 | 1936 */ |
1937 void | |
1938 qf_list(eap) | |
1939 exarg_T *eap; | |
1940 { | |
230 | 1941 buf_T *buf; |
1942 char_u *fname; | |
1943 qfline_T *qfp; | |
1944 int i; | |
1945 int idx1 = 1; | |
1946 int idx2 = -1; | |
1947 char_u *arg = eap->arg; | |
1948 int all = eap->forceit; /* if not :cl!, only show | |
7 | 1949 recognised errors */ |
644 | 1950 qf_info_T *qi = &ql_info; |
1951 | |
1952 if (eap->cmdidx == CMD_llist) | |
1953 { | |
1954 qi = GET_LOC_LIST(curwin); | |
1955 if (qi == NULL) | |
1956 { | |
1957 EMSG(_(e_loclist)); | |
1958 return; | |
1959 } | |
1960 } | |
1961 | |
1962 if (qi->qf_curlist >= qi->qf_listcount | |
1963 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | |
7 | 1964 { |
1965 EMSG(_(e_quickfix)); | |
1966 return; | |
1967 } | |
1968 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) | |
1969 { | |
1970 EMSG(_(e_trailing)); | |
1971 return; | |
1972 } | |
644 | 1973 i = qi->qf_lists[qi->qf_curlist].qf_count; |
7 | 1974 if (idx1 < 0) |
1975 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1; | |
1976 if (idx2 < 0) | |
1977 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1; | |
1978 | |
644 | 1979 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid) |
7 | 1980 all = TRUE; |
644 | 1981 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
1982 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ) | |
7 | 1983 { |
1984 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) | |
1985 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
1986 msg_putchar('\n'); |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
1987 if (got_int) |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
1988 break; |
446 | 1989 |
1990 fname = NULL; | |
1991 if (qfp->qf_fnum != 0 | |
7 | 1992 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL) |
446 | 1993 { |
1994 fname = buf->b_fname; | |
1995 if (qfp->qf_type == 1) /* :helpgrep */ | |
1996 fname = gettail(fname); | |
1997 } | |
1998 if (fname == NULL) | |
1999 sprintf((char *)IObuff, "%2d", i); | |
2000 else | |
2001 vim_snprintf((char *)IObuff, IOSIZE, "%2d %s", | |
273 | 2002 i, (char *)fname); |
644 | 2003 msg_outtrans_attr(IObuff, i == qi->qf_lists[qi->qf_curlist].qf_index |
446 | 2004 ? hl_attr(HLF_L) : hl_attr(HLF_D)); |
2005 if (qfp->qf_lnum == 0) | |
2006 IObuff[0] = NUL; | |
2007 else if (qfp->qf_col == 0) | |
2008 sprintf((char *)IObuff, ":%ld", qfp->qf_lnum); | |
2009 else | |
2010 sprintf((char *)IObuff, ":%ld col %d", | |
7 | 2011 qfp->qf_lnum, qfp->qf_col); |
446 | 2012 sprintf((char *)IObuff + STRLEN(IObuff), "%s:", |
7 | 2013 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); |
446 | 2014 msg_puts_attr(IObuff, hl_attr(HLF_N)); |
2015 if (qfp->qf_pattern != NULL) | |
2016 { | |
2017 qf_fmt_text(qfp->qf_pattern, IObuff, IOSIZE); | |
2018 STRCAT(IObuff, ":"); | |
2019 msg_puts(IObuff); | |
2020 } | |
2021 msg_puts((char_u *)" "); | |
230 | 2022 |
446 | 2023 /* Remove newlines and leading whitespace from the text. For an |
2024 * unrecognized line keep the indent, the compiler may mark a word | |
2025 * with ^^^^. */ | |
2026 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) | |
7 | 2027 ? skipwhite(qfp->qf_text) : qfp->qf_text, |
2028 IObuff, IOSIZE); | |
446 | 2029 msg_prt_line(IObuff, FALSE); |
2030 out_flush(); /* show one line at a time */ | |
7 | 2031 } |
446 | 2032 |
2033 qfp = qfp->qf_next; | |
2034 ++i; | |
7 | 2035 ui_breakcheck(); |
2036 } | |
2037 } | |
2038 | |
2039 /* | |
2040 * Remove newlines and leading whitespace from an error message. | |
2041 * Put the result in "buf[bufsize]". | |
2042 */ | |
2043 static void | |
2044 qf_fmt_text(text, buf, bufsize) | |
2045 char_u *text; | |
2046 char_u *buf; | |
2047 int bufsize; | |
2048 { | |
2049 int i; | |
2050 char_u *p = text; | |
2051 | |
2052 for (i = 0; *p != NUL && i < bufsize - 1; ++i) | |
2053 { | |
2054 if (*p == '\n') | |
2055 { | |
2056 buf[i] = ' '; | |
2057 while (*++p != NUL) | |
2058 if (!vim_iswhite(*p) && *p != '\n') | |
2059 break; | |
2060 } | |
2061 else | |
2062 buf[i] = *p++; | |
2063 } | |
2064 buf[i] = NUL; | |
2065 } | |
2066 | |
2067 /* | |
2068 * ":colder [count]": Up in the quickfix stack. | |
2069 * ":cnewer [count]": Down in the quickfix stack. | |
644 | 2070 * ":lolder [count]": Up in the location list stack. |
2071 * ":lnewer [count]": Down in the location list stack. | |
7 | 2072 */ |
2073 void | |
2074 qf_age(eap) | |
2075 exarg_T *eap; | |
2076 { | |
644 | 2077 qf_info_T *qi = &ql_info; |
7 | 2078 int count; |
2079 | |
644 | 2080 if (eap->cmdidx == CMD_lolder || eap->cmdidx == CMD_lnewer) |
2081 { | |
2082 qi = GET_LOC_LIST(curwin); | |
2083 if (qi == NULL) | |
2084 { | |
2085 EMSG(_(e_loclist)); | |
2086 return; | |
2087 } | |
2088 } | |
2089 | |
7 | 2090 if (eap->addr_count != 0) |
2091 count = eap->line2; | |
2092 else | |
2093 count = 1; | |
2094 while (count--) | |
2095 { | |
644 | 2096 if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) |
7 | 2097 { |
644 | 2098 if (qi->qf_curlist == 0) |
7 | 2099 { |
2100 EMSG(_("E380: At bottom of quickfix stack")); | |
4371 | 2101 break; |
7 | 2102 } |
644 | 2103 --qi->qf_curlist; |
7 | 2104 } |
2105 else | |
2106 { | |
644 | 2107 if (qi->qf_curlist >= qi->qf_listcount - 1) |
7 | 2108 { |
2109 EMSG(_("E381: At top of quickfix stack")); | |
4371 | 2110 break; |
7 | 2111 } |
644 | 2112 ++qi->qf_curlist; |
7 | 2113 } |
2114 } | |
644 | 2115 qf_msg(qi); |
7 | 2116 } |
2117 | |
2118 static void | |
644 | 2119 qf_msg(qi) |
2120 qf_info_T *qi; | |
7 | 2121 { |
2122 smsg((char_u *)_("error list %d of %d; %d errors"), | |
644 | 2123 qi->qf_curlist + 1, qi->qf_listcount, |
2124 qi->qf_lists[qi->qf_curlist].qf_count); | |
7 | 2125 #ifdef FEAT_WINDOWS |
644 | 2126 qf_update_buffer(qi); |
7 | 2127 #endif |
2128 } | |
2129 | |
2130 /* | |
581 | 2131 * Free error list "idx". |
7 | 2132 */ |
2133 static void | |
644 | 2134 qf_free(qi, idx) |
2135 qf_info_T *qi; | |
7 | 2136 int idx; |
2137 { | |
230 | 2138 qfline_T *qfp; |
3982 | 2139 int stop = FALSE; |
7 | 2140 |
644 | 2141 while (qi->qf_lists[idx].qf_count) |
7 | 2142 { |
644 | 2143 qfp = qi->qf_lists[idx].qf_start->qf_next; |
3982 | 2144 if (qi->qf_lists[idx].qf_title != NULL && !stop) |
3949 | 2145 { |
2146 vim_free(qi->qf_lists[idx].qf_start->qf_text); | |
3982 | 2147 stop = (qi->qf_lists[idx].qf_start == qfp); |
3949 | 2148 vim_free(qi->qf_lists[idx].qf_start->qf_pattern); |
2149 vim_free(qi->qf_lists[idx].qf_start); | |
3982 | 2150 if (stop) |
2151 /* Somehow qf_count may have an incorrect value, set it to 1 | |
2152 * to avoid crashing when it's wrong. | |
2153 * TODO: Avoid qf_count being incorrect. */ | |
2154 qi->qf_lists[idx].qf_count = 1; | |
3949 | 2155 } |
644 | 2156 qi->qf_lists[idx].qf_start = qfp; |
2157 --qi->qf_lists[idx].qf_count; | |
7 | 2158 } |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2159 vim_free(qi->qf_lists[idx].qf_title); |
2576 | 2160 qi->qf_lists[idx].qf_title = NULL; |
7 | 2161 } |
2162 | |
2163 /* | |
2164 * qf_mark_adjust: adjust marks | |
2165 */ | |
2166 void | |
644 | 2167 qf_mark_adjust(wp, line1, line2, amount, amount_after) |
2168 win_T *wp; | |
7 | 2169 linenr_T line1; |
2170 linenr_T line2; | |
2171 long amount; | |
2172 long amount_after; | |
2173 { | |
230 | 2174 int i; |
2175 qfline_T *qfp; | |
2176 int idx; | |
644 | 2177 qf_info_T *qi = &ql_info; |
2178 | |
2179 if (wp != NULL) | |
2180 { | |
2181 if (wp->w_llist == NULL) | |
2182 return; | |
2183 qi = wp->w_llist; | |
2184 } | |
2185 | |
2186 for (idx = 0; idx < qi->qf_listcount; ++idx) | |
2187 if (qi->qf_lists[idx].qf_count) | |
2188 for (i = 0, qfp = qi->qf_lists[idx].qf_start; | |
2189 i < qi->qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next) | |
7 | 2190 if (qfp->qf_fnum == curbuf->b_fnum) |
2191 { | |
2192 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) | |
2193 { | |
2194 if (amount == MAXLNUM) | |
2195 qfp->qf_cleared = TRUE; | |
2196 else | |
2197 qfp->qf_lnum += amount; | |
2198 } | |
2199 else if (amount_after && qfp->qf_lnum > line2) | |
2200 qfp->qf_lnum += amount_after; | |
2201 } | |
2202 } | |
2203 | |
2204 /* | |
2205 * Make a nice message out of the error character and the error number: | |
2206 * char number message | |
2207 * e or E 0 " error" | |
2208 * w or W 0 " warning" | |
2209 * i or I 0 " info" | |
2210 * 0 0 "" | |
2211 * other 0 " c" | |
2212 * e or E n " error n" | |
2213 * w or W n " warning n" | |
2214 * i or I n " info n" | |
2215 * 0 n " error n" | |
2216 * other n " c n" | |
2217 * 1 x "" :helpgrep | |
2218 */ | |
2219 static char_u * | |
2220 qf_types(c, nr) | |
2221 int c, nr; | |
2222 { | |
2223 static char_u buf[20]; | |
2224 static char_u cc[3]; | |
2225 char_u *p; | |
2226 | |
2227 if (c == 'W' || c == 'w') | |
2228 p = (char_u *)" warning"; | |
2229 else if (c == 'I' || c == 'i') | |
2230 p = (char_u *)" info"; | |
2231 else if (c == 'E' || c == 'e' || (c == 0 && nr > 0)) | |
2232 p = (char_u *)" error"; | |
2233 else if (c == 0 || c == 1) | |
2234 p = (char_u *)""; | |
2235 else | |
2236 { | |
2237 cc[0] = ' '; | |
2238 cc[1] = c; | |
2239 cc[2] = NUL; | |
2240 p = cc; | |
2241 } | |
2242 | |
2243 if (nr <= 0) | |
2244 return p; | |
2245 | |
2246 sprintf((char *)buf, "%s %3d", (char *)p, nr); | |
2247 return buf; | |
2248 } | |
2249 | |
2250 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
2251 /* | |
2252 * ":cwindow": open the quickfix window if we have errors to display, | |
2253 * close it if not. | |
644 | 2254 * ":lwindow": open the location list window if we have locations to display, |
2255 * close it if not. | |
7 | 2256 */ |
2257 void | |
2258 ex_cwindow(eap) | |
2259 exarg_T *eap; | |
2260 { | |
644 | 2261 qf_info_T *qi = &ql_info; |
7 | 2262 win_T *win; |
2263 | |
644 | 2264 if (eap->cmdidx == CMD_lwindow) |
2265 { | |
2266 qi = GET_LOC_LIST(curwin); | |
2267 if (qi == NULL) | |
2268 return; | |
2269 } | |
2270 | |
2271 /* Look for an existing quickfix window. */ | |
2272 win = qf_find_win(qi); | |
7 | 2273 |
2274 /* | |
2275 * If a quickfix window is open but we have no errors to display, | |
2276 * close the window. If a quickfix window is not open, then open | |
2277 * it if we have errors; otherwise, leave it closed. | |
2278 */ | |
644 | 2279 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid |
2795 | 2280 || qi->qf_lists[qi->qf_curlist].qf_count == 0 |
857 | 2281 || qi->qf_curlist >= qi->qf_listcount) |
7 | 2282 { |
2283 if (win != NULL) | |
2284 ex_cclose(eap); | |
2285 } | |
2286 else if (win == NULL) | |
2287 ex_copen(eap); | |
2288 } | |
2289 | |
2290 /* | |
2291 * ":cclose": close the window showing the list of errors. | |
644 | 2292 * ":lclose": close the window showing the location list |
7 | 2293 */ |
2294 void | |
2295 ex_cclose(eap) | |
2296 exarg_T *eap; | |
2297 { | |
644 | 2298 win_T *win = NULL; |
2299 qf_info_T *qi = &ql_info; | |
2300 | |
2301 if (eap->cmdidx == CMD_lclose || eap->cmdidx == CMD_lwindow) | |
2302 { | |
2303 qi = GET_LOC_LIST(curwin); | |
2304 if (qi == NULL) | |
2305 return; | |
2306 } | |
2307 | |
2308 /* Find existing quickfix window and close it. */ | |
2309 win = qf_find_win(qi); | |
7 | 2310 if (win != NULL) |
2311 win_close(win, FALSE); | |
2312 } | |
2313 | |
2314 /* | |
2315 * ":copen": open a window that shows the list of errors. | |
644 | 2316 * ":lopen": open a window that shows the location list. |
7 | 2317 */ |
2318 void | |
2319 ex_copen(eap) | |
2320 exarg_T *eap; | |
2321 { | |
644 | 2322 qf_info_T *qi = &ql_info; |
7 | 2323 int height; |
2324 win_T *win; | |
682 | 2325 tabpage_T *prevtab = curtab; |
859 | 2326 buf_T *qf_buf; |
1743 | 2327 win_T *oldwin = curwin; |
7 | 2328 |
644 | 2329 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow) |
2330 { | |
2331 qi = GET_LOC_LIST(curwin); | |
2332 if (qi == NULL) | |
2333 { | |
2334 EMSG(_(e_loclist)); | |
2335 return; | |
2336 } | |
2337 } | |
2338 | |
7 | 2339 if (eap->addr_count != 0) |
2340 height = eap->line2; | |
2341 else | |
2342 height = QF_WINHEIGHT; | |
2343 | |
2344 #ifdef FEAT_VISUAL | |
2345 reset_VIsual_and_resel(); /* stop Visual mode */ | |
2346 #endif | |
2347 #ifdef FEAT_GUI | |
2348 need_mouse_correct = TRUE; | |
2349 #endif | |
2350 | |
2351 /* | |
2352 * Find existing quickfix window, or open a new one. | |
2353 */ | |
644 | 2354 win = qf_find_win(qi); |
2355 | |
682 | 2356 if (win != NULL && cmdmod.tab == 0) |
7 | 2357 win_goto(win); |
2358 else | |
2359 { | |
859 | 2360 qf_buf = qf_find_buf(qi); |
2361 | |
7 | 2362 /* The current window becomes the previous window afterwards. */ |
2363 win = curwin; | |
2364 | |
3939 | 2365 if ((eap->cmdidx == CMD_copen || eap->cmdidx == CMD_cwindow) |
2366 && cmdmod.split == 0) | |
2367 /* Create the new window at the very bottom, except when | |
2368 * :belowright or :aboveleft is used. */ | |
644 | 2369 win_goto(lastwin); |
1822 | 2370 if (win_split(height, WSP_BELOW | WSP_NEWLOC) == FAIL) |
7 | 2371 return; /* not enough room for window */ |
2583 | 2372 RESET_BINDING(curwin); |
7 | 2373 |
644 | 2374 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow) |
7 | 2375 { |
644 | 2376 /* |
2377 * For the location list window, create a reference to the | |
2378 * location list from the window 'win'. | |
2379 */ | |
2380 curwin->w_llist_ref = win->w_llist; | |
2381 win->w_llist->qf_refcount++; | |
7 | 2382 } |
644 | 2383 |
1743 | 2384 if (oldwin != curwin) |
2385 oldwin = NULL; /* don't store info when in another window */ | |
859 | 2386 if (qf_buf != NULL) |
2387 /* Use the existing quickfix buffer */ | |
2388 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE, | |
1743 | 2389 ECMD_HIDE + ECMD_OLDBUF, oldwin); |
859 | 2390 else |
2391 { | |
2392 /* Create a new quickfix buffer */ | |
1743 | 2393 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin); |
859 | 2394 /* switch off 'swapfile' */ |
2395 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
2396 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix", | |
729 | 2397 OPT_LOCAL); |
859 | 2398 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL); |
2651 | 2399 RESET_BINDING(curwin); |
1864 | 2400 #ifdef FEAT_DIFF |
2401 curwin->w_p_diff = FALSE; | |
2402 #endif | |
2403 #ifdef FEAT_FOLDING | |
2404 set_option_value((char_u *)"fdm", 0L, (char_u *)"manual", | |
2405 OPT_LOCAL); | |
2406 #endif | |
859 | 2407 } |
7 | 2408 |
682 | 2409 /* Only set the height when still in the same tab page and there is no |
2410 * window to the side. */ | |
2411 if (curtab == prevtab | |
119 | 2412 #ifdef FEAT_VERTSPLIT |
682 | 2413 && curwin->w_width == Columns |
119 | 2414 #endif |
682 | 2415 ) |
7 | 2416 win_setheight(height); |
2417 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */ | |
2418 if (win_valid(win)) | |
2419 prevwin = win; | |
2420 } | |
2421 | |
2422 /* | |
2423 * Fill the buffer with the quickfix list. | |
2424 */ | |
644 | 2425 qf_fill_buffer(qi); |
2426 | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2427 if (qi->qf_lists[qi->qf_curlist].qf_title != NULL) |
3016 | 2428 qf_set_title(qi); |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2429 |
644 | 2430 curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 2431 curwin->w_cursor.col = 0; |
2432 check_cursor(); | |
2433 update_topline(); /* scroll to show the line */ | |
2434 } | |
2435 | |
2436 /* | |
2437 * Return the number of the current entry (line number in the quickfix | |
2438 * window). | |
2439 */ | |
2440 linenr_T | |
644 | 2441 qf_current_entry(wp) |
2442 win_T *wp; | |
7 | 2443 { |
644 | 2444 qf_info_T *qi = &ql_info; |
2445 | |
2446 if (IS_LL_WINDOW(wp)) | |
2447 /* In the location list window, use the referenced location list */ | |
2448 qi = wp->w_llist_ref; | |
2449 | |
2450 return qi->qf_lists[qi->qf_curlist].qf_index; | |
7 | 2451 } |
2452 | |
2453 /* | |
2454 * Update the cursor position in the quickfix window to the current error. | |
2455 * Return TRUE if there is a quickfix window. | |
2456 */ | |
2457 static int | |
644 | 2458 qf_win_pos_update(qi, old_qf_index) |
2459 qf_info_T *qi; | |
7 | 2460 int old_qf_index; /* previous qf_index or zero */ |
2461 { | |
2462 win_T *win; | |
644 | 2463 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 2464 |
2465 /* | |
2466 * Put the cursor on the current error in the quickfix window, so that | |
2467 * it's viewable. | |
2468 */ | |
644 | 2469 win = qf_find_win(qi); |
7 | 2470 if (win != NULL |
2471 && qf_index <= win->w_buffer->b_ml.ml_line_count | |
2472 && old_qf_index != qf_index) | |
2473 { | |
2474 win_T *old_curwin = curwin; | |
2475 | |
2476 curwin = win; | |
2477 curbuf = win->w_buffer; | |
2478 if (qf_index > old_qf_index) | |
2479 { | |
2480 curwin->w_redraw_top = old_qf_index; | |
2481 curwin->w_redraw_bot = qf_index; | |
2482 } | |
2483 else | |
2484 { | |
2485 curwin->w_redraw_top = qf_index; | |
2486 curwin->w_redraw_bot = old_qf_index; | |
2487 } | |
2488 curwin->w_cursor.lnum = qf_index; | |
2489 curwin->w_cursor.col = 0; | |
2490 update_topline(); /* scroll to show the line */ | |
2491 redraw_later(VALID); | |
2492 curwin->w_redr_status = TRUE; /* update ruler */ | |
2493 curwin = old_curwin; | |
2494 curbuf = curwin->w_buffer; | |
2495 } | |
2496 return win != NULL; | |
2497 } | |
2498 | |
2499 /* | |
859 | 2500 * Check whether the given window is displaying the specified quickfix/location |
2501 * list buffer | |
2502 */ | |
2503 static int | |
2504 is_qf_win(win, qi) | |
2505 win_T *win; | |
2506 qf_info_T *qi; | |
2507 { | |
2508 /* | |
2509 * A window displaying the quickfix buffer will have the w_llist_ref field | |
2510 * set to NULL. | |
2511 * A window displaying a location list buffer will have the w_llist_ref | |
2512 * pointing to the location list. | |
2513 */ | |
2514 if (bt_quickfix(win->w_buffer)) | |
2515 if ((qi == &ql_info && win->w_llist_ref == NULL) | |
2516 || (qi != &ql_info && win->w_llist_ref == qi)) | |
2517 return TRUE; | |
2518 | |
2519 return FALSE; | |
2520 } | |
2521 | |
2522 /* | |
644 | 2523 * Find a window displaying the quickfix/location list 'qi' |
859 | 2524 * Searches in only the windows opened in the current tab. |
644 | 2525 */ |
2526 static win_T * | |
2527 qf_find_win(qi) | |
2528 qf_info_T *qi; | |
2529 { | |
2530 win_T *win; | |
2531 | |
2532 FOR_ALL_WINDOWS(win) | |
859 | 2533 if (is_qf_win(win, qi)) |
2534 break; | |
644 | 2535 |
2536 return win; | |
2537 } | |
2538 | |
2539 /* | |
859 | 2540 * Find a quickfix buffer. |
2541 * Searches in windows opened in all the tabs. | |
7 | 2542 */ |
2543 static buf_T * | |
644 | 2544 qf_find_buf(qi) |
2545 qf_info_T *qi; | |
7 | 2546 { |
859 | 2547 tabpage_T *tp; |
644 | 2548 win_T *win; |
2549 | |
859 | 2550 FOR_ALL_TAB_WINDOWS(tp, win) |
2551 if (is_qf_win(win, qi)) | |
2552 return win->w_buffer; | |
2553 | |
2554 return NULL; | |
7 | 2555 } |
2556 | |
2557 /* | |
2558 * Find the quickfix buffer. If it exists, update the contents. | |
2559 */ | |
2560 static void | |
644 | 2561 qf_update_buffer(qi) |
2562 qf_info_T *qi; | |
7 | 2563 { |
2564 buf_T *buf; | |
3016 | 2565 win_T *win; |
2566 win_T *curwin_save; | |
7 | 2567 aco_save_T aco; |
2568 | |
2569 /* Check if a buffer for the quickfix list exists. Update it. */ | |
644 | 2570 buf = qf_find_buf(qi); |
7 | 2571 if (buf != NULL) |
2572 { | |
2573 /* set curwin/curbuf to buf and save a few things */ | |
2574 aucmd_prepbuf(&aco, buf); | |
2575 | |
644 | 2576 qf_fill_buffer(qi); |
7 | 2577 |
3016 | 2578 if (qi->qf_lists[qi->qf_curlist].qf_title != NULL |
2579 && (win = qf_find_win(qi)) != NULL) | |
2580 { | |
2581 curwin_save = curwin; | |
2582 curwin = win; | |
2583 qf_set_title(qi); | |
2584 curwin = curwin_save; | |
2585 | |
2586 } | |
2587 | |
7 | 2588 /* restore curwin/curbuf and a few other things */ |
2589 aucmd_restbuf(&aco); | |
2590 | |
644 | 2591 (void)qf_win_pos_update(qi, 0); |
7 | 2592 } |
2593 } | |
2594 | |
3016 | 2595 static void |
2596 qf_set_title(qi) | |
2597 qf_info_T *qi; | |
2598 { | |
2599 set_internal_string_var((char_u *)"w:quickfix_title", | |
2600 qi->qf_lists[qi->qf_curlist].qf_title); | |
2601 } | |
2602 | |
7 | 2603 /* |
2604 * Fill current buffer with quickfix errors, replacing any previous contents. | |
2605 * curbuf must be the quickfix buffer! | |
2606 */ | |
2607 static void | |
644 | 2608 qf_fill_buffer(qi) |
2609 qf_info_T *qi; | |
7 | 2610 { |
230 | 2611 linenr_T lnum; |
2612 qfline_T *qfp; | |
2613 buf_T *errbuf; | |
2614 int len; | |
2615 int old_KeyTyped = KeyTyped; | |
7 | 2616 |
2617 /* delete all existing lines */ | |
2618 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) | |
2619 (void)ml_delete((linenr_T)1, FALSE); | |
2620 | |
2621 /* Check if there is anything to display */ | |
644 | 2622 if (qi->qf_curlist < qi->qf_listcount) |
7 | 2623 { |
2624 /* Add one line for each error */ | |
644 | 2625 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
2626 for (lnum = 0; lnum < qi->qf_lists[qi->qf_curlist].qf_count; ++lnum) | |
7 | 2627 { |
2628 if (qfp->qf_fnum != 0 | |
2629 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL | |
2630 && errbuf->b_fname != NULL) | |
2631 { | |
2632 if (qfp->qf_type == 1) /* :helpgrep */ | |
2633 STRCPY(IObuff, gettail(errbuf->b_fname)); | |
2634 else | |
2635 STRCPY(IObuff, errbuf->b_fname); | |
2636 len = (int)STRLEN(IObuff); | |
2637 } | |
2638 else | |
2639 len = 0; | |
2640 IObuff[len++] = '|'; | |
2641 | |
2642 if (qfp->qf_lnum > 0) | |
2643 { | |
2644 sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum); | |
2645 len += (int)STRLEN(IObuff + len); | |
2646 | |
2647 if (qfp->qf_col > 0) | |
2648 { | |
2649 sprintf((char *)IObuff + len, " col %d", qfp->qf_col); | |
2650 len += (int)STRLEN(IObuff + len); | |
2651 } | |
2652 | |
2653 sprintf((char *)IObuff + len, "%s", | |
2654 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); | |
2655 len += (int)STRLEN(IObuff + len); | |
2656 } | |
230 | 2657 else if (qfp->qf_pattern != NULL) |
2658 { | |
2659 qf_fmt_text(qfp->qf_pattern, IObuff + len, IOSIZE - len); | |
2660 len += (int)STRLEN(IObuff + len); | |
2661 } | |
7 | 2662 IObuff[len++] = '|'; |
2663 IObuff[len++] = ' '; | |
2664 | |
2665 /* Remove newlines and leading whitespace from the text. | |
2666 * For an unrecognized line keep the indent, the compiler may | |
2667 * mark a word with ^^^^. */ | |
2668 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text, | |
2669 IObuff + len, IOSIZE - len); | |
2670 | |
2671 if (ml_append(lnum, IObuff, (colnr_T)STRLEN(IObuff) + 1, FALSE) | |
2672 == FAIL) | |
2673 break; | |
2674 qfp = qfp->qf_next; | |
2675 } | |
2676 /* Delete the empty line which is now at the end */ | |
2677 (void)ml_delete(lnum + 1, FALSE); | |
2678 } | |
2679 | |
2680 /* correct cursor position */ | |
2681 check_lnums(TRUE); | |
2682 | |
2683 /* Set the 'filetype' to "qf" each time after filling the buffer. This | |
2684 * resembles reading a file into a buffer, it's more logical when using | |
2685 * autocommands. */ | |
2686 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL); | |
2687 curbuf->b_p_ma = FALSE; | |
2688 | |
2689 #ifdef FEAT_AUTOCMD | |
1864 | 2690 keep_filetype = TRUE; /* don't detect 'filetype' */ |
7 | 2691 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL, |
2692 FALSE, curbuf); | |
2693 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL, | |
2694 FALSE, curbuf); | |
1864 | 2695 keep_filetype = FALSE; |
7 | 2696 #endif |
2697 | |
2698 /* make sure it will be redrawn */ | |
2699 redraw_curbuf_later(NOT_VALID); | |
2700 | |
2701 /* Restore KeyTyped, setting 'filetype' may reset it. */ | |
2702 KeyTyped = old_KeyTyped; | |
2703 } | |
2704 | |
2705 #endif /* FEAT_WINDOWS */ | |
2706 | |
2707 /* | |
2708 * Return TRUE if "buf" is the quickfix buffer. | |
2709 */ | |
2710 int | |
2711 bt_quickfix(buf) | |
2712 buf_T *buf; | |
2713 { | |
3242 | 2714 return buf != NULL && buf->b_p_bt[0] == 'q'; |
7 | 2715 } |
2716 | |
2717 /* | |
17 | 2718 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer. |
2719 * This means the buffer name is not a file name. | |
7 | 2720 */ |
2721 int | |
2722 bt_nofile(buf) | |
2723 buf_T *buf; | |
2724 { | |
3242 | 2725 return buf != NULL && ((buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f') |
2726 || buf->b_p_bt[0] == 'a'); | |
7 | 2727 } |
2728 | |
2729 /* | |
2730 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer. | |
2731 */ | |
2732 int | |
2733 bt_dontwrite(buf) | |
2734 buf_T *buf; | |
2735 { | |
3242 | 2736 return buf != NULL && buf->b_p_bt[0] == 'n'; |
7 | 2737 } |
2738 | |
2739 int | |
2740 bt_dontwrite_msg(buf) | |
2741 buf_T *buf; | |
2742 { | |
2743 if (bt_dontwrite(buf)) | |
2744 { | |
2745 EMSG(_("E382: Cannot write, 'buftype' option is set")); | |
2746 return TRUE; | |
2747 } | |
2748 return FALSE; | |
2749 } | |
2750 | |
2751 /* | |
2752 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide" | |
2753 * and 'bufhidden'. | |
2754 */ | |
2755 int | |
2756 buf_hide(buf) | |
2757 buf_T *buf; | |
2758 { | |
2759 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ | |
2760 switch (buf->b_p_bh[0]) | |
2761 { | |
2762 case 'u': /* "unload" */ | |
2763 case 'w': /* "wipe" */ | |
2764 case 'd': return FALSE; /* "delete" */ | |
2765 case 'h': return TRUE; /* "hide" */ | |
2766 } | |
2767 return (p_hid || cmdmod.hide); | |
2768 } | |
2769 | |
2770 /* | |
41 | 2771 * Return TRUE when using ":vimgrep" for ":grep". |
2772 */ | |
2773 int | |
42 | 2774 grep_internal(cmdidx) |
2775 cmdidx_T cmdidx; | |
41 | 2776 { |
661 | 2777 return ((cmdidx == CMD_grep |
2778 || cmdidx == CMD_lgrep | |
2779 || cmdidx == CMD_grepadd | |
2780 || cmdidx == CMD_lgrepadd) | |
41 | 2781 && STRCMP("internal", |
2782 *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0); | |
2783 } | |
2784 | |
2785 /* | |
657 | 2786 * Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd" |
7 | 2787 */ |
2788 void | |
2789 ex_make(eap) | |
2790 exarg_T *eap; | |
2791 { | |
161 | 2792 char_u *fname; |
7 | 2793 char_u *cmd; |
2794 unsigned len; | |
657 | 2795 win_T *wp = NULL; |
659 | 2796 qf_info_T *qi = &ql_info; |
842 | 2797 int res; |
161 | 2798 #ifdef FEAT_AUTOCMD |
2799 char_u *au_name = NULL; | |
2800 | |
2782 | 2801 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */ |
2802 if (grep_internal(eap->cmdidx)) | |
2803 { | |
2804 ex_vimgrep(eap); | |
2805 return; | |
2806 } | |
2807 | |
161 | 2808 switch (eap->cmdidx) |
2809 { | |
661 | 2810 case CMD_make: au_name = (char_u *)"make"; break; |
2811 case CMD_lmake: au_name = (char_u *)"lmake"; break; | |
2812 case CMD_grep: au_name = (char_u *)"grep"; break; | |
2813 case CMD_lgrep: au_name = (char_u *)"lgrep"; break; | |
2814 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; | |
2815 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break; | |
161 | 2816 default: break; |
2817 } | |
2818 if (au_name != NULL) | |
2819 { | |
2820 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
2821 curbuf->b_fname, TRUE, curbuf); | |
532 | 2822 # ifdef FEAT_EVAL |
161 | 2823 if (did_throw || force_abort) |
2824 return; | |
532 | 2825 # endif |
161 | 2826 } |
2827 #endif | |
7 | 2828 |
657 | 2829 if (eap->cmdidx == CMD_lmake || eap->cmdidx == CMD_lgrep |
2830 || eap->cmdidx == CMD_lgrepadd) | |
2831 wp = curwin; | |
2832 | |
7 | 2833 autowrite_all(); |
161 | 2834 fname = get_mef_name(); |
2835 if (fname == NULL) | |
7 | 2836 return; |
161 | 2837 mch_remove(fname); /* in case it's not unique */ |
7 | 2838 |
2839 /* | |
2840 * If 'shellpipe' empty: don't redirect to 'errorfile'. | |
2841 */ | |
2842 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; | |
2843 if (*p_sp != NUL) | |
161 | 2844 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; |
7 | 2845 cmd = alloc(len); |
2846 if (cmd == NULL) | |
2847 return; | |
2848 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, | |
2849 (char *)p_shq); | |
2850 if (*p_sp != NUL) | |
1872 | 2851 append_redir(cmd, len, p_sp, fname); |
7 | 2852 /* |
2853 * Output a newline if there's something else than the :make command that | |
2854 * was typed (in which case the cursor is in column 0). | |
2855 */ | |
2856 if (msg_col == 0) | |
2857 msg_didout = FALSE; | |
2858 msg_start(); | |
2859 MSG_PUTS(":!"); | |
2860 msg_outtrans(cmd); /* show what we are doing */ | |
2861 | |
2862 /* let the shell know if we are redirecting output or not */ | |
2863 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0); | |
2864 | |
2865 #ifdef AMIGA | |
2866 out_flush(); | |
2867 /* read window status report and redraw before message */ | |
2868 (void)char_avail(); | |
2869 #endif | |
2870 | |
842 | 2871 res = qf_init(wp, fname, (eap->cmdidx != CMD_make |
657 | 2872 && eap->cmdidx != CMD_lmake) ? p_gefm : p_efm, |
2873 (eap->cmdidx != CMD_grepadd | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2874 && eap->cmdidx != CMD_lgrepadd), |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2875 *eap->cmdlinep); |
2847 | 2876 if (wp != NULL) |
2877 qi = GET_LOC_LIST(wp); | |
842 | 2878 #ifdef FEAT_AUTOCMD |
2879 if (au_name != NULL) | |
2847 | 2880 { |
842 | 2881 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, |
2882 curbuf->b_fname, TRUE, curbuf); | |
2847 | 2883 if (qi->qf_curlist < qi->qf_listcount) |
2884 res = qi->qf_lists[qi->qf_curlist].qf_count; | |
2885 else | |
2886 res = 0; | |
2887 } | |
842 | 2888 #endif |
2889 if (res > 0 && !eap->forceit) | |
659 | 2890 qf_jump(qi, 0, 0, FALSE); /* display first error */ |
7 | 2891 |
161 | 2892 mch_remove(fname); |
2893 vim_free(fname); | |
7 | 2894 vim_free(cmd); |
2895 } | |
2896 | |
2897 /* | |
2898 * Return the name for the errorfile, in allocated memory. | |
2899 * Find a new unique name when 'makeef' contains "##". | |
2900 * Returns NULL for error. | |
2901 */ | |
2902 static char_u * | |
2903 get_mef_name() | |
2904 { | |
2905 char_u *p; | |
2906 char_u *name; | |
2907 static int start = -1; | |
2908 static int off = 0; | |
2909 #ifdef HAVE_LSTAT | |
2910 struct stat sb; | |
2911 #endif | |
2912 | |
2913 if (*p_mef == NUL) | |
2914 { | |
2915 name = vim_tempname('e'); | |
2916 if (name == NULL) | |
2917 EMSG(_(e_notmp)); | |
2918 return name; | |
2919 } | |
2920 | |
2921 for (p = p_mef; *p; ++p) | |
2922 if (p[0] == '#' && p[1] == '#') | |
2923 break; | |
2924 | |
2925 if (*p == NUL) | |
2926 return vim_strsave(p_mef); | |
2927 | |
2928 /* Keep trying until the name doesn't exist yet. */ | |
2929 for (;;) | |
2930 { | |
2931 if (start == -1) | |
2932 start = mch_get_pid(); | |
2933 else | |
2934 off += 19; | |
2935 | |
2936 name = alloc((unsigned)STRLEN(p_mef) + 30); | |
2937 if (name == NULL) | |
2938 break; | |
2939 STRCPY(name, p_mef); | |
2940 sprintf((char *)name + (p - p_mef), "%d%d", start, off); | |
2941 STRCAT(name, p + 2); | |
2942 if (mch_getperm(name) < 0 | |
2943 #ifdef HAVE_LSTAT | |
2944 /* Don't accept a symbolic link, its a security risk. */ | |
2945 && mch_lstat((char *)name, &sb) < 0 | |
2946 #endif | |
2947 ) | |
2948 break; | |
2949 vim_free(name); | |
2950 } | |
2951 return name; | |
2952 } | |
2953 | |
2954 /* | |
2955 * ":cc", ":crewind", ":cfirst" and ":clast". | |
644 | 2956 * ":ll", ":lrewind", ":lfirst" and ":llast". |
7 | 2957 */ |
2958 void | |
2959 ex_cc(eap) | |
2960 exarg_T *eap; | |
2961 { | |
659 | 2962 qf_info_T *qi = &ql_info; |
2963 | |
2964 if (eap->cmdidx == CMD_ll | |
2965 || eap->cmdidx == CMD_lrewind | |
2966 || eap->cmdidx == CMD_lfirst | |
2967 || eap->cmdidx == CMD_llast) | |
644 | 2968 { |
2969 qi = GET_LOC_LIST(curwin); | |
2970 if (qi == NULL) | |
2971 { | |
2972 EMSG(_(e_loclist)); | |
2973 return; | |
2974 } | |
2975 } | |
2976 | |
659 | 2977 qf_jump(qi, 0, |
7 | 2978 eap->addr_count > 0 |
2979 ? (int)eap->line2 | |
644 | 2980 : (eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll) |
7 | 2981 ? 0 |
644 | 2982 : (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_lrewind |
2983 || eap->cmdidx == CMD_cfirst || eap->cmdidx == CMD_lfirst) | |
7 | 2984 ? 1 |
2985 : 32767, | |
2986 eap->forceit); | |
2987 } | |
2988 | |
2989 /* | |
2990 * ":cnext", ":cnfile", ":cNext" and ":cprevious". | |
644 | 2991 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile". |
7 | 2992 */ |
2993 void | |
2994 ex_cnext(eap) | |
2995 exarg_T *eap; | |
2996 { | |
659 | 2997 qf_info_T *qi = &ql_info; |
2998 | |
2999 if (eap->cmdidx == CMD_lnext | |
3000 || eap->cmdidx == CMD_lNext | |
3001 || eap->cmdidx == CMD_lprevious | |
3002 || eap->cmdidx == CMD_lnfile | |
3003 || eap->cmdidx == CMD_lNfile | |
3004 || eap->cmdidx == CMD_lpfile) | |
644 | 3005 { |
3006 qi = GET_LOC_LIST(curwin); | |
3007 if (qi == NULL) | |
3008 { | |
3009 EMSG(_(e_loclist)); | |
3010 return; | |
3011 } | |
3012 } | |
3013 | |
659 | 3014 qf_jump(qi, (eap->cmdidx == CMD_cnext || eap->cmdidx == CMD_lnext) |
7 | 3015 ? FORWARD |
644 | 3016 : (eap->cmdidx == CMD_cnfile || eap->cmdidx == CMD_lnfile) |
7 | 3017 ? FORWARD_FILE |
644 | 3018 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_lpfile |
3019 || eap->cmdidx == CMD_cNfile || eap->cmdidx == CMD_lNfile) | |
7 | 3020 ? BACKWARD_FILE |
3021 : BACKWARD, | |
3022 eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit); | |
3023 } | |
3024 | |
3025 /* | |
446 | 3026 * ":cfile"/":cgetfile"/":caddfile" commands. |
644 | 3027 * ":lfile"/":lgetfile"/":laddfile" commands. |
7 | 3028 */ |
3029 void | |
3030 ex_cfile(eap) | |
3031 exarg_T *eap; | |
3032 { | |
644 | 3033 win_T *wp = NULL; |
659 | 3034 qf_info_T *qi = &ql_info; |
3404 | 3035 #ifdef FEAT_AUTOCMD |
3036 char_u *au_name = NULL; | |
3037 #endif | |
644 | 3038 |
3039 if (eap->cmdidx == CMD_lfile || eap->cmdidx == CMD_lgetfile | |
3404 | 3040 || eap->cmdidx == CMD_laddfile) |
644 | 3041 wp = curwin; |
3042 | |
3404 | 3043 #ifdef FEAT_AUTOCMD |
3044 switch (eap->cmdidx) | |
3045 { | |
3046 case CMD_cfile: au_name = (char_u *)"cfile"; break; | |
3047 case CMD_cgetfile: au_name = (char_u *)"cgetfile"; break; | |
3048 case CMD_caddfile: au_name = (char_u *)"caddfile"; break; | |
3049 case CMD_lfile: au_name = (char_u *)"lfile"; break; | |
3050 case CMD_lgetfile: au_name = (char_u *)"lgetfile"; break; | |
3051 case CMD_laddfile: au_name = (char_u *)"laddfile"; break; | |
3052 default: break; | |
3053 } | |
3054 if (au_name != NULL) | |
3055 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf); | |
3056 #endif | |
2296
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3057 #ifdef FEAT_BROWSE |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3058 if (cmdmod.browse) |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3059 { |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3060 char_u *browse_file = do_browse(0, (char_u *)_("Error file"), eap->arg, |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3061 NULL, NULL, BROWSE_FILTER_ALL_FILES, NULL); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3062 if (browse_file == NULL) |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3063 return; |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3064 set_string_option_direct((char_u *)"ef", -1, browse_file, OPT_FREE, 0); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3065 vim_free(browse_file); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3066 } |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3067 else |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3068 #endif |
7 | 3069 if (*eap->arg != NUL) |
694 | 3070 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0); |
446 | 3071 |
3072 /* | |
3073 * This function is used by the :cfile, :cgetfile and :caddfile | |
3074 * commands. | |
3075 * :cfile always creates a new quickfix list and jumps to the | |
3076 * first error. | |
3077 * :cgetfile creates a new quickfix list but doesn't jump to the | |
3078 * first error. | |
3079 * :caddfile adds to an existing quickfix list. If there is no | |
3080 * quickfix list then a new list is created. | |
3081 */ | |
644 | 3082 if (qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3083 && eap->cmdidx != CMD_laddfile), |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3084 *eap->cmdlinep) > 0 |
644 | 3085 && (eap->cmdidx == CMD_cfile |
3086 || eap->cmdidx == CMD_lfile)) | |
665 | 3087 { |
3404 | 3088 #ifdef FEAT_AUTOCMD |
3089 if (au_name != NULL) | |
3090 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | |
3091 #endif | |
665 | 3092 if (wp != NULL) |
3093 qi = GET_LOC_LIST(wp); | |
659 | 3094 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
665 | 3095 } |
3404 | 3096 |
3097 else | |
3098 { | |
3099 #ifdef FEAT_AUTOCMD | |
3100 if (au_name != NULL) | |
3101 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | |
3102 #endif | |
3103 } | |
7 | 3104 } |
3105 | |
3106 /* | |
41 | 3107 * ":vimgrep {pattern} file(s)" |
657 | 3108 * ":vimgrepadd {pattern} file(s)" |
3109 * ":lvimgrep {pattern} file(s)" | |
3110 * ":lvimgrepadd {pattern} file(s)" | |
41 | 3111 */ |
3112 void | |
3113 ex_vimgrep(eap) | |
3114 exarg_T *eap; | |
3115 { | |
42 | 3116 regmmatch_T regmatch; |
153 | 3117 int fcount; |
41 | 3118 char_u **fnames; |
1411 | 3119 char_u *fname; |
153 | 3120 char_u *s; |
3121 char_u *p; | |
3122 int fi; | |
657 | 3123 qf_info_T *qi = &ql_info; |
4003 | 3124 #ifdef FEAT_AUTOCMD |
3125 qfline_T *cur_qf_start; | |
3126 #endif | |
230 | 3127 qfline_T *prevp = NULL; |
41 | 3128 long lnum; |
42 | 3129 buf_T *buf; |
3130 int duplicate_name = FALSE; | |
3131 int using_dummy; | |
1396 | 3132 int redraw_for_dummy = FALSE; |
42 | 3133 int found_match; |
123 | 3134 buf_T *first_match_buf = NULL; |
3135 time_t seconds = 0; | |
677 | 3136 int save_mls; |
123 | 3137 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3138 char_u *save_ei = NULL; | |
677 | 3139 #endif |
123 | 3140 aco_save_T aco; |
170 | 3141 int flags = 0; |
3142 colnr_T col; | |
716 | 3143 long tomatch; |
2770 | 3144 char_u *dirname_start = NULL; |
3145 char_u *dirname_now = NULL; | |
1411 | 3146 char_u *target_dir = NULL; |
1683 | 3147 #ifdef FEAT_AUTOCMD |
3148 char_u *au_name = NULL; | |
161 | 3149 |
3150 switch (eap->cmdidx) | |
3151 { | |
2782 | 3152 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; |
3153 case CMD_lvimgrep: au_name = (char_u *)"lvimgrep"; break; | |
3154 case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break; | |
657 | 3155 case CMD_lvimgrepadd: au_name = (char_u *)"lvimgrepadd"; break; |
2782 | 3156 case CMD_grep: au_name = (char_u *)"grep"; break; |
3157 case CMD_lgrep: au_name = (char_u *)"lgrep"; break; | |
3158 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; | |
3159 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break; | |
161 | 3160 default: break; |
3161 } | |
3162 if (au_name != NULL) | |
3163 { | |
3164 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
3165 curbuf->b_fname, TRUE, curbuf); | |
3166 if (did_throw || force_abort) | |
3167 return; | |
3168 } | |
3169 #endif | |
41 | 3170 |
661 | 3171 if (eap->cmdidx == CMD_lgrep |
659 | 3172 || eap->cmdidx == CMD_lvimgrep |
3173 || eap->cmdidx == CMD_lgrepadd | |
3174 || eap->cmdidx == CMD_lvimgrepadd) | |
657 | 3175 { |
3176 qi = ll_get_or_alloc_list(curwin); | |
3177 if (qi == NULL) | |
3178 return; | |
3179 } | |
3180 | |
716 | 3181 if (eap->addr_count > 0) |
3182 tomatch = eap->line2; | |
3183 else | |
3184 tomatch = MAXLNUM; | |
3185 | |
42 | 3186 /* Get the search pattern: either white-separated or enclosed in // */ |
41 | 3187 regmatch.regprog = NULL; |
170 | 3188 p = skip_vimgrep_pat(eap->arg, &s, &flags); |
153 | 3189 if (p == NULL) |
41 | 3190 { |
282 | 3191 EMSG(_(e_invalpat)); |
153 | 3192 goto theend; |
41 | 3193 } |
4197 | 3194 |
3195 if (s != NULL && *s == NUL) | |
3196 { | |
3197 /* Pattern is empty, use last search pattern. */ | |
3198 if (last_search_pat() == NULL) | |
3199 { | |
3200 EMSG(_(e_noprevre)); | |
3201 goto theend; | |
3202 } | |
3203 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); | |
3204 } | |
3205 else | |
3206 regmatch.regprog = vim_regcomp(s, RE_MAGIC); | |
3207 | |
41 | 3208 if (regmatch.regprog == NULL) |
3209 goto theend; | |
95 | 3210 regmatch.rmm_ic = p_ic; |
410 | 3211 regmatch.rmm_maxcol = 0; |
41 | 3212 |
3213 p = skipwhite(p); | |
3214 if (*p == NUL) | |
3215 { | |
3216 EMSG(_("E683: File name missing or invalid pattern")); | |
3217 goto theend; | |
3218 } | |
3219 | |
661 | 3220 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && |
657 | 3221 eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) |
644 | 3222 || qi->qf_curlist == qi->qf_listcount) |
41 | 3223 /* make place for a new list */ |
3965 | 3224 qf_new_list(qi, *eap->cmdlinep); |
644 | 3225 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
41 | 3226 /* Adding to existing list, find last entry. */ |
644 | 3227 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; |
41 | 3228 prevp->qf_next != prevp; prevp = prevp->qf_next) |
3229 ; | |
3230 | |
3231 /* parse the list of arguments */ | |
3620 | 3232 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL) |
41 | 3233 goto theend; |
3234 if (fcount == 0) | |
3235 { | |
3236 EMSG(_(e_nomatch)); | |
3237 goto theend; | |
3238 } | |
3239 | |
2770 | 3240 dirname_start = alloc(MAXPATHL); |
3241 dirname_now = alloc(MAXPATHL); | |
3242 if (dirname_start == NULL || dirname_now == NULL) | |
3243 goto theend; | |
3244 | |
1411 | 3245 /* Remember the current directory, because a BufRead autocommand that does |
3246 * ":lcd %:p:h" changes the meaning of short path names. */ | |
3247 mch_dirname(dirname_start, MAXPATHL); | |
3248 | |
4003 | 3249 #ifdef FEAT_AUTOCMD |
4352 | 3250 /* Remember the value of qf_start, so that we can check for autocommands |
4003 | 3251 * changing the current quickfix list. */ |
3252 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3253 #endif | |
3254 | |
123 | 3255 seconds = (time_t)0; |
716 | 3256 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) |
41 | 3257 { |
1411 | 3258 fname = shorten_fname1(fnames[fi]); |
123 | 3259 if (time(NULL) > seconds) |
3260 { | |
1411 | 3261 /* Display the file name every second or so, show the user we are |
3262 * working on it. */ | |
123 | 3263 seconds = time(NULL); |
3264 msg_start(); | |
1411 | 3265 p = msg_strtrunc(fname, TRUE); |
123 | 3266 if (p == NULL) |
1411 | 3267 msg_outtrans(fname); |
123 | 3268 else |
3269 { | |
3270 msg_outtrans(p); | |
3271 vim_free(p); | |
3272 } | |
3273 msg_clr_eos(); | |
3274 msg_didout = FALSE; /* overwrite this message */ | |
3275 msg_nowait = TRUE; /* don't wait for this message */ | |
3276 msg_col = 0; | |
3277 out_flush(); | |
3278 } | |
3279 | |
42 | 3280 buf = buflist_findname_exp(fnames[fi]); |
3281 if (buf == NULL || buf->b_ml.ml_mfp == NULL) | |
3282 { | |
3283 /* Remember that a buffer with this name already exists. */ | |
3284 duplicate_name = (buf != NULL); | |
123 | 3285 using_dummy = TRUE; |
1396 | 3286 redraw_for_dummy = TRUE; |
123 | 3287 |
3288 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
3289 /* Don't do Filetype autocommands to avoid loading syntax and | |
3290 * indent scripts, a great speed improvement. */ | |
3291 save_ei = au_event_disable(",Filetype"); | |
3292 #endif | |
677 | 3293 /* Don't use modelines here, it's useless. */ |
3294 save_mls = p_mls; | |
3295 p_mls = 0; | |
42 | 3296 |
3297 /* Load file into a buffer, so that 'fileencoding' is detected, | |
3298 * autocommands applied, etc. */ | |
3490 | 3299 buf = load_dummy_buffer(fname, dirname_start, dirname_now); |
123 | 3300 |
677 | 3301 p_mls = save_mls; |
123 | 3302 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3303 au_event_restore(save_ei); | |
3304 #endif | |
42 | 3305 } |
3306 else | |
3307 /* Use existing, loaded buffer. */ | |
3308 using_dummy = FALSE; | |
123 | 3309 |
4003 | 3310 #ifdef FEAT_AUTOCMD |
3311 if (cur_qf_start != qi->qf_lists[qi->qf_curlist].qf_start) | |
3312 { | |
3313 int idx; | |
3314 | |
3315 /* Autocommands changed the quickfix list. Find the one we were | |
3316 * using and restore it. */ | |
3317 for (idx = 0; idx < LISTCOUNT; ++idx) | |
3318 if (cur_qf_start == qi->qf_lists[idx].qf_start) | |
3319 { | |
3320 qi->qf_curlist = idx; | |
3321 break; | |
3322 } | |
3323 if (idx == LISTCOUNT) | |
3324 { | |
3325 /* List cannot be found, create a new one. */ | |
3326 qf_new_list(qi, *eap->cmdlinep); | |
3327 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3328 } | |
3329 } | |
3330 #endif | |
3331 | |
42 | 3332 if (buf == NULL) |
123 | 3333 { |
3334 if (!got_int) | |
1411 | 3335 smsg((char_u *)_("Cannot open file \"%s\""), fname); |
123 | 3336 } |
41 | 3337 else |
3338 { | |
717 | 3339 /* Try for a match in all lines of the buffer. |
3340 * For ":1vimgrep" look for first match only. */ | |
42 | 3341 found_match = FALSE; |
716 | 3342 for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0; |
3343 ++lnum) | |
41 | 3344 { |
170 | 3345 col = 0; |
3346 while (vim_regexec_multi(®match, curwin, buf, lnum, | |
1521 | 3347 col, NULL) > 0) |
41 | 3348 { |
1411 | 3349 ; |
644 | 3350 if (qf_add_entry(qi, &prevp, |
41 | 3351 NULL, /* dir */ |
1411 | 3352 fname, |
1065 | 3353 0, |
42 | 3354 ml_get_buf(buf, |
3355 regmatch.startpos[0].lnum + lnum, FALSE), | |
3356 regmatch.startpos[0].lnum + lnum, | |
3357 regmatch.startpos[0].col + 1, | |
170 | 3358 FALSE, /* vis_col */ |
230 | 3359 NULL, /* search pattern */ |
856 | 3360 0, /* nr */ |
3361 0, /* type */ | |
3362 TRUE /* valid */ | |
41 | 3363 ) == FAIL) |
3364 { | |
3365 got_int = TRUE; | |
3366 break; | |
3367 } | |
716 | 3368 found_match = TRUE; |
3369 if (--tomatch == 0) | |
3370 break; | |
170 | 3371 if ((flags & VGR_GLOBAL) == 0 |
3372 || regmatch.endpos[0].lnum > 0) | |
3373 break; | |
3374 col = regmatch.endpos[0].col | |
3375 + (col == regmatch.endpos[0].col); | |
1883 | 3376 if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE))) |
170 | 3377 break; |
41 | 3378 } |
3379 line_breakcheck(); | |
42 | 3380 if (got_int) |
3381 break; | |
41 | 3382 } |
4003 | 3383 #ifdef FEAT_AUTOCMD |
3384 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3385 #endif | |
42 | 3386 |
3387 if (using_dummy) | |
3388 { | |
123 | 3389 if (found_match && first_match_buf == NULL) |
3390 first_match_buf = buf; | |
42 | 3391 if (duplicate_name) |
123 | 3392 { |
42 | 3393 /* Never keep a dummy buffer if there is another buffer |
3394 * with the same name. */ | |
3490 | 3395 wipe_dummy_buffer(buf, dirname_start); |
123 | 3396 buf = NULL; |
3397 } | |
717 | 3398 else if (!cmdmod.hide |
3399 || buf->b_p_bh[0] == 'u' /* "unload" */ | |
3400 || buf->b_p_bh[0] == 'w' /* "wipe" */ | |
3401 || buf->b_p_bh[0] == 'd') /* "delete" */ | |
42 | 3402 { |
717 | 3403 /* When no match was found we don't need to remember the |
3404 * buffer, wipe it out. If there was a match and it | |
3405 * wasn't the first one or we won't jump there: only | |
3406 * unload the buffer. | |
3407 * Ignore 'hidden' here, because it may lead to having too | |
3408 * many swap files. */ | |
42 | 3409 if (!found_match) |
123 | 3410 { |
3490 | 3411 wipe_dummy_buffer(buf, dirname_start); |
123 | 3412 buf = NULL; |
3413 } | |
170 | 3414 else if (buf != first_match_buf || (flags & VGR_NOJUMP)) |
123 | 3415 { |
3490 | 3416 unload_dummy_buffer(buf, dirname_start); |
123 | 3417 buf = NULL; |
3418 } | |
42 | 3419 } |
123 | 3420 |
3421 if (buf != NULL) | |
3422 { | |
1411 | 3423 /* If the buffer is still loaded we need to use the |
3424 * directory we jumped to below. */ | |
3425 if (buf == first_match_buf | |
3426 && target_dir == NULL | |
3427 && STRCMP(dirname_start, dirname_now) != 0) | |
3428 target_dir = vim_strsave(dirname_now); | |
3429 | |
123 | 3430 /* The buffer is still loaded, the Filetype autocommands |
677 | 3431 * need to be done now, in that buffer. And the modelines |
717 | 3432 * need to be done (again). But not the window-local |
3433 * options! */ | |
123 | 3434 aucmd_prepbuf(&aco, buf); |
677 | 3435 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
123 | 3436 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, |
3437 buf->b_fname, TRUE, buf); | |
677 | 3438 #endif |
717 | 3439 do_modelines(OPT_NOWIN); |
123 | 3440 aucmd_restbuf(&aco); |
3441 } | |
42 | 3442 } |
41 | 3443 } |
3444 } | |
3445 | |
3446 FreeWild(fcount, fnames); | |
3447 | |
644 | 3448 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
3449 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; | |
3450 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
41 | 3451 |
3452 #ifdef FEAT_WINDOWS | |
644 | 3453 qf_update_buffer(qi); |
41 | 3454 #endif |
3455 | |
842 | 3456 #ifdef FEAT_AUTOCMD |
3457 if (au_name != NULL) | |
3458 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
3459 curbuf->b_fname, TRUE, curbuf); | |
3460 #endif | |
3461 | |
41 | 3462 /* Jump to first match. */ |
644 | 3463 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
170 | 3464 { |
3465 if ((flags & VGR_NOJUMP) == 0) | |
1396 | 3466 { |
3467 buf = curbuf; | |
659 | 3468 qf_jump(qi, 0, 0, eap->forceit); |
1396 | 3469 if (buf != curbuf) |
3470 /* If we jumped to another buffer redrawing will already be | |
3471 * taken care of. */ | |
3472 redraw_for_dummy = FALSE; | |
1411 | 3473 |
3474 /* Jump to the directory used after loading the buffer. */ | |
3475 if (curbuf == first_match_buf && target_dir != NULL) | |
3476 { | |
3477 exarg_T ea; | |
3478 | |
3479 ea.arg = target_dir; | |
3480 ea.cmdidx = CMD_lcd; | |
3481 ex_cd(&ea); | |
3482 } | |
1396 | 3483 } |
170 | 3484 } |
42 | 3485 else |
3486 EMSG2(_(e_nomatch2), s); | |
41 | 3487 |
1396 | 3488 /* If we loaded a dummy buffer into the current window, the autocommands |
3489 * may have messed up things, need to redraw and recompute folds. */ | |
3490 if (redraw_for_dummy) | |
3491 { | |
3492 #ifdef FEAT_FOLDING | |
3493 foldUpdateAll(curwin); | |
3494 #else | |
3495 redraw_later(NOT_VALID); | |
3496 #endif | |
3497 } | |
3498 | |
41 | 3499 theend: |
2770 | 3500 vim_free(dirname_now); |
3501 vim_free(dirname_start); | |
1411 | 3502 vim_free(target_dir); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
3503 vim_regfree(regmatch.regprog); |
41 | 3504 } |
3505 | |
3506 /* | |
170 | 3507 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". |
153 | 3508 * Put the start of the pattern in "*s", unless "s" is NULL. |
170 | 3509 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP. |
3510 * If "s" is not NULL terminate the pattern with a NUL. | |
3511 * Return a pointer to the char just past the pattern plus flags. | |
153 | 3512 */ |
3513 char_u * | |
170 | 3514 skip_vimgrep_pat(p, s, flags) |
3515 char_u *p; | |
3516 char_u **s; | |
3517 int *flags; | |
153 | 3518 { |
3519 int c; | |
3520 | |
3521 if (vim_isIDc(*p)) | |
3522 { | |
170 | 3523 /* ":vimgrep pattern fname" */ |
153 | 3524 if (s != NULL) |
3525 *s = p; | |
170 | 3526 p = skiptowhite(p); |
3527 if (s != NULL && *p != NUL) | |
3528 *p++ = NUL; | |
153 | 3529 } |
170 | 3530 else |
3531 { | |
3532 /* ":vimgrep /pattern/[g][j] fname" */ | |
3533 if (s != NULL) | |
3534 *s = p + 1; | |
3535 c = *p; | |
3536 p = skip_regexp(p + 1, c, TRUE, NULL); | |
3537 if (*p != c) | |
3538 return NULL; | |
3539 | |
3540 /* Truncate the pattern. */ | |
3541 if (s != NULL) | |
3542 *p = NUL; | |
3543 ++p; | |
3544 | |
3545 /* Find the flags */ | |
3546 while (*p == 'g' || *p == 'j') | |
3547 { | |
3548 if (flags != NULL) | |
3549 { | |
3550 if (*p == 'g') | |
3551 *flags |= VGR_GLOBAL; | |
3552 else | |
3553 *flags |= VGR_NOJUMP; | |
3554 } | |
3555 ++p; | |
3556 } | |
3557 } | |
153 | 3558 return p; |
3559 } | |
3560 | |
3561 /* | |
3490 | 3562 * Restore current working directory to "dirname_start" if they differ, taking |
3563 * into account whether it is set locally or globally. | |
3564 */ | |
3565 static void | |
3566 restore_start_dir(dirname_start) | |
3567 char_u *dirname_start; | |
3568 { | |
3569 char_u *dirname_now = alloc(MAXPATHL); | |
3570 | |
3571 if (NULL != dirname_now) | |
3572 { | |
3573 mch_dirname(dirname_now, MAXPATHL); | |
3574 if (STRCMP(dirname_start, dirname_now) != 0) | |
3575 { | |
3576 /* If the directory has changed, change it back by building up an | |
3577 * appropriate ex command and executing it. */ | |
3578 exarg_T ea; | |
3579 | |
3580 ea.arg = dirname_start; | |
3581 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; | |
3582 ex_cd(&ea); | |
3583 } | |
3974 | 3584 vim_free(dirname_now); |
3490 | 3585 } |
3586 } | |
3587 | |
3588 /* | |
3589 * Load file "fname" into a dummy buffer and return the buffer pointer, | |
3590 * placing the directory resulting from the buffer load into the | |
3591 * "resulting_dir" pointer. "resulting_dir" must be allocated by the caller | |
3592 * prior to calling this function. Restores directory to "dirname_start" prior | |
3593 * to returning, if autocmds or the 'autochdir' option have changed it. | |
3594 * | |
3595 * If creating the dummy buffer does not fail, must call unload_dummy_buffer() | |
3596 * or wipe_dummy_buffer() later! | |
3597 * | |
42 | 3598 * Returns NULL if it fails. |
3599 */ | |
3600 static buf_T * | |
3490 | 3601 load_dummy_buffer(fname, dirname_start, resulting_dir) |
42 | 3602 char_u *fname; |
3490 | 3603 char_u *dirname_start; /* in: old directory */ |
3604 char_u *resulting_dir; /* out: new directory */ | |
42 | 3605 { |
3606 buf_T *newbuf; | |
2646 | 3607 buf_T *newbuf_to_wipe = NULL; |
42 | 3608 int failed = TRUE; |
3609 aco_save_T aco; | |
3610 | |
3611 /* Allocate a buffer without putting it in the buffer list. */ | |
3612 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); | |
3613 if (newbuf == NULL) | |
3614 return NULL; | |
3615 | |
177 | 3616 /* Init the options. */ |
3617 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); | |
3618 | |
1918 | 3619 /* need to open the memfile before putting the buffer in a window */ |
3620 if (ml_open(newbuf) == OK) | |
42 | 3621 { |
1918 | 3622 /* set curwin/curbuf to buf and save a few things */ |
3623 aucmd_prepbuf(&aco, newbuf); | |
3624 | |
3625 /* Need to set the filename for autocommands. */ | |
3626 (void)setfname(curbuf, fname, NULL, FALSE); | |
3627 | |
42 | 3628 /* Create swap file now to avoid the ATTENTION message. */ |
3629 check_need_swap(TRUE); | |
3630 | |
3631 /* Remove the "dummy" flag, otherwise autocommands may not | |
3632 * work. */ | |
3633 curbuf->b_flags &= ~BF_DUMMY; | |
3634 | |
3635 if (readfile(fname, NULL, | |
3636 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, | |
3637 NULL, READ_NEW | READ_DUMMY) == OK | |
857 | 3638 && !got_int |
42 | 3639 && !(curbuf->b_flags & BF_NEW)) |
3640 { | |
3641 failed = FALSE; | |
3642 if (curbuf != newbuf) | |
3643 { | |
2646 | 3644 /* Bloody autocommands changed the buffer! Can happen when |
3645 * using netrw and editing a remote file. Use the current | |
3646 * buffer instead, delete the dummy one after restoring the | |
3647 * window stuff. */ | |
3648 newbuf_to_wipe = newbuf; | |
42 | 3649 newbuf = curbuf; |
3650 } | |
3651 } | |
1918 | 3652 |
3653 /* restore curwin/curbuf and a few other things */ | |
3654 aucmd_restbuf(&aco); | |
2646 | 3655 if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) |
3656 wipe_buffer(newbuf_to_wipe, FALSE); | |
42 | 3657 } |
3658 | |
3490 | 3659 /* |
3660 * When autocommands/'autochdir' option changed directory: go back. | |
3661 * Let the caller know what the resulting dir was first, in case it is | |
3662 * important. | |
3663 */ | |
3664 mch_dirname(resulting_dir, MAXPATHL); | |
3665 restore_start_dir(dirname_start); | |
3666 | |
42 | 3667 if (!buf_valid(newbuf)) |
3668 return NULL; | |
3669 if (failed) | |
3670 { | |
3490 | 3671 wipe_dummy_buffer(newbuf, dirname_start); |
42 | 3672 return NULL; |
3673 } | |
3674 return newbuf; | |
3675 } | |
3676 | |
3677 /* | |
3490 | 3678 * Wipe out the dummy buffer that load_dummy_buffer() created. Restores |
3679 * directory to "dirname_start" prior to returning, if autocmds or the | |
3680 * 'autochdir' option have changed it. | |
42 | 3681 */ |
3682 static void | |
3490 | 3683 wipe_dummy_buffer(buf, dirname_start) |
42 | 3684 buf_T *buf; |
3490 | 3685 char_u *dirname_start; |
42 | 3686 { |
3687 if (curbuf != buf) /* safety check */ | |
857 | 3688 { |
3689 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
3690 cleanup_T cs; | |
3691 | |
3692 /* Reset the error/interrupt/exception state here so that aborting() | |
3693 * returns FALSE when wiping out the buffer. Otherwise it doesn't | |
3694 * work when got_int is set. */ | |
3695 enter_cleanup(&cs); | |
3696 #endif | |
3697 | |
42 | 3698 wipe_buffer(buf, FALSE); |
857 | 3699 |
3700 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
3701 /* Restore the error/interrupt/exception state if not discarded by a | |
3702 * new aborting error, interrupt, or uncaught exception. */ | |
3703 leave_cleanup(&cs); | |
3704 #endif | |
3490 | 3705 /* When autocommands/'autochdir' option changed directory: go back. */ |
3706 restore_start_dir(dirname_start); | |
857 | 3707 } |
42 | 3708 } |
3709 | |
3710 /* | |
3490 | 3711 * Unload the dummy buffer that load_dummy_buffer() created. Restores |
3712 * directory to "dirname_start" prior to returning, if autocmds or the | |
3713 * 'autochdir' option have changed it. | |
42 | 3714 */ |
3715 static void | |
3490 | 3716 unload_dummy_buffer(buf, dirname_start) |
42 | 3717 buf_T *buf; |
3490 | 3718 char_u *dirname_start; |
42 | 3719 { |
3720 if (curbuf != buf) /* safety check */ | |
3490 | 3721 { |
3365 | 3722 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE); |
3490 | 3723 |
3724 /* When autocommands/'autochdir' option changed directory: go back. */ | |
3725 restore_start_dir(dirname_start); | |
3726 } | |
42 | 3727 } |
3728 | |
170 | 3729 #if defined(FEAT_EVAL) || defined(PROTO) |
3730 /* | |
3731 * Add each quickfix error to list "list" as a dictionary. | |
3732 */ | |
3733 int | |
647 | 3734 get_errorlist(wp, list) |
3735 win_T *wp; | |
170 | 3736 list_T *list; |
3737 { | |
644 | 3738 qf_info_T *qi = &ql_info; |
230 | 3739 dict_T *dict; |
3740 char_u buf[2]; | |
3741 qfline_T *qfp; | |
3742 int i; | |
1065 | 3743 int bufnum; |
170 | 3744 |
647 | 3745 if (wp != NULL) |
3746 { | |
3747 qi = GET_LOC_LIST(wp); | |
3748 if (qi == NULL) | |
3749 return FAIL; | |
3750 } | |
3751 | |
644 | 3752 if (qi->qf_curlist >= qi->qf_listcount |
712 | 3753 || qi->qf_lists[qi->qf_curlist].qf_count == 0) |
170 | 3754 return FAIL; |
3755 | |
644 | 3756 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
3757 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i) | |
170 | 3758 { |
1065 | 3759 /* Handle entries with a non-existing buffer number. */ |
3760 bufnum = qfp->qf_fnum; | |
3761 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
3762 bufnum = 0; | |
3763 | |
170 | 3764 if ((dict = dict_alloc()) == NULL) |
3765 return FAIL; | |
3766 if (list_append_dict(list, dict) == FAIL) | |
3767 return FAIL; | |
3768 | |
3769 buf[0] = qfp->qf_type; | |
3770 buf[1] = NUL; | |
1065 | 3771 if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL |
170 | 3772 || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL |
3773 || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL | |
3774 || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL | |
3775 || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL | |
960 | 3776 || dict_add_nr_str(dict, "pattern", 0L, |
3777 qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL | |
3778 || dict_add_nr_str(dict, "text", 0L, | |
3779 qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL | |
170 | 3780 || dict_add_nr_str(dict, "type", 0L, buf) == FAIL |
3781 || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL) | |
3782 return FAIL; | |
3783 | |
3784 qfp = qfp->qf_next; | |
3785 } | |
3786 return OK; | |
3787 } | |
230 | 3788 |
3789 /* | |
3790 * Populate the quickfix list with the items supplied in the list | |
2530
9fe4164cb586
Fix: :ltag command did not set w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2416
diff
changeset
|
3791 * of dictionaries. "title" will be copied to w:quickfix_title |
230 | 3792 */ |
3793 int | |
2530
9fe4164cb586
Fix: :ltag command did not set w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2416
diff
changeset
|
3794 set_errorlist(wp, list, action, title) |
647 | 3795 win_T *wp; |
230 | 3796 list_T *list; |
277 | 3797 int action; |
2530
9fe4164cb586
Fix: :ltag command did not set w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2416
diff
changeset
|
3798 char_u *title; |
230 | 3799 { |
3800 listitem_T *li; | |
3801 dict_T *d; | |
3802 char_u *filename, *pattern, *text, *type; | |
1065 | 3803 int bufnum; |
230 | 3804 long lnum; |
3805 int col, nr; | |
3806 int vcol; | |
3807 qfline_T *prevp = NULL; | |
3808 int valid, status; | |
3809 int retval = OK; | |
644 | 3810 qf_info_T *qi = &ql_info; |
1065 | 3811 int did_bufnr_emsg = FALSE; |
644 | 3812 |
647 | 3813 if (wp != NULL) |
3814 { | |
648 | 3815 qi = ll_get_or_alloc_list(wp); |
647 | 3816 if (qi == NULL) |
3817 return FAIL; | |
3818 } | |
3819 | |
644 | 3820 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) |
277 | 3821 /* make place for a new list */ |
3965 | 3822 qf_new_list(qi, title); |
644 | 3823 else if (action == 'a' && qi->qf_lists[qi->qf_curlist].qf_count > 0) |
277 | 3824 /* Adding to existing list, find last entry. */ |
644 | 3825 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; |
277 | 3826 prevp->qf_next != prevp; prevp = prevp->qf_next) |
3827 ; | |
3828 else if (action == 'r') | |
644 | 3829 qf_free(qi, qi->qf_curlist); |
230 | 3830 |
3831 for (li = list->lv_first; li != NULL; li = li->li_next) | |
3832 { | |
3833 if (li->li_tv.v_type != VAR_DICT) | |
3834 continue; /* Skip non-dict items */ | |
3835 | |
3836 d = li->li_tv.vval.v_dict; | |
3837 if (d == NULL) | |
3838 continue; | |
3839 | |
659 | 3840 filename = get_dict_string(d, (char_u *)"filename", TRUE); |
1065 | 3841 bufnum = get_dict_number(d, (char_u *)"bufnr"); |
230 | 3842 lnum = get_dict_number(d, (char_u *)"lnum"); |
3843 col = get_dict_number(d, (char_u *)"col"); | |
3844 vcol = get_dict_number(d, (char_u *)"vcol"); | |
3845 nr = get_dict_number(d, (char_u *)"nr"); | |
659 | 3846 type = get_dict_string(d, (char_u *)"type", TRUE); |
3847 pattern = get_dict_string(d, (char_u *)"pattern", TRUE); | |
3848 text = get_dict_string(d, (char_u *)"text", TRUE); | |
230 | 3849 if (text == NULL) |
3850 text = vim_strsave((char_u *)""); | |
3851 | |
3852 valid = TRUE; | |
1065 | 3853 if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) |
230 | 3854 valid = FALSE; |
3855 | |
1065 | 3856 /* Mark entries with non-existing buffer number as not valid. Give the |
3857 * error message only once. */ | |
3858 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
3859 { | |
3860 if (!did_bufnr_emsg) | |
3861 { | |
3862 did_bufnr_emsg = TRUE; | |
3863 EMSGN(_("E92: Buffer %ld not found"), bufnum); | |
3864 } | |
3865 valid = FALSE; | |
3866 bufnum = 0; | |
3867 } | |
3868 | |
644 | 3869 status = qf_add_entry(qi, &prevp, |
230 | 3870 NULL, /* dir */ |
3871 filename, | |
1065 | 3872 bufnum, |
230 | 3873 text, |
3874 lnum, | |
3875 col, | |
3876 vcol, /* vis_col */ | |
3877 pattern, /* search pattern */ | |
3878 nr, | |
3879 type == NULL ? NUL : *type, | |
3880 valid); | |
3881 | |
3882 vim_free(filename); | |
3883 vim_free(pattern); | |
3884 vim_free(text); | |
3885 vim_free(type); | |
3886 | |
3887 if (status == FAIL) | |
3888 { | |
3889 retval = FAIL; | |
3890 break; | |
3891 } | |
3892 } | |
3893 | |
2146
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3894 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) |
2795 | 3895 /* no valid entry */ |
2146
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3896 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; |
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3897 else |
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3898 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
644 | 3899 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; |
3900 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
230 | 3901 |
3902 #ifdef FEAT_WINDOWS | |
644 | 3903 qf_update_buffer(qi); |
230 | 3904 #endif |
3905 | |
3906 return retval; | |
3907 } | |
170 | 3908 #endif |
3909 | |
42 | 3910 /* |
41 | 3911 * ":[range]cbuffer [bufnr]" command. |
657 | 3912 * ":[range]caddbuffer [bufnr]" command. |
798 | 3913 * ":[range]cgetbuffer [bufnr]" command. |
644 | 3914 * ":[range]lbuffer [bufnr]" command. |
657 | 3915 * ":[range]laddbuffer [bufnr]" command. |
798 | 3916 * ":[range]lgetbuffer [bufnr]" command. |
41 | 3917 */ |
3918 void | |
3919 ex_cbuffer(eap) | |
3920 exarg_T *eap; | |
3921 { | |
3922 buf_T *buf = NULL; | |
644 | 3923 qf_info_T *qi = &ql_info; |
3924 | |
798 | 3925 if (eap->cmdidx == CMD_lbuffer || eap->cmdidx == CMD_lgetbuffer |
3926 || eap->cmdidx == CMD_laddbuffer) | |
644 | 3927 { |
3928 qi = ll_get_or_alloc_list(curwin); | |
3929 if (qi == NULL) | |
3930 return; | |
3931 } | |
41 | 3932 |
3933 if (*eap->arg == NUL) | |
3934 buf = curbuf; | |
3935 else if (*skipwhite(skipdigits(eap->arg)) == NUL) | |
3936 buf = buflist_findnr(atoi((char *)eap->arg)); | |
3937 if (buf == NULL) | |
3938 EMSG(_(e_invarg)); | |
3939 else if (buf->b_ml.ml_mfp == NULL) | |
3940 EMSG(_("E681: Buffer is not loaded")); | |
3941 else | |
3942 { | |
3943 if (eap->addr_count == 0) | |
3944 { | |
3945 eap->line1 = 1; | |
3946 eap->line2 = buf->b_ml.ml_line_count; | |
3947 } | |
3948 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count | |
3949 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) | |
3950 EMSG(_(e_invrange)); | |
3951 else | |
661 | 3952 { |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3953 char_u *qf_title = *eap->cmdlinep; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3954 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3955 if (buf->b_sfname) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3956 { |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3957 vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)", |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3958 (char *)qf_title, (char *)buf->b_sfname); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3959 qf_title = IObuff; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3960 } |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3961 |
798 | 3962 if (qf_init_ext(qi, NULL, buf, NULL, p_efm, |
3963 (eap->cmdidx != CMD_caddbuffer | |
3964 && eap->cmdidx != CMD_laddbuffer), | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3965 eap->line1, eap->line2, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3966 qf_title) > 0 |
798 | 3967 && (eap->cmdidx == CMD_cbuffer |
3968 || eap->cmdidx == CMD_lbuffer)) | |
661 | 3969 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
3970 } | |
41 | 3971 } |
3972 } | |
3973 | |
532 | 3974 #if defined(FEAT_EVAL) || defined(PROTO) |
41 | 3975 /* |
798 | 3976 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command. |
3977 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command. | |
446 | 3978 */ |
3979 void | |
3980 ex_cexpr(eap) | |
3981 exarg_T *eap; | |
3982 { | |
3983 typval_T *tv; | |
644 | 3984 qf_info_T *qi = &ql_info; |
3985 | |
798 | 3986 if (eap->cmdidx == CMD_lexpr || eap->cmdidx == CMD_lgetexpr |
3987 || eap->cmdidx == CMD_laddexpr) | |
644 | 3988 { |
3989 qi = ll_get_or_alloc_list(curwin); | |
3990 if (qi == NULL) | |
3991 return; | |
3992 } | |
446 | 3993 |
625 | 3994 /* Evaluate the expression. When the result is a string or a list we can |
3995 * use it to fill the errorlist. */ | |
446 | 3996 tv = eval_expr(eap->arg, NULL); |
625 | 3997 if (tv != NULL) |
3998 { | |
3999 if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL) | |
4000 || (tv->v_type == VAR_LIST && tv->vval.v_list != NULL)) | |
4001 { | |
798 | 4002 if (qf_init_ext(qi, NULL, NULL, tv, p_efm, |
4003 (eap->cmdidx != CMD_caddexpr | |
4004 && eap->cmdidx != CMD_laddexpr), | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4005 (linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0 |
798 | 4006 && (eap->cmdidx == CMD_cexpr |
4007 || eap->cmdidx == CMD_lexpr)) | |
659 | 4008 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
625 | 4009 } |
4010 else | |
626 | 4011 EMSG(_("E777: String or List expected")); |
625 | 4012 free_tv(tv); |
4013 } | |
446 | 4014 } |
532 | 4015 #endif |
446 | 4016 |
4017 /* | |
7 | 4018 * ":helpgrep {pattern}" |
4019 */ | |
4020 void | |
4021 ex_helpgrep(eap) | |
4022 exarg_T *eap; | |
4023 { | |
4024 regmatch_T regmatch; | |
4025 char_u *save_cpo; | |
4026 char_u *p; | |
4027 int fcount; | |
4028 char_u **fnames; | |
4029 FILE *fd; | |
4030 int fi; | |
230 | 4031 qfline_T *prevp = NULL; |
7 | 4032 long lnum; |
9 | 4033 #ifdef FEAT_MULTI_LANG |
4034 char_u *lang; | |
4035 #endif | |
644 | 4036 qf_info_T *qi = &ql_info; |
659 | 4037 int new_qi = FALSE; |
4038 win_T *wp; | |
3269 | 4039 #ifdef FEAT_AUTOCMD |
4040 char_u *au_name = NULL; | |
4041 #endif | |
7 | 4042 |
9 | 4043 #ifdef FEAT_MULTI_LANG |
4044 /* Check for a specified language */ | |
4045 lang = check_help_lang(eap->arg); | |
4046 #endif | |
4047 | |
3269 | 4048 #ifdef FEAT_AUTOCMD |
4049 switch (eap->cmdidx) | |
4050 { | |
4051 case CMD_helpgrep: au_name = (char_u *)"helpgrep"; break; | |
4052 case CMD_lhelpgrep: au_name = (char_u *)"lhelpgrep"; break; | |
4053 default: break; | |
4054 } | |
4055 if (au_name != NULL) | |
4056 { | |
4057 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
4058 curbuf->b_fname, TRUE, curbuf); | |
4059 if (did_throw || force_abort) | |
4060 return; | |
4061 } | |
4062 #endif | |
4063 | |
4064 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | |
4065 save_cpo = p_cpo; | |
4066 p_cpo = empty_option; | |
4067 | |
659 | 4068 if (eap->cmdidx == CMD_lhelpgrep) |
4069 { | |
4070 /* Find an existing help window */ | |
4071 FOR_ALL_WINDOWS(wp) | |
4072 if (wp->w_buffer != NULL && wp->w_buffer->b_help) | |
4073 break; | |
4074 | |
4075 if (wp == NULL) /* Help window not found */ | |
4076 qi = NULL; | |
4077 else | |
4078 qi = wp->w_llist; | |
4079 | |
4080 if (qi == NULL) | |
4081 { | |
4082 /* Allocate a new location list for help text matches */ | |
4083 if ((qi = ll_new_list()) == NULL) | |
4084 return; | |
4085 new_qi = TRUE; | |
4086 } | |
4087 } | |
4088 | |
7 | 4089 regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING); |
4090 regmatch.rm_ic = FALSE; | |
4091 if (regmatch.regprog != NULL) | |
4092 { | |
3257 | 4093 #ifdef FEAT_MBYTE |
4094 vimconv_T vc; | |
4095 | |
4096 /* Help files are in utf-8 or latin1, convert lines when 'encoding' | |
4097 * differs. */ | |
4098 vc.vc_type = CONV_NONE; | |
4099 if (!enc_utf8) | |
4100 convert_setup(&vc, (char_u *)"utf-8", p_enc); | |
4101 #endif | |
4102 | |
7 | 4103 /* create a new quickfix list */ |
3965 | 4104 qf_new_list(qi, *eap->cmdlinep); |
7 | 4105 |
4106 /* Go through all directories in 'runtimepath' */ | |
4107 p = p_rtp; | |
4108 while (*p != NUL && !got_int) | |
4109 { | |
4110 copy_option_part(&p, NameBuff, MAXPATHL, ","); | |
4111 | |
4112 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */ | |
4113 add_pathsep(NameBuff); | |
4114 STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)"); | |
4115 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
4116 &fnames, EW_FILE|EW_SILENT) == OK | |
4117 && fcount > 0) | |
4118 { | |
4119 for (fi = 0; fi < fcount && !got_int; ++fi) | |
4120 { | |
9 | 4121 #ifdef FEAT_MULTI_LANG |
4122 /* Skip files for a different language. */ | |
4123 if (lang != NULL | |
4124 && STRNICMP(lang, fnames[fi] | |
4125 + STRLEN(fnames[fi]) - 3, 2) != 0 | |
4126 && !(STRNICMP(lang, "en", 2) == 0 | |
4127 && STRNICMP("txt", fnames[fi] | |
4128 + STRLEN(fnames[fi]) - 3, 3) == 0)) | |
4129 continue; | |
4130 #endif | |
531 | 4131 fd = mch_fopen((char *)fnames[fi], "r"); |
7 | 4132 if (fd != NULL) |
4133 { | |
4134 lnum = 1; | |
4135 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
4136 { | |
3257 | 4137 char_u *line = IObuff; |
4138 #ifdef FEAT_MBYTE | |
4139 /* Convert a line if 'encoding' is not utf-8 and | |
4140 * the line contains a non-ASCII character. */ | |
4141 if (vc.vc_type != CONV_NONE | |
4142 && has_non_ascii(IObuff)) { | |
4143 line = string_convert(&vc, IObuff, NULL); | |
4144 if (line == NULL) | |
4145 line = IObuff; | |
4146 } | |
4147 #endif | |
4148 | |
4149 if (vim_regexec(®match, line, (colnr_T)0)) | |
7 | 4150 { |
3257 | 4151 int l = (int)STRLEN(line); |
7 | 4152 |
4153 /* remove trailing CR, LF, spaces, etc. */ | |
3257 | 4154 while (l > 0 && line[l - 1] <= ' ') |
4155 line[--l] = NUL; | |
7 | 4156 |
644 | 4157 if (qf_add_entry(qi, &prevp, |
7 | 4158 NULL, /* dir */ |
4159 fnames[fi], | |
1065 | 4160 0, |
3257 | 4161 line, |
7 | 4162 lnum, |
3257 | 4163 (int)(regmatch.startp[0] - line) |
42 | 4164 + 1, /* col */ |
170 | 4165 FALSE, /* vis_col */ |
230 | 4166 NULL, /* search pattern */ |
7 | 4167 0, /* nr */ |
4168 1, /* type */ | |
4169 TRUE /* valid */ | |
4170 ) == FAIL) | |
4171 { | |
4172 got_int = TRUE; | |
3257 | 4173 #ifdef FEAT_MBYTE |
4174 if (line != IObuff) | |
4175 vim_free(line); | |
4176 #endif | |
7 | 4177 break; |
4178 } | |
4179 } | |
3257 | 4180 #ifdef FEAT_MBYTE |
4181 if (line != IObuff) | |
4182 vim_free(line); | |
4183 #endif | |
7 | 4184 ++lnum; |
4185 line_breakcheck(); | |
4186 } | |
4187 fclose(fd); | |
4188 } | |
4189 } | |
4190 FreeWild(fcount, fnames); | |
4191 } | |
4192 } | |
3257 | 4193 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
4194 vim_regfree(regmatch.regprog); |
3257 | 4195 #ifdef FEAT_MBYTE |
4196 if (vc.vc_type != CONV_NONE) | |
4197 convert_setup(&vc, NULL, NULL); | |
4198 #endif | |
7 | 4199 |
644 | 4200 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
4201 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
4202 qi->qf_lists[qi->qf_curlist].qf_start; | |
4203 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
7 | 4204 } |
4205 | |
1672 | 4206 if (p_cpo == empty_option) |
4207 p_cpo = save_cpo; | |
4208 else | |
4209 /* Darn, some plugin changed the value. */ | |
4210 free_string_option(save_cpo); | |
7 | 4211 |
4212 #ifdef FEAT_WINDOWS | |
644 | 4213 qf_update_buffer(qi); |
7 | 4214 #endif |
4215 | |
3269 | 4216 #ifdef FEAT_AUTOCMD |
4217 if (au_name != NULL) | |
4218 { | |
4219 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
4220 curbuf->b_fname, TRUE, curbuf); | |
4221 if (!new_qi && qi != &ql_info && qf_find_buf(qi) == NULL) | |
4222 /* autocommands made "qi" invalid */ | |
4223 return; | |
4224 } | |
4225 #endif | |
4226 | |
7 | 4227 /* Jump to first match. */ |
644 | 4228 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
659 | 4229 qf_jump(qi, 0, 0, FALSE); |
9 | 4230 else |
4231 EMSG2(_(e_nomatch2), eap->arg); | |
659 | 4232 |
4233 if (eap->cmdidx == CMD_lhelpgrep) | |
4234 { | |
4235 /* If the help window is not opened or if it already points to the | |
661 | 4236 * correct location list, then free the new location list. */ |
659 | 4237 if (!curwin->w_buffer->b_help || curwin->w_llist == qi) |
4238 { | |
4239 if (new_qi) | |
4240 ll_free_all(&qi); | |
4241 } | |
4242 else if (curwin->w_llist == NULL) | |
4243 curwin->w_llist = qi; | |
4244 } | |
7 | 4245 } |
4246 | |
4247 #endif /* FEAT_QUICKFIX */ |