blob: d465787017bac49de39895df4fd7b0d046fa1fe5 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* 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
18struct dir_stack_T
19{
20 struct dir_stack_T *next;
21 char_u *dirname;
22};
23
24static struct dir_stack_T *dir_stack = NULL;
25
26/*
Bram Moolenaar68b76a62005-03-25 21:53:48 +000027 * For each error the next struct is allocated and linked in a list.
Bram Moolenaar071d4272004-06-13 20:20:40 +000028 */
Bram Moolenaar68b76a62005-03-25 21:53:48 +000029typedef struct qfline_S qfline_T;
30struct qfline_S
Bram Moolenaar071d4272004-06-13 20:20:40 +000031{
Bram Moolenaar68b76a62005-03-25 21:53:48 +000032 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 :helpgrep */
Bram Moolenaar68b76a62005-03-25 21:53:48 +000044 char_u qf_valid; /* valid error message detected */
Bram Moolenaar071d4272004-06-13 20:20:40 +000045};
46
47/*
48 * There is a stack of error lists.
49 */
50#define LISTCOUNT 10
51
Bram Moolenaard6f676d2005-06-01 21:51:55 +000052static struct qf_list
Bram Moolenaar071d4272004-06-13 20:20:40 +000053{
Bram Moolenaar68b76a62005-03-25 21:53:48 +000054 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 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000059} qf_lists[LISTCOUNT];
60
61static int qf_curlist = 0; /* current error list */
62static int qf_listcount = 0; /* current number of lists */
63
Bram Moolenaar68b76a62005-03-25 21:53:48 +000064#define FMT_PATTERNS 10 /* maximum number of % recognized */
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
66/*
67 * Structure used to hold the info of one part of 'errorformat'
68 */
69struct eformat
70{
71 regprog_T *prog; /* pre-formatted part of 'errorformat' */
72 struct eformat *next; /* pointer to next (NULL if last) */
73 char_u addr[FMT_PATTERNS]; /* indices of used % patterns */
74 char_u prefix; /* prefix of this format line: */
75 /* 'D' enter directory */
76 /* 'X' leave directory */
77 /* 'A' start of multi-line message */
78 /* 'E' error message */
79 /* 'W' warning message */
80 /* 'I' informational message */
81 /* 'C' continuation line */
82 /* 'Z' end of multi-line message */
83 /* 'G' general, unspecific message */
84 /* 'P' push file (partial) message */
85 /* 'Q' pop/quit file (partial) message */
86 /* 'O' overread (partial) message */
87 char_u flags; /* additional flags given in prefix */
88 /* '-' do not include this line */
89};
90
Bram Moolenaar86b68352004-12-27 21:59:20 +000091static int qf_init_ext __ARGS((char_u *efile, buf_T *buf, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast));
Bram Moolenaar071d4272004-06-13 20:20:40 +000092static void qf_new_list __ARGS((void));
Bram Moolenaar68b76a62005-03-25 21:53:48 +000093static int qf_add_entry __ARGS((qfline_T **prevp, char_u *dir, char_u *fname, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid));
Bram Moolenaar071d4272004-06-13 20:20:40 +000094static void qf_msg __ARGS((void));
95static void qf_free __ARGS((int idx));
96static char_u *qf_types __ARGS((int, int));
97static int qf_get_fnum __ARGS((char_u *, char_u *));
98static char_u *qf_push_dir __ARGS((char_u *, struct dir_stack_T **));
99static char_u *qf_pop_dir __ARGS((struct dir_stack_T **));
100static char_u *qf_guess_filepath __ARGS((char_u *));
101static void qf_fmt_text __ARGS((char_u *text, char_u *buf, int bufsize));
102static void qf_clean_dir_stack __ARGS((struct dir_stack_T **));
103#ifdef FEAT_WINDOWS
104static int qf_win_pos_update __ARGS((int old_qf_index));
105static buf_T *qf_find_buf __ARGS((void));
106static void qf_update_buffer __ARGS((void));
107static void qf_fill_buffer __ARGS((void));
108#endif
109static char_u *get_mef_name __ARGS((void));
Bram Moolenaar81695252004-12-29 20:58:21 +0000110static buf_T *load_dummy_buffer __ARGS((char_u *fname));
111static void wipe_dummy_buffer __ARGS((buf_T *buf));
112static void unload_dummy_buffer __ARGS((buf_T *buf));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
114/*
Bram Moolenaar86b68352004-12-27 21:59:20 +0000115 * Read the errorfile "efile" into memory, line by line, building the error
116 * list.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117 * Return -1 for error, number of errors for success.
118 */
119 int
120qf_init(efile, errorformat, newlist)
121 char_u *efile;
122 char_u *errorformat;
123 int newlist; /* TRUE: start a new error list */
124{
Bram Moolenaar86b68352004-12-27 21:59:20 +0000125 if (efile == NULL)
126 return FAIL;
127 return qf_init_ext(efile, curbuf, errorformat, newlist,
128 (linenr_T)0, (linenr_T)0);
129}
130
131/*
132 * Read the errorfile "efile" into memory, line by line, building the error
133 * list.
134 * Alternative: when "efile" is null read errors from buffer "buf".
135 * Always use 'errorformat' from "buf" if there is a local value.
136 * Then lnumfirst and lnumlast specify the range of lines to use.
137 * Return -1 for error, number of errors for success.
138 */
139 static int
140qf_init_ext(efile, buf, errorformat, newlist, lnumfirst, lnumlast)
141 char_u *efile;
142 buf_T *buf;
143 char_u *errorformat;
144 int newlist; /* TRUE: start a new error list */
145 linenr_T lnumfirst; /* first line number to use */
146 linenr_T lnumlast; /* last line number to use */
147{
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148 char_u *namebuf;
149 char_u *errmsg;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000150 char_u *pattern;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151 char_u *fmtstr = NULL;
152 int col = 0;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000153 char_u use_viscol = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154 int type = 0;
155 int valid;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000156 linenr_T buflnum = lnumfirst;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157 long lnum = 0L;
158 int enr = 0;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000159 FILE *fd = NULL;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000160 qfline_T *qfprev = NULL; /* init to make SASC shut up */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161 char_u *efmp;
162 struct eformat *fmt_first = NULL;
163 struct eformat *fmt_last = NULL;
164 struct eformat *fmt_ptr;
165 char_u *efm;
166 char_u *ptr;
167 char_u *srcptr;
168 int len;
169 int i;
170 int round;
171 int idx = 0;
172 int multiline = FALSE;
173 int multiignore = FALSE;
174 int multiscan = FALSE;
175 int retval = -1; /* default: return error flag */
176 char_u *directory = NULL;
177 char_u *currfile = NULL;
178 char_u *tail = NULL;
179 struct dir_stack_T *file_stack = NULL;
180 regmatch_T regmatch;
181 static struct fmtpattern
182 {
183 char_u convchar;
184 char *pattern;
185 } fmt_pat[FMT_PATTERNS] =
186 {
187 {'f', "\\f\\+"},
188 {'n', "\\d\\+"},
189 {'l', "\\d\\+"},
190 {'c', "\\d\\+"},
191 {'t', "."},
192 {'m', ".\\+"},
193 {'r', ".*"},
194 {'p', "[- .]*"},
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000195 {'v', "\\d\\+"},
196 {'s', ".\\+"}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197 };
198
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199 namebuf = alloc(CMDBUFFSIZE + 1);
200 errmsg = alloc(CMDBUFFSIZE + 1);
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000201 pattern = alloc(CMDBUFFSIZE + 1);
202 if (namebuf == NULL || errmsg == NULL || pattern == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203 goto qf_init_end;
204
Bram Moolenaar86b68352004-12-27 21:59:20 +0000205 if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206 {
207 EMSG2(_(e_openerrf), efile);
208 goto qf_init_end;
209 }
210
211 if (newlist || qf_curlist == qf_listcount)
212 /* make place for a new list */
213 qf_new_list();
214 else if (qf_lists[qf_curlist].qf_count > 0)
215 /* Adding to existing list, find last entry. */
216 for (qfprev = qf_lists[qf_curlist].qf_start;
217 qfprev->qf_next != qfprev; qfprev = qfprev->qf_next)
218 ;
219
220/*
221 * Each part of the format string is copied and modified from errorformat to
222 * regex prog. Only a few % characters are allowed.
223 */
224 /* Use the local value of 'errorformat' if it's set. */
Bram Moolenaar86b68352004-12-27 21:59:20 +0000225 if (errorformat == p_efm && *buf->b_p_efm != NUL)
226 efm = buf->b_p_efm;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227 else
228 efm = errorformat;
229 /*
230 * Get some space to modify the format string into.
231 */
232 i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2);
233 for (round = FMT_PATTERNS; round > 0; )
234 i += (int)STRLEN(fmt_pat[--round].pattern);
235#ifdef COLON_IN_FILENAME
236 i += 12; /* "%f" can become twelve chars longer */
237#else
238 i += 2; /* "%f" can become two chars longer */
239#endif
240 if ((fmtstr = alloc(i)) == NULL)
241 goto error2;
242
243 while (efm[0])
244 {
245 /*
246 * Allocate a new eformat structure and put it at the end of the list
247 */
248 fmt_ptr = (struct eformat *)alloc((unsigned)sizeof(struct eformat));
249 if (fmt_ptr == NULL)
250 goto error2;
251 if (fmt_first == NULL) /* first one */
252 fmt_first = fmt_ptr;
253 else
254 fmt_last->next = fmt_ptr;
255 fmt_last = fmt_ptr;
256 fmt_ptr->prefix = NUL;
257 fmt_ptr->flags = NUL;
258 fmt_ptr->next = NULL;
259 fmt_ptr->prog = NULL;
260 for (round = FMT_PATTERNS; round > 0; )
261 fmt_ptr->addr[--round] = NUL;
262 /* round is 0 now */
263
264 /*
265 * Isolate one part in the 'errorformat' option
266 */
267 for (len = 0; efm[len] != NUL && efm[len] != ','; ++len)
268 if (efm[len] == '\\' && efm[len + 1] != NUL)
269 ++len;
270
271 /*
272 * Build regexp pattern from current 'errorformat' option
273 */
274 ptr = fmtstr;
275 *ptr++ = '^';
276 for (efmp = efm; efmp < efm + len; ++efmp)
277 {
278 if (*efmp == '%')
279 {
280 ++efmp;
281 for (idx = 0; idx < FMT_PATTERNS; ++idx)
282 if (fmt_pat[idx].convchar == *efmp)
283 break;
284 if (idx < FMT_PATTERNS)
285 {
286 if (fmt_ptr->addr[idx])
287 {
288 sprintf((char *)errmsg,
289 _("E372: Too many %%%c in format string"), *efmp);
290 EMSG(errmsg);
291 goto error2;
292 }
293 if ((idx
294 && idx < 6
295 && vim_strchr((char_u *)"DXOPQ",
296 fmt_ptr->prefix) != NULL)
297 || (idx == 6
298 && vim_strchr((char_u *)"OPQ",
299 fmt_ptr->prefix) == NULL))
300 {
301 sprintf((char *)errmsg,
302 _("E373: Unexpected %%%c in format string"), *efmp);
303 EMSG(errmsg);
304 goto error2;
305 }
306 fmt_ptr->addr[idx] = (char_u)++round;
307 *ptr++ = '\\';
308 *ptr++ = '(';
309#ifdef BACKSLASH_IN_FILENAME
310 if (*efmp == 'f')
311 {
312 /* Also match "c:" in the file name, even when
313 * checking for a colon next: "%f:".
314 * "\%(\a:\)\=" */
315 STRCPY(ptr, "\\%(\\a:\\)\\=");
316 ptr += 10;
317 }
318#endif
319 if (*efmp == 'f' && efmp[1] != NUL
320 && efmp[1] != '\\' && efmp[1] != '%')
321 {
322 /* A file name may contain spaces, but this isn't in
323 * "\f". use "[^x]\+" instead (x is next character) */
324 *ptr++ = '[';
325 *ptr++ = '^';
326 *ptr++ = efmp[1];
327 *ptr++ = ']';
328 *ptr++ = '\\';
329 *ptr++ = '+';
330 }
331 else
332 {
333 srcptr = (char_u *)fmt_pat[idx].pattern;
334 while ((*ptr = *srcptr++) != NUL)
335 ++ptr;
336 }
337 *ptr++ = '\\';
338 *ptr++ = ')';
339 }
340 else if (*efmp == '*')
341 {
342 if (*++efmp == '[' || *efmp == '\\')
343 {
344 if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */
345 {
346 if (efmp[1] == '^')
347 *ptr++ = *++efmp;
348 if (efmp < efm + len)
349 {
350 *ptr++ = *++efmp; /* could be ']' */
351 while (efmp < efm + len
352 && (*ptr++ = *++efmp) != ']')
353 /* skip */;
354 if (efmp == efm + len)
355 {
356 EMSG(_("E374: Missing ] in format string"));
357 goto error2;
358 }
359 }
360 }
361 else if (efmp < efm + len) /* %*\D, %*\s etc. */
362 *ptr++ = *++efmp;
363 *ptr++ = '\\';
364 *ptr++ = '+';
365 }
366 else
367 {
368 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */
369 sprintf((char *)errmsg,
370 _("E375: Unsupported %%%c in format string"), *efmp);
371 EMSG(errmsg);
372 goto error2;
373 }
374 }
375 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
376 *ptr++ = *efmp; /* regexp magic characters */
377 else if (*efmp == '#')
378 *ptr++ = '*';
379 else if (efmp == efm + 1) /* analyse prefix */
380 {
381 if (vim_strchr((char_u *)"+-", *efmp) != NULL)
382 fmt_ptr->flags = *efmp++;
383 if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL)
384 fmt_ptr->prefix = *efmp;
385 else
386 {
387 sprintf((char *)errmsg,
388 _("E376: Invalid %%%c in format string prefix"), *efmp);
389 EMSG(errmsg);
390 goto error2;
391 }
392 }
393 else
394 {
395 sprintf((char *)errmsg,
396 _("E377: Invalid %%%c in format string"), *efmp);
397 EMSG(errmsg);
398 goto error2;
399 }
400 }
401 else /* copy normal character */
402 {
403 if (*efmp == '\\' && efmp + 1 < efm + len)
404 ++efmp;
405 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL)
406 *ptr++ = '\\'; /* escape regexp atoms */
407 if (*efmp)
408 *ptr++ = *efmp;
409 }
410 }
411 *ptr++ = '$';
412 *ptr = NUL;
413 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL)
414 goto error2;
415 /*
416 * Advance to next part
417 */
418 efm = skip_to_option_part(efm + len); /* skip comma and spaces */
419 }
420 if (fmt_first == NULL) /* nothing found */
421 {
422 EMSG(_("E378: 'errorformat' contains no pattern"));
423 goto error2;
424 }
425
426 /*
427 * got_int is reset here, because it was probably set when killing the
428 * ":make" command, but we still want to read the errorfile then.
429 */
430 got_int = FALSE;
431
432 /* Always ignore case when looking for a matching error. */
433 regmatch.rm_ic = TRUE;
434
435 /*
436 * Read the lines in the error file one by one.
437 * Try to recognize one of the error formats in each line.
438 */
Bram Moolenaar86b68352004-12-27 21:59:20 +0000439 while (!got_int)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 {
Bram Moolenaar86b68352004-12-27 21:59:20 +0000441 /* Get the next line. */
442 if (fd == NULL)
443 {
444 if (buflnum > lnumlast)
445 break;
Bram Moolenaarbbebc852005-07-18 21:47:53 +0000446 vim_strncpy(IObuff, ml_get_buf(buf, buflnum++, FALSE),
447 CMDBUFFSIZE - 2);
Bram Moolenaar86b68352004-12-27 21:59:20 +0000448 }
449 else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL)
450 break;
451
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452 IObuff[CMDBUFFSIZE - 2] = NUL; /* for very long lines */
453 if ((efmp = vim_strrchr(IObuff, '\n')) != NULL)
454 *efmp = NUL;
455#ifdef USE_CRNL
456 if ((efmp = vim_strrchr(IObuff, '\r')) != NULL)
457 *efmp = NUL;
458#endif
459
460 /*
461 * Try to match each part of 'errorformat' until we find a complete
462 * match or no match.
463 */
464 valid = TRUE;
465restofline:
466 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next)
467 {
468 idx = fmt_ptr->prefix;
469 if (multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL)
470 continue;
471 namebuf[0] = NUL;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000472 pattern[0] = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473 if (!multiscan)
474 errmsg[0] = NUL;
475 lnum = 0;
476 col = 0;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000477 use_viscol = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000478 enr = -1;
479 type = 0;
480 tail = NULL;
481
482 regmatch.regprog = fmt_ptr->prog;
483 if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
484 {
485 if ((idx == 'C' || idx == 'Z') && !multiline)
486 continue;
487 if (vim_strchr((char_u *)"EWI", idx) != NULL)
488 type = idx;
489 else
490 type = 0;
491 /*
492 * Extract error message data from matched line
493 */
494 if ((i = (int)fmt_ptr->addr[0]) > 0) /* %f */
495 {
Bram Moolenaar35c54e52005-05-20 21:25:31 +0000496 int c = *regmatch.endp[i];
497
498 /* Expand ~/file and $HOME/file to full path. */
499 *regmatch.endp[i] = NUL;
500 expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE);
501 *regmatch.endp[i] = c;
502
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 if (vim_strchr((char_u *)"OPQ", idx) != NULL
Bram Moolenaar35c54e52005-05-20 21:25:31 +0000504 && mch_getperm(namebuf) == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 continue;
506 }
507 if ((i = (int)fmt_ptr->addr[1]) > 0) /* %n */
508 enr = (int)atol((char *)regmatch.startp[i]);
509 if ((i = (int)fmt_ptr->addr[2]) > 0) /* %l */
510 lnum = atol((char *)regmatch.startp[i]);
511 if ((i = (int)fmt_ptr->addr[3]) > 0) /* %c */
512 col = (int)atol((char *)regmatch.startp[i]);
513 if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */
514 type = *regmatch.startp[i];
515 if (fmt_ptr->flags == '+' && !multiscan) /* %+ */
516 STRCPY(errmsg, IObuff);
517 else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */
518 {
519 len = (int)(regmatch.endp[i] - regmatch.startp[i]);
Bram Moolenaarbbebc852005-07-18 21:47:53 +0000520 vim_strncpy(errmsg, regmatch.startp[i], len);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521 }
522 if ((i = (int)fmt_ptr->addr[6]) > 0) /* %r */
523 tail = regmatch.startp[i];
524 if ((i = (int)fmt_ptr->addr[7]) > 0) /* %p */
525 {
526 col = (int)(regmatch.endp[i] - regmatch.startp[i] + 1);
527 if (*((char_u *)regmatch.startp[i]) != TAB)
Bram Moolenaar05159a02005-02-26 23:04:13 +0000528 use_viscol = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 }
530 if ((i = (int)fmt_ptr->addr[8]) > 0) /* %v */
531 {
532 col = (int)atol((char *)regmatch.startp[i]);
Bram Moolenaar05159a02005-02-26 23:04:13 +0000533 use_viscol = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 }
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000535 if ((i = (int)fmt_ptr->addr[9]) > 0) /* %s */
536 {
537 len = (int)(regmatch.endp[i] - regmatch.startp[i]);
538 if (len > CMDBUFFSIZE - 5)
539 len = CMDBUFFSIZE - 5;
540 STRCPY(pattern, "^\\V");
541 STRNCAT(pattern, regmatch.startp[i], len);
542 pattern[len + 3] = '\\';
543 pattern[len + 4] = '$';
544 pattern[len + 5] = NUL;
545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 break;
547 }
548 }
549 multiscan = FALSE;
550 if (!fmt_ptr || idx == 'D' || idx == 'X')
551 {
552 if (fmt_ptr)
553 {
554 if (idx == 'D') /* enter directory */
555 {
556 if (*namebuf == NUL)
557 {
558 EMSG(_("E379: Missing or empty directory name"));
559 goto error2;
560 }
561 if ((directory = qf_push_dir(namebuf, &dir_stack)) == NULL)
562 goto error2;
563 }
564 else if (idx == 'X') /* leave directory */
565 directory = qf_pop_dir(&dir_stack);
566 }
567 namebuf[0] = NUL; /* no match found, remove file name */
568 lnum = 0; /* don't jump to this line */
569 valid = FALSE;
570 STRCPY(errmsg, IObuff); /* copy whole line to error message */
571 if (!fmt_ptr)
572 multiline = multiignore = FALSE;
573 }
574 else if (fmt_ptr)
575 {
576 if (vim_strchr((char_u *)"AEWI", idx) != NULL)
577 multiline = TRUE; /* start of a multi-line message */
578 else if (vim_strchr((char_u *)"CZ", idx) != NULL)
579 { /* continuation of multi-line msg */
580 if (qfprev == NULL)
581 goto error2;
582 if (*errmsg && !multiignore)
583 {
584 len = (int)STRLEN(qfprev->qf_text);
585 if ((ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2)))
586 == NULL)
587 goto error2;
588 STRCPY(ptr, qfprev->qf_text);
589 vim_free(qfprev->qf_text);
590 qfprev->qf_text = ptr;
591 *(ptr += len) = '\n';
592 STRCPY(++ptr, errmsg);
593 }
594 if (qfprev->qf_nr == -1)
595 qfprev->qf_nr = enr;
596 if (vim_isprintc(type) && !qfprev->qf_type)
597 qfprev->qf_type = type; /* only printable chars allowed */
598 if (!qfprev->qf_lnum)
599 qfprev->qf_lnum = lnum;
600 if (!qfprev->qf_col)
601 qfprev->qf_col = col;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000602 qfprev->qf_viscol = use_viscol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 if (!qfprev->qf_fnum)
604 qfprev->qf_fnum = qf_get_fnum(directory,
605 *namebuf || directory ? namebuf
606 : currfile && valid ? currfile : 0);
607 if (idx == 'Z')
608 multiline = multiignore = FALSE;
609 line_breakcheck();
610 continue;
611 }
612 else if (vim_strchr((char_u *)"OPQ", idx) != NULL)
613 {
614 /* global file names */
615 valid = FALSE;
616 if (*namebuf == NUL || mch_getperm(namebuf) >= 0)
617 {
618 if (*namebuf && idx == 'P')
619 currfile = qf_push_dir(namebuf, &file_stack);
620 else if (idx == 'Q')
621 currfile = qf_pop_dir(&file_stack);
622 *namebuf = NUL;
623 if (tail && *tail)
624 {
625 STRCPY(IObuff, skipwhite(tail));
626 multiscan = TRUE;
627 goto restofline;
628 }
629 }
630 }
631 if (fmt_ptr->flags == '-') /* generally exclude this line */
632 {
633 if (multiline)
634 multiignore = TRUE; /* also exclude continuation lines */
635 continue;
636 }
637 }
638
639 if (qf_add_entry(&qfprev,
640 directory,
Bram Moolenaar9d75c832005-01-25 21:57:23 +0000641 (*namebuf || directory)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 ? namebuf
Bram Moolenaar9d75c832005-01-25 21:57:23 +0000643 : ((currfile && valid) ? currfile : (char_u *)NULL),
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644 errmsg,
645 lnum,
646 col,
Bram Moolenaar05159a02005-02-26 23:04:13 +0000647 use_viscol,
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000648 pattern,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 enr,
650 type,
651 valid) == FAIL)
652 goto error2;
653 line_breakcheck();
654 }
Bram Moolenaar86b68352004-12-27 21:59:20 +0000655 if (fd == NULL || !ferror(fd))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {
657 if (qf_lists[qf_curlist].qf_index == 0) /* no valid entry found */
658 {
659 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start;
660 qf_lists[qf_curlist].qf_index = 1;
661 qf_lists[qf_curlist].qf_nonevalid = TRUE;
662 }
663 else
664 {
665 qf_lists[qf_curlist].qf_nonevalid = FALSE;
666 if (qf_lists[qf_curlist].qf_ptr == NULL)
667 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start;
668 }
669 retval = qf_lists[qf_curlist].qf_count; /* return number of matches */
670 goto qf_init_ok;
671 }
672 EMSG(_(e_readerrf));
673error2:
674 qf_free(qf_curlist);
675 qf_listcount--;
676 if (qf_curlist > 0)
677 --qf_curlist;
678qf_init_ok:
Bram Moolenaar86b68352004-12-27 21:59:20 +0000679 if (fd != NULL)
680 fclose(fd);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first)
682 {
683 fmt_first = fmt_ptr->next;
684 vim_free(fmt_ptr->prog);
685 vim_free(fmt_ptr);
686 }
687 qf_clean_dir_stack(&dir_stack);
688 qf_clean_dir_stack(&file_stack);
689qf_init_end:
690 vim_free(namebuf);
691 vim_free(errmsg);
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000692 vim_free(pattern);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000693 vim_free(fmtstr);
694
695#ifdef FEAT_WINDOWS
696 qf_update_buffer();
697#endif
698
699 return retval;
700}
701
702/*
703 * Prepare for adding a new quickfix list.
704 */
705 static void
706qf_new_list()
707{
708 int i;
709
710 /*
711 * If the current entry is not the last entry, delete entries below
712 * the current entry. This makes it possible to browse in a tree-like
713 * way with ":grep'.
714 */
715 while (qf_listcount > qf_curlist + 1)
716 qf_free(--qf_listcount);
717
718 /*
719 * When the stack is full, remove to oldest entry
720 * Otherwise, add a new entry.
721 */
722 if (qf_listcount == LISTCOUNT)
723 {
724 qf_free(0);
725 for (i = 1; i < LISTCOUNT; ++i)
726 qf_lists[i - 1] = qf_lists[i];
727 qf_curlist = LISTCOUNT - 1;
728 }
729 else
730 qf_curlist = qf_listcount++;
731 qf_lists[qf_curlist].qf_index = 0;
732 qf_lists[qf_curlist].qf_count = 0;
733}
734
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000735#if defined(EXITFREE) || defined(PROTO)
736 void
737qf_free_all()
738{
739 int i;
740
741 for (i = 0; i < qf_listcount; ++i)
742 qf_free(i);
743}
744#endif
745
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746/*
747 * Add an entry to the end of the list of errors.
748 * Returns OK or FAIL.
749 */
750 static int
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000751qf_add_entry(prevp, dir, fname, mesg, lnum, col, vis_col, pattern, nr, type,
752 valid)
753 qfline_T **prevp; /* pointer to previously added entry or NULL */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 char_u *dir; /* optional directory name */
755 char_u *fname; /* file name or NULL */
756 char_u *mesg; /* message */
757 long lnum; /* line number */
758 int col; /* column */
Bram Moolenaar05159a02005-02-26 23:04:13 +0000759 int vis_col; /* using visual column */
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000760 char_u *pattern; /* search pattern */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761 int nr; /* error number */
762 int type; /* type character */
763 int valid; /* valid entry */
764{
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000765 qfline_T *qfp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000767 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 return FAIL;
769 qfp->qf_fnum = qf_get_fnum(dir, fname);
770 if ((qfp->qf_text = vim_strsave(mesg)) == NULL)
771 {
772 vim_free(qfp);
773 return FAIL;
774 }
775 qfp->qf_lnum = lnum;
776 qfp->qf_col = col;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000777 qfp->qf_viscol = vis_col;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000778 if (pattern == NULL || *pattern == NUL)
779 qfp->qf_pattern = NULL;
780 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL)
781 {
782 vim_free(qfp->qf_text);
783 vim_free(qfp);
784 return FAIL;
785 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786 qfp->qf_nr = nr;
787 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */
788 type = 0;
789 qfp->qf_type = type;
790 qfp->qf_valid = valid;
791
792 if (qf_lists[qf_curlist].qf_count == 0) /* first element in the list */
793 {
794 qf_lists[qf_curlist].qf_start = qfp;
795 qfp->qf_prev = qfp; /* first element points to itself */
796 }
797 else
798 {
799 qfp->qf_prev = *prevp;
800 (*prevp)->qf_next = qfp;
801 }
802 qfp->qf_next = qfp; /* last element points to itself */
803 qfp->qf_cleared = FALSE;
804 *prevp = qfp;
805 ++qf_lists[qf_curlist].qf_count;
806 if (qf_lists[qf_curlist].qf_index == 0 && qfp->qf_valid)
807 /* first valid entry */
808 {
809 qf_lists[qf_curlist].qf_index = qf_lists[qf_curlist].qf_count;
810 qf_lists[qf_curlist].qf_ptr = qfp;
811 }
812
813 return OK;
814}
815
816/*
817 * get buffer number for file "dir.name"
818 */
819 static int
820qf_get_fnum(directory, fname)
821 char_u *directory;
822 char_u *fname;
823{
824 if (fname == NULL || *fname == NUL) /* no file name */
825 return 0;
826 {
827#ifdef RISCOS
828 /* Name is reported as `main.c', but file is `c.main' */
829 return ro_buflist_add(fname);
830#else
831 char_u *ptr;
832 int fnum;
833
834# ifdef VMS
835 vms_remove_version(fname);
836# endif
837# ifdef BACKSLASH_IN_FILENAME
838 if (directory != NULL)
839 slash_adjust(directory);
840 slash_adjust(fname);
841# endif
842 if (directory != NULL && !vim_isAbsName(fname)
843 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL)
844 {
845 /*
846 * Here we check if the file really exists.
847 * This should normally be true, but if make works without
848 * "leaving directory"-messages we might have missed a
849 * directory change.
850 */
851 if (mch_getperm(ptr) < 0)
852 {
853 vim_free(ptr);
854 directory = qf_guess_filepath(fname);
855 if (directory)
856 ptr = concat_fnames(directory, fname, TRUE);
857 else
858 ptr = vim_strsave(fname);
859 }
860 /* Use concatenated directory name and file name */
861 fnum = buflist_add(ptr, 0);
862 vim_free(ptr);
863 return fnum;
864 }
865 return buflist_add(fname, 0);
866#endif
867 }
868}
869
870/*
871 * push dirbuf onto the directory stack and return pointer to actual dir or
872 * NULL on error
873 */
874 static char_u *
875qf_push_dir(dirbuf, stackptr)
876 char_u *dirbuf;
877 struct dir_stack_T **stackptr;
878{
879 struct dir_stack_T *ds_new;
880 struct dir_stack_T *ds_ptr;
881
882 /* allocate new stack element and hook it in */
883 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T));
884 if (ds_new == NULL)
885 return NULL;
886
887 ds_new->next = *stackptr;
888 *stackptr = ds_new;
889
890 /* store directory on the stack */
891 if (vim_isAbsName(dirbuf)
892 || (*stackptr)->next == NULL
893 || (*stackptr && dir_stack != *stackptr))
894 (*stackptr)->dirname = vim_strsave(dirbuf);
895 else
896 {
897 /* Okay we don't have an absolute path.
898 * dirbuf must be a subdir of one of the directories on the stack.
899 * Let's search...
900 */
901 ds_new = (*stackptr)->next;
902 (*stackptr)->dirname = NULL;
903 while (ds_new)
904 {
905 vim_free((*stackptr)->dirname);
906 (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf,
907 TRUE);
908 if (mch_isdir((*stackptr)->dirname) == TRUE)
909 break;
910
911 ds_new = ds_new->next;
912 }
913
914 /* clean up all dirs we already left */
915 while ((*stackptr)->next != ds_new)
916 {
917 ds_ptr = (*stackptr)->next;
918 (*stackptr)->next = (*stackptr)->next->next;
919 vim_free(ds_ptr->dirname);
920 vim_free(ds_ptr);
921 }
922
923 /* Nothing found -> it must be on top level */
924 if (ds_new == NULL)
925 {
926 vim_free((*stackptr)->dirname);
927 (*stackptr)->dirname = vim_strsave(dirbuf);
928 }
929 }
930
931 if ((*stackptr)->dirname != NULL)
932 return (*stackptr)->dirname;
933 else
934 {
935 ds_ptr = *stackptr;
936 *stackptr = (*stackptr)->next;
937 vim_free(ds_ptr);
938 return NULL;
939 }
940}
941
942
943/*
944 * pop dirbuf from the directory stack and return previous directory or NULL if
945 * stack is empty
946 */
947 static char_u *
948qf_pop_dir(stackptr)
949 struct dir_stack_T **stackptr;
950{
951 struct dir_stack_T *ds_ptr;
952
953 /* TODO: Should we check if dirbuf is the directory on top of the stack?
954 * What to do if it isn't? */
955
956 /* pop top element and free it */
957 if (*stackptr != NULL)
958 {
959 ds_ptr = *stackptr;
960 *stackptr = (*stackptr)->next;
961 vim_free(ds_ptr->dirname);
962 vim_free(ds_ptr);
963 }
964
965 /* return NEW top element as current dir or NULL if stack is empty*/
966 return *stackptr ? (*stackptr)->dirname : NULL;
967}
968
969/*
970 * clean up directory stack
971 */
972 static void
973qf_clean_dir_stack(stackptr)
974 struct dir_stack_T **stackptr;
975{
976 struct dir_stack_T *ds_ptr;
977
978 while ((ds_ptr = *stackptr) != NULL)
979 {
980 *stackptr = (*stackptr)->next;
981 vim_free(ds_ptr->dirname);
982 vim_free(ds_ptr);
983 }
984}
985
986/*
987 * Check in which directory of the directory stack the given file can be
988 * found.
989 * Returns a pointer to the directory name or NULL if not found
990 * Cleans up intermediate directory entries.
991 *
992 * TODO: How to solve the following problem?
993 * If we have the this directory tree:
994 * ./
995 * ./aa
996 * ./aa/bb
997 * ./bb
998 * ./bb/x.c
999 * and make says:
1000 * making all in aa
1001 * making all in bb
1002 * x.c:9: Error
1003 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb.
1004 * qf_guess_filepath will return NULL.
1005 */
1006 static char_u *
1007qf_guess_filepath(filename)
1008 char_u *filename;
1009{
1010 struct dir_stack_T *ds_ptr;
1011 struct dir_stack_T *ds_tmp;
1012 char_u *fullname;
1013
1014 /* no dirs on the stack - there's nothing we can do */
1015 if (dir_stack == NULL)
1016 return NULL;
1017
1018 ds_ptr = dir_stack->next;
1019 fullname = NULL;
1020 while (ds_ptr)
1021 {
1022 vim_free(fullname);
1023 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE);
1024
1025 /* If concat_fnames failed, just go on. The worst thing that can happen
1026 * is that we delete the entire stack.
1027 */
1028 if ((fullname != NULL) && (mch_getperm(fullname) >= 0))
1029 break;
1030
1031 ds_ptr = ds_ptr->next;
1032 }
1033
1034 vim_free(fullname);
1035
1036 /* clean up all dirs we already left */
1037 while (dir_stack->next != ds_ptr)
1038 {
1039 ds_tmp = dir_stack->next;
1040 dir_stack->next = dir_stack->next->next;
1041 vim_free(ds_tmp->dirname);
1042 vim_free(ds_tmp);
1043 }
1044
1045 return ds_ptr==NULL? NULL: ds_ptr->dirname;
1046
1047}
1048
1049/*
1050 * jump to a quickfix line
1051 * if dir == FORWARD go "errornr" valid entries forward
1052 * if dir == BACKWARD go "errornr" valid entries backward
1053 * if dir == FORWARD_FILE go "errornr" valid entries files backward
1054 * if dir == BACKWARD_FILE go "errornr" valid entries files backward
1055 * else if "errornr" is zero, redisplay the same line
1056 * else go to entry "errornr"
1057 */
1058 void
1059qf_jump(dir, errornr, forceit)
1060 int dir;
1061 int errornr;
1062 int forceit;
1063{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001064 qfline_T *qf_ptr;
1065 qfline_T *old_qf_ptr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 int qf_index;
1067 int old_qf_fnum;
1068 int old_qf_index;
1069 int prev_index;
1070 static char_u *e_no_more_items = (char_u *)N_("E553: No more items");
1071 char_u *err = e_no_more_items;
1072 linenr_T i;
1073 buf_T *old_curbuf;
1074 linenr_T old_lnum;
1075 char_u *old_swb = p_swb;
1076 colnr_T screen_col;
1077 colnr_T char_col;
1078 char_u *line;
1079#ifdef FEAT_WINDOWS
1080 int opened_window = FALSE;
1081 win_T *win;
1082 win_T *altwin;
1083#endif
1084 int print_message = TRUE;
1085 int len;
1086#ifdef FEAT_FOLDING
1087 int old_KeyTyped = KeyTyped; /* getting file may reset it */
1088#endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001089 int ok = OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090
1091 if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0)
1092 {
1093 EMSG(_(e_quickfix));
1094 return;
1095 }
1096
1097 qf_ptr = qf_lists[qf_curlist].qf_ptr;
1098 old_qf_ptr = qf_ptr;
1099 qf_index = qf_lists[qf_curlist].qf_index;
1100 old_qf_index = qf_index;
1101 if (dir == FORWARD || dir == FORWARD_FILE) /* next valid entry */
1102 {
1103 while (errornr--)
1104 {
1105 old_qf_ptr = qf_ptr;
1106 prev_index = qf_index;
1107 old_qf_fnum = qf_ptr->qf_fnum;
1108 do
1109 {
1110 if (qf_index == qf_lists[qf_curlist].qf_count
1111 || qf_ptr->qf_next == NULL)
1112 {
1113 qf_ptr = old_qf_ptr;
1114 qf_index = prev_index;
1115 if (err != NULL)
1116 {
1117 EMSG(_(err));
1118 goto theend;
1119 }
1120 errornr = 0;
1121 break;
1122 }
1123 ++qf_index;
1124 qf_ptr = qf_ptr->qf_next;
1125 } while ((!qf_lists[qf_curlist].qf_nonevalid && !qf_ptr->qf_valid)
1126 || (dir == FORWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum));
1127 err = NULL;
1128 }
1129 }
1130 else if (dir == BACKWARD || dir == BACKWARD_FILE) /* prev. valid entry */
1131 {
1132 while (errornr--)
1133 {
1134 old_qf_ptr = qf_ptr;
1135 prev_index = qf_index;
1136 old_qf_fnum = qf_ptr->qf_fnum;
1137 do
1138 {
1139 if (qf_index == 1 || qf_ptr->qf_prev == NULL)
1140 {
1141 qf_ptr = old_qf_ptr;
1142 qf_index = prev_index;
1143 if (err != NULL)
1144 {
1145 EMSG(_(err));
1146 goto theend;
1147 }
1148 errornr = 0;
1149 break;
1150 }
1151 --qf_index;
1152 qf_ptr = qf_ptr->qf_prev;
1153 } while ((!qf_lists[qf_curlist].qf_nonevalid && !qf_ptr->qf_valid)
1154 || (dir == BACKWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum));
1155 err = NULL;
1156 }
1157 }
1158 else if (errornr != 0) /* go to specified number */
1159 {
1160 while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL)
1161 {
1162 --qf_index;
1163 qf_ptr = qf_ptr->qf_prev;
1164 }
1165 while (errornr > qf_index && qf_index < qf_lists[qf_curlist].qf_count
1166 && qf_ptr->qf_next != NULL)
1167 {
1168 ++qf_index;
1169 qf_ptr = qf_ptr->qf_next;
1170 }
1171 }
1172
1173#ifdef FEAT_WINDOWS
1174 qf_lists[qf_curlist].qf_index = qf_index;
1175 if (qf_win_pos_update(old_qf_index))
1176 /* No need to print the error message if it's visible in the error
1177 * window */
1178 print_message = FALSE;
1179
1180 /*
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001181 * For ":helpgrep" find a help window or open one.
1182 */
1183 if (qf_ptr->qf_type == 1 && !curwin->w_buffer->b_help)
1184 {
1185 win_T *wp;
1186 int n;
1187
1188 for (wp = firstwin; wp != NULL; wp = wp->w_next)
1189 if (wp->w_buffer != NULL && wp->w_buffer->b_help)
1190 break;
1191 if (wp != NULL && wp->w_buffer->b_nwindows > 0)
1192 win_enter(wp, TRUE);
1193 else
1194 {
1195 /*
1196 * Split off help window; put it at far top if no position
1197 * specified, the current window is vertically split and narrow.
1198 */
1199 n = WSP_HELP;
1200# ifdef FEAT_VERTSPLIT
1201 if (cmdmod.split == 0 && curwin->w_width != Columns
1202 && curwin->w_width < 80)
1203 n |= WSP_TOP;
1204# endif
1205 if (win_split(0, n) == FAIL)
1206 goto theend;
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001207 opened_window = TRUE; /* close it when fail */
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001208
1209 if (curwin->w_height < p_hh)
1210 win_setheight((int)p_hh);
1211 }
1212
1213 if (!p_im)
1214 restart_edit = 0; /* don't want insert mode in help file */
1215 }
1216
1217 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 * If currently in the quickfix window, find another window to show the
1219 * file in.
1220 */
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001221 if (bt_quickfix(curbuf) && !opened_window)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 {
1223 /*
1224 * If there is no file specified, we don't know where to go.
1225 * But do advance, otherwise ":cn" gets stuck.
1226 */
1227 if (qf_ptr->qf_fnum == 0)
1228 goto theend;
1229
1230 /*
1231 * If there is only one window, create a new one above the quickfix
1232 * window.
1233 */
1234 if (firstwin == lastwin)
1235 {
1236 if (win_split(0, WSP_ABOVE) == FAIL)
1237 goto failed; /* not enough room for window */
1238 opened_window = TRUE; /* close it when fail */
1239 p_swb = empty_option; /* don't split again */
1240# ifdef FEAT_SCROLLBIND
1241 curwin->w_p_scb = FALSE;
1242# endif
1243 }
1244 else
1245 {
1246 /*
1247 * Try to find a window that shows the right buffer.
1248 * Default to the window just above the quickfix buffer.
1249 */
1250 win = curwin;
1251 altwin = NULL;
1252 for (;;)
1253 {
1254 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum)
1255 break;
1256 if (win->w_prev == NULL)
1257 win = lastwin; /* wrap around the top */
1258 else
1259 win = win->w_prev; /* go to previous window */
1260
1261 if (bt_quickfix(win->w_buffer))
1262 {
1263 /* Didn't find it, go to the window before the quickfix
1264 * window. */
1265 if (altwin != NULL)
1266 win = altwin;
1267 else if (curwin->w_prev != NULL)
1268 win = curwin->w_prev;
1269 else
1270 win = curwin->w_next;
1271 break;
1272 }
1273
1274 /* Remember a usable window. */
1275 if (altwin == NULL && !win->w_p_pvw
1276 && win->w_buffer->b_p_bt[0] == NUL)
1277 altwin = win;
1278 }
1279
1280 win_goto(win);
1281 }
1282 }
1283#endif
1284
1285 /*
1286 * If there is a file name,
1287 * read the wanted file if needed, and check autowrite etc.
1288 */
1289 old_curbuf = curbuf;
1290 old_lnum = curwin->w_cursor.lnum;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001291
1292 if (qf_ptr->qf_fnum != 0)
1293 {
1294 if (qf_ptr->qf_type == 1)
1295 {
1296 /* Open help file (do_ecmd() will set b_help flag, readfile() will
1297 * set b_p_ro flag). */
1298 if (!can_abandon(curbuf, forceit))
1299 {
1300 EMSG(_(e_nowrtmsg));
1301 ok = FALSE;
1302 }
1303 else
1304 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
1305 ECMD_HIDE + ECMD_SET_HELP);
1306 }
1307 else
1308 ok = buflist_getfile(qf_ptr->qf_fnum,
1309 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit);
1310 }
1311
1312 if (ok == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {
1314 /* When not switched to another buffer, still need to set pc mark */
1315 if (curbuf == old_curbuf)
1316 setpcmark();
1317
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001318 if (qf_ptr->qf_pattern == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 {
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001320 /*
1321 * Go to line with error, unless qf_lnum is 0.
1322 */
1323 i = qf_ptr->qf_lnum;
1324 if (i > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001326 if (i > curbuf->b_ml.ml_line_count)
1327 i = curbuf->b_ml.ml_line_count;
1328 curwin->w_cursor.lnum = i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 }
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001330 if (qf_ptr->qf_col > 0)
1331 {
1332 curwin->w_cursor.col = qf_ptr->qf_col - 1;
1333 if (qf_ptr->qf_viscol == TRUE)
1334 {
1335 /*
1336 * Check each character from the beginning of the error
1337 * line up to the error column. For each tab character
1338 * found, reduce the error column value by the length of
1339 * a tab character.
1340 */
1341 line = ml_get_curline();
1342 screen_col = 0;
1343 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col)
1344 {
1345 if (*line == NUL)
1346 break;
1347 if (*line++ == '\t')
1348 {
1349 curwin->w_cursor.col -= 7 - (screen_col % 8);
1350 screen_col += 8 - (screen_col % 8);
1351 }
1352 else
1353 ++screen_col;
1354 }
1355 }
1356 check_cursor();
1357 }
1358 else
1359 beginline(BL_WHITE | BL_FIX);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 }
1361 else
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001362 {
1363 pos_T save_cursor;
1364
1365 /* Move the cursor to the first line in the buffer */
1366 save_cursor = curwin->w_cursor;
1367 curwin->w_cursor.lnum = 0;
1368 if (!do_search(NULL, '/', qf_ptr->qf_pattern, (long)1, SEARCH_KEEP))
1369 curwin->w_cursor = save_cursor;
1370 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371
1372#ifdef FEAT_FOLDING
1373 if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped)
1374 foldOpenCursor();
1375#endif
1376 if (print_message)
1377 {
1378 /* Update the screen before showing the message */
1379 update_topline_redraw();
1380 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index,
1381 qf_lists[qf_curlist].qf_count,
1382 qf_ptr->qf_cleared ? _(" (line deleted)") : "",
1383 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr));
1384 /* Add the message, skipping leading whitespace and newlines. */
1385 len = (int)STRLEN(IObuff);
1386 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len);
1387
1388 /* Output the message. Overwrite to avoid scrolling when the 'O'
1389 * flag is present in 'shortmess'; But when not jumping, print the
1390 * whole message. */
1391 i = msg_scroll;
1392 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum)
1393 msg_scroll = TRUE;
1394 else if (!msg_scrolled && shortmess(SHM_OVERALL))
1395 msg_scroll = FALSE;
1396 msg_attr_keep(IObuff, 0, TRUE);
1397 msg_scroll = i;
1398 }
1399 }
1400 else
1401 {
1402#ifdef FEAT_WINDOWS
1403 if (opened_window)
1404 win_close(curwin, TRUE); /* Close opened window */
1405#endif
1406 if (qf_ptr->qf_fnum != 0)
1407 {
1408 /*
1409 * Couldn't open file, so put index back where it was. This could
1410 * happen if the file was readonly and we changed something.
1411 */
1412#ifdef FEAT_WINDOWS
1413failed:
1414#endif
1415 qf_ptr = old_qf_ptr;
1416 qf_index = old_qf_index;
1417 }
1418 }
1419theend:
1420 qf_lists[qf_curlist].qf_ptr = qf_ptr;
1421 qf_lists[qf_curlist].qf_index = qf_index;
1422#ifdef FEAT_WINDOWS
1423 if (p_swb != old_swb && opened_window)
1424 {
1425 /* Restore old 'switchbuf' value, but not when an autocommand or
1426 * modeline has changed the value. */
1427 if (p_swb == empty_option)
1428 p_swb = old_swb;
1429 else
1430 free_string_option(old_swb);
1431 }
1432#endif
1433}
1434
1435/*
1436 * ":clist": list all errors
1437 */
1438 void
1439qf_list(eap)
1440 exarg_T *eap;
1441{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001442 buf_T *buf;
1443 char_u *fname;
1444 qfline_T *qfp;
1445 int i;
1446 int idx1 = 1;
1447 int idx2 = -1;
1448 int need_return = TRUE;
1449 int last_printed = 1;
1450 char_u *arg = eap->arg;
1451 int all = eap->forceit; /* if not :cl!, only show
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 recognised errors */
1453
1454 if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0)
1455 {
1456 EMSG(_(e_quickfix));
1457 return;
1458 }
1459 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL)
1460 {
1461 EMSG(_(e_trailing));
1462 return;
1463 }
1464 i = qf_lists[qf_curlist].qf_count;
1465 if (idx1 < 0)
1466 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1;
1467 if (idx2 < 0)
1468 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
1469
1470 more_back_used = TRUE;
1471 if (qf_lists[qf_curlist].qf_nonevalid)
1472 all = TRUE;
1473 qfp = qf_lists[qf_curlist].qf_start;
1474 for (i = 1; !got_int && i <= qf_lists[qf_curlist].qf_count; )
1475 {
1476 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2)
1477 {
1478 if (need_return)
1479 {
1480 msg_putchar('\n');
1481 need_return = FALSE;
1482 }
1483 if (more_back == 0)
1484 {
1485 fname = NULL;
1486 if (qfp->qf_fnum != 0
1487 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL)
1488 {
1489 fname = buf->b_fname;
1490 if (qfp->qf_type == 1) /* :helpgrep */
1491 fname = gettail(fname);
1492 }
1493 if (fname == NULL)
1494 sprintf((char *)IObuff, "%2d", i);
1495 else
Bram Moolenaar051b7822005-05-19 21:00:46 +00001496 vim_snprintf((char *)IObuff, IOSIZE, "%2d %s",
1497 i, (char *)fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 msg_outtrans_attr(IObuff, i == qf_lists[qf_curlist].qf_index
1499 ? hl_attr(HLF_L) : hl_attr(HLF_D));
1500 if (qfp->qf_lnum == 0)
1501 IObuff[0] = NUL;
1502 else if (qfp->qf_col == 0)
1503 sprintf((char *)IObuff, ":%ld", qfp->qf_lnum);
1504 else
1505 sprintf((char *)IObuff, ":%ld col %d",
1506 qfp->qf_lnum, qfp->qf_col);
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001507 sprintf((char *)IObuff + STRLEN(IObuff), "%s:",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 (char *)qf_types(qfp->qf_type, qfp->qf_nr));
1509 msg_puts_attr(IObuff, hl_attr(HLF_N));
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001510 if (qfp->qf_pattern != NULL)
1511 {
1512 qf_fmt_text(qfp->qf_pattern, IObuff, IOSIZE);
1513 STRCAT(IObuff, ":");
1514 msg_puts(IObuff);
1515 }
1516 msg_puts((char_u *)" ");
1517
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 /* Remove newlines and leading whitespace from the text.
1519 * For an unrecognized line keep the indent, the compiler may
1520 * mark a word with ^^^^. */
1521 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0)
1522 ? skipwhite(qfp->qf_text) : qfp->qf_text,
1523 IObuff, IOSIZE);
Bram Moolenaardf177f62005-02-22 08:39:57 +00001524 msg_prt_line(IObuff, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 out_flush(); /* show one line at a time */
1526 need_return = TRUE;
1527 last_printed = i;
1528 }
1529 }
1530 if (more_back)
1531 {
1532 /* scrolling backwards from the more-prompt */
1533 /* TODO: compute the number of items from the screen lines */
1534 more_back = more_back * 2 - 1;
1535 while (i > last_printed - more_back && i > idx1)
1536 {
1537 do
1538 {
1539 qfp = qfp->qf_prev;
1540 --i;
1541 }
1542 while (i > idx1 && !qfp->qf_valid && !all);
1543 }
1544 more_back = 0;
1545 }
1546 else
1547 {
1548 qfp = qfp->qf_next;
1549 ++i;
1550 }
1551 ui_breakcheck();
1552 }
1553 more_back_used = FALSE;
1554}
1555
1556/*
1557 * Remove newlines and leading whitespace from an error message.
1558 * Put the result in "buf[bufsize]".
1559 */
1560 static void
1561qf_fmt_text(text, buf, bufsize)
1562 char_u *text;
1563 char_u *buf;
1564 int bufsize;
1565{
1566 int i;
1567 char_u *p = text;
1568
1569 for (i = 0; *p != NUL && i < bufsize - 1; ++i)
1570 {
1571 if (*p == '\n')
1572 {
1573 buf[i] = ' ';
1574 while (*++p != NUL)
1575 if (!vim_iswhite(*p) && *p != '\n')
1576 break;
1577 }
1578 else
1579 buf[i] = *p++;
1580 }
1581 buf[i] = NUL;
1582}
1583
1584/*
1585 * ":colder [count]": Up in the quickfix stack.
1586 * ":cnewer [count]": Down in the quickfix stack.
1587 */
1588 void
1589qf_age(eap)
1590 exarg_T *eap;
1591{
1592 int count;
1593
1594 if (eap->addr_count != 0)
1595 count = eap->line2;
1596 else
1597 count = 1;
1598 while (count--)
1599 {
1600 if (eap->cmdidx == CMD_colder)
1601 {
1602 if (qf_curlist == 0)
1603 {
1604 EMSG(_("E380: At bottom of quickfix stack"));
1605 return;
1606 }
1607 --qf_curlist;
1608 }
1609 else
1610 {
1611 if (qf_curlist >= qf_listcount - 1)
1612 {
1613 EMSG(_("E381: At top of quickfix stack"));
1614 return;
1615 }
1616 ++qf_curlist;
1617 }
1618 }
1619 qf_msg();
1620}
1621
1622 static void
1623qf_msg()
1624{
1625 smsg((char_u *)_("error list %d of %d; %d errors"),
1626 qf_curlist + 1, qf_listcount, qf_lists[qf_curlist].qf_count);
1627#ifdef FEAT_WINDOWS
1628 qf_update_buffer();
1629#endif
1630}
1631
1632/*
1633 * free the error list
1634 */
1635 static void
1636qf_free(idx)
1637 int idx;
1638{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001639 qfline_T *qfp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640
1641 while (qf_lists[idx].qf_count)
1642 {
1643 qfp = qf_lists[idx].qf_start->qf_next;
1644 vim_free(qf_lists[idx].qf_start->qf_text);
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001645 vim_free(qf_lists[idx].qf_start->qf_pattern);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646 vim_free(qf_lists[idx].qf_start);
1647 qf_lists[idx].qf_start = qfp;
1648 --qf_lists[idx].qf_count;
1649 }
1650}
1651
1652/*
1653 * qf_mark_adjust: adjust marks
1654 */
1655 void
1656qf_mark_adjust(line1, line2, amount, amount_after)
1657 linenr_T line1;
1658 linenr_T line2;
1659 long amount;
1660 long amount_after;
1661{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001662 int i;
1663 qfline_T *qfp;
1664 int idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665
1666 for (idx = 0; idx < qf_listcount; ++idx)
1667 if (qf_lists[idx].qf_count)
1668 for (i = 0, qfp = qf_lists[idx].qf_start;
1669 i < qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next)
1670 if (qfp->qf_fnum == curbuf->b_fnum)
1671 {
1672 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2)
1673 {
1674 if (amount == MAXLNUM)
1675 qfp->qf_cleared = TRUE;
1676 else
1677 qfp->qf_lnum += amount;
1678 }
1679 else if (amount_after && qfp->qf_lnum > line2)
1680 qfp->qf_lnum += amount_after;
1681 }
1682}
1683
1684/*
1685 * Make a nice message out of the error character and the error number:
1686 * char number message
1687 * e or E 0 " error"
1688 * w or W 0 " warning"
1689 * i or I 0 " info"
1690 * 0 0 ""
1691 * other 0 " c"
1692 * e or E n " error n"
1693 * w or W n " warning n"
1694 * i or I n " info n"
1695 * 0 n " error n"
1696 * other n " c n"
1697 * 1 x "" :helpgrep
1698 */
1699 static char_u *
1700qf_types(c, nr)
1701 int c, nr;
1702{
1703 static char_u buf[20];
1704 static char_u cc[3];
1705 char_u *p;
1706
1707 if (c == 'W' || c == 'w')
1708 p = (char_u *)" warning";
1709 else if (c == 'I' || c == 'i')
1710 p = (char_u *)" info";
1711 else if (c == 'E' || c == 'e' || (c == 0 && nr > 0))
1712 p = (char_u *)" error";
1713 else if (c == 0 || c == 1)
1714 p = (char_u *)"";
1715 else
1716 {
1717 cc[0] = ' ';
1718 cc[1] = c;
1719 cc[2] = NUL;
1720 p = cc;
1721 }
1722
1723 if (nr <= 0)
1724 return p;
1725
1726 sprintf((char *)buf, "%s %3d", (char *)p, nr);
1727 return buf;
1728}
1729
1730#if defined(FEAT_WINDOWS) || defined(PROTO)
1731/*
1732 * ":cwindow": open the quickfix window if we have errors to display,
1733 * close it if not.
1734 */
1735 void
1736ex_cwindow(eap)
1737 exarg_T *eap;
1738{
1739 win_T *win;
1740
1741 /*
1742 * Look for an existing quickfix window.
1743 */
1744 for (win = firstwin; win != NULL; win = win->w_next)
1745 if (bt_quickfix(win->w_buffer))
1746 break;
1747
1748 /*
1749 * If a quickfix window is open but we have no errors to display,
1750 * close the window. If a quickfix window is not open, then open
1751 * it if we have errors; otherwise, leave it closed.
1752 */
1753 if (qf_lists[qf_curlist].qf_nonevalid || qf_curlist >= qf_listcount)
1754 {
1755 if (win != NULL)
1756 ex_cclose(eap);
1757 }
1758 else if (win == NULL)
1759 ex_copen(eap);
1760}
1761
1762/*
1763 * ":cclose": close the window showing the list of errors.
1764 */
1765/*ARGSUSED*/
1766 void
1767ex_cclose(eap)
1768 exarg_T *eap;
1769{
1770 win_T *win;
1771
1772 /*
1773 * Find existing quickfix window and close it.
1774 */
1775 for (win = firstwin; win != NULL; win = win->w_next)
1776 if (bt_quickfix(win->w_buffer))
1777 break;
1778
1779 if (win != NULL)
1780 win_close(win, FALSE);
1781}
1782
1783/*
1784 * ":copen": open a window that shows the list of errors.
1785 */
1786 void
1787ex_copen(eap)
1788 exarg_T *eap;
1789{
1790 int height;
1791 buf_T *buf;
1792 win_T *win;
1793
1794 if (eap->addr_count != 0)
1795 height = eap->line2;
1796 else
1797 height = QF_WINHEIGHT;
1798
1799#ifdef FEAT_VISUAL
1800 reset_VIsual_and_resel(); /* stop Visual mode */
1801#endif
1802#ifdef FEAT_GUI
1803 need_mouse_correct = TRUE;
1804#endif
1805
1806 /*
1807 * Find existing quickfix window, or open a new one.
1808 */
1809 for (win = firstwin; win != NULL; win = win->w_next)
1810 if (bt_quickfix(win->w_buffer))
1811 break;
1812 if (win != NULL)
1813 win_goto(win);
1814 else
1815 {
1816 /* The current window becomes the previous window afterwards. */
1817 win = curwin;
1818
1819 /* Create the new window at the very bottom. */
1820 win_goto(lastwin);
1821 if (win_split(height, WSP_BELOW) == FAIL)
1822 return; /* not enough room for window */
1823#ifdef FEAT_SCROLLBIND
1824 curwin->w_p_scb = FALSE;
1825#endif
1826
1827 /*
1828 * Find existing quickfix buffer, or create a new one.
1829 */
1830 buf = qf_find_buf();
1831 if (buf == NULL)
1832 {
1833 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE);
1834 /* switch off 'swapfile' */
1835 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
1836 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix",
1837 OPT_LOCAL);
1838 set_option_value((char_u *)"bh", 0L, (char_u *)"delete", OPT_LOCAL);
1839 set_option_value((char_u *)"diff", 0L, (char_u *)"", OPT_LOCAL);
1840 }
1841 else if (buf != curbuf)
1842 set_curbuf(buf, DOBUF_GOTO);
1843
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00001844#ifdef FEAT_VERTSPLIT
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 /* Only set the height when there is no window to the side. */
1846 if (curwin->w_width == Columns)
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00001847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 win_setheight(height);
1849 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */
1850 if (win_valid(win))
1851 prevwin = win;
1852 }
1853
1854 /*
1855 * Fill the buffer with the quickfix list.
1856 */
1857 qf_fill_buffer();
1858
1859 curwin->w_cursor.lnum = qf_lists[qf_curlist].qf_index;
1860 curwin->w_cursor.col = 0;
1861 check_cursor();
1862 update_topline(); /* scroll to show the line */
1863}
1864
1865/*
1866 * Return the number of the current entry (line number in the quickfix
1867 * window).
1868 */
1869 linenr_T
1870qf_current_entry()
1871{
1872 return qf_lists[qf_curlist].qf_index;
1873}
1874
1875/*
1876 * Update the cursor position in the quickfix window to the current error.
1877 * Return TRUE if there is a quickfix window.
1878 */
1879 static int
1880qf_win_pos_update(old_qf_index)
1881 int old_qf_index; /* previous qf_index or zero */
1882{
1883 win_T *win;
1884 int qf_index = qf_lists[qf_curlist].qf_index;
1885
1886 /*
1887 * Put the cursor on the current error in the quickfix window, so that
1888 * it's viewable.
1889 */
1890 for (win = firstwin; win != NULL; win = win->w_next)
1891 if (bt_quickfix(win->w_buffer))
1892 break;
1893 if (win != NULL
1894 && qf_index <= win->w_buffer->b_ml.ml_line_count
1895 && old_qf_index != qf_index)
1896 {
1897 win_T *old_curwin = curwin;
1898
1899 curwin = win;
1900 curbuf = win->w_buffer;
1901 if (qf_index > old_qf_index)
1902 {
1903 curwin->w_redraw_top = old_qf_index;
1904 curwin->w_redraw_bot = qf_index;
1905 }
1906 else
1907 {
1908 curwin->w_redraw_top = qf_index;
1909 curwin->w_redraw_bot = old_qf_index;
1910 }
1911 curwin->w_cursor.lnum = qf_index;
1912 curwin->w_cursor.col = 0;
1913 update_topline(); /* scroll to show the line */
1914 redraw_later(VALID);
1915 curwin->w_redr_status = TRUE; /* update ruler */
1916 curwin = old_curwin;
1917 curbuf = curwin->w_buffer;
1918 }
1919 return win != NULL;
1920}
1921
1922/*
1923 * Find quickfix buffer.
1924 */
1925 static buf_T *
1926qf_find_buf()
1927{
1928 buf_T *buf;
1929
1930 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
1931 if (bt_quickfix(buf))
1932 break;
1933 return buf;
1934}
1935
1936/*
1937 * Find the quickfix buffer. If it exists, update the contents.
1938 */
1939 static void
1940qf_update_buffer()
1941{
1942 buf_T *buf;
1943#ifdef FEAT_AUTOCMD
1944 aco_save_T aco;
1945#else
1946 buf_T *save_curbuf;
1947#endif
1948
1949 /* Check if a buffer for the quickfix list exists. Update it. */
1950 buf = qf_find_buf();
1951 if (buf != NULL)
1952 {
1953#ifdef FEAT_AUTOCMD
1954 /* set curwin/curbuf to buf and save a few things */
1955 aucmd_prepbuf(&aco, buf);
1956#else
1957 save_curbuf = curbuf;
1958 curbuf = buf;
1959#endif
1960
1961 qf_fill_buffer();
1962
1963#ifdef FEAT_AUTOCMD
1964 /* restore curwin/curbuf and a few other things */
1965 aucmd_restbuf(&aco);
1966#else
1967 curbuf = save_curbuf;
1968#endif
1969
1970 (void)qf_win_pos_update(0);
1971 }
1972}
1973
1974/*
1975 * Fill current buffer with quickfix errors, replacing any previous contents.
1976 * curbuf must be the quickfix buffer!
1977 */
1978 static void
1979qf_fill_buffer()
1980{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001981 linenr_T lnum;
1982 qfline_T *qfp;
1983 buf_T *errbuf;
1984 int len;
1985 int old_KeyTyped = KeyTyped;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986
1987 /* delete all existing lines */
1988 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0)
1989 (void)ml_delete((linenr_T)1, FALSE);
1990
1991 /* Check if there is anything to display */
1992 if (qf_curlist < qf_listcount)
1993 {
1994 /* Add one line for each error */
1995 qfp = qf_lists[qf_curlist].qf_start;
1996 for (lnum = 0; lnum < qf_lists[qf_curlist].qf_count; ++lnum)
1997 {
1998 if (qfp->qf_fnum != 0
1999 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL
2000 && errbuf->b_fname != NULL)
2001 {
2002 if (qfp->qf_type == 1) /* :helpgrep */
2003 STRCPY(IObuff, gettail(errbuf->b_fname));
2004 else
2005 STRCPY(IObuff, errbuf->b_fname);
2006 len = (int)STRLEN(IObuff);
2007 }
2008 else
2009 len = 0;
2010 IObuff[len++] = '|';
2011
2012 if (qfp->qf_lnum > 0)
2013 {
2014 sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum);
2015 len += (int)STRLEN(IObuff + len);
2016
2017 if (qfp->qf_col > 0)
2018 {
2019 sprintf((char *)IObuff + len, " col %d", qfp->qf_col);
2020 len += (int)STRLEN(IObuff + len);
2021 }
2022
2023 sprintf((char *)IObuff + len, "%s",
2024 (char *)qf_types(qfp->qf_type, qfp->qf_nr));
2025 len += (int)STRLEN(IObuff + len);
2026 }
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002027 else if (qfp->qf_pattern != NULL)
2028 {
2029 qf_fmt_text(qfp->qf_pattern, IObuff + len, IOSIZE - len);
2030 len += (int)STRLEN(IObuff + len);
2031 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 IObuff[len++] = '|';
2033 IObuff[len++] = ' ';
2034
2035 /* Remove newlines and leading whitespace from the text.
2036 * For an unrecognized line keep the indent, the compiler may
2037 * mark a word with ^^^^. */
2038 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text,
2039 IObuff + len, IOSIZE - len);
2040
2041 if (ml_append(lnum, IObuff, (colnr_T)STRLEN(IObuff) + 1, FALSE)
2042 == FAIL)
2043 break;
2044 qfp = qfp->qf_next;
2045 }
2046 /* Delete the empty line which is now at the end */
2047 (void)ml_delete(lnum + 1, FALSE);
2048 }
2049
2050 /* correct cursor position */
2051 check_lnums(TRUE);
2052
2053 /* Set the 'filetype' to "qf" each time after filling the buffer. This
2054 * resembles reading a file into a buffer, it's more logical when using
2055 * autocommands. */
2056 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL);
2057 curbuf->b_p_ma = FALSE;
2058
2059#ifdef FEAT_AUTOCMD
2060 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL,
2061 FALSE, curbuf);
2062 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL,
2063 FALSE, curbuf);
2064#endif
2065
2066 /* make sure it will be redrawn */
2067 redraw_curbuf_later(NOT_VALID);
2068
2069 /* Restore KeyTyped, setting 'filetype' may reset it. */
2070 KeyTyped = old_KeyTyped;
2071}
2072
2073#endif /* FEAT_WINDOWS */
2074
2075/*
2076 * Return TRUE if "buf" is the quickfix buffer.
2077 */
2078 int
2079bt_quickfix(buf)
2080 buf_T *buf;
2081{
2082 return (buf->b_p_bt[0] == 'q');
2083}
2084
2085/*
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002086 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer.
2087 * This means the buffer name is not a file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 */
2089 int
2090bt_nofile(buf)
2091 buf_T *buf;
2092{
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002093 return (buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f')
2094 || buf->b_p_bt[0] == 'a';
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095}
2096
2097/*
2098 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer.
2099 */
2100 int
2101bt_dontwrite(buf)
2102 buf_T *buf;
2103{
2104 return (buf->b_p_bt[0] == 'n');
2105}
2106
2107 int
2108bt_dontwrite_msg(buf)
2109 buf_T *buf;
2110{
2111 if (bt_dontwrite(buf))
2112 {
2113 EMSG(_("E382: Cannot write, 'buftype' option is set"));
2114 return TRUE;
2115 }
2116 return FALSE;
2117}
2118
2119/*
2120 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide"
2121 * and 'bufhidden'.
2122 */
2123 int
2124buf_hide(buf)
2125 buf_T *buf;
2126{
2127 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */
2128 switch (buf->b_p_bh[0])
2129 {
2130 case 'u': /* "unload" */
2131 case 'w': /* "wipe" */
2132 case 'd': return FALSE; /* "delete" */
2133 case 'h': return TRUE; /* "hide" */
2134 }
2135 return (p_hid || cmdmod.hide);
2136}
2137
2138/*
Bram Moolenaar86b68352004-12-27 21:59:20 +00002139 * Return TRUE when using ":vimgrep" for ":grep".
2140 */
2141 int
Bram Moolenaar81695252004-12-29 20:58:21 +00002142grep_internal(cmdidx)
2143 cmdidx_T cmdidx;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002144{
Bram Moolenaar81695252004-12-29 20:58:21 +00002145 return ((cmdidx == CMD_grep || cmdidx == CMD_grepadd)
Bram Moolenaar86b68352004-12-27 21:59:20 +00002146 && STRCMP("internal",
2147 *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0);
2148}
2149
2150/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 * Used for ":make", ":grep" and ":grepadd".
2152 */
2153 void
2154ex_make(eap)
2155 exarg_T *eap;
2156{
Bram Moolenaar7c626922005-02-07 22:01:03 +00002157 char_u *fname;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 char_u *cmd;
2159 unsigned len;
Bram Moolenaar7c626922005-02-07 22:01:03 +00002160#ifdef FEAT_AUTOCMD
2161 char_u *au_name = NULL;
2162
2163 switch (eap->cmdidx)
2164 {
2165 case CMD_make: au_name = (char_u *)"make"; break;
2166 case CMD_grep: au_name = (char_u *)"grep"; break;
2167 case CMD_grepadd: au_name = (char_u *)"grepadd"; break;
2168 default: break;
2169 }
2170 if (au_name != NULL)
2171 {
2172 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
2173 curbuf->b_fname, TRUE, curbuf);
2174 if (did_throw || force_abort)
2175 return;
2176 }
2177#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178
Bram Moolenaar86b68352004-12-27 21:59:20 +00002179 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
Bram Moolenaar81695252004-12-29 20:58:21 +00002180 if (grep_internal(eap->cmdidx))
Bram Moolenaar86b68352004-12-27 21:59:20 +00002181 {
2182 ex_vimgrep(eap);
2183 return;
2184 }
2185
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 autowrite_all();
Bram Moolenaar7c626922005-02-07 22:01:03 +00002187 fname = get_mef_name();
2188 if (fname == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 return;
Bram Moolenaar7c626922005-02-07 22:01:03 +00002190 mch_remove(fname); /* in case it's not unique */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191
2192 /*
2193 * If 'shellpipe' empty: don't redirect to 'errorfile'.
2194 */
2195 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1;
2196 if (*p_sp != NUL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00002197 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198 cmd = alloc(len);
2199 if (cmd == NULL)
2200 return;
2201 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg,
2202 (char *)p_shq);
2203 if (*p_sp != NUL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00002204 append_redir(cmd, p_sp, fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 /*
2206 * Output a newline if there's something else than the :make command that
2207 * was typed (in which case the cursor is in column 0).
2208 */
2209 if (msg_col == 0)
2210 msg_didout = FALSE;
2211 msg_start();
2212 MSG_PUTS(":!");
2213 msg_outtrans(cmd); /* show what we are doing */
2214
2215 /* let the shell know if we are redirecting output or not */
2216 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0);
2217
2218#ifdef AMIGA
2219 out_flush();
2220 /* read window status report and redraw before message */
2221 (void)char_avail();
2222#endif
2223
Bram Moolenaar7c626922005-02-07 22:01:03 +00002224 if (qf_init(fname, eap->cmdidx != CMD_make ? p_gefm : p_efm,
Bram Moolenaar86b68352004-12-27 21:59:20 +00002225 eap->cmdidx != CMD_grepadd) > 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 && !eap->forceit)
2227 qf_jump(0, 0, FALSE); /* display first error */
2228
Bram Moolenaar7c626922005-02-07 22:01:03 +00002229 mch_remove(fname);
2230 vim_free(fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 vim_free(cmd);
Bram Moolenaar7c626922005-02-07 22:01:03 +00002232
2233#ifdef FEAT_AUTOCMD
2234 if (au_name != NULL)
2235 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
2236 curbuf->b_fname, TRUE, curbuf);
2237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238}
2239
2240/*
2241 * Return the name for the errorfile, in allocated memory.
2242 * Find a new unique name when 'makeef' contains "##".
2243 * Returns NULL for error.
2244 */
2245 static char_u *
2246get_mef_name()
2247{
2248 char_u *p;
2249 char_u *name;
2250 static int start = -1;
2251 static int off = 0;
2252#ifdef HAVE_LSTAT
2253 struct stat sb;
2254#endif
2255
2256 if (*p_mef == NUL)
2257 {
2258 name = vim_tempname('e');
2259 if (name == NULL)
2260 EMSG(_(e_notmp));
2261 return name;
2262 }
2263
2264 for (p = p_mef; *p; ++p)
2265 if (p[0] == '#' && p[1] == '#')
2266 break;
2267
2268 if (*p == NUL)
2269 return vim_strsave(p_mef);
2270
2271 /* Keep trying until the name doesn't exist yet. */
2272 for (;;)
2273 {
2274 if (start == -1)
2275 start = mch_get_pid();
2276 else
2277 off += 19;
2278
2279 name = alloc((unsigned)STRLEN(p_mef) + 30);
2280 if (name == NULL)
2281 break;
2282 STRCPY(name, p_mef);
2283 sprintf((char *)name + (p - p_mef), "%d%d", start, off);
2284 STRCAT(name, p + 2);
2285 if (mch_getperm(name) < 0
2286#ifdef HAVE_LSTAT
2287 /* Don't accept a symbolic link, its a security risk. */
2288 && mch_lstat((char *)name, &sb) < 0
2289#endif
2290 )
2291 break;
2292 vim_free(name);
2293 }
2294 return name;
2295}
2296
2297/*
2298 * ":cc", ":crewind", ":cfirst" and ":clast".
2299 */
2300 void
2301ex_cc(eap)
2302 exarg_T *eap;
2303{
2304 qf_jump(0,
2305 eap->addr_count > 0
2306 ? (int)eap->line2
2307 : eap->cmdidx == CMD_cc
2308 ? 0
2309 : (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_cfirst)
2310 ? 1
2311 : 32767,
2312 eap->forceit);
2313}
2314
2315/*
2316 * ":cnext", ":cnfile", ":cNext" and ":cprevious".
2317 */
2318 void
2319ex_cnext(eap)
2320 exarg_T *eap;
2321{
2322 qf_jump(eap->cmdidx == CMD_cnext
2323 ? FORWARD
2324 : eap->cmdidx == CMD_cnfile
2325 ? FORWARD_FILE
2326 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_cNfile)
2327 ? BACKWARD_FILE
2328 : BACKWARD,
2329 eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit);
2330}
2331
2332/*
2333 * ":cfile" command.
2334 */
2335 void
2336ex_cfile(eap)
2337 exarg_T *eap;
2338{
2339 if (*eap->arg != NUL)
2340 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE);
2341 if (qf_init(p_ef, p_efm, TRUE) > 0 && eap->cmdidx == CMD_cfile)
2342 qf_jump(0, 0, eap->forceit); /* display first error */
2343}
2344
2345/*
Bram Moolenaar86b68352004-12-27 21:59:20 +00002346 * ":vimgrep {pattern} file(s)"
2347 */
2348 void
2349ex_vimgrep(eap)
2350 exarg_T *eap;
2351{
Bram Moolenaar81695252004-12-29 20:58:21 +00002352 regmmatch_T regmatch;
Bram Moolenaar748bf032005-02-02 23:04:36 +00002353 int fcount;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002354 char_u **fnames;
Bram Moolenaar748bf032005-02-02 23:04:36 +00002355 char_u *s;
2356 char_u *p;
Bram Moolenaar748bf032005-02-02 23:04:36 +00002357 int fi;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002358 qfline_T *prevp = NULL;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002359 long lnum;
Bram Moolenaar81695252004-12-29 20:58:21 +00002360 buf_T *buf;
2361 int duplicate_name = FALSE;
2362 int using_dummy;
2363 int found_match;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002364 buf_T *first_match_buf = NULL;
2365 time_t seconds = 0;
2366#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
2367 char_u *save_ei = NULL;
2368 aco_save_T aco;
2369#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002370#ifdef FEAT_AUTOCMD
2371 char_u *au_name = NULL;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002372 int flags = 0;
2373 colnr_T col;
Bram Moolenaar7c626922005-02-07 22:01:03 +00002374
2375 switch (eap->cmdidx)
2376 {
2377 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break;
2378 case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break;
2379 default: break;
2380 }
2381 if (au_name != NULL)
2382 {
2383 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
2384 curbuf->b_fname, TRUE, curbuf);
2385 if (did_throw || force_abort)
2386 return;
2387 }
2388#endif
Bram Moolenaar86b68352004-12-27 21:59:20 +00002389
Bram Moolenaar81695252004-12-29 20:58:21 +00002390 /* Get the search pattern: either white-separated or enclosed in // */
Bram Moolenaar86b68352004-12-27 21:59:20 +00002391 regmatch.regprog = NULL;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002392 p = skip_vimgrep_pat(eap->arg, &s, &flags);
Bram Moolenaar748bf032005-02-02 23:04:36 +00002393 if (p == NULL)
Bram Moolenaar86b68352004-12-27 21:59:20 +00002394 {
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00002395 EMSG(_(e_invalpat));
Bram Moolenaar748bf032005-02-02 23:04:36 +00002396 goto theend;
Bram Moolenaar81695252004-12-29 20:58:21 +00002397 }
Bram Moolenaar81695252004-12-29 20:58:21 +00002398 regmatch.regprog = vim_regcomp(s, RE_MAGIC);
Bram Moolenaar86b68352004-12-27 21:59:20 +00002399 if (regmatch.regprog == NULL)
2400 goto theend;
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00002401 regmatch.rmm_ic = p_ic;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002402 regmatch.rmm_maxcol = 0;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002403
2404 p = skipwhite(p);
2405 if (*p == NUL)
2406 {
2407 EMSG(_("E683: File name missing or invalid pattern"));
2408 goto theend;
2409 }
2410
2411 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_vimgrepadd)
2412 || qf_curlist == qf_listcount)
2413 /* make place for a new list */
2414 qf_new_list();
2415 else if (qf_lists[qf_curlist].qf_count > 0)
2416 /* Adding to existing list, find last entry. */
2417 for (prevp = qf_lists[qf_curlist].qf_start;
2418 prevp->qf_next != prevp; prevp = prevp->qf_next)
2419 ;
2420
2421 /* parse the list of arguments */
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00002422 if (get_arglist_exp(p, &fcount, &fnames) == FAIL)
Bram Moolenaar86b68352004-12-27 21:59:20 +00002423 goto theend;
2424 if (fcount == 0)
2425 {
2426 EMSG(_(e_nomatch));
2427 goto theend;
2428 }
2429
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002430 seconds = (time_t)0;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002431 for (fi = 0; fi < fcount && !got_int; ++fi)
2432 {
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002433 if (time(NULL) > seconds)
2434 {
2435 /* Display the file name every second or so. */
2436 seconds = time(NULL);
2437 msg_start();
2438 p = msg_strtrunc(fnames[fi]);
2439 if (p == NULL)
2440 msg_outtrans(fnames[fi]);
2441 else
2442 {
2443 msg_outtrans(p);
2444 vim_free(p);
2445 }
2446 msg_clr_eos();
2447 msg_didout = FALSE; /* overwrite this message */
2448 msg_nowait = TRUE; /* don't wait for this message */
2449 msg_col = 0;
2450 out_flush();
2451 }
2452
Bram Moolenaar81695252004-12-29 20:58:21 +00002453 buf = buflist_findname_exp(fnames[fi]);
2454 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
2455 {
2456 /* Remember that a buffer with this name already exists. */
2457 duplicate_name = (buf != NULL);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002458 using_dummy = TRUE;
2459
2460#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
2461 /* Don't do Filetype autocommands to avoid loading syntax and
2462 * indent scripts, a great speed improvement. */
2463 save_ei = au_event_disable(",Filetype");
2464#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00002465
2466 /* Load file into a buffer, so that 'fileencoding' is detected,
2467 * autocommands applied, etc. */
2468 buf = load_dummy_buffer(fnames[fi]);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002469
2470#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
2471 au_event_restore(save_ei);
2472#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00002473 }
2474 else
2475 /* Use existing, loaded buffer. */
2476 using_dummy = FALSE;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002477
Bram Moolenaar81695252004-12-29 20:58:21 +00002478 if (buf == NULL)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002479 {
2480 if (!got_int)
2481 smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]);
2482 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00002483 else
2484 {
Bram Moolenaar81695252004-12-29 20:58:21 +00002485 found_match = FALSE;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002486 /* Try for a match in all lines of the buffer. */
Bram Moolenaar81695252004-12-29 20:58:21 +00002487 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
Bram Moolenaar86b68352004-12-27 21:59:20 +00002488 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002489 /* For ":1vimgrep" look for multiple matches. */
2490 col = 0;
2491 while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
2492 col) > 0)
Bram Moolenaar86b68352004-12-27 21:59:20 +00002493 {
Bram Moolenaar86b68352004-12-27 21:59:20 +00002494 if (qf_add_entry(&prevp,
2495 NULL, /* dir */
2496 fnames[fi],
Bram Moolenaar81695252004-12-29 20:58:21 +00002497 ml_get_buf(buf,
2498 regmatch.startpos[0].lnum + lnum, FALSE),
2499 regmatch.startpos[0].lnum + lnum,
2500 regmatch.startpos[0].col + 1,
Bram Moolenaar05159a02005-02-26 23:04:13 +00002501 FALSE, /* vis_col */
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002502 NULL, /* search pattern */
Bram Moolenaar86b68352004-12-27 21:59:20 +00002503 0, /* nr */
2504 0, /* type */
2505 TRUE /* valid */
2506 ) == FAIL)
2507 {
2508 got_int = TRUE;
2509 break;
2510 }
Bram Moolenaar81695252004-12-29 20:58:21 +00002511 else
2512 found_match = TRUE;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002513 if ((flags & VGR_GLOBAL) == 0
2514 || regmatch.endpos[0].lnum > 0)
2515 break;
2516 col = regmatch.endpos[0].col
2517 + (col == regmatch.endpos[0].col);
2518 if (col > STRLEN(ml_get_buf(buf, lnum, FALSE)))
2519 break;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002520 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00002521 line_breakcheck();
Bram Moolenaar81695252004-12-29 20:58:21 +00002522 if (got_int)
2523 break;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002524 }
Bram Moolenaar81695252004-12-29 20:58:21 +00002525
2526 if (using_dummy)
2527 {
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002528 if (found_match && first_match_buf == NULL)
2529 first_match_buf = buf;
Bram Moolenaar81695252004-12-29 20:58:21 +00002530 if (duplicate_name)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002531 {
Bram Moolenaar81695252004-12-29 20:58:21 +00002532 /* Never keep a dummy buffer if there is another buffer
2533 * with the same name. */
2534 wipe_dummy_buffer(buf);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002535 buf = NULL;
2536 }
Bram Moolenaar81695252004-12-29 20:58:21 +00002537 else if (!buf_hide(buf))
2538 {
2539 /* When not hiding the buffer and no match was found we
2540 * don't need to remember the buffer, wipe it out. If
Bram Moolenaar05159a02005-02-26 23:04:13 +00002541 * there was a match and it wasn't the first one or we
2542 * won't jump there: only unload the buffer. */
Bram Moolenaar81695252004-12-29 20:58:21 +00002543 if (!found_match)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002544 {
Bram Moolenaar81695252004-12-29 20:58:21 +00002545 wipe_dummy_buffer(buf);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002546 buf = NULL;
2547 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002548 else if (buf != first_match_buf || (flags & VGR_NOJUMP))
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002549 {
Bram Moolenaar81695252004-12-29 20:58:21 +00002550 unload_dummy_buffer(buf);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002551 buf = NULL;
2552 }
Bram Moolenaar81695252004-12-29 20:58:21 +00002553 }
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002554
2555#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
2556 if (buf != NULL)
2557 {
2558 /* The buffer is still loaded, the Filetype autocommands
Bram Moolenaar748bf032005-02-02 23:04:36 +00002559 * need to be done now, in that buffer. And then the
Bram Moolenaar8cd06ca2005-02-28 22:44:58 +00002560 * modelines need to be done (again). */
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002561 aucmd_prepbuf(&aco, buf);
2562 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft,
2563 buf->b_fname, TRUE, buf);
Bram Moolenaar748bf032005-02-02 23:04:36 +00002564 do_modelines(FALSE);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002565 aucmd_restbuf(&aco);
2566 }
2567#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00002568 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00002569 }
2570 }
2571
2572 FreeWild(fcount, fnames);
2573
2574 qf_lists[qf_curlist].qf_nonevalid = FALSE;
2575 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start;
2576 qf_lists[qf_curlist].qf_index = 1;
2577
2578#ifdef FEAT_WINDOWS
2579 qf_update_buffer();
2580#endif
2581
2582 /* Jump to first match. */
2583 if (qf_lists[qf_curlist].qf_count > 0)
Bram Moolenaar05159a02005-02-26 23:04:13 +00002584 {
2585 if ((flags & VGR_NOJUMP) == 0)
2586 qf_jump(0, 0, eap->forceit);
2587 }
Bram Moolenaar81695252004-12-29 20:58:21 +00002588 else
2589 EMSG2(_(e_nomatch2), s);
Bram Moolenaar86b68352004-12-27 21:59:20 +00002590
Bram Moolenaar7c626922005-02-07 22:01:03 +00002591#ifdef FEAT_AUTOCMD
2592 if (au_name != NULL)
2593 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
2594 curbuf->b_fname, TRUE, curbuf);
2595#endif
2596
Bram Moolenaar86b68352004-12-27 21:59:20 +00002597theend:
2598 vim_free(regmatch.regprog);
Bram Moolenaar86b68352004-12-27 21:59:20 +00002599}
2600
2601/*
Bram Moolenaar05159a02005-02-26 23:04:13 +00002602 * Skip over the pattern argument of ":vimgrep /pat/[g][j]".
Bram Moolenaar748bf032005-02-02 23:04:36 +00002603 * Put the start of the pattern in "*s", unless "s" is NULL.
Bram Moolenaar05159a02005-02-26 23:04:13 +00002604 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP.
2605 * If "s" is not NULL terminate the pattern with a NUL.
2606 * Return a pointer to the char just past the pattern plus flags.
Bram Moolenaar748bf032005-02-02 23:04:36 +00002607 */
2608 char_u *
Bram Moolenaar05159a02005-02-26 23:04:13 +00002609skip_vimgrep_pat(p, s, flags)
2610 char_u *p;
2611 char_u **s;
2612 int *flags;
Bram Moolenaar748bf032005-02-02 23:04:36 +00002613{
2614 int c;
2615
2616 if (vim_isIDc(*p))
2617 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002618 /* ":vimgrep pattern fname" */
Bram Moolenaar748bf032005-02-02 23:04:36 +00002619 if (s != NULL)
2620 *s = p;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002621 p = skiptowhite(p);
2622 if (s != NULL && *p != NUL)
2623 *p++ = NUL;
Bram Moolenaar748bf032005-02-02 23:04:36 +00002624 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002625 else
2626 {
2627 /* ":vimgrep /pattern/[g][j] fname" */
2628 if (s != NULL)
2629 *s = p + 1;
2630 c = *p;
2631 p = skip_regexp(p + 1, c, TRUE, NULL);
2632 if (*p != c)
2633 return NULL;
2634
2635 /* Truncate the pattern. */
2636 if (s != NULL)
2637 *p = NUL;
2638 ++p;
2639
2640 /* Find the flags */
2641 while (*p == 'g' || *p == 'j')
2642 {
2643 if (flags != NULL)
2644 {
2645 if (*p == 'g')
2646 *flags |= VGR_GLOBAL;
2647 else
2648 *flags |= VGR_NOJUMP;
2649 }
2650 ++p;
2651 }
2652 }
Bram Moolenaar748bf032005-02-02 23:04:36 +00002653 return p;
2654}
2655
2656/*
Bram Moolenaar81695252004-12-29 20:58:21 +00002657 * Load file "fname" into a dummy buffer and return the buffer pointer.
2658 * Returns NULL if it fails.
2659 * Must call unload_dummy_buffer() or wipe_dummy_buffer() later!
2660 */
2661 static buf_T *
2662load_dummy_buffer(fname)
2663 char_u *fname;
2664{
2665 buf_T *newbuf;
2666 int failed = TRUE;
2667#ifdef FEAT_AUTOCMD
2668 aco_save_T aco;
2669#else
2670 buf_T *old_curbuf = curbuf;
2671#endif
2672
2673 /* Allocate a buffer without putting it in the buffer list. */
2674 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
2675 if (newbuf == NULL)
2676 return NULL;
2677
Bram Moolenaar8cd06ca2005-02-28 22:44:58 +00002678 /* Init the options. */
2679 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP);
2680
Bram Moolenaar81695252004-12-29 20:58:21 +00002681#ifdef FEAT_AUTOCMD
2682 /* set curwin/curbuf to buf and save a few things */
2683 aucmd_prepbuf(&aco, newbuf);
2684#else
2685 curbuf = newbuf;
2686 curwin->w_buffer = newbuf;
2687#endif
2688
2689 /* Need to set the filename for autocommands. */
2690 (void)setfname(curbuf, fname, NULL, FALSE);
2691
2692 if (ml_open() == OK)
2693 {
2694 /* Create swap file now to avoid the ATTENTION message. */
2695 check_need_swap(TRUE);
2696
2697 /* Remove the "dummy" flag, otherwise autocommands may not
2698 * work. */
2699 curbuf->b_flags &= ~BF_DUMMY;
2700
2701 if (readfile(fname, NULL,
2702 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
2703 NULL, READ_NEW | READ_DUMMY) == OK
2704 && !(curbuf->b_flags & BF_NEW))
2705 {
2706 failed = FALSE;
2707 if (curbuf != newbuf)
2708 {
2709 /* Bloody autocommands changed the buffer! */
2710 if (buf_valid(newbuf))
2711 wipe_buffer(newbuf, FALSE);
2712 newbuf = curbuf;
2713 }
2714 }
2715 }
2716
2717#ifdef FEAT_AUTOCMD
2718 /* restore curwin/curbuf and a few other things */
2719 aucmd_restbuf(&aco);
2720#else
2721 curbuf = old_curbuf;
2722 curwin->w_buffer = old_curbuf;
2723#endif
2724
2725 if (!buf_valid(newbuf))
2726 return NULL;
2727 if (failed)
2728 {
2729 wipe_dummy_buffer(newbuf);
2730 return NULL;
2731 }
2732 return newbuf;
2733}
2734
2735/*
2736 * Wipe out the dummy buffer that load_dummy_buffer() created.
2737 */
2738 static void
2739wipe_dummy_buffer(buf)
2740 buf_T *buf;
2741{
2742 if (curbuf != buf) /* safety check */
2743 wipe_buffer(buf, FALSE);
2744}
2745
2746/*
2747 * Unload the dummy buffer that load_dummy_buffer() created.
2748 */
2749 static void
2750unload_dummy_buffer(buf)
2751 buf_T *buf;
2752{
2753 if (curbuf != buf) /* safety check */
2754 close_buffer(NULL, buf, DOBUF_UNLOAD);
2755}
2756
Bram Moolenaar05159a02005-02-26 23:04:13 +00002757#if defined(FEAT_EVAL) || defined(PROTO)
2758/*
2759 * Add each quickfix error to list "list" as a dictionary.
2760 */
2761 int
2762get_errorlist(list)
2763 list_T *list;
2764{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002765 dict_T *dict;
2766 char_u buf[2];
2767 qfline_T *qfp;
2768 int i;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002769
2770 if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0)
2771 {
2772 EMSG(_(e_quickfix));
2773 return FAIL;
2774 }
2775
2776 qfp = qf_lists[qf_curlist].qf_start;
2777 for (i = 1; !got_int && i <= qf_lists[qf_curlist].qf_count; ++i)
2778 {
2779 if ((dict = dict_alloc()) == NULL)
2780 return FAIL;
2781 if (list_append_dict(list, dict) == FAIL)
2782 return FAIL;
2783
2784 buf[0] = qfp->qf_type;
2785 buf[1] = NUL;
2786 if ( dict_add_nr_str(dict, "bufnr", (long)qfp->qf_fnum, NULL) == FAIL
2787 || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL
2788 || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL
2789 || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL
2790 || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002791 || dict_add_nr_str(dict, "pattern", 0L, qfp->qf_pattern) == FAIL
Bram Moolenaar05159a02005-02-26 23:04:13 +00002792 || dict_add_nr_str(dict, "text", 0L, qfp->qf_text) == FAIL
2793 || dict_add_nr_str(dict, "type", 0L, buf) == FAIL
2794 || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL)
2795 return FAIL;
2796
2797 qfp = qfp->qf_next;
2798 }
2799 return OK;
2800}
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002801
2802/*
2803 * Populate the quickfix list with the items supplied in the list
2804 * of dictionaries.
2805 */
2806 int
Bram Moolenaar35c54e52005-05-20 21:25:31 +00002807set_errorlist(list, action)
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002808 list_T *list;
Bram Moolenaar35c54e52005-05-20 21:25:31 +00002809 int action;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002810{
2811 listitem_T *li;
2812 dict_T *d;
2813 char_u *filename, *pattern, *text, *type;
2814 long lnum;
2815 int col, nr;
2816 int vcol;
2817 qfline_T *prevp = NULL;
2818 int valid, status;
2819 int retval = OK;
2820
Bram Moolenaar35c54e52005-05-20 21:25:31 +00002821 if (action == ' ' || qf_curlist == qf_listcount)
2822 /* make place for a new list */
2823 qf_new_list();
2824 else if (action == 'a' && qf_lists[qf_curlist].qf_count > 0)
2825 /* Adding to existing list, find last entry. */
2826 for (prevp = qf_lists[qf_curlist].qf_start;
2827 prevp->qf_next != prevp; prevp = prevp->qf_next)
2828 ;
2829 else if (action == 'r')
2830 qf_free(qf_curlist);
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002831
2832 for (li = list->lv_first; li != NULL; li = li->li_next)
2833 {
2834 if (li->li_tv.v_type != VAR_DICT)
2835 continue; /* Skip non-dict items */
2836
2837 d = li->li_tv.vval.v_dict;
2838 if (d == NULL)
2839 continue;
2840
2841 filename = get_dict_string(d, (char_u *)"filename");
2842 lnum = get_dict_number(d, (char_u *)"lnum");
2843 col = get_dict_number(d, (char_u *)"col");
2844 vcol = get_dict_number(d, (char_u *)"vcol");
2845 nr = get_dict_number(d, (char_u *)"nr");
2846 type = get_dict_string(d, (char_u *)"type");
2847 pattern = get_dict_string(d, (char_u *)"pattern");
2848 text = get_dict_string(d, (char_u *)"text");
2849 if (text == NULL)
2850 text = vim_strsave((char_u *)"");
2851
2852 valid = TRUE;
2853 if (filename == NULL || (lnum == 0 && pattern == NULL))
2854 valid = FALSE;
2855
2856 status = qf_add_entry(&prevp,
2857 NULL, /* dir */
2858 filename,
2859 text,
2860 lnum,
2861 col,
2862 vcol, /* vis_col */
2863 pattern, /* search pattern */
2864 nr,
2865 type == NULL ? NUL : *type,
2866 valid);
2867
2868 vim_free(filename);
2869 vim_free(pattern);
2870 vim_free(text);
2871 vim_free(type);
2872
2873 if (status == FAIL)
2874 {
2875 retval = FAIL;
2876 break;
2877 }
2878 }
2879
2880 qf_lists[qf_curlist].qf_nonevalid = FALSE;
2881 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start;
2882 qf_lists[qf_curlist].qf_index = 1;
2883
2884#ifdef FEAT_WINDOWS
2885 qf_update_buffer();
2886#endif
2887
2888 return retval;
2889}
Bram Moolenaar05159a02005-02-26 23:04:13 +00002890#endif
2891
Bram Moolenaar81695252004-12-29 20:58:21 +00002892/*
Bram Moolenaar86b68352004-12-27 21:59:20 +00002893 * ":[range]cbuffer [bufnr]" command.
2894 */
2895 void
2896ex_cbuffer(eap)
2897 exarg_T *eap;
2898{
2899 buf_T *buf = NULL;
2900
2901 if (*eap->arg == NUL)
2902 buf = curbuf;
2903 else if (*skipwhite(skipdigits(eap->arg)) == NUL)
2904 buf = buflist_findnr(atoi((char *)eap->arg));
2905 if (buf == NULL)
2906 EMSG(_(e_invarg));
2907 else if (buf->b_ml.ml_mfp == NULL)
2908 EMSG(_("E681: Buffer is not loaded"));
2909 else
2910 {
2911 if (eap->addr_count == 0)
2912 {
2913 eap->line1 = 1;
2914 eap->line2 = buf->b_ml.ml_line_count;
2915 }
2916 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count
2917 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count)
2918 EMSG(_(e_invrange));
2919 else
2920 qf_init_ext(NULL, buf, p_efm, TRUE, eap->line1, eap->line2);
2921 }
2922}
2923
2924/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 * ":helpgrep {pattern}"
2926 */
2927 void
2928ex_helpgrep(eap)
2929 exarg_T *eap;
2930{
2931 regmatch_T regmatch;
2932 char_u *save_cpo;
2933 char_u *p;
2934 int fcount;
2935 char_u **fnames;
2936 FILE *fd;
2937 int fi;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002938 qfline_T *prevp = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 long lnum;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002940#ifdef FEAT_MULTI_LANG
2941 char_u *lang;
2942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943
2944 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
2945 save_cpo = p_cpo;
2946 p_cpo = (char_u *)"";
2947
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002948#ifdef FEAT_MULTI_LANG
2949 /* Check for a specified language */
2950 lang = check_help_lang(eap->arg);
2951#endif
2952
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING);
2954 regmatch.rm_ic = FALSE;
2955 if (regmatch.regprog != NULL)
2956 {
2957 /* create a new quickfix list */
2958 qf_new_list();
2959
2960 /* Go through all directories in 'runtimepath' */
2961 p = p_rtp;
2962 while (*p != NUL && !got_int)
2963 {
2964 copy_option_part(&p, NameBuff, MAXPATHL, ",");
2965
2966 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */
2967 add_pathsep(NameBuff);
2968 STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)");
2969 if (gen_expand_wildcards(1, &NameBuff, &fcount,
2970 &fnames, EW_FILE|EW_SILENT) == OK
2971 && fcount > 0)
2972 {
2973 for (fi = 0; fi < fcount && !got_int; ++fi)
2974 {
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002975#ifdef FEAT_MULTI_LANG
2976 /* Skip files for a different language. */
2977 if (lang != NULL
2978 && STRNICMP(lang, fnames[fi]
2979 + STRLEN(fnames[fi]) - 3, 2) != 0
2980 && !(STRNICMP(lang, "en", 2) == 0
2981 && STRNICMP("txt", fnames[fi]
2982 + STRLEN(fnames[fi]) - 3, 3) == 0))
2983 continue;
2984#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 fd = fopen((char *)fnames[fi], "r");
2986 if (fd != NULL)
2987 {
2988 lnum = 1;
2989 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
2990 {
2991 if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
2992 {
2993 int l = STRLEN(IObuff);
2994
2995 /* remove trailing CR, LF, spaces, etc. */
2996 while (l > 0 && IObuff[l - 1] <= ' ')
2997 IObuff[--l] = NUL;
2998
2999 if (qf_add_entry(&prevp,
3000 NULL, /* dir */
3001 fnames[fi],
3002 IObuff,
3003 lnum,
Bram Moolenaar81695252004-12-29 20:58:21 +00003004 (int)(regmatch.startp[0] - IObuff)
3005 + 1, /* col */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003006 FALSE, /* vis_col */
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003007 NULL, /* search pattern */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 0, /* nr */
3009 1, /* type */
3010 TRUE /* valid */
3011 ) == FAIL)
3012 {
3013 got_int = TRUE;
3014 break;
3015 }
3016 }
3017 ++lnum;
3018 line_breakcheck();
3019 }
3020 fclose(fd);
3021 }
3022 }
3023 FreeWild(fcount, fnames);
3024 }
3025 }
3026 vim_free(regmatch.regprog);
3027
3028 qf_lists[qf_curlist].qf_nonevalid = FALSE;
3029 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start;
3030 qf_lists[qf_curlist].qf_index = 1;
3031 }
3032
3033 p_cpo = save_cpo;
3034
3035#ifdef FEAT_WINDOWS
3036 qf_update_buffer();
3037#endif
3038
3039 /* Jump to first match. */
3040 if (qf_lists[qf_curlist].qf_count > 0)
3041 qf_jump(0, 0, FALSE);
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003042 else
3043 EMSG2(_(e_nomatch2), eap->arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044}
3045
3046#endif /* FEAT_QUICKFIX */