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