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