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