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