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