1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
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.
11 * quickfix.c: functions for quickfix mode, using a file with error messages
16 #if defined(FEAT_QUICKFIX) || defined(PROTO)
20 struct dir_stack_T
*next
;
24 static struct dir_stack_T
*dir_stack
= NULL
;
27 * For each error the next struct is allocated and linked in a list.
29 typedef struct qfline_S qfline_T
;
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
44 char_u qf_valid
; /* valid error message detected */
48 * There is a stack of error lists.
52 typedef struct qf_list_S
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 */
64 * Count of references to this list. Used only for location lists.
65 * When a location list window reference this list, qf_refcount
66 * will be 2. Otherwise, qf_refcount will be 1. When qf_refcount
67 * reaches 0, the list is freed.
70 int qf_listcount
; /* current number of lists */
71 int qf_curlist
; /* current error list */
72 qf_list_T qf_lists
[LISTCOUNT
];
75 static qf_info_T ql_info
; /* global quickfix list */
77 #define FMT_PATTERNS 10 /* maximum number of % recognized */
80 * Structure used to hold the info of one part of 'errorformat'
82 typedef struct efm_S efm_T
;
85 regprog_T
*prog
; /* pre-formatted part of 'errorformat' */
86 efm_T
*next
; /* pointer to next (NULL if last) */
87 char_u addr
[FMT_PATTERNS
]; /* indices of used % patterns */
88 char_u prefix
; /* prefix of this format line: */
89 /* 'D' enter directory */
90 /* 'X' leave directory */
91 /* 'A' start of multi-line message */
92 /* 'E' error message */
93 /* 'W' warning message */
94 /* 'I' informational message */
95 /* 'C' continuation line */
96 /* 'Z' end of multi-line message */
97 /* 'G' general, unspecific message */
98 /* 'P' push file (partial) message */
99 /* 'Q' pop/quit file (partial) message */
100 /* 'O' overread (partial) message */
101 char_u flags
; /* additional flags given in prefix */
102 /* '-' do not include this line */
103 /* '+' include whole line in message */
104 int conthere
; /* %> used */
107 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
));
108 static void qf_new_list
__ARGS((qf_info_T
*qi
));
109 static void ll_free_all
__ARGS((qf_info_T
**pqi
));
110 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
));
111 static qf_info_T
*ll_new_list
__ARGS((void));
112 static void qf_msg
__ARGS((qf_info_T
*qi
));
113 static void qf_free
__ARGS((qf_info_T
*qi
, int idx
));
114 static char_u
*qf_types
__ARGS((int, int));
115 static int qf_get_fnum
__ARGS((char_u
*, char_u
*));
116 static char_u
*qf_push_dir
__ARGS((char_u
*, struct dir_stack_T
**));
117 static char_u
*qf_pop_dir
__ARGS((struct dir_stack_T
**));
118 static char_u
*qf_guess_filepath
__ARGS((char_u
*));
119 static void qf_fmt_text
__ARGS((char_u
*text
, char_u
*buf
, int bufsize
));
120 static void qf_clean_dir_stack
__ARGS((struct dir_stack_T
**));
122 static int qf_win_pos_update
__ARGS((qf_info_T
*qi
, int old_qf_index
));
123 static int is_qf_win
__ARGS((win_T
*win
, qf_info_T
*qi
));
124 static win_T
*qf_find_win
__ARGS((qf_info_T
*qi
));
125 static buf_T
*qf_find_buf
__ARGS((qf_info_T
*qi
));
126 static void qf_update_buffer
__ARGS((qf_info_T
*qi
));
127 static void qf_fill_buffer
__ARGS((qf_info_T
*qi
));
129 static char_u
*get_mef_name
__ARGS((void));
130 static buf_T
*load_dummy_buffer
__ARGS((char_u
*fname
));
131 static void wipe_dummy_buffer
__ARGS((buf_T
*buf
));
132 static void unload_dummy_buffer
__ARGS((buf_T
*buf
));
133 static qf_info_T
*ll_get_or_alloc_list
__ARGS((win_T
*));
135 /* Quickfix window check helper macro */
136 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL)
137 /* Location list window check helper macro */
138 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
140 * Return location list for window 'wp'
141 * For location list window, return the referenced location list
143 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist)
146 * Read the errorfile "efile" into memory, line by line, building the error
148 * Return -1 for error, number of errors for success.
151 qf_init(wp
, efile
, errorformat
, newlist
)
155 int newlist
; /* TRUE: start a new error list */
157 qf_info_T
*qi
= &ql_info
;
164 qi
= ll_get_or_alloc_list(wp
);
169 return qf_init_ext(qi
, efile
, curbuf
, NULL
, errorformat
, newlist
,
170 (linenr_T
)0, (linenr_T
)0);
174 * Read the errorfile "efile" into memory, line by line, building the error
176 * Alternative: when "efile" is null read errors from buffer "buf".
177 * Always use 'errorformat' from "buf" if there is a local value.
178 * Then lnumfirst and lnumlast specify the range of lines to use.
179 * Return -1 for error, number of errors for success.
182 qf_init_ext(qi
, efile
, buf
, tv
, errorformat
, newlist
, lnumfirst
, lnumlast
)
188 int newlist
; /* TRUE: start a new error list */
189 linenr_T lnumfirst
; /* first line number to use */
190 linenr_T lnumlast
; /* last line number to use */
195 char_u
*fmtstr
= NULL
;
197 char_u use_viscol
= FALSE
;
200 linenr_T buflnum
= lnumfirst
;
204 qfline_T
*qfprev
= NULL
; /* init to make SASC shut up */
206 efm_T
*fmt_first
= NULL
;
207 efm_T
*fmt_last
= NULL
;
209 efm_T
*fmt_start
= NULL
;
217 int multiline
= FALSE
;
218 int multiignore
= FALSE
;
219 int multiscan
= FALSE
;
220 int retval
= -1; /* default: return error flag */
221 char_u
*directory
= NULL
;
222 char_u
*currfile
= NULL
;
224 char_u
*p_str
= NULL
;
225 listitem_T
*p_li
= NULL
;
226 struct dir_stack_T
*file_stack
= NULL
;
228 static struct fmtpattern
232 } fmt_pat
[FMT_PATTERNS
] =
234 {'f', ".\\+"}, /* only used when at end */
246 namebuf
= alloc(CMDBUFFSIZE
+ 1);
247 errmsg
= alloc(CMDBUFFSIZE
+ 1);
248 pattern
= alloc(CMDBUFFSIZE
+ 1);
249 if (namebuf
== NULL
|| errmsg
== NULL
|| pattern
== NULL
)
252 if (efile
!= NULL
&& (fd
= mch_fopen((char *)efile
, "r")) == NULL
)
254 EMSG2(_(e_openerrf
), efile
);
258 if (newlist
|| qi
->qf_curlist
== qi
->qf_listcount
)
259 /* make place for a new list */
261 else if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
262 /* Adding to existing list, find last entry. */
263 for (qfprev
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
264 qfprev
->qf_next
!= qfprev
; qfprev
= qfprev
->qf_next
)
268 * Each part of the format string is copied and modified from errorformat to
269 * regex prog. Only a few % characters are allowed.
271 /* Use the local value of 'errorformat' if it's set. */
272 if (errorformat
== p_efm
&& tv
== NULL
&& *buf
->b_p_efm
!= NUL
)
277 * Get some space to modify the format string into.
279 i
= (FMT_PATTERNS
* 3) + ((int)STRLEN(efm
) << 2);
280 for (round
= FMT_PATTERNS
; round
> 0; )
281 i
+= (int)STRLEN(fmt_pat
[--round
].pattern
);
282 #ifdef COLON_IN_FILENAME
283 i
+= 12; /* "%f" can become twelve chars longer */
285 i
+= 2; /* "%f" can become two chars longer */
287 if ((fmtstr
= alloc(i
)) == NULL
)
290 while (efm
[0] != NUL
)
293 * Allocate a new eformat structure and put it at the end of the list
295 fmt_ptr
= (efm_T
*)alloc_clear((unsigned)sizeof(efm_T
));
298 if (fmt_first
== NULL
) /* first one */
301 fmt_last
->next
= fmt_ptr
;
305 * Isolate one part in the 'errorformat' option
307 for (len
= 0; efm
[len
] != NUL
&& efm
[len
] != ','; ++len
)
308 if (efm
[len
] == '\\' && efm
[len
+ 1] != NUL
)
312 * Build regexp pattern from current 'errorformat' option
317 for (efmp
= efm
; efmp
< efm
+ len
; ++efmp
)
322 for (idx
= 0; idx
< FMT_PATTERNS
; ++idx
)
323 if (fmt_pat
[idx
].convchar
== *efmp
)
325 if (idx
< FMT_PATTERNS
)
327 if (fmt_ptr
->addr
[idx
])
329 sprintf((char *)errmsg
,
330 _("E372: Too many %%%c in format string"), *efmp
);
336 && vim_strchr((char_u
*)"DXOPQ",
337 fmt_ptr
->prefix
) != NULL
)
339 && vim_strchr((char_u
*)"OPQ",
340 fmt_ptr
->prefix
) == NULL
))
342 sprintf((char *)errmsg
,
343 _("E373: Unexpected %%%c in format string"), *efmp
);
347 fmt_ptr
->addr
[idx
] = (char_u
)++round
;
350 #ifdef BACKSLASH_IN_FILENAME
353 /* Also match "c:" in the file name, even when
354 * checking for a colon next: "%f:".
356 STRCPY(ptr
, "\\%(\\a:\\)\\=");
360 if (*efmp
== 'f' && efmp
[1] != NUL
)
362 if (efmp
[1] != '\\' && efmp
[1] != '%')
364 /* A file name may contain spaces, but this isn't
365 * in "\f". For "%f:%l:%m" there may be a ":" in
366 * the file name. Use ".\{-1,}x" instead (x is
367 * the next character), the requirement that :999:
368 * follows should work. */
369 STRCPY(ptr
, ".\\{-1,}");
374 /* File name followed by '\\' or '%': include as
375 * many file name chars as possible. */
376 STRCPY(ptr
, "\\f\\+");
382 srcptr
= (char_u
*)fmt_pat
[idx
].pattern
;
383 while ((*ptr
= *srcptr
++) != NUL
)
389 else if (*efmp
== '*')
391 if (*++efmp
== '[' || *efmp
== '\\')
393 if ((*ptr
++ = *efmp
) == '[') /* %*[^a-z0-9] etc. */
397 if (efmp
< efm
+ len
)
399 *ptr
++ = *++efmp
; /* could be ']' */
400 while (efmp
< efm
+ len
401 && (*ptr
++ = *++efmp
) != ']')
403 if (efmp
== efm
+ len
)
405 EMSG(_("E374: Missing ] in format string"));
410 else if (efmp
< efm
+ len
) /* %*\D, %*\s etc. */
417 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */
418 sprintf((char *)errmsg
,
419 _("E375: Unsupported %%%c in format string"), *efmp
);
424 else if (vim_strchr((char_u
*)"%\\.^$~[", *efmp
) != NULL
)
425 *ptr
++ = *efmp
; /* regexp magic characters */
426 else if (*efmp
== '#')
428 else if (*efmp
== '>')
429 fmt_ptr
->conthere
= TRUE
;
430 else if (efmp
== efm
+ 1) /* analyse prefix */
432 if (vim_strchr((char_u
*)"+-", *efmp
) != NULL
)
433 fmt_ptr
->flags
= *efmp
++;
434 if (vim_strchr((char_u
*)"DXAEWICZGOPQ", *efmp
) != NULL
)
435 fmt_ptr
->prefix
= *efmp
;
438 sprintf((char *)errmsg
,
439 _("E376: Invalid %%%c in format string prefix"), *efmp
);
446 sprintf((char *)errmsg
,
447 _("E377: Invalid %%%c in format string"), *efmp
);
452 else /* copy normal character */
454 if (*efmp
== '\\' && efmp
+ 1 < efm
+ len
)
456 else if (vim_strchr((char_u
*)".*^$~[", *efmp
) != NULL
)
457 *ptr
++ = '\\'; /* escape regexp atoms */
464 if ((fmt_ptr
->prog
= vim_regcomp(fmtstr
, RE_MAGIC
+ RE_STRING
)) == NULL
)
467 * Advance to next part
469 efm
= skip_to_option_part(efm
+ len
); /* skip comma and spaces */
471 if (fmt_first
== NULL
) /* nothing found */
473 EMSG(_("E378: 'errorformat' contains no pattern"));
478 * got_int is reset here, because it was probably set when killing the
479 * ":make" command, but we still want to read the errorfile then.
483 /* Always ignore case when looking for a matching error. */
484 regmatch
.rm_ic
= TRUE
;
488 if (tv
->v_type
== VAR_STRING
)
489 p_str
= tv
->vval
.v_string
;
490 else if (tv
->v_type
== VAR_LIST
)
491 p_li
= tv
->vval
.v_list
->lv_first
;
495 * Read the lines in the error file one by one.
496 * Try to recognize one of the error formats in each line.
500 /* Get the next line. */
505 if (tv
->v_type
== VAR_STRING
)
507 /* Get the next line from the supplied string */
510 if (!*p_str
) /* Reached the end of the string */
513 p
= vim_strchr(p_str
, '\n');
515 len
= (int)(p
- p_str
+ 1);
517 len
= (int)STRLEN(p_str
);
519 if (len
> CMDBUFFSIZE
- 2)
520 vim_strncpy(IObuff
, p_str
, CMDBUFFSIZE
- 2);
522 vim_strncpy(IObuff
, p_str
, len
);
526 else if (tv
->v_type
== VAR_LIST
)
528 /* Get the next line from the supplied list */
529 while (p_li
&& p_li
->li_tv
.v_type
!= VAR_STRING
)
530 p_li
= p_li
->li_next
; /* Skip non-string items */
532 if (!p_li
) /* End of the list */
535 len
= (int)STRLEN(p_li
->li_tv
.vval
.v_string
);
536 if (len
> CMDBUFFSIZE
- 2)
537 len
= CMDBUFFSIZE
- 2;
539 vim_strncpy(IObuff
, p_li
->li_tv
.vval
.v_string
, len
);
541 p_li
= p_li
->li_next
; /* next item */
546 /* Get the next line from the supplied buffer */
547 if (buflnum
> lnumlast
)
549 vim_strncpy(IObuff
, ml_get_buf(buf
, buflnum
++, FALSE
),
553 else if (fgets((char *)IObuff
, CMDBUFFSIZE
- 2, fd
) == NULL
)
556 IObuff
[CMDBUFFSIZE
- 2] = NUL
; /* for very long lines */
557 if ((efmp
= vim_strrchr(IObuff
, '\n')) != NULL
)
560 if ((efmp
= vim_strrchr(IObuff
, '\r')) != NULL
)
564 /* If there was no %> item start at the first pattern */
565 if (fmt_start
== NULL
)
574 * Try to match each part of 'errorformat' until we find a complete
579 for ( ; fmt_ptr
!= NULL
; fmt_ptr
= fmt_ptr
->next
)
581 idx
= fmt_ptr
->prefix
;
582 if (multiscan
&& vim_strchr((char_u
*)"OPQ", idx
) == NULL
)
595 regmatch
.regprog
= fmt_ptr
->prog
;
596 if (vim_regexec(®match
, IObuff
, (colnr_T
)0))
598 if ((idx
== 'C' || idx
== 'Z') && !multiline
)
600 if (vim_strchr((char_u
*)"EWI", idx
) != NULL
)
605 * Extract error message data from matched line.
606 * We check for an actual submatch, because "\[" and "\]" in
607 * the 'errorformat' may cause the wrong submatch to be used.
609 if ((i
= (int)fmt_ptr
->addr
[0]) > 0) /* %f */
613 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
616 /* Expand ~/file and $HOME/file to full path. */
617 c
= *regmatch
.endp
[i
];
618 *regmatch
.endp
[i
] = NUL
;
619 expand_env(regmatch
.startp
[i
], namebuf
, CMDBUFFSIZE
);
620 *regmatch
.endp
[i
] = c
;
622 if (vim_strchr((char_u
*)"OPQ", idx
) != NULL
623 && mch_getperm(namebuf
) == -1)
626 if ((i
= (int)fmt_ptr
->addr
[1]) > 0) /* %n */
628 if (regmatch
.startp
[i
] == NULL
)
630 enr
= (int)atol((char *)regmatch
.startp
[i
]);
632 if ((i
= (int)fmt_ptr
->addr
[2]) > 0) /* %l */
634 if (regmatch
.startp
[i
] == NULL
)
636 lnum
= atol((char *)regmatch
.startp
[i
]);
638 if ((i
= (int)fmt_ptr
->addr
[3]) > 0) /* %c */
640 if (regmatch
.startp
[i
] == NULL
)
642 col
= (int)atol((char *)regmatch
.startp
[i
]);
644 if ((i
= (int)fmt_ptr
->addr
[4]) > 0) /* %t */
646 if (regmatch
.startp
[i
] == NULL
)
648 type
= *regmatch
.startp
[i
];
650 if (fmt_ptr
->flags
== '+' && !multiscan
) /* %+ */
651 STRCPY(errmsg
, IObuff
);
652 else if ((i
= (int)fmt_ptr
->addr
[5]) > 0) /* %m */
654 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
656 len
= (int)(regmatch
.endp
[i
] - regmatch
.startp
[i
]);
657 vim_strncpy(errmsg
, regmatch
.startp
[i
], len
);
659 if ((i
= (int)fmt_ptr
->addr
[6]) > 0) /* %r */
661 if (regmatch
.startp
[i
] == NULL
)
663 tail
= regmatch
.startp
[i
];
665 if ((i
= (int)fmt_ptr
->addr
[7]) > 0) /* %p */
667 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
669 col
= (int)(regmatch
.endp
[i
] - regmatch
.startp
[i
] + 1);
670 if (*((char_u
*)regmatch
.startp
[i
]) != TAB
)
673 if ((i
= (int)fmt_ptr
->addr
[8]) > 0) /* %v */
675 if (regmatch
.startp
[i
] == NULL
)
677 col
= (int)atol((char *)regmatch
.startp
[i
]);
680 if ((i
= (int)fmt_ptr
->addr
[9]) > 0) /* %s */
682 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
684 len
= (int)(regmatch
.endp
[i
] - regmatch
.startp
[i
]);
685 if (len
> CMDBUFFSIZE
- 5)
686 len
= CMDBUFFSIZE
- 5;
687 STRCPY(pattern
, "^\\V");
688 STRNCAT(pattern
, regmatch
.startp
[i
], len
);
689 pattern
[len
+ 3] = '\\';
690 pattern
[len
+ 4] = '$';
691 pattern
[len
+ 5] = NUL
;
698 if (fmt_ptr
== NULL
|| idx
== 'D' || idx
== 'X')
702 if (idx
== 'D') /* enter directory */
706 EMSG(_("E379: Missing or empty directory name"));
709 if ((directory
= qf_push_dir(namebuf
, &dir_stack
)) == NULL
)
712 else if (idx
== 'X') /* leave directory */
713 directory
= qf_pop_dir(&dir_stack
);
715 namebuf
[0] = NUL
; /* no match found, remove file name */
716 lnum
= 0; /* don't jump to this line */
718 STRCPY(errmsg
, IObuff
); /* copy whole line to error message */
720 multiline
= multiignore
= FALSE
;
722 else if (fmt_ptr
!= NULL
)
725 if (fmt_ptr
->conthere
)
728 if (vim_strchr((char_u
*)"AEWI", idx
) != NULL
)
729 multiline
= TRUE
; /* start of a multi-line message */
730 else if (vim_strchr((char_u
*)"CZ", idx
) != NULL
)
731 { /* continuation of multi-line msg */
734 if (*errmsg
&& !multiignore
)
736 len
= (int)STRLEN(qfprev
->qf_text
);
737 if ((ptr
= alloc((unsigned)(len
+ STRLEN(errmsg
) + 2)))
740 STRCPY(ptr
, qfprev
->qf_text
);
741 vim_free(qfprev
->qf_text
);
742 qfprev
->qf_text
= ptr
;
743 *(ptr
+= len
) = '\n';
744 STRCPY(++ptr
, errmsg
);
746 if (qfprev
->qf_nr
== -1)
748 if (vim_isprintc(type
) && !qfprev
->qf_type
)
749 qfprev
->qf_type
= type
; /* only printable chars allowed */
750 if (!qfprev
->qf_lnum
)
751 qfprev
->qf_lnum
= lnum
;
753 qfprev
->qf_col
= col
;
754 qfprev
->qf_viscol
= use_viscol
;
755 if (!qfprev
->qf_fnum
)
756 qfprev
->qf_fnum
= qf_get_fnum(directory
,
757 *namebuf
|| directory
? namebuf
758 : currfile
&& valid
? currfile
: 0);
760 multiline
= multiignore
= FALSE
;
764 else if (vim_strchr((char_u
*)"OPQ", idx
) != NULL
)
766 /* global file names */
768 if (*namebuf
== NUL
|| mch_getperm(namebuf
) >= 0)
770 if (*namebuf
&& idx
== 'P')
771 currfile
= qf_push_dir(namebuf
, &file_stack
);
773 currfile
= qf_pop_dir(&file_stack
);
777 STRMOVE(IObuff
, skipwhite(tail
));
783 if (fmt_ptr
->flags
== '-') /* generally exclude this line */
786 multiignore
= TRUE
; /* also exclude continuation lines */
791 if (qf_add_entry(qi
, &qfprev
,
793 (*namebuf
|| directory
)
795 : ((currfile
&& valid
) ? currfile
: (char_u
*)NULL
),
808 if (fd
== NULL
|| !ferror(fd
))
810 if (qi
->qf_lists
[qi
->qf_curlist
].qf_index
== 0)
812 /* no valid entry found */
813 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
=
814 qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
815 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
816 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= TRUE
;
820 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
821 if (qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
== NULL
)
822 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
=
823 qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
825 /* return number of matches */
826 retval
= qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
831 qf_free(qi
, qi
->qf_curlist
);
833 if (qi
->qf_curlist
> 0)
838 for (fmt_ptr
= fmt_first
; fmt_ptr
!= NULL
; fmt_ptr
= fmt_first
)
840 fmt_first
= fmt_ptr
->next
;
841 vim_free(fmt_ptr
->prog
);
844 qf_clean_dir_stack(&dir_stack
);
845 qf_clean_dir_stack(&file_stack
);
853 qf_update_buffer(qi
);
860 * Prepare for adding a new quickfix list.
869 * If the current entry is not the last entry, delete entries below
870 * the current entry. This makes it possible to browse in a tree-like
873 while (qi
->qf_listcount
> qi
->qf_curlist
+ 1)
874 qf_free(qi
, --qi
->qf_listcount
);
877 * When the stack is full, remove to oldest entry
878 * Otherwise, add a new entry.
880 if (qi
->qf_listcount
== LISTCOUNT
)
883 for (i
= 1; i
< LISTCOUNT
; ++i
)
884 qi
->qf_lists
[i
- 1] = qi
->qf_lists
[i
];
885 qi
->qf_curlist
= LISTCOUNT
- 1;
888 qi
->qf_curlist
= qi
->qf_listcount
++;
889 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 0;
890 qi
->qf_lists
[qi
->qf_curlist
].qf_count
= 0;
894 * Free a location list
906 *pqi
= NULL
; /* Remove reference to this list */
909 if (qi
->qf_refcount
< 1)
911 /* No references to this location list */
912 for (i
= 0; i
< qi
->qf_listcount
; ++i
)
923 qf_info_T
*qi
= &ql_info
;
928 ll_free_all(&wp
->w_llist
);
929 ll_free_all(&wp
->w_llist_ref
);
933 for (i
= 0; i
< qi
->qf_listcount
; ++i
)
938 * Add an entry to the end of the list of errors.
939 * Returns OK or FAIL.
942 qf_add_entry(qi
, prevp
, dir
, fname
, bufnum
, mesg
, lnum
, col
, vis_col
, pattern
,
944 qf_info_T
*qi
; /* quickfix list */
945 qfline_T
**prevp
; /* pointer to previously added entry or NULL */
946 char_u
*dir
; /* optional directory name */
947 char_u
*fname
; /* file name or NULL */
948 int bufnum
; /* buffer number or zero */
949 char_u
*mesg
; /* message */
950 long lnum
; /* line number */
951 int col
; /* column */
952 int vis_col
; /* using visual column */
953 char_u
*pattern
; /* search pattern */
954 int nr
; /* error number */
955 int type
; /* type character */
956 int valid
; /* valid entry */
960 if ((qfp
= (qfline_T
*)alloc((unsigned)sizeof(qfline_T
))) == NULL
)
963 qfp
->qf_fnum
= bufnum
;
965 qfp
->qf_fnum
= qf_get_fnum(dir
, fname
);
966 if ((qfp
->qf_text
= vim_strsave(mesg
)) == NULL
)
973 qfp
->qf_viscol
= vis_col
;
974 if (pattern
== NULL
|| *pattern
== NUL
)
975 qfp
->qf_pattern
= NULL
;
976 else if ((qfp
->qf_pattern
= vim_strsave(pattern
)) == NULL
)
978 vim_free(qfp
->qf_text
);
983 if (type
!= 1 && !vim_isprintc(type
)) /* only printable chars allowed */
986 qfp
->qf_valid
= valid
;
988 if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
989 /* first element in the list */
991 qi
->qf_lists
[qi
->qf_curlist
].qf_start
= qfp
;
992 qfp
->qf_prev
= qfp
; /* first element points to itself */
996 qfp
->qf_prev
= *prevp
;
997 (*prevp
)->qf_next
= qfp
;
999 qfp
->qf_next
= qfp
; /* last element points to itself */
1000 qfp
->qf_cleared
= FALSE
;
1002 ++qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
1003 if (qi
->qf_lists
[qi
->qf_curlist
].qf_index
== 0 && qfp
->qf_valid
)
1004 /* first valid entry */
1006 qi
->qf_lists
[qi
->qf_curlist
].qf_index
=
1007 qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
1008 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qfp
;
1015 * Allocate a new location list
1022 qi
= (qf_info_T
*)alloc((unsigned)sizeof(qf_info_T
));
1025 vim_memset(qi
, 0, (size_t)(sizeof(qf_info_T
)));
1033 * Return the location list for window 'wp'.
1034 * If not present, allocate a location list
1037 ll_get_or_alloc_list(wp
)
1040 if (IS_LL_WINDOW(wp
))
1041 /* For a location list window, use the referenced location list */
1042 return wp
->w_llist_ref
;
1045 * For a non-location list window, w_llist_ref should not point to a
1048 ll_free_all(&wp
->w_llist_ref
);
1050 if (wp
->w_llist
== NULL
)
1051 wp
->w_llist
= ll_new_list(); /* new location list */
1056 * Copy the location list from window "from" to window "to".
1059 copy_loclist(from
, to
)
1068 * When copying from a location list window, copy the referenced
1069 * location list. For other windows, copy the location list for
1072 if (IS_LL_WINDOW(from
))
1073 qi
= from
->w_llist_ref
;
1077 if (qi
== NULL
) /* no location list to copy */
1080 /* allocate a new location list */
1081 if ((to
->w_llist
= ll_new_list()) == NULL
)
1084 to
->w_llist
->qf_listcount
= qi
->qf_listcount
;
1086 /* Copy the location lists one at a time */
1087 for (idx
= 0; idx
< qi
->qf_listcount
; idx
++)
1089 qf_list_T
*from_qfl
;
1092 to
->w_llist
->qf_curlist
= idx
;
1094 from_qfl
= &qi
->qf_lists
[idx
];
1095 to_qfl
= &to
->w_llist
->qf_lists
[idx
];
1097 /* Some of the fields are populated by qf_add_entry() */
1098 to_qfl
->qf_nonevalid
= from_qfl
->qf_nonevalid
;
1099 to_qfl
->qf_count
= 0;
1100 to_qfl
->qf_index
= 0;
1101 to_qfl
->qf_start
= NULL
;
1102 to_qfl
->qf_ptr
= NULL
;
1104 if (from_qfl
->qf_count
)
1107 qfline_T
*prevp
= NULL
;
1109 /* copy all the location entries in this list */
1110 for (i
= 0, from_qfp
= from_qfl
->qf_start
; i
< from_qfl
->qf_count
;
1111 ++i
, from_qfp
= from_qfp
->qf_next
)
1113 if (qf_add_entry(to
->w_llist
, &prevp
,
1120 from_qfp
->qf_viscol
,
1121 from_qfp
->qf_pattern
,
1124 from_qfp
->qf_valid
) == FAIL
)
1130 * qf_add_entry() will not set the qf_num field, as the
1131 * directory and file names are not supplied. So the qf_fnum
1132 * field is copied here.
1134 prevp
->qf_fnum
= from_qfp
->qf_fnum
; /* file number */
1135 prevp
->qf_type
= from_qfp
->qf_type
; /* error type */
1136 if (from_qfl
->qf_ptr
== from_qfp
)
1137 to_qfl
->qf_ptr
= prevp
; /* current location */
1141 to_qfl
->qf_index
= from_qfl
->qf_index
; /* current index in the list */
1143 /* When no valid entries are present in the list, qf_ptr points to
1144 * the first item in the list */
1145 if (to_qfl
->qf_nonevalid
== TRUE
)
1146 to_qfl
->qf_ptr
= to_qfl
->qf_start
;
1149 to
->w_llist
->qf_curlist
= qi
->qf_curlist
; /* current list */
1153 * get buffer number for file "dir.name"
1156 qf_get_fnum(directory
, fname
)
1160 if (fname
== NULL
|| *fname
== NUL
) /* no file name */
1164 /* Name is reported as `main.c', but file is `c.main' */
1165 return ro_buflist_add(fname
);
1171 vms_remove_version(fname
);
1173 # ifdef BACKSLASH_IN_FILENAME
1174 if (directory
!= NULL
)
1175 slash_adjust(directory
);
1176 slash_adjust(fname
);
1178 if (directory
!= NULL
&& !vim_isAbsName(fname
)
1179 && (ptr
= concat_fnames(directory
, fname
, TRUE
)) != NULL
)
1182 * Here we check if the file really exists.
1183 * This should normally be true, but if make works without
1184 * "leaving directory"-messages we might have missed a
1187 if (mch_getperm(ptr
) < 0)
1190 directory
= qf_guess_filepath(fname
);
1192 ptr
= concat_fnames(directory
, fname
, TRUE
);
1194 ptr
= vim_strsave(fname
);
1196 /* Use concatenated directory name and file name */
1197 fnum
= buflist_add(ptr
, 0);
1201 return buflist_add(fname
, 0);
1207 * push dirbuf onto the directory stack and return pointer to actual dir or
1211 qf_push_dir(dirbuf
, stackptr
)
1213 struct dir_stack_T
**stackptr
;
1215 struct dir_stack_T
*ds_new
;
1216 struct dir_stack_T
*ds_ptr
;
1218 /* allocate new stack element and hook it in */
1219 ds_new
= (struct dir_stack_T
*)alloc((unsigned)sizeof(struct dir_stack_T
));
1223 ds_new
->next
= *stackptr
;
1226 /* store directory on the stack */
1227 if (vim_isAbsName(dirbuf
)
1228 || (*stackptr
)->next
== NULL
1229 || (*stackptr
&& dir_stack
!= *stackptr
))
1230 (*stackptr
)->dirname
= vim_strsave(dirbuf
);
1233 /* Okay we don't have an absolute path.
1234 * dirbuf must be a subdir of one of the directories on the stack.
1237 ds_new
= (*stackptr
)->next
;
1238 (*stackptr
)->dirname
= NULL
;
1241 vim_free((*stackptr
)->dirname
);
1242 (*stackptr
)->dirname
= concat_fnames(ds_new
->dirname
, dirbuf
,
1244 if (mch_isdir((*stackptr
)->dirname
) == TRUE
)
1247 ds_new
= ds_new
->next
;
1250 /* clean up all dirs we already left */
1251 while ((*stackptr
)->next
!= ds_new
)
1253 ds_ptr
= (*stackptr
)->next
;
1254 (*stackptr
)->next
= (*stackptr
)->next
->next
;
1255 vim_free(ds_ptr
->dirname
);
1259 /* Nothing found -> it must be on top level */
1262 vim_free((*stackptr
)->dirname
);
1263 (*stackptr
)->dirname
= vim_strsave(dirbuf
);
1267 if ((*stackptr
)->dirname
!= NULL
)
1268 return (*stackptr
)->dirname
;
1272 *stackptr
= (*stackptr
)->next
;
1280 * pop dirbuf from the directory stack and return previous directory or NULL if
1284 qf_pop_dir(stackptr
)
1285 struct dir_stack_T
**stackptr
;
1287 struct dir_stack_T
*ds_ptr
;
1289 /* TODO: Should we check if dirbuf is the directory on top of the stack?
1290 * What to do if it isn't? */
1292 /* pop top element and free it */
1293 if (*stackptr
!= NULL
)
1296 *stackptr
= (*stackptr
)->next
;
1297 vim_free(ds_ptr
->dirname
);
1301 /* return NEW top element as current dir or NULL if stack is empty*/
1302 return *stackptr
? (*stackptr
)->dirname
: NULL
;
1306 * clean up directory stack
1309 qf_clean_dir_stack(stackptr
)
1310 struct dir_stack_T
**stackptr
;
1312 struct dir_stack_T
*ds_ptr
;
1314 while ((ds_ptr
= *stackptr
) != NULL
)
1316 *stackptr
= (*stackptr
)->next
;
1317 vim_free(ds_ptr
->dirname
);
1323 * Check in which directory of the directory stack the given file can be
1325 * Returns a pointer to the directory name or NULL if not found
1326 * Cleans up intermediate directory entries.
1328 * TODO: How to solve the following problem?
1329 * If we have the this directory tree:
1339 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb.
1340 * qf_guess_filepath will return NULL.
1343 qf_guess_filepath(filename
)
1346 struct dir_stack_T
*ds_ptr
;
1347 struct dir_stack_T
*ds_tmp
;
1350 /* no dirs on the stack - there's nothing we can do */
1351 if (dir_stack
== NULL
)
1354 ds_ptr
= dir_stack
->next
;
1359 fullname
= concat_fnames(ds_ptr
->dirname
, filename
, TRUE
);
1361 /* If concat_fnames failed, just go on. The worst thing that can happen
1362 * is that we delete the entire stack.
1364 if ((fullname
!= NULL
) && (mch_getperm(fullname
) >= 0))
1367 ds_ptr
= ds_ptr
->next
;
1372 /* clean up all dirs we already left */
1373 while (dir_stack
->next
!= ds_ptr
)
1375 ds_tmp
= dir_stack
->next
;
1376 dir_stack
->next
= dir_stack
->next
->next
;
1377 vim_free(ds_tmp
->dirname
);
1381 return ds_ptr
==NULL
? NULL
: ds_ptr
->dirname
;
1386 * jump to a quickfix line
1387 * if dir == FORWARD go "errornr" valid entries forward
1388 * if dir == BACKWARD go "errornr" valid entries backward
1389 * if dir == FORWARD_FILE go "errornr" valid entries files backward
1390 * if dir == BACKWARD_FILE go "errornr" valid entries files backward
1391 * else if "errornr" is zero, redisplay the same line
1392 * else go to entry "errornr"
1395 qf_jump(qi
, dir
, errornr
, forceit
)
1403 qfline_T
*old_qf_ptr
;
1408 static char_u
*e_no_more_items
= (char_u
*)N_("E553: No more items");
1409 char_u
*err
= e_no_more_items
;
1417 char_u
*old_swb
= p_swb
;
1418 unsigned old_swb_flags
= swb_flags
;
1419 int opened_window
= FALSE
;
1424 win_T
*oldwin
= curwin
;
1425 int print_message
= TRUE
;
1428 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
1436 if (qi
->qf_curlist
>= qi
->qf_listcount
1437 || qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
1439 EMSG(_(e_quickfix
));
1443 qf_ptr
= qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
;
1444 old_qf_ptr
= qf_ptr
;
1445 qf_index
= qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
1446 old_qf_index
= qf_index
;
1447 if (dir
== FORWARD
|| dir
== FORWARD_FILE
) /* next valid entry */
1451 old_qf_ptr
= qf_ptr
;
1452 prev_index
= qf_index
;
1453 old_qf_fnum
= qf_ptr
->qf_fnum
;
1456 if (qf_index
== qi
->qf_lists
[qi
->qf_curlist
].qf_count
1457 || qf_ptr
->qf_next
== NULL
)
1459 qf_ptr
= old_qf_ptr
;
1460 qf_index
= prev_index
;
1470 qf_ptr
= qf_ptr
->qf_next
;
1471 } while ((!qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
1472 && !qf_ptr
->qf_valid
)
1473 || (dir
== FORWARD_FILE
&& qf_ptr
->qf_fnum
== old_qf_fnum
));
1477 else if (dir
== BACKWARD
|| dir
== BACKWARD_FILE
) /* prev. valid entry */
1481 old_qf_ptr
= qf_ptr
;
1482 prev_index
= qf_index
;
1483 old_qf_fnum
= qf_ptr
->qf_fnum
;
1486 if (qf_index
== 1 || qf_ptr
->qf_prev
== NULL
)
1488 qf_ptr
= old_qf_ptr
;
1489 qf_index
= prev_index
;
1499 qf_ptr
= qf_ptr
->qf_prev
;
1500 } while ((!qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
1501 && !qf_ptr
->qf_valid
)
1502 || (dir
== BACKWARD_FILE
&& qf_ptr
->qf_fnum
== old_qf_fnum
));
1506 else if (errornr
!= 0) /* go to specified number */
1508 while (errornr
< qf_index
&& qf_index
> 1 && qf_ptr
->qf_prev
!= NULL
)
1511 qf_ptr
= qf_ptr
->qf_prev
;
1513 while (errornr
> qf_index
&& qf_index
<
1514 qi
->qf_lists
[qi
->qf_curlist
].qf_count
1515 && qf_ptr
->qf_next
!= NULL
)
1518 qf_ptr
= qf_ptr
->qf_next
;
1523 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= qf_index
;
1524 if (qf_win_pos_update(qi
, old_qf_index
))
1525 /* No need to print the error message if it's visible in the error
1527 print_message
= FALSE
;
1530 * For ":helpgrep" find a help window or open one.
1532 if (qf_ptr
->qf_type
== 1 && (!curwin
->w_buffer
->b_help
|| cmdmod
.tab
!= 0))
1536 if (cmdmod
.tab
!= 0)
1539 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1540 if (wp
->w_buffer
!= NULL
&& wp
->w_buffer
->b_help
)
1542 if (wp
!= NULL
&& wp
->w_buffer
->b_nwindows
> 0)
1543 win_enter(wp
, TRUE
);
1547 * Split off help window; put it at far top if no position
1548 * specified, the current window is vertically split and narrow.
1551 # ifdef FEAT_VERTSPLIT
1552 if (cmdmod
.split
== 0 && curwin
->w_width
!= Columns
1553 && curwin
->w_width
< 80)
1557 flags
|= WSP_NEWLOC
; /* don't copy the location list */
1559 if (win_split(0, flags
) == FAIL
)
1561 opened_window
= TRUE
; /* close it when fail */
1563 if (curwin
->w_height
< p_hh
)
1564 win_setheight((int)p_hh
);
1566 if (qi
!= &ql_info
) /* not a quickfix list */
1568 /* The new window should use the supplied location list */
1569 curwin
->w_llist
= qi
;
1575 restart_edit
= 0; /* don't want insert mode in help file */
1579 * If currently in the quickfix window, find another window to show the
1582 if (bt_quickfix(curbuf
) && !opened_window
)
1585 * If there is no file specified, we don't know where to go.
1586 * But do advance, otherwise ":cn" gets stuck.
1588 if (qf_ptr
->qf_fnum
== 0)
1591 /* Locate a window showing a normal buffer */
1593 FOR_ALL_WINDOWS(win
)
1594 if (win
->w_buffer
->b_p_bt
[0] == NUL
)
1601 * If no usable window is found and 'switchbuf' contains "usetab"
1602 * then search in other tabs.
1604 if (!usable_win
&& (swb_flags
& SWB_USETAB
))
1609 FOR_ALL_TAB_WINDOWS(tp
, wp
)
1611 if (wp
->w_buffer
->b_fnum
== qf_ptr
->qf_fnum
)
1613 goto_tabpage_win(tp
, wp
);
1622 * If there is only one window and it is the quickfix window, create a
1623 * new one above the quickfix window.
1625 if (((firstwin
== lastwin
) && bt_quickfix(curbuf
)) || !usable_win
)
1627 ll_ref
= curwin
->w_llist_ref
;
1631 flags
|= WSP_NEWLOC
;
1632 if (win_split(0, flags
) == FAIL
)
1633 goto failed
; /* not enough room for window */
1634 opened_window
= TRUE
; /* close it when fail */
1635 p_swb
= empty_option
; /* don't split again */
1637 # ifdef FEAT_SCROLLBIND
1638 curwin
->w_p_scb
= FALSE
;
1642 /* The new window should use the location list from the
1643 * location list window */
1644 curwin
->w_llist
= ll_ref
;
1645 ll_ref
->qf_refcount
++;
1650 if (curwin
->w_llist_ref
!= NULL
)
1652 /* In a location window */
1653 ll_ref
= curwin
->w_llist_ref
;
1655 /* Find the window with the same location list */
1656 FOR_ALL_WINDOWS(win
)
1657 if (win
->w_llist
== ll_ref
)
1661 /* Find the window showing the selected file */
1662 FOR_ALL_WINDOWS(win
)
1663 if (win
->w_buffer
->b_fnum
== qf_ptr
->qf_fnum
)
1667 /* Find a previous usable window */
1671 if (win
->w_buffer
->b_p_bt
[0] == NUL
)
1673 if (win
->w_prev
== NULL
)
1674 win
= lastwin
; /* wrap around the top */
1676 win
= win
->w_prev
; /* go to previous window */
1677 } while (win
!= curwin
);
1682 /* If the location list for the window is not set, then set it
1683 * to the location list from the location window */
1684 if (win
->w_llist
== NULL
)
1686 win
->w_llist
= ll_ref
;
1687 ll_ref
->qf_refcount
++;
1694 * Try to find a window that shows the right buffer.
1695 * Default to the window just above the quickfix buffer.
1701 if (win
->w_buffer
->b_fnum
== qf_ptr
->qf_fnum
)
1703 if (win
->w_prev
== NULL
)
1704 win
= lastwin
; /* wrap around the top */
1706 win
= win
->w_prev
; /* go to previous window */
1708 if (IS_QF_WINDOW(win
))
1710 /* Didn't find it, go to the window before the quickfix
1714 else if (curwin
->w_prev
!= NULL
)
1715 win
= curwin
->w_prev
;
1717 win
= curwin
->w_next
;
1721 /* Remember a usable window. */
1722 if (altwin
== NULL
&& !win
->w_p_pvw
1723 && win
->w_buffer
->b_p_bt
[0] == NUL
)
1734 * If there is a file name,
1735 * read the wanted file if needed, and check autowrite etc.
1737 old_curbuf
= curbuf
;
1738 old_lnum
= curwin
->w_cursor
.lnum
;
1740 if (qf_ptr
->qf_fnum
!= 0)
1742 if (qf_ptr
->qf_type
== 1)
1744 /* Open help file (do_ecmd() will set b_help flag, readfile() will
1745 * set b_p_ro flag). */
1746 if (!can_abandon(curbuf
, forceit
))
1748 EMSG(_(e_nowrtmsg
));
1752 ok
= do_ecmd(qf_ptr
->qf_fnum
, NULL
, NULL
, NULL
, (linenr_T
)1,
1753 ECMD_HIDE
+ ECMD_SET_HELP
,
1754 oldwin
== curwin
? curwin
: NULL
);
1757 ok
= buflist_getfile(qf_ptr
->qf_fnum
,
1758 (linenr_T
)1, GETF_SETMARK
| GETF_SWITCH
, forceit
);
1763 /* When not switched to another buffer, still need to set pc mark */
1764 if (curbuf
== old_curbuf
)
1767 if (qf_ptr
->qf_pattern
== NULL
)
1770 * Go to line with error, unless qf_lnum is 0.
1772 i
= qf_ptr
->qf_lnum
;
1775 if (i
> curbuf
->b_ml
.ml_line_count
)
1776 i
= curbuf
->b_ml
.ml_line_count
;
1777 curwin
->w_cursor
.lnum
= i
;
1779 if (qf_ptr
->qf_col
> 0)
1781 curwin
->w_cursor
.col
= qf_ptr
->qf_col
- 1;
1782 if (qf_ptr
->qf_viscol
== TRUE
)
1785 * Check each character from the beginning of the error
1786 * line up to the error column. For each tab character
1787 * found, reduce the error column value by the length of
1790 line
= ml_get_curline();
1792 for (char_col
= 0; char_col
< curwin
->w_cursor
.col
; ++char_col
)
1796 if (*line
++ == '\t')
1798 curwin
->w_cursor
.col
-= 7 - (screen_col
% 8);
1799 screen_col
+= 8 - (screen_col
% 8);
1808 beginline(BL_WHITE
| BL_FIX
);
1814 /* Move the cursor to the first line in the buffer */
1815 save_cursor
= curwin
->w_cursor
;
1816 curwin
->w_cursor
.lnum
= 0;
1817 if (!do_search(NULL
, '/', qf_ptr
->qf_pattern
, (long)1,
1819 curwin
->w_cursor
= save_cursor
;
1823 if ((fdo_flags
& FDO_QUICKFIX
) && old_KeyTyped
)
1828 /* Update the screen before showing the message */
1829 update_topline_redraw();
1830 sprintf((char *)IObuff
, _("(%d of %d)%s%s: "), qf_index
,
1831 qi
->qf_lists
[qi
->qf_curlist
].qf_count
,
1832 qf_ptr
->qf_cleared
? _(" (line deleted)") : "",
1833 (char *)qf_types(qf_ptr
->qf_type
, qf_ptr
->qf_nr
));
1834 /* Add the message, skipping leading whitespace and newlines. */
1835 len
= (int)STRLEN(IObuff
);
1836 qf_fmt_text(skipwhite(qf_ptr
->qf_text
), IObuff
+ len
, IOSIZE
- len
);
1838 /* Output the message. Overwrite to avoid scrolling when the 'O'
1839 * flag is present in 'shortmess'; But when not jumping, print the
1842 if (curbuf
== old_curbuf
&& curwin
->w_cursor
.lnum
== old_lnum
)
1844 else if (!msg_scrolled
&& shortmess(SHM_OVERALL
))
1846 msg_attr_keep(IObuff
, 0, TRUE
);
1854 win_close(curwin
, TRUE
); /* Close opened window */
1856 if (qf_ptr
->qf_fnum
!= 0)
1859 * Couldn't open file, so put index back where it was. This could
1860 * happen if the file was readonly and we changed something.
1865 qf_ptr
= old_qf_ptr
;
1866 qf_index
= old_qf_index
;
1870 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qf_ptr
;
1871 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= qf_index
;
1873 if (p_swb
!= old_swb
&& opened_window
)
1875 /* Restore old 'switchbuf' value, but not when an autocommand or
1876 * modeline has changed the value. */
1877 if (p_swb
== empty_option
)
1880 swb_flags
= old_swb_flags
;
1883 free_string_option(old_swb
);
1889 * ":clist": list all errors
1890 * ":llist": list all locations
1902 int need_return
= TRUE
;
1903 char_u
*arg
= eap
->arg
;
1904 int all
= eap
->forceit
; /* if not :cl!, only show
1905 recognised errors */
1906 qf_info_T
*qi
= &ql_info
;
1908 if (eap
->cmdidx
== CMD_llist
)
1910 qi
= GET_LOC_LIST(curwin
);
1918 if (qi
->qf_curlist
>= qi
->qf_listcount
1919 || qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
1921 EMSG(_(e_quickfix
));
1924 if (!get_list_range(&arg
, &idx1
, &idx2
) || *arg
!= NUL
)
1926 EMSG(_(e_trailing
));
1929 i
= qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
1931 idx1
= (-idx1
> i
) ? 0 : idx1
+ i
+ 1;
1933 idx2
= (-idx2
> i
) ? 0 : idx2
+ i
+ 1;
1935 if (qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
)
1937 qfp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
1938 for (i
= 1; !got_int
&& i
<= qi
->qf_lists
[qi
->qf_curlist
].qf_count
; )
1940 if ((qfp
->qf_valid
|| all
) && idx1
<= i
&& i
<= idx2
)
1947 need_return
= FALSE
;
1951 if (qfp
->qf_fnum
!= 0
1952 && (buf
= buflist_findnr(qfp
->qf_fnum
)) != NULL
)
1954 fname
= buf
->b_fname
;
1955 if (qfp
->qf_type
== 1) /* :helpgrep */
1956 fname
= gettail(fname
);
1959 sprintf((char *)IObuff
, "%2d", i
);
1961 vim_snprintf((char *)IObuff
, IOSIZE
, "%2d %s",
1963 msg_outtrans_attr(IObuff
, i
== qi
->qf_lists
[qi
->qf_curlist
].qf_index
1964 ? hl_attr(HLF_L
) : hl_attr(HLF_D
));
1965 if (qfp
->qf_lnum
== 0)
1967 else if (qfp
->qf_col
== 0)
1968 sprintf((char *)IObuff
, ":%ld", qfp
->qf_lnum
);
1970 sprintf((char *)IObuff
, ":%ld col %d",
1971 qfp
->qf_lnum
, qfp
->qf_col
);
1972 sprintf((char *)IObuff
+ STRLEN(IObuff
), "%s:",
1973 (char *)qf_types(qfp
->qf_type
, qfp
->qf_nr
));
1974 msg_puts_attr(IObuff
, hl_attr(HLF_N
));
1975 if (qfp
->qf_pattern
!= NULL
)
1977 qf_fmt_text(qfp
->qf_pattern
, IObuff
, IOSIZE
);
1978 STRCAT(IObuff
, ":");
1981 msg_puts((char_u
*)" ");
1983 /* Remove newlines and leading whitespace from the text. For an
1984 * unrecognized line keep the indent, the compiler may mark a word
1986 qf_fmt_text((fname
!= NULL
|| qfp
->qf_lnum
!= 0)
1987 ? skipwhite(qfp
->qf_text
) : qfp
->qf_text
,
1989 msg_prt_line(IObuff
, FALSE
);
1990 out_flush(); /* show one line at a time */
2001 * Remove newlines and leading whitespace from an error message.
2002 * Put the result in "buf[bufsize]".
2005 qf_fmt_text(text
, buf
, bufsize
)
2013 for (i
= 0; *p
!= NUL
&& i
< bufsize
- 1; ++i
)
2019 if (!vim_iswhite(*p
) && *p
!= '\n')
2029 * ":colder [count]": Up in the quickfix stack.
2030 * ":cnewer [count]": Down in the quickfix stack.
2031 * ":lolder [count]": Up in the location list stack.
2032 * ":lnewer [count]": Down in the location list stack.
2038 qf_info_T
*qi
= &ql_info
;
2041 if (eap
->cmdidx
== CMD_lolder
|| eap
->cmdidx
== CMD_lnewer
)
2043 qi
= GET_LOC_LIST(curwin
);
2051 if (eap
->addr_count
!= 0)
2057 if (eap
->cmdidx
== CMD_colder
|| eap
->cmdidx
== CMD_lolder
)
2059 if (qi
->qf_curlist
== 0)
2061 EMSG(_("E380: At bottom of quickfix stack"));
2068 if (qi
->qf_curlist
>= qi
->qf_listcount
- 1)
2070 EMSG(_("E381: At top of quickfix stack"));
2084 smsg((char_u
*)_("error list %d of %d; %d errors"),
2085 qi
->qf_curlist
+ 1, qi
->qf_listcount
,
2086 qi
->qf_lists
[qi
->qf_curlist
].qf_count
);
2088 qf_update_buffer(qi
);
2093 * Free error list "idx".
2102 while (qi
->qf_lists
[idx
].qf_count
)
2104 qfp
= qi
->qf_lists
[idx
].qf_start
->qf_next
;
2105 vim_free(qi
->qf_lists
[idx
].qf_start
->qf_text
);
2106 vim_free(qi
->qf_lists
[idx
].qf_start
->qf_pattern
);
2107 vim_free(qi
->qf_lists
[idx
].qf_start
);
2108 qi
->qf_lists
[idx
].qf_start
= qfp
;
2109 --qi
->qf_lists
[idx
].qf_count
;
2114 * qf_mark_adjust: adjust marks
2117 qf_mark_adjust(wp
, line1
, line2
, amount
, amount_after
)
2127 qf_info_T
*qi
= &ql_info
;
2131 if (wp
->w_llist
== NULL
)
2136 for (idx
= 0; idx
< qi
->qf_listcount
; ++idx
)
2137 if (qi
->qf_lists
[idx
].qf_count
)
2138 for (i
= 0, qfp
= qi
->qf_lists
[idx
].qf_start
;
2139 i
< qi
->qf_lists
[idx
].qf_count
; ++i
, qfp
= qfp
->qf_next
)
2140 if (qfp
->qf_fnum
== curbuf
->b_fnum
)
2142 if (qfp
->qf_lnum
>= line1
&& qfp
->qf_lnum
<= line2
)
2144 if (amount
== MAXLNUM
)
2145 qfp
->qf_cleared
= TRUE
;
2147 qfp
->qf_lnum
+= amount
;
2149 else if (amount_after
&& qfp
->qf_lnum
> line2
)
2150 qfp
->qf_lnum
+= amount_after
;
2155 * Make a nice message out of the error character and the error number:
2156 * char number message
2158 * w or W 0 " warning"
2162 * e or E n " error n"
2163 * w or W n " warning n"
2164 * i or I n " info n"
2173 static char_u buf
[20];
2174 static char_u cc
[3];
2177 if (c
== 'W' || c
== 'w')
2178 p
= (char_u
*)" warning";
2179 else if (c
== 'I' || c
== 'i')
2180 p
= (char_u
*)" info";
2181 else if (c
== 'E' || c
== 'e' || (c
== 0 && nr
> 0))
2182 p
= (char_u
*)" error";
2183 else if (c
== 0 || c
== 1)
2196 sprintf((char *)buf
, "%s %3d", (char *)p
, nr
);
2200 #if defined(FEAT_WINDOWS) || defined(PROTO)
2202 * ":cwindow": open the quickfix window if we have errors to display,
2204 * ":lwindow": open the location list window if we have locations to display,
2211 qf_info_T
*qi
= &ql_info
;
2214 if (eap
->cmdidx
== CMD_lwindow
)
2216 qi
= GET_LOC_LIST(curwin
);
2221 /* Look for an existing quickfix window. */
2222 win
= qf_find_win(qi
);
2225 * If a quickfix window is open but we have no errors to display,
2226 * close the window. If a quickfix window is not open, then open
2227 * it if we have errors; otherwise, leave it closed.
2229 if (qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
2230 || qi
->qf_curlist
>= qi
->qf_listcount
)
2235 else if (win
== NULL
)
2240 * ":cclose": close the window showing the list of errors.
2241 * ":lclose": close the window showing the location list
2248 qf_info_T
*qi
= &ql_info
;
2250 if (eap
->cmdidx
== CMD_lclose
|| eap
->cmdidx
== CMD_lwindow
)
2252 qi
= GET_LOC_LIST(curwin
);
2257 /* Find existing quickfix window and close it. */
2258 win
= qf_find_win(qi
);
2260 win_close(win
, FALSE
);
2264 * ":copen": open a window that shows the list of errors.
2265 * ":lopen": open a window that shows the location list.
2271 qf_info_T
*qi
= &ql_info
;
2274 tabpage_T
*prevtab
= curtab
;
2276 win_T
*oldwin
= curwin
;
2278 if (eap
->cmdidx
== CMD_lopen
|| eap
->cmdidx
== CMD_lwindow
)
2280 qi
= GET_LOC_LIST(curwin
);
2288 if (eap
->addr_count
!= 0)
2289 height
= eap
->line2
;
2291 height
= QF_WINHEIGHT
;
2294 reset_VIsual_and_resel(); /* stop Visual mode */
2297 need_mouse_correct
= TRUE
;
2301 * Find existing quickfix window, or open a new one.
2303 win
= qf_find_win(qi
);
2305 if (win
!= NULL
&& cmdmod
.tab
== 0)
2309 qf_buf
= qf_find_buf(qi
);
2311 /* The current window becomes the previous window afterwards. */
2314 if (eap
->cmdidx
== CMD_copen
|| eap
->cmdidx
== CMD_cwindow
)
2315 /* Create the new window at the very bottom. */
2317 if (win_split(height
, WSP_BELOW
| WSP_NEWLOC
) == FAIL
)
2318 return; /* not enough room for window */
2319 #ifdef FEAT_SCROLLBIND
2320 curwin
->w_p_scb
= FALSE
;
2323 if (eap
->cmdidx
== CMD_lopen
|| eap
->cmdidx
== CMD_lwindow
)
2326 * For the location list window, create a reference to the
2327 * location list from the window 'win'.
2329 curwin
->w_llist_ref
= win
->w_llist
;
2330 win
->w_llist
->qf_refcount
++;
2333 if (oldwin
!= curwin
)
2334 oldwin
= NULL
; /* don't store info when in another window */
2336 /* Use the existing quickfix buffer */
2337 (void)do_ecmd(qf_buf
->b_fnum
, NULL
, NULL
, NULL
, ECMD_ONE
,
2338 ECMD_HIDE
+ ECMD_OLDBUF
, oldwin
);
2341 /* Create a new quickfix buffer */
2342 (void)do_ecmd(0, NULL
, NULL
, NULL
, ECMD_ONE
, ECMD_HIDE
, oldwin
);
2343 /* switch off 'swapfile' */
2344 set_option_value((char_u
*)"swf", 0L, NULL
, OPT_LOCAL
);
2345 set_option_value((char_u
*)"bt", 0L, (char_u
*)"quickfix",
2347 set_option_value((char_u
*)"bh", 0L, (char_u
*)"wipe", OPT_LOCAL
);
2349 curwin
->w_p_diff
= FALSE
;
2352 set_option_value((char_u
*)"fdm", 0L, (char_u
*)"manual",
2357 /* Only set the height when still in the same tab page and there is no
2358 * window to the side. */
2359 if (curtab
== prevtab
2360 #ifdef FEAT_VERTSPLIT
2361 && curwin
->w_width
== Columns
2364 win_setheight(height
);
2365 curwin
->w_p_wfh
= TRUE
; /* set 'winfixheight' */
2371 * Fill the buffer with the quickfix list.
2375 curwin
->w_cursor
.lnum
= qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
2376 curwin
->w_cursor
.col
= 0;
2378 update_topline(); /* scroll to show the line */
2382 * Return the number of the current entry (line number in the quickfix
2386 qf_current_entry(wp
)
2389 qf_info_T
*qi
= &ql_info
;
2391 if (IS_LL_WINDOW(wp
))
2392 /* In the location list window, use the referenced location list */
2393 qi
= wp
->w_llist_ref
;
2395 return qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
2399 * Update the cursor position in the quickfix window to the current error.
2400 * Return TRUE if there is a quickfix window.
2403 qf_win_pos_update(qi
, old_qf_index
)
2405 int old_qf_index
; /* previous qf_index or zero */
2408 int qf_index
= qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
2411 * Put the cursor on the current error in the quickfix window, so that
2414 win
= qf_find_win(qi
);
2416 && qf_index
<= win
->w_buffer
->b_ml
.ml_line_count
2417 && old_qf_index
!= qf_index
)
2419 win_T
*old_curwin
= curwin
;
2422 curbuf
= win
->w_buffer
;
2423 if (qf_index
> old_qf_index
)
2425 curwin
->w_redraw_top
= old_qf_index
;
2426 curwin
->w_redraw_bot
= qf_index
;
2430 curwin
->w_redraw_top
= qf_index
;
2431 curwin
->w_redraw_bot
= old_qf_index
;
2433 curwin
->w_cursor
.lnum
= qf_index
;
2434 curwin
->w_cursor
.col
= 0;
2435 update_topline(); /* scroll to show the line */
2436 redraw_later(VALID
);
2437 curwin
->w_redr_status
= TRUE
; /* update ruler */
2438 curwin
= old_curwin
;
2439 curbuf
= curwin
->w_buffer
;
2445 * Check whether the given window is displaying the specified quickfix/location
2454 * A window displaying the quickfix buffer will have the w_llist_ref field
2456 * A window displaying a location list buffer will have the w_llist_ref
2457 * pointing to the location list.
2459 if (bt_quickfix(win
->w_buffer
))
2460 if ((qi
== &ql_info
&& win
->w_llist_ref
== NULL
)
2461 || (qi
!= &ql_info
&& win
->w_llist_ref
== qi
))
2468 * Find a window displaying the quickfix/location list 'qi'
2469 * Searches in only the windows opened in the current tab.
2477 FOR_ALL_WINDOWS(win
)
2478 if (is_qf_win(win
, qi
))
2485 * Find a quickfix buffer.
2486 * Searches in windows opened in all the tabs.
2495 FOR_ALL_TAB_WINDOWS(tp
, win
)
2496 if (is_qf_win(win
, qi
))
2497 return win
->w_buffer
;
2503 * Find the quickfix buffer. If it exists, update the contents.
2506 qf_update_buffer(qi
)
2512 /* Check if a buffer for the quickfix list exists. Update it. */
2513 buf
= qf_find_buf(qi
);
2516 /* set curwin/curbuf to buf and save a few things */
2517 aucmd_prepbuf(&aco
, buf
);
2521 /* restore curwin/curbuf and a few other things */
2522 aucmd_restbuf(&aco
);
2524 (void)qf_win_pos_update(qi
, 0);
2529 * Fill current buffer with quickfix errors, replacing any previous contents.
2530 * curbuf must be the quickfix buffer!
2540 int old_KeyTyped
= KeyTyped
;
2542 /* delete all existing lines */
2543 while ((curbuf
->b_ml
.ml_flags
& ML_EMPTY
) == 0)
2544 (void)ml_delete((linenr_T
)1, FALSE
);
2546 /* Check if there is anything to display */
2547 if (qi
->qf_curlist
< qi
->qf_listcount
)
2549 /* Add one line for each error */
2550 qfp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
2551 for (lnum
= 0; lnum
< qi
->qf_lists
[qi
->qf_curlist
].qf_count
; ++lnum
)
2553 if (qfp
->qf_fnum
!= 0
2554 && (errbuf
= buflist_findnr(qfp
->qf_fnum
)) != NULL
2555 && errbuf
->b_fname
!= NULL
)
2557 if (qfp
->qf_type
== 1) /* :helpgrep */
2558 STRCPY(IObuff
, gettail(errbuf
->b_fname
));
2560 STRCPY(IObuff
, errbuf
->b_fname
);
2561 len
= (int)STRLEN(IObuff
);
2565 IObuff
[len
++] = '|';
2567 if (qfp
->qf_lnum
> 0)
2569 sprintf((char *)IObuff
+ len
, "%ld", qfp
->qf_lnum
);
2570 len
+= (int)STRLEN(IObuff
+ len
);
2572 if (qfp
->qf_col
> 0)
2574 sprintf((char *)IObuff
+ len
, " col %d", qfp
->qf_col
);
2575 len
+= (int)STRLEN(IObuff
+ len
);
2578 sprintf((char *)IObuff
+ len
, "%s",
2579 (char *)qf_types(qfp
->qf_type
, qfp
->qf_nr
));
2580 len
+= (int)STRLEN(IObuff
+ len
);
2582 else if (qfp
->qf_pattern
!= NULL
)
2584 qf_fmt_text(qfp
->qf_pattern
, IObuff
+ len
, IOSIZE
- len
);
2585 len
+= (int)STRLEN(IObuff
+ len
);
2587 IObuff
[len
++] = '|';
2588 IObuff
[len
++] = ' ';
2590 /* Remove newlines and leading whitespace from the text.
2591 * For an unrecognized line keep the indent, the compiler may
2592 * mark a word with ^^^^. */
2593 qf_fmt_text(len
> 3 ? skipwhite(qfp
->qf_text
) : qfp
->qf_text
,
2594 IObuff
+ len
, IOSIZE
- len
);
2596 if (ml_append(lnum
, IObuff
, (colnr_T
)STRLEN(IObuff
) + 1, FALSE
)
2601 /* Delete the empty line which is now at the end */
2602 (void)ml_delete(lnum
+ 1, FALSE
);
2605 /* correct cursor position */
2608 /* Set the 'filetype' to "qf" each time after filling the buffer. This
2609 * resembles reading a file into a buffer, it's more logical when using
2611 set_option_value((char_u
*)"ft", 0L, (char_u
*)"qf", OPT_LOCAL
);
2612 curbuf
->b_p_ma
= FALSE
;
2615 keep_filetype
= TRUE
; /* don't detect 'filetype' */
2616 apply_autocmds(EVENT_BUFREADPOST
, (char_u
*)"quickfix", NULL
,
2618 apply_autocmds(EVENT_BUFWINENTER
, (char_u
*)"quickfix", NULL
,
2620 keep_filetype
= FALSE
;
2623 /* make sure it will be redrawn */
2624 redraw_curbuf_later(NOT_VALID
);
2626 /* Restore KeyTyped, setting 'filetype' may reset it. */
2627 KeyTyped
= old_KeyTyped
;
2630 #endif /* FEAT_WINDOWS */
2633 * Return TRUE if "buf" is the quickfix buffer.
2639 return (buf
->b_p_bt
[0] == 'q');
2643 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer.
2644 * This means the buffer name is not a file name.
2650 return (buf
->b_p_bt
[0] == 'n' && buf
->b_p_bt
[2] == 'f')
2651 || buf
->b_p_bt
[0] == 'a';
2655 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer.
2661 return (buf
->b_p_bt
[0] == 'n');
2665 bt_dontwrite_msg(buf
)
2668 if (bt_dontwrite(buf
))
2670 EMSG(_("E382: Cannot write, 'buftype' option is set"));
2677 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide"
2684 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */
2685 switch (buf
->b_p_bh
[0])
2687 case 'u': /* "unload" */
2688 case 'w': /* "wipe" */
2689 case 'd': return FALSE
; /* "delete" */
2690 case 'h': return TRUE
; /* "hide" */
2692 return (p_hid
|| cmdmod
.hide
);
2696 * Return TRUE when using ":vimgrep" for ":grep".
2699 grep_internal(cmdidx
)
2702 return ((cmdidx
== CMD_grep
2703 || cmdidx
== CMD_lgrep
2704 || cmdidx
== CMD_grepadd
2705 || cmdidx
== CMD_lgrepadd
)
2706 && STRCMP("internal",
2707 *curbuf
->b_p_gp
== NUL
? p_gp
: curbuf
->b_p_gp
) == 0);
2711 * Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd"
2721 qf_info_T
*qi
= &ql_info
;
2724 char_u
*au_name
= NULL
;
2726 switch (eap
->cmdidx
)
2728 case CMD_make
: au_name
= (char_u
*)"make"; break;
2729 case CMD_lmake
: au_name
= (char_u
*)"lmake"; break;
2730 case CMD_grep
: au_name
= (char_u
*)"grep"; break;
2731 case CMD_lgrep
: au_name
= (char_u
*)"lgrep"; break;
2732 case CMD_grepadd
: au_name
= (char_u
*)"grepadd"; break;
2733 case CMD_lgrepadd
: au_name
= (char_u
*)"lgrepadd"; break;
2736 if (au_name
!= NULL
)
2738 apply_autocmds(EVENT_QUICKFIXCMDPRE
, au_name
,
2739 curbuf
->b_fname
, TRUE
, curbuf
);
2741 if (did_throw
|| force_abort
)
2747 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
2748 if (grep_internal(eap
->cmdidx
))
2754 if (eap
->cmdidx
== CMD_lmake
|| eap
->cmdidx
== CMD_lgrep
2755 || eap
->cmdidx
== CMD_lgrepadd
)
2759 fname
= get_mef_name();
2762 mch_remove(fname
); /* in case it's not unique */
2765 * If 'shellpipe' empty: don't redirect to 'errorfile'.
2767 len
= (unsigned)STRLEN(p_shq
) * 2 + (unsigned)STRLEN(eap
->arg
) + 1;
2769 len
+= (unsigned)STRLEN(p_sp
) + (unsigned)STRLEN(fname
) + 3;
2773 sprintf((char *)cmd
, "%s%s%s", (char *)p_shq
, (char *)eap
->arg
,
2776 append_redir(cmd
, len
, p_sp
, fname
);
2778 * Output a newline if there's something else than the :make command that
2779 * was typed (in which case the cursor is in column 0).
2785 msg_outtrans(cmd
); /* show what we are doing */
2787 /* let the shell know if we are redirecting output or not */
2788 do_shell(cmd
, *p_sp
!= NUL
? SHELL_DOOUT
: 0);
2792 /* read window status report and redraw before message */
2796 res
= qf_init(wp
, fname
, (eap
->cmdidx
!= CMD_make
2797 && eap
->cmdidx
!= CMD_lmake
) ? p_gefm
: p_efm
,
2798 (eap
->cmdidx
!= CMD_grepadd
2799 && eap
->cmdidx
!= CMD_lgrepadd
));
2801 if (au_name
!= NULL
)
2802 apply_autocmds(EVENT_QUICKFIXCMDPOST
, au_name
,
2803 curbuf
->b_fname
, TRUE
, curbuf
);
2805 if (res
> 0 && !eap
->forceit
)
2808 qi
= GET_LOC_LIST(wp
);
2809 qf_jump(qi
, 0, 0, FALSE
); /* display first error */
2818 * Return the name for the errorfile, in allocated memory.
2819 * Find a new unique name when 'makeef' contains "##".
2820 * Returns NULL for error.
2827 static int start
= -1;
2835 name
= vim_tempname('e');
2841 for (p
= p_mef
; *p
; ++p
)
2842 if (p
[0] == '#' && p
[1] == '#')
2846 return vim_strsave(p_mef
);
2848 /* Keep trying until the name doesn't exist yet. */
2852 start
= mch_get_pid();
2856 name
= alloc((unsigned)STRLEN(p_mef
) + 30);
2859 STRCPY(name
, p_mef
);
2860 sprintf((char *)name
+ (p
- p_mef
), "%d%d", start
, off
);
2861 STRCAT(name
, p
+ 2);
2862 if (mch_getperm(name
) < 0
2864 /* Don't accept a symbolic link, its a security risk. */
2865 && mch_lstat((char *)name
, &sb
) < 0
2875 * ":cc", ":crewind", ":cfirst" and ":clast".
2876 * ":ll", ":lrewind", ":lfirst" and ":llast".
2882 qf_info_T
*qi
= &ql_info
;
2884 if (eap
->cmdidx
== CMD_ll
2885 || eap
->cmdidx
== CMD_lrewind
2886 || eap
->cmdidx
== CMD_lfirst
2887 || eap
->cmdidx
== CMD_llast
)
2889 qi
= GET_LOC_LIST(curwin
);
2900 : (eap
->cmdidx
== CMD_cc
|| eap
->cmdidx
== CMD_ll
)
2902 : (eap
->cmdidx
== CMD_crewind
|| eap
->cmdidx
== CMD_lrewind
2903 || eap
->cmdidx
== CMD_cfirst
|| eap
->cmdidx
== CMD_lfirst
)
2910 * ":cnext", ":cnfile", ":cNext" and ":cprevious".
2911 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile".
2917 qf_info_T
*qi
= &ql_info
;
2919 if (eap
->cmdidx
== CMD_lnext
2920 || eap
->cmdidx
== CMD_lNext
2921 || eap
->cmdidx
== CMD_lprevious
2922 || eap
->cmdidx
== CMD_lnfile
2923 || eap
->cmdidx
== CMD_lNfile
2924 || eap
->cmdidx
== CMD_lpfile
)
2926 qi
= GET_LOC_LIST(curwin
);
2934 qf_jump(qi
, (eap
->cmdidx
== CMD_cnext
|| eap
->cmdidx
== CMD_lnext
)
2936 : (eap
->cmdidx
== CMD_cnfile
|| eap
->cmdidx
== CMD_lnfile
)
2938 : (eap
->cmdidx
== CMD_cpfile
|| eap
->cmdidx
== CMD_lpfile
2939 || eap
->cmdidx
== CMD_cNfile
|| eap
->cmdidx
== CMD_lNfile
)
2942 eap
->addr_count
> 0 ? (int)eap
->line2
: 1, eap
->forceit
);
2946 * ":cfile"/":cgetfile"/":caddfile" commands.
2947 * ":lfile"/":lgetfile"/":laddfile" commands.
2954 qf_info_T
*qi
= &ql_info
;
2956 if (eap
->cmdidx
== CMD_lfile
|| eap
->cmdidx
== CMD_lgetfile
2957 || eap
->cmdidx
== CMD_laddfile
)
2960 if (*eap
->arg
!= NUL
)
2961 set_string_option_direct((char_u
*)"ef", -1, eap
->arg
, OPT_FREE
, 0);
2964 * This function is used by the :cfile, :cgetfile and :caddfile
2966 * :cfile always creates a new quickfix list and jumps to the
2968 * :cgetfile creates a new quickfix list but doesn't jump to the
2970 * :caddfile adds to an existing quickfix list. If there is no
2971 * quickfix list then a new list is created.
2973 if (qf_init(wp
, p_ef
, p_efm
, (eap
->cmdidx
!= CMD_caddfile
2974 && eap
->cmdidx
!= CMD_laddfile
)) > 0
2975 && (eap
->cmdidx
== CMD_cfile
2976 || eap
->cmdidx
== CMD_lfile
))
2979 qi
= GET_LOC_LIST(wp
);
2980 qf_jump(qi
, 0, 0, eap
->forceit
); /* display first error */
2985 * ":vimgrep {pattern} file(s)"
2986 * ":vimgrepadd {pattern} file(s)"
2987 * ":lvimgrep {pattern} file(s)"
2988 * ":lvimgrepadd {pattern} file(s)"
2994 regmmatch_T regmatch
;
3001 qf_info_T
*qi
= &ql_info
;
3002 qfline_T
*prevp
= NULL
;
3005 int duplicate_name
= FALSE
;
3007 int redraw_for_dummy
= FALSE
;
3009 buf_T
*first_match_buf
= NULL
;
3012 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3013 char_u
*save_ei
= NULL
;
3019 char_u dirname_start
[MAXPATHL
];
3020 char_u dirname_now
[MAXPATHL
];
3021 char_u
*target_dir
= NULL
;
3023 char_u
*au_name
= NULL
;
3025 switch (eap
->cmdidx
)
3027 case CMD_vimgrep
: au_name
= (char_u
*)"vimgrep"; break;
3028 case CMD_lvimgrep
: au_name
= (char_u
*)"lvimgrep"; break;
3029 case CMD_vimgrepadd
: au_name
= (char_u
*)"vimgrepadd"; break;
3030 case CMD_lvimgrepadd
: au_name
= (char_u
*)"lvimgrepadd"; break;
3033 if (au_name
!= NULL
)
3035 apply_autocmds(EVENT_QUICKFIXCMDPRE
, au_name
,
3036 curbuf
->b_fname
, TRUE
, curbuf
);
3037 if (did_throw
|| force_abort
)
3042 if (eap
->cmdidx
== CMD_lgrep
3043 || eap
->cmdidx
== CMD_lvimgrep
3044 || eap
->cmdidx
== CMD_lgrepadd
3045 || eap
->cmdidx
== CMD_lvimgrepadd
)
3047 qi
= ll_get_or_alloc_list(curwin
);
3052 if (eap
->addr_count
> 0)
3053 tomatch
= eap
->line2
;
3057 /* Get the search pattern: either white-separated or enclosed in // */
3058 regmatch
.regprog
= NULL
;
3059 p
= skip_vimgrep_pat(eap
->arg
, &s
, &flags
);
3062 EMSG(_(e_invalpat
));
3065 regmatch
.regprog
= vim_regcomp(s
, RE_MAGIC
);
3066 if (regmatch
.regprog
== NULL
)
3068 regmatch
.rmm_ic
= p_ic
;
3069 regmatch
.rmm_maxcol
= 0;
3074 EMSG(_("E683: File name missing or invalid pattern"));
3078 if ((eap
->cmdidx
!= CMD_grepadd
&& eap
->cmdidx
!= CMD_lgrepadd
&&
3079 eap
->cmdidx
!= CMD_vimgrepadd
&& eap
->cmdidx
!= CMD_lvimgrepadd
)
3080 || qi
->qf_curlist
== qi
->qf_listcount
)
3081 /* make place for a new list */
3083 else if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3084 /* Adding to existing list, find last entry. */
3085 for (prevp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3086 prevp
->qf_next
!= prevp
; prevp
= prevp
->qf_next
)
3089 /* parse the list of arguments */
3090 if (get_arglist_exp(p
, &fcount
, &fnames
) == FAIL
)
3098 /* Remember the current directory, because a BufRead autocommand that does
3099 * ":lcd %:p:h" changes the meaning of short path names. */
3100 mch_dirname(dirname_start
, MAXPATHL
);
3102 seconds
= (time_t)0;
3103 for (fi
= 0; fi
< fcount
&& !got_int
&& tomatch
> 0; ++fi
)
3105 fname
= shorten_fname1(fnames
[fi
]);
3106 if (time(NULL
) > seconds
)
3108 /* Display the file name every second or so, show the user we are
3110 seconds
= time(NULL
);
3112 p
= msg_strtrunc(fname
, TRUE
);
3114 msg_outtrans(fname
);
3121 msg_didout
= FALSE
; /* overwrite this message */
3122 msg_nowait
= TRUE
; /* don't wait for this message */
3127 buf
= buflist_findname_exp(fnames
[fi
]);
3128 if (buf
== NULL
|| buf
->b_ml
.ml_mfp
== NULL
)
3130 /* Remember that a buffer with this name already exists. */
3131 duplicate_name
= (buf
!= NULL
);
3133 redraw_for_dummy
= TRUE
;
3135 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3136 /* Don't do Filetype autocommands to avoid loading syntax and
3137 * indent scripts, a great speed improvement. */
3138 save_ei
= au_event_disable(",Filetype");
3140 /* Don't use modelines here, it's useless. */
3144 /* Load file into a buffer, so that 'fileencoding' is detected,
3145 * autocommands applied, etc. */
3146 buf
= load_dummy_buffer(fname
);
3148 /* When autocommands changed directory: go back. We assume it was
3150 mch_dirname(dirname_now
, MAXPATHL
);
3151 if (STRCMP(dirname_start
, dirname_now
) != 0)
3155 ea
.arg
= dirname_start
;
3156 ea
.cmdidx
= CMD_lcd
;
3161 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3162 au_event_restore(save_ei
);
3166 /* Use existing, loaded buffer. */
3167 using_dummy
= FALSE
;
3172 smsg((char_u
*)_("Cannot open file \"%s\""), fname
);
3176 /* Try for a match in all lines of the buffer.
3177 * For ":1vimgrep" look for first match only. */
3178 found_match
= FALSE
;
3179 for (lnum
= 1; lnum
<= buf
->b_ml
.ml_line_count
&& tomatch
> 0;
3183 while (vim_regexec_multi(®match
, curwin
, buf
, lnum
,
3187 if (qf_add_entry(qi
, &prevp
,
3192 regmatch
.startpos
[0].lnum
+ lnum
, FALSE
),
3193 regmatch
.startpos
[0].lnum
+ lnum
,
3194 regmatch
.startpos
[0].col
+ 1,
3195 FALSE
, /* vis_col */
3196 NULL
, /* search pattern */
3208 if ((flags
& VGR_GLOBAL
) == 0
3209 || regmatch
.endpos
[0].lnum
> 0)
3211 col
= regmatch
.endpos
[0].col
3212 + (col
== regmatch
.endpos
[0].col
);
3213 if (col
> (colnr_T
)STRLEN(ml_get_buf(buf
, lnum
, FALSE
)))
3223 if (found_match
&& first_match_buf
== NULL
)
3224 first_match_buf
= buf
;
3227 /* Never keep a dummy buffer if there is another buffer
3228 * with the same name. */
3229 wipe_dummy_buffer(buf
);
3232 else if (!cmdmod
.hide
3233 || buf
->b_p_bh
[0] == 'u' /* "unload" */
3234 || buf
->b_p_bh
[0] == 'w' /* "wipe" */
3235 || buf
->b_p_bh
[0] == 'd') /* "delete" */
3237 /* When no match was found we don't need to remember the
3238 * buffer, wipe it out. If there was a match and it
3239 * wasn't the first one or we won't jump there: only
3240 * unload the buffer.
3241 * Ignore 'hidden' here, because it may lead to having too
3242 * many swap files. */
3245 wipe_dummy_buffer(buf
);
3248 else if (buf
!= first_match_buf
|| (flags
& VGR_NOJUMP
))
3250 unload_dummy_buffer(buf
);
3257 /* If the buffer is still loaded we need to use the
3258 * directory we jumped to below. */
3259 if (buf
== first_match_buf
3260 && target_dir
== NULL
3261 && STRCMP(dirname_start
, dirname_now
) != 0)
3262 target_dir
= vim_strsave(dirname_now
);
3264 /* The buffer is still loaded, the Filetype autocommands
3265 * need to be done now, in that buffer. And the modelines
3266 * need to be done (again). But not the window-local
3268 aucmd_prepbuf(&aco
, buf
);
3269 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3270 apply_autocmds(EVENT_FILETYPE
, buf
->b_p_ft
,
3271 buf
->b_fname
, TRUE
, buf
);
3273 do_modelines(OPT_NOWIN
);
3274 aucmd_restbuf(&aco
);
3280 FreeWild(fcount
, fnames
);
3282 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
3283 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3284 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
3287 qf_update_buffer(qi
);
3291 if (au_name
!= NULL
)
3292 apply_autocmds(EVENT_QUICKFIXCMDPOST
, au_name
,
3293 curbuf
->b_fname
, TRUE
, curbuf
);
3296 /* Jump to first match. */
3297 if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3299 if ((flags
& VGR_NOJUMP
) == 0)
3302 qf_jump(qi
, 0, 0, eap
->forceit
);
3304 /* If we jumped to another buffer redrawing will already be
3306 redraw_for_dummy
= FALSE
;
3308 /* Jump to the directory used after loading the buffer. */
3309 if (curbuf
== first_match_buf
&& target_dir
!= NULL
)
3313 ea
.arg
= target_dir
;
3314 ea
.cmdidx
= CMD_lcd
;
3320 EMSG2(_(e_nomatch2
), s
);
3322 /* If we loaded a dummy buffer into the current window, the autocommands
3323 * may have messed up things, need to redraw and recompute folds. */
3324 if (redraw_for_dummy
)
3327 foldUpdateAll(curwin
);
3329 redraw_later(NOT_VALID
);
3334 vim_free(target_dir
);
3335 vim_free(regmatch
.regprog
);
3339 * Skip over the pattern argument of ":vimgrep /pat/[g][j]".
3340 * Put the start of the pattern in "*s", unless "s" is NULL.
3341 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP.
3342 * If "s" is not NULL terminate the pattern with a NUL.
3343 * Return a pointer to the char just past the pattern plus flags.
3346 skip_vimgrep_pat(p
, s
, flags
)
3355 /* ":vimgrep pattern fname" */
3359 if (s
!= NULL
&& *p
!= NUL
)
3364 /* ":vimgrep /pattern/[g][j] fname" */
3368 p
= skip_regexp(p
+ 1, c
, TRUE
, NULL
);
3372 /* Truncate the pattern. */
3377 /* Find the flags */
3378 while (*p
== 'g' || *p
== 'j')
3383 *flags
|= VGR_GLOBAL
;
3385 *flags
|= VGR_NOJUMP
;
3394 * Load file "fname" into a dummy buffer and return the buffer pointer.
3395 * Returns NULL if it fails.
3396 * Must call unload_dummy_buffer() or wipe_dummy_buffer() later!
3399 load_dummy_buffer(fname
)
3406 /* Allocate a buffer without putting it in the buffer list. */
3407 newbuf
= buflist_new(NULL
, NULL
, (linenr_T
)1, BLN_DUMMY
);
3411 /* Init the options. */
3412 buf_copy_options(newbuf
, BCO_ENTER
| BCO_NOHELP
);
3414 /* need to open the memfile before putting the buffer in a window */
3415 if (ml_open(newbuf
) == OK
)
3417 /* set curwin/curbuf to buf and save a few things */
3418 aucmd_prepbuf(&aco
, newbuf
);
3420 /* Need to set the filename for autocommands. */
3421 (void)setfname(curbuf
, fname
, NULL
, FALSE
);
3423 /* Create swap file now to avoid the ATTENTION message. */
3424 check_need_swap(TRUE
);
3426 /* Remove the "dummy" flag, otherwise autocommands may not
3428 curbuf
->b_flags
&= ~BF_DUMMY
;
3430 if (readfile(fname
, NULL
,
3431 (linenr_T
)0, (linenr_T
)0, (linenr_T
)MAXLNUM
,
3432 NULL
, READ_NEW
| READ_DUMMY
) == OK
3434 && !(curbuf
->b_flags
& BF_NEW
))
3437 if (curbuf
!= newbuf
)
3439 /* Bloody autocommands changed the buffer! */
3440 if (buf_valid(newbuf
))
3441 wipe_buffer(newbuf
, FALSE
);
3446 /* restore curwin/curbuf and a few other things */
3447 aucmd_restbuf(&aco
);
3450 if (!buf_valid(newbuf
))
3454 wipe_dummy_buffer(newbuf
);
3461 * Wipe out the dummy buffer that load_dummy_buffer() created.
3464 wipe_dummy_buffer(buf
)
3467 if (curbuf
!= buf
) /* safety check */
3469 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
3472 /* Reset the error/interrupt/exception state here so that aborting()
3473 * returns FALSE when wiping out the buffer. Otherwise it doesn't
3474 * work when got_int is set. */
3478 wipe_buffer(buf
, FALSE
);
3480 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
3481 /* Restore the error/interrupt/exception state if not discarded by a
3482 * new aborting error, interrupt, or uncaught exception. */
3489 * Unload the dummy buffer that load_dummy_buffer() created.
3492 unload_dummy_buffer(buf
)
3495 if (curbuf
!= buf
) /* safety check */
3496 close_buffer(NULL
, buf
, DOBUF_UNLOAD
);
3499 #if defined(FEAT_EVAL) || defined(PROTO)
3501 * Add each quickfix error to list "list" as a dictionary.
3504 get_errorlist(wp
, list
)
3508 qf_info_T
*qi
= &ql_info
;
3517 qi
= GET_LOC_LIST(wp
);
3522 if (qi
->qf_curlist
>= qi
->qf_listcount
3523 || qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
3526 qfp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3527 for (i
= 1; !got_int
&& i
<= qi
->qf_lists
[qi
->qf_curlist
].qf_count
; ++i
)
3529 /* Handle entries with a non-existing buffer number. */
3530 bufnum
= qfp
->qf_fnum
;
3531 if (bufnum
!= 0 && (buflist_findnr(bufnum
) == NULL
))
3534 if ((dict
= dict_alloc()) == NULL
)
3536 if (list_append_dict(list
, dict
) == FAIL
)
3539 buf
[0] = qfp
->qf_type
;
3541 if ( dict_add_nr_str(dict
, "bufnr", (long)bufnum
, NULL
) == FAIL
3542 || dict_add_nr_str(dict
, "lnum", (long)qfp
->qf_lnum
, NULL
) == FAIL
3543 || dict_add_nr_str(dict
, "col", (long)qfp
->qf_col
, NULL
) == FAIL
3544 || dict_add_nr_str(dict
, "vcol", (long)qfp
->qf_viscol
, NULL
) == FAIL
3545 || dict_add_nr_str(dict
, "nr", (long)qfp
->qf_nr
, NULL
) == FAIL
3546 || dict_add_nr_str(dict
, "pattern", 0L,
3547 qfp
->qf_pattern
== NULL
? (char_u
*)"" : qfp
->qf_pattern
) == FAIL
3548 || dict_add_nr_str(dict
, "text", 0L,
3549 qfp
->qf_text
== NULL
? (char_u
*)"" : qfp
->qf_text
) == FAIL
3550 || dict_add_nr_str(dict
, "type", 0L, buf
) == FAIL
3551 || dict_add_nr_str(dict
, "valid", (long)qfp
->qf_valid
, NULL
) == FAIL
)
3560 * Populate the quickfix list with the items supplied in the list
3564 set_errorlist(wp
, list
, action
)
3571 char_u
*filename
, *pattern
, *text
, *type
;
3576 qfline_T
*prevp
= NULL
;
3579 qf_info_T
*qi
= &ql_info
;
3580 int did_bufnr_emsg
= FALSE
;
3584 qi
= ll_get_or_alloc_list(wp
);
3589 if (action
== ' ' || qi
->qf_curlist
== qi
->qf_listcount
)
3590 /* make place for a new list */
3592 else if (action
== 'a' && qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3593 /* Adding to existing list, find last entry. */
3594 for (prevp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3595 prevp
->qf_next
!= prevp
; prevp
= prevp
->qf_next
)
3597 else if (action
== 'r')
3598 qf_free(qi
, qi
->qf_curlist
);
3600 for (li
= list
->lv_first
; li
!= NULL
; li
= li
->li_next
)
3602 if (li
->li_tv
.v_type
!= VAR_DICT
)
3603 continue; /* Skip non-dict items */
3605 d
= li
->li_tv
.vval
.v_dict
;
3609 filename
= get_dict_string(d
, (char_u
*)"filename", TRUE
);
3610 bufnum
= get_dict_number(d
, (char_u
*)"bufnr");
3611 lnum
= get_dict_number(d
, (char_u
*)"lnum");
3612 col
= get_dict_number(d
, (char_u
*)"col");
3613 vcol
= get_dict_number(d
, (char_u
*)"vcol");
3614 nr
= get_dict_number(d
, (char_u
*)"nr");
3615 type
= get_dict_string(d
, (char_u
*)"type", TRUE
);
3616 pattern
= get_dict_string(d
, (char_u
*)"pattern", TRUE
);
3617 text
= get_dict_string(d
, (char_u
*)"text", TRUE
);
3619 text
= vim_strsave((char_u
*)"");
3622 if ((filename
== NULL
&& bufnum
== 0) || (lnum
== 0 && pattern
== NULL
))
3625 /* Mark entries with non-existing buffer number as not valid. Give the
3626 * error message only once. */
3627 if (bufnum
!= 0 && (buflist_findnr(bufnum
) == NULL
))
3629 if (!did_bufnr_emsg
)
3631 did_bufnr_emsg
= TRUE
;
3632 EMSGN(_("E92: Buffer %ld not found"), bufnum
);
3638 status
= qf_add_entry(qi
, &prevp
,
3646 pattern
, /* search pattern */
3648 type
== NULL
? NUL
: *type
,
3663 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
3664 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3665 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
3668 qf_update_buffer(qi
);
3676 * ":[range]cbuffer [bufnr]" command.
3677 * ":[range]caddbuffer [bufnr]" command.
3678 * ":[range]cgetbuffer [bufnr]" command.
3679 * ":[range]lbuffer [bufnr]" command.
3680 * ":[range]laddbuffer [bufnr]" command.
3681 * ":[range]lgetbuffer [bufnr]" command.
3688 qf_info_T
*qi
= &ql_info
;
3690 if (eap
->cmdidx
== CMD_lbuffer
|| eap
->cmdidx
== CMD_lgetbuffer
3691 || eap
->cmdidx
== CMD_laddbuffer
)
3693 qi
= ll_get_or_alloc_list(curwin
);
3698 if (*eap
->arg
== NUL
)
3700 else if (*skipwhite(skipdigits(eap
->arg
)) == NUL
)
3701 buf
= buflist_findnr(atoi((char *)eap
->arg
));
3704 else if (buf
->b_ml
.ml_mfp
== NULL
)
3705 EMSG(_("E681: Buffer is not loaded"));
3708 if (eap
->addr_count
== 0)
3711 eap
->line2
= buf
->b_ml
.ml_line_count
;
3713 if (eap
->line1
< 1 || eap
->line1
> buf
->b_ml
.ml_line_count
3714 || eap
->line2
< 1 || eap
->line2
> buf
->b_ml
.ml_line_count
)
3715 EMSG(_(e_invrange
));
3718 if (qf_init_ext(qi
, NULL
, buf
, NULL
, p_efm
,
3719 (eap
->cmdidx
!= CMD_caddbuffer
3720 && eap
->cmdidx
!= CMD_laddbuffer
),
3721 eap
->line1
, eap
->line2
) > 0
3722 && (eap
->cmdidx
== CMD_cbuffer
3723 || eap
->cmdidx
== CMD_lbuffer
))
3724 qf_jump(qi
, 0, 0, eap
->forceit
); /* display first error */
3729 #if defined(FEAT_EVAL) || defined(PROTO)
3731 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command.
3732 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command.
3739 qf_info_T
*qi
= &ql_info
;
3741 if (eap
->cmdidx
== CMD_lexpr
|| eap
->cmdidx
== CMD_lgetexpr
3742 || eap
->cmdidx
== CMD_laddexpr
)
3744 qi
= ll_get_or_alloc_list(curwin
);
3749 /* Evaluate the expression. When the result is a string or a list we can
3750 * use it to fill the errorlist. */
3751 tv
= eval_expr(eap
->arg
, NULL
);
3754 if ((tv
->v_type
== VAR_STRING
&& tv
->vval
.v_string
!= NULL
)
3755 || (tv
->v_type
== VAR_LIST
&& tv
->vval
.v_list
!= NULL
))
3757 if (qf_init_ext(qi
, NULL
, NULL
, tv
, p_efm
,
3758 (eap
->cmdidx
!= CMD_caddexpr
3759 && eap
->cmdidx
!= CMD_laddexpr
),
3760 (linenr_T
)0, (linenr_T
)0) > 0
3761 && (eap
->cmdidx
== CMD_cexpr
3762 || eap
->cmdidx
== CMD_lexpr
))
3763 qf_jump(qi
, 0, 0, eap
->forceit
); /* display first error */
3766 EMSG(_("E777: String or List expected"));
3773 * ":helpgrep {pattern}"
3779 regmatch_T regmatch
;
3786 qfline_T
*prevp
= NULL
;
3788 #ifdef FEAT_MULTI_LANG
3791 qf_info_T
*qi
= &ql_info
;
3795 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
3797 p_cpo
= empty_option
;
3799 #ifdef FEAT_MULTI_LANG
3800 /* Check for a specified language */
3801 lang
= check_help_lang(eap
->arg
);
3804 if (eap
->cmdidx
== CMD_lhelpgrep
)
3806 /* Find an existing help window */
3808 if (wp
->w_buffer
!= NULL
&& wp
->w_buffer
->b_help
)
3811 if (wp
== NULL
) /* Help window not found */
3818 /* Allocate a new location list for help text matches */
3819 if ((qi
= ll_new_list()) == NULL
)
3825 regmatch
.regprog
= vim_regcomp(eap
->arg
, RE_MAGIC
+ RE_STRING
);
3826 regmatch
.rm_ic
= FALSE
;
3827 if (regmatch
.regprog
!= NULL
)
3829 /* create a new quickfix list */
3832 /* Go through all directories in 'runtimepath' */
3834 while (*p
!= NUL
&& !got_int
)
3836 copy_option_part(&p
, NameBuff
, MAXPATHL
, ",");
3838 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */
3839 add_pathsep(NameBuff
);
3840 STRCAT(NameBuff
, "doc/*.\\(txt\\|??x\\)");
3841 if (gen_expand_wildcards(1, &NameBuff
, &fcount
,
3842 &fnames
, EW_FILE
|EW_SILENT
) == OK
3845 for (fi
= 0; fi
< fcount
&& !got_int
; ++fi
)
3847 #ifdef FEAT_MULTI_LANG
3848 /* Skip files for a different language. */
3850 && STRNICMP(lang
, fnames
[fi
]
3851 + STRLEN(fnames
[fi
]) - 3, 2) != 0
3852 && !(STRNICMP(lang
, "en", 2) == 0
3853 && STRNICMP("txt", fnames
[fi
]
3854 + STRLEN(fnames
[fi
]) - 3, 3) == 0))
3857 fd
= mch_fopen((char *)fnames
[fi
], "r");
3861 while (!vim_fgets(IObuff
, IOSIZE
, fd
) && !got_int
)
3863 if (vim_regexec(®match
, IObuff
, (colnr_T
)0))
3865 int l
= (int)STRLEN(IObuff
);
3867 /* remove trailing CR, LF, spaces, etc. */
3868 while (l
> 0 && IObuff
[l
- 1] <= ' ')
3871 if (qf_add_entry(qi
, &prevp
,
3877 (int)(regmatch
.startp
[0] - IObuff
)
3879 FALSE
, /* vis_col */
3880 NULL
, /* search pattern */
3896 FreeWild(fcount
, fnames
);
3899 vim_free(regmatch
.regprog
);
3901 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
3902 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
=
3903 qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3904 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
3907 if (p_cpo
== empty_option
)
3910 /* Darn, some plugin changed the value. */
3911 free_string_option(save_cpo
);
3914 qf_update_buffer(qi
);
3917 /* Jump to first match. */
3918 if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3919 qf_jump(qi
, 0, 0, FALSE
);
3921 EMSG2(_(e_nomatch2
), eap
->arg
);
3923 if (eap
->cmdidx
== CMD_lhelpgrep
)
3925 /* If the help window is not opened or if it already points to the
3926 * correct location list, then free the new location list. */
3927 if (!curwin
->w_buffer
->b_help
|| curwin
->w_llist
== qi
)
3932 else if (curwin
->w_llist
== NULL
)
3933 curwin
->w_llist
= qi
;
3937 #endif /* FEAT_QUICKFIX */