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