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