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