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