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