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