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