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 */
59 char *qf_title
; /* title derived from the command that created
62 char *qf_user_title
; /* title specified by the :csettitle or
65 int qf_use_user_title
; /* indicates that qf_user_title should
66 * be used instead of qf_title
73 * Count of references to this list. Used only for location lists.
74 * When a location list window reference this list, qf_refcount
75 * will be 2. Otherwise, qf_refcount will be 1. When qf_refcount
76 * reaches 0, the list is freed.
79 int qf_listcount
; /* current number of lists */
80 int qf_curlist
; /* current error list */
81 qf_list_T qf_lists
[LISTCOUNT
];
84 static qf_info_T ql_info
; /* global quickfix list */
86 #define FMT_PATTERNS 10 /* maximum number of % recognized */
89 * Structure used to hold the info of one part of 'errorformat'
91 typedef struct efm_S efm_T
;
94 regprog_T
*prog
; /* pre-formatted part of 'errorformat' */
95 efm_T
*next
; /* pointer to next (NULL if last) */
96 char_u addr
[FMT_PATTERNS
]; /* indices of used % patterns */
97 char_u prefix
; /* prefix of this format line: */
98 /* 'D' enter directory */
99 /* 'X' leave directory */
100 /* 'A' start of multi-line message */
101 /* 'E' error message */
102 /* 'W' warning message */
103 /* 'I' informational message */
104 /* 'C' continuation line */
105 /* 'Z' end of multi-line message */
106 /* 'G' general, unspecific message */
107 /* 'P' push file (partial) message */
108 /* 'Q' pop/quit file (partial) message */
109 /* 'O' overread (partial) message */
110 char_u flags
; /* additional flags given in prefix */
111 /* '-' do not include this line */
112 /* '+' include whole line in message */
113 int conthere
; /* %> used */
116 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 *qf_title
));
117 static void qf_new_list
__ARGS((qf_info_T
*qi
, char *qf_title
));
118 static void ll_free_all
__ARGS((qf_info_T
**pqi
));
119 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
));
120 static qf_info_T
*ll_new_list
__ARGS((void));
121 static void qf_msg
__ARGS((qf_info_T
*qi
));
122 static void qf_free
__ARGS((qf_info_T
*qi
, int idx
));
123 static char_u
*qf_types
__ARGS((int, int));
124 static int qf_get_fnum
__ARGS((char_u
*, char_u
*));
125 static char_u
*qf_push_dir
__ARGS((char_u
*, struct dir_stack_T
**));
126 static char_u
*qf_pop_dir
__ARGS((struct dir_stack_T
**));
127 static char_u
*qf_guess_filepath
__ARGS((char_u
*));
128 static void qf_fmt_text
__ARGS((char_u
*text
, char_u
*buf
, int bufsize
));
129 static void qf_clean_dir_stack
__ARGS((struct dir_stack_T
**));
131 static int qf_win_pos_update
__ARGS((qf_info_T
*qi
, int old_qf_index
));
132 static int is_qf_win
__ARGS((win_T
*win
, qf_info_T
*qi
));
133 static win_T
*qf_find_win
__ARGS((qf_info_T
*qi
));
134 static buf_T
*qf_find_buf
__ARGS((qf_info_T
*qi
));
135 static void qf_update_buffer
__ARGS((qf_info_T
*qi
));
136 static void qf_fill_buffer
__ARGS((qf_info_T
*qi
));
138 static char_u
*get_mef_name
__ARGS((void));
139 static buf_T
*load_dummy_buffer
__ARGS((char_u
*fname
));
140 static void wipe_dummy_buffer
__ARGS((buf_T
*buf
));
141 static void unload_dummy_buffer
__ARGS((buf_T
*buf
));
142 static qf_info_T
*ll_get_or_alloc_list
__ARGS((win_T
*));
144 /* Quickfix window check helper macro */
145 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL)
146 /* Location list window check helper macro */
147 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
149 * Return location list for window 'wp'
150 * For location list window, return the referenced location list
152 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist)
155 * Read the errorfile "efile" into memory, line by line, building the error
156 * list. Set the error list's title to qf_title.
157 * Return -1 for error, number of errors for success.
160 qf_init(wp
, efile
, errorformat
, newlist
, qf_title
)
164 int newlist
; /* TRUE: start a new error list */
167 qf_info_T
*qi
= &ql_info
;
174 qi
= ll_get_or_alloc_list(wp
);
179 return qf_init_ext(qi
, efile
, curbuf
, NULL
, errorformat
, newlist
,
180 (linenr_T
)0, (linenr_T
)0,
185 * Returns the title of the qf_info_T's current qf_list_T.
194 if (qi
->qf_lists
[qi
->qf_curlist
].qf_use_user_title
)
195 return qi
->qf_lists
[qi
->qf_curlist
].qf_user_title
;
197 return qi
->qf_lists
[qi
->qf_curlist
].qf_title
;
201 * Sets the title of a quickfix window / location list window.
211 if (eap
->cmdidx
== CMD_csettitle
)
214 err_msg
= e_quickfix
;
218 list_ref
= GET_LOC_LIST(curwin
);
222 if (!list_ref
|| !list_ref
->qf_listcount
)
230 if (!list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_use_user_title
)
233 /* restore the title derived from the command that created the error list */
234 vim_free(list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_user_title
);
235 list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_user_title
= NULL
;
236 list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_use_user_title
= FALSE
;
240 /* set the user's title */
241 vim_free(list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_user_title
);
243 if (eap
->arg
&& *eap
->arg
!= NUL
)
244 list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_user_title
= (char *)vim_strsave(eap
->arg
);
246 list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_user_title
= NULL
;
248 list_ref
->qf_lists
[list_ref
->qf_curlist
].qf_use_user_title
= TRUE
;
251 if (eap
->cmdidx
== CMD_csettitle
)
254 need_maketitle
= TRUE
;
257 if (bt_quickfix(win
->w_buffer
) && list_ref
== win
->w_llist_ref
)
258 win_redr_status(win
);
263 * Read the errorfile "efile" into memory, line by line, building the error
265 * Alternative: when "efile" is null read errors from buffer "buf".
266 * Always use 'errorformat' from "buf" if there is a local value.
267 * Then lnumfirst and lnumlast specify the range of lines to use.
268 * Set the title of the list to qf_title.
269 * Return -1 for error, number of errors for success.
272 qf_init_ext(qi
, efile
, buf
, tv
, errorformat
, newlist
, lnumfirst
, lnumlast
, qf_title
)
278 int newlist
; /* TRUE: start a new error list */
279 linenr_T lnumfirst
; /* first line number to use */
280 linenr_T lnumlast
; /* last line number to use */
286 char_u
*fmtstr
= NULL
;
288 char_u use_viscol
= FALSE
;
291 linenr_T buflnum
= lnumfirst
;
295 qfline_T
*qfprev
= NULL
; /* init to make SASC shut up */
297 efm_T
*fmt_first
= NULL
;
298 efm_T
*fmt_last
= NULL
;
300 efm_T
*fmt_start
= NULL
;
308 int multiline
= FALSE
;
309 int multiignore
= FALSE
;
310 int multiscan
= FALSE
;
311 int retval
= -1; /* default: return error flag */
312 char_u
*directory
= NULL
;
313 char_u
*currfile
= NULL
;
315 char_u
*p_str
= NULL
;
316 listitem_T
*p_li
= NULL
;
317 struct dir_stack_T
*file_stack
= NULL
;
319 static struct fmtpattern
323 } fmt_pat
[FMT_PATTERNS
] =
325 {'f', ".\\+"}, /* only used when at end */
337 namebuf
= alloc(CMDBUFFSIZE
+ 1);
338 errmsg
= alloc(CMDBUFFSIZE
+ 1);
339 pattern
= alloc(CMDBUFFSIZE
+ 1);
340 if (namebuf
== NULL
|| errmsg
== NULL
|| pattern
== NULL
)
343 if (efile
!= NULL
&& (fd
= mch_fopen((char *)efile
, "r")) == NULL
)
345 EMSG2(_(e_openerrf
), efile
);
349 if (newlist
|| qi
->qf_curlist
== qi
->qf_listcount
)
350 /* make place for a new list */
351 qf_new_list(qi
, qf_title
);
352 else if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
353 /* Adding to existing list, find last entry. */
354 for (qfprev
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
355 qfprev
->qf_next
!= qfprev
;
356 qfprev
= qfprev
->qf_next
)
360 * Each part of the format string is copied and modified from errorformat to
361 * regex prog. Only a few % characters are allowed.
363 /* Use the local value of 'errorformat' if it's set. */
364 if (errorformat
== p_efm
&& tv
== NULL
&& *buf
->b_p_efm
!= NUL
)
369 * Get some space to modify the format string into.
371 i
= (FMT_PATTERNS
* 3) + ((int)STRLEN(efm
) << 2);
372 for (round
= FMT_PATTERNS
; round
> 0; )
373 i
+= (int)STRLEN(fmt_pat
[--round
].pattern
);
374 #ifdef COLON_IN_FILENAME
375 i
+= 12; /* "%f" can become twelve chars longer */
377 i
+= 2; /* "%f" can become two chars longer */
379 if ((fmtstr
= alloc(i
)) == NULL
)
382 while (efm
[0] != NUL
)
385 * Allocate a new eformat structure and put it at the end of the list
387 fmt_ptr
= (efm_T
*)alloc_clear((unsigned)sizeof(efm_T
));
390 if (fmt_first
== NULL
) /* first one */
393 fmt_last
->next
= fmt_ptr
;
397 * Isolate one part in the 'errorformat' option
399 for (len
= 0; efm
[len
] != NUL
&& efm
[len
] != ','; ++len
)
400 if (efm
[len
] == '\\' && efm
[len
+ 1] != NUL
)
404 * Build regexp pattern from current 'errorformat' option
409 for (efmp
= efm
; efmp
< efm
+ len
; ++efmp
)
414 for (idx
= 0; idx
< FMT_PATTERNS
; ++idx
)
415 if (fmt_pat
[idx
].convchar
== *efmp
)
417 if (idx
< FMT_PATTERNS
)
419 if (fmt_ptr
->addr
[idx
])
421 sprintf((char *)errmsg
,
422 _("E372: Too many %%%c in format string"), *efmp
);
428 && vim_strchr((char_u
*)"DXOPQ",
429 fmt_ptr
->prefix
) != NULL
)
431 && vim_strchr((char_u
*)"OPQ",
432 fmt_ptr
->prefix
) == NULL
))
434 sprintf((char *)errmsg
,
435 _("E373: Unexpected %%%c in format string"), *efmp
);
439 fmt_ptr
->addr
[idx
] = (char_u
)++round
;
442 #ifdef BACKSLASH_IN_FILENAME
445 /* Also match "c:" in the file name, even when
446 * checking for a colon next: "%f:".
448 STRCPY(ptr
, "\\%(\\a:\\)\\=");
452 if (*efmp
== 'f' && efmp
[1] != NUL
)
454 if (efmp
[1] != '\\' && efmp
[1] != '%')
456 /* A file name may contain spaces, but this isn't
457 * in "\f". For "%f:%l:%m" there may be a ":" in
458 * the file name. Use ".\{-1,}x" instead (x is
459 * the next character), the requirement that :999:
460 * follows should work. */
461 STRCPY(ptr
, ".\\{-1,}");
466 /* File name followed by '\\' or '%': include as
467 * many file name chars as possible. */
468 STRCPY(ptr
, "\\f\\+");
474 srcptr
= (char_u
*)fmt_pat
[idx
].pattern
;
475 while ((*ptr
= *srcptr
++) != NUL
)
481 else if (*efmp
== '*')
483 if (*++efmp
== '[' || *efmp
== '\\')
485 if ((*ptr
++ = *efmp
) == '[') /* %*[^a-z0-9] etc. */
489 if (efmp
< efm
+ len
)
491 *ptr
++ = *++efmp
; /* could be ']' */
492 while (efmp
< efm
+ len
493 && (*ptr
++ = *++efmp
) != ']')
495 if (efmp
== efm
+ len
)
497 EMSG(_("E374: Missing ] in format string"));
502 else if (efmp
< efm
+ len
) /* %*\D, %*\s etc. */
509 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */
510 sprintf((char *)errmsg
,
511 _("E375: Unsupported %%%c in format string"), *efmp
);
516 else if (vim_strchr((char_u
*)"%\\.^$~[", *efmp
) != NULL
)
517 *ptr
++ = *efmp
; /* regexp magic characters */
518 else if (*efmp
== '#')
520 else if (*efmp
== '>')
521 fmt_ptr
->conthere
= TRUE
;
522 else if (efmp
== efm
+ 1) /* analyse prefix */
524 if (vim_strchr((char_u
*)"+-", *efmp
) != NULL
)
525 fmt_ptr
->flags
= *efmp
++;
526 if (vim_strchr((char_u
*)"DXAEWICZGOPQ", *efmp
) != NULL
)
527 fmt_ptr
->prefix
= *efmp
;
530 sprintf((char *)errmsg
,
531 _("E376: Invalid %%%c in format string prefix"), *efmp
);
538 sprintf((char *)errmsg
,
539 _("E377: Invalid %%%c in format string"), *efmp
);
544 else /* copy normal character */
546 if (*efmp
== '\\' && efmp
+ 1 < efm
+ len
)
548 else if (vim_strchr((char_u
*)".*^$~[", *efmp
) != NULL
)
549 *ptr
++ = '\\'; /* escape regexp atoms */
556 if ((fmt_ptr
->prog
= vim_regcomp(fmtstr
, RE_MAGIC
+ RE_STRING
)) == NULL
)
559 * Advance to next part
561 efm
= skip_to_option_part(efm
+ len
); /* skip comma and spaces */
563 if (fmt_first
== NULL
) /* nothing found */
565 EMSG(_("E378: 'errorformat' contains no pattern"));
570 * got_int is reset here, because it was probably set when killing the
571 * ":make" command, but we still want to read the errorfile then.
575 /* Always ignore case when looking for a matching error. */
576 regmatch
.rm_ic
= TRUE
;
580 if (tv
->v_type
== VAR_STRING
)
581 p_str
= tv
->vval
.v_string
;
582 else if (tv
->v_type
== VAR_LIST
)
583 p_li
= tv
->vval
.v_list
->lv_first
;
587 * Read the lines in the error file one by one.
588 * Try to recognize one of the error formats in each line.
592 /* Get the next line. */
597 if (tv
->v_type
== VAR_STRING
)
599 /* Get the next line from the supplied string */
602 if (!*p_str
) /* Reached the end of the string */
605 p
= vim_strchr(p_str
, '\n');
607 len
= (int)(p
- p_str
+ 1);
609 len
= (int)STRLEN(p_str
);
611 if (len
> CMDBUFFSIZE
- 2)
612 vim_strncpy(IObuff
, p_str
, CMDBUFFSIZE
- 2);
614 vim_strncpy(IObuff
, p_str
, len
);
618 else if (tv
->v_type
== VAR_LIST
)
620 /* Get the next line from the supplied list */
621 while (p_li
&& p_li
->li_tv
.v_type
!= VAR_STRING
)
622 p_li
= p_li
->li_next
; /* Skip non-string items */
624 if (!p_li
) /* End of the list */
627 len
= (int)STRLEN(p_li
->li_tv
.vval
.v_string
);
628 if (len
> CMDBUFFSIZE
- 2)
629 len
= CMDBUFFSIZE
- 2;
631 vim_strncpy(IObuff
, p_li
->li_tv
.vval
.v_string
, len
);
633 p_li
= p_li
->li_next
; /* next item */
638 /* Get the next line from the supplied buffer */
639 if (buflnum
> lnumlast
)
641 vim_strncpy(IObuff
, ml_get_buf(buf
, buflnum
++, FALSE
),
645 else if (fgets((char *)IObuff
, CMDBUFFSIZE
- 2, fd
) == NULL
)
648 IObuff
[CMDBUFFSIZE
- 2] = NUL
; /* for very long lines */
649 if ((efmp
= vim_strrchr(IObuff
, '\n')) != NULL
)
652 if ((efmp
= vim_strrchr(IObuff
, '\r')) != NULL
)
656 /* If there was no %> item start at the first pattern */
657 if (fmt_start
== NULL
)
666 * Try to match each part of 'errorformat' until we find a complete
671 for ( ; fmt_ptr
!= NULL
; fmt_ptr
= fmt_ptr
->next
)
673 idx
= fmt_ptr
->prefix
;
674 if (multiscan
&& vim_strchr((char_u
*)"OPQ", idx
) == NULL
)
687 regmatch
.regprog
= fmt_ptr
->prog
;
688 if (vim_regexec(®match
, IObuff
, (colnr_T
)0))
690 if ((idx
== 'C' || idx
== 'Z') && !multiline
)
692 if (vim_strchr((char_u
*)"EWI", idx
) != NULL
)
697 * Extract error message data from matched line.
698 * We check for an actual submatch, because "\[" and "\]" in
699 * the 'errorformat' may cause the wrong submatch to be used.
701 if ((i
= (int)fmt_ptr
->addr
[0]) > 0) /* %f */
705 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
708 /* Expand ~/file and $HOME/file to full path. */
709 c
= *regmatch
.endp
[i
];
710 *regmatch
.endp
[i
] = NUL
;
711 expand_env(regmatch
.startp
[i
], namebuf
, CMDBUFFSIZE
);
712 *regmatch
.endp
[i
] = c
;
714 if (vim_strchr((char_u
*)"OPQ", idx
) != NULL
715 && mch_getperm(namebuf
) == -1)
718 if ((i
= (int)fmt_ptr
->addr
[1]) > 0) /* %n */
720 if (regmatch
.startp
[i
] == NULL
)
722 enr
= (int)atol((char *)regmatch
.startp
[i
]);
724 if ((i
= (int)fmt_ptr
->addr
[2]) > 0) /* %l */
726 if (regmatch
.startp
[i
] == NULL
)
728 lnum
= atol((char *)regmatch
.startp
[i
]);
730 if ((i
= (int)fmt_ptr
->addr
[3]) > 0) /* %c */
732 if (regmatch
.startp
[i
] == NULL
)
734 col
= (int)atol((char *)regmatch
.startp
[i
]);
736 if ((i
= (int)fmt_ptr
->addr
[4]) > 0) /* %t */
738 if (regmatch
.startp
[i
] == NULL
)
740 type
= *regmatch
.startp
[i
];
742 if (fmt_ptr
->flags
== '+' && !multiscan
) /* %+ */
743 STRCPY(errmsg
, IObuff
);
744 else if ((i
= (int)fmt_ptr
->addr
[5]) > 0) /* %m */
746 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
748 len
= (int)(regmatch
.endp
[i
] - regmatch
.startp
[i
]);
749 vim_strncpy(errmsg
, regmatch
.startp
[i
], len
);
751 if ((i
= (int)fmt_ptr
->addr
[6]) > 0) /* %r */
753 if (regmatch
.startp
[i
] == NULL
)
755 tail
= regmatch
.startp
[i
];
757 if ((i
= (int)fmt_ptr
->addr
[7]) > 0) /* %p */
759 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
761 col
= (int)(regmatch
.endp
[i
] - regmatch
.startp
[i
] + 1);
762 if (*((char_u
*)regmatch
.startp
[i
]) != TAB
)
765 if ((i
= (int)fmt_ptr
->addr
[8]) > 0) /* %v */
767 if (regmatch
.startp
[i
] == NULL
)
769 col
= (int)atol((char *)regmatch
.startp
[i
]);
772 if ((i
= (int)fmt_ptr
->addr
[9]) > 0) /* %s */
774 if (regmatch
.startp
[i
] == NULL
|| regmatch
.endp
[i
] == NULL
)
776 len
= (int)(regmatch
.endp
[i
] - regmatch
.startp
[i
]);
777 if (len
> CMDBUFFSIZE
- 5)
778 len
= CMDBUFFSIZE
- 5;
779 STRCPY(pattern
, "^\\V");
780 STRNCAT(pattern
, regmatch
.startp
[i
], len
);
781 pattern
[len
+ 3] = '\\';
782 pattern
[len
+ 4] = '$';
783 pattern
[len
+ 5] = NUL
;
790 if (fmt_ptr
== NULL
|| idx
== 'D' || idx
== 'X')
794 if (idx
== 'D') /* enter directory */
798 EMSG(_("E379: Missing or empty directory name"));
801 if ((directory
= qf_push_dir(namebuf
, &dir_stack
)) == NULL
)
804 else if (idx
== 'X') /* leave directory */
805 directory
= qf_pop_dir(&dir_stack
);
807 namebuf
[0] = NUL
; /* no match found, remove file name */
808 lnum
= 0; /* don't jump to this line */
810 STRCPY(errmsg
, IObuff
); /* copy whole line to error message */
812 multiline
= multiignore
= FALSE
;
814 else if (fmt_ptr
!= NULL
)
817 if (fmt_ptr
->conthere
)
820 if (vim_strchr((char_u
*)"AEWI", idx
) != NULL
)
821 multiline
= TRUE
; /* start of a multi-line message */
822 else if (vim_strchr((char_u
*)"CZ", idx
) != NULL
)
823 { /* continuation of multi-line msg */
826 if (*errmsg
&& !multiignore
)
828 len
= (int)STRLEN(qfprev
->qf_text
);
829 if ((ptr
= alloc((unsigned)(len
+ STRLEN(errmsg
) + 2)))
832 STRCPY(ptr
, qfprev
->qf_text
);
833 vim_free(qfprev
->qf_text
);
834 qfprev
->qf_text
= ptr
;
835 *(ptr
+= len
) = '\n';
836 STRCPY(++ptr
, errmsg
);
838 if (qfprev
->qf_nr
== -1)
840 if (vim_isprintc(type
) && !qfprev
->qf_type
)
841 qfprev
->qf_type
= type
; /* only printable chars allowed */
842 if (!qfprev
->qf_lnum
)
843 qfprev
->qf_lnum
= lnum
;
845 qfprev
->qf_col
= col
;
846 qfprev
->qf_viscol
= use_viscol
;
847 if (!qfprev
->qf_fnum
)
848 qfprev
->qf_fnum
= qf_get_fnum(directory
,
849 *namebuf
|| directory
? namebuf
850 : currfile
&& valid
? currfile
: 0);
852 multiline
= multiignore
= FALSE
;
856 else if (vim_strchr((char_u
*)"OPQ", idx
) != NULL
)
858 /* global file names */
860 if (*namebuf
== NUL
|| mch_getperm(namebuf
) >= 0)
862 if (*namebuf
&& idx
== 'P')
863 currfile
= qf_push_dir(namebuf
, &file_stack
);
865 currfile
= qf_pop_dir(&file_stack
);
869 STRMOVE(IObuff
, skipwhite(tail
));
875 if (fmt_ptr
->flags
== '-') /* generally exclude this line */
878 multiignore
= TRUE
; /* also exclude continuation lines */
883 if (qf_add_entry(qi
, &qfprev
,
885 (*namebuf
|| directory
)
887 : ((currfile
&& valid
) ? currfile
: (char_u
*)NULL
),
900 if (fd
== NULL
|| !ferror(fd
))
902 if (qi
->qf_lists
[qi
->qf_curlist
].qf_index
== 0)
904 /* no valid entry found */
905 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
=
906 qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
907 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
908 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= TRUE
;
912 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
913 if (qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
== NULL
)
914 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
=
915 qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
917 /* return number of matches */
918 retval
= qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
923 qf_free(qi
, qi
->qf_curlist
);
925 if (qi
->qf_curlist
> 0)
930 for (fmt_ptr
= fmt_first
; fmt_ptr
!= NULL
; fmt_ptr
= fmt_first
)
932 fmt_first
= fmt_ptr
->next
;
933 vim_free(fmt_ptr
->prog
);
936 qf_clean_dir_stack(&dir_stack
);
937 qf_clean_dir_stack(&file_stack
);
945 qf_update_buffer(qi
);
952 * Prepare for adding a new quickfix list.
955 qf_new_list(qi
, qf_title
)
962 * If the current entry is not the last entry, delete entries below
963 * the current entry. This makes it possible to browse in a tree-like
966 while (qi
->qf_listcount
> qi
->qf_curlist
+ 1)
967 qf_free(qi
, --qi
->qf_listcount
);
970 * When the stack is full, remove to oldest entry
971 * Otherwise, add a new entry.
973 if (qi
->qf_listcount
== LISTCOUNT
)
976 for (i
= 1; i
< LISTCOUNT
; ++i
)
977 qi
->qf_lists
[i
- 1] = qi
->qf_lists
[i
];
978 qi
->qf_curlist
= LISTCOUNT
- 1;
981 qi
->qf_curlist
= qi
->qf_listcount
++;
982 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 0;
983 qi
->qf_lists
[qi
->qf_curlist
].qf_count
= 0;
986 if ((qi
->qf_lists
[qi
->qf_curlist
].qf_title
= (char *)alloc(STRLEN(qf_title
) + 2)))
987 sprintf(qi
->qf_lists
[qi
->qf_curlist
].qf_title
, ":%s", qf_title
);
990 qi
->qf_lists
[qi
->qf_curlist
].qf_title
= NULL
;
992 qi
->qf_lists
[qi
->qf_curlist
].qf_user_title
= NULL
;
993 qi
->qf_lists
[qi
->qf_curlist
].qf_use_user_title
= FALSE
;
997 * Free a location list
1009 *pqi
= NULL
; /* Remove reference to this list */
1012 if (qi
->qf_refcount
< 1)
1014 /* No references to this location list */
1015 for (i
= 0; i
< qi
->qf_listcount
; ++i
)
1026 qf_info_T
*qi
= &ql_info
;
1031 ll_free_all(&wp
->w_llist
);
1032 ll_free_all(&wp
->w_llist_ref
);
1036 for (i
= 0; i
< qi
->qf_listcount
; ++i
)
1041 * Add an entry to the end of the list of errors.
1042 * Returns OK or FAIL.
1045 qf_add_entry(qi
, prevp
, dir
, fname
, bufnum
, mesg
, lnum
, col
, vis_col
, pattern
,
1047 qf_info_T
*qi
; /* quickfix list */
1048 qfline_T
**prevp
; /* pointer to previously added entry or NULL */
1049 char_u
*dir
; /* optional directory name */
1050 char_u
*fname
; /* file name or NULL */
1051 int bufnum
; /* buffer number or zero */
1052 char_u
*mesg
; /* message */
1053 long lnum
; /* line number */
1054 int col
; /* column */
1055 int vis_col
; /* using visual column */
1056 char_u
*pattern
; /* search pattern */
1057 int nr
; /* error number */
1058 int type
; /* type character */
1059 int valid
; /* valid entry */
1063 if ((qfp
= (qfline_T
*)alloc((unsigned)sizeof(qfline_T
))) == NULL
)
1066 qfp
->qf_fnum
= bufnum
;
1068 qfp
->qf_fnum
= qf_get_fnum(dir
, fname
);
1069 if ((qfp
->qf_text
= vim_strsave(mesg
)) == NULL
)
1074 qfp
->qf_lnum
= lnum
;
1076 qfp
->qf_viscol
= vis_col
;
1077 if (pattern
== NULL
|| *pattern
== NUL
)
1078 qfp
->qf_pattern
= NULL
;
1079 else if ((qfp
->qf_pattern
= vim_strsave(pattern
)) == NULL
)
1081 vim_free(qfp
->qf_text
);
1086 if (type
!= 1 && !vim_isprintc(type
)) /* only printable chars allowed */
1088 qfp
->qf_type
= type
;
1089 qfp
->qf_valid
= valid
;
1091 if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
1092 /* first element in the list */
1094 qi
->qf_lists
[qi
->qf_curlist
].qf_start
= qfp
;
1095 qfp
->qf_prev
= qfp
; /* first element points to itself */
1099 qfp
->qf_prev
= *prevp
;
1100 (*prevp
)->qf_next
= qfp
;
1102 qfp
->qf_next
= qfp
; /* last element points to itself */
1103 qfp
->qf_cleared
= FALSE
;
1105 ++qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
1106 if (qi
->qf_lists
[qi
->qf_curlist
].qf_index
== 0 && qfp
->qf_valid
)
1107 /* first valid entry */
1109 qi
->qf_lists
[qi
->qf_curlist
].qf_index
=
1110 qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
1111 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qfp
;
1118 * Allocate a new location list
1125 qi
= (qf_info_T
*)alloc((unsigned)sizeof(qf_info_T
));
1128 vim_memset(qi
, 0, (size_t)(sizeof(qf_info_T
)));
1136 * Return the location list for window 'wp'.
1137 * If not present, allocate a location list
1140 ll_get_or_alloc_list(wp
)
1143 if (IS_LL_WINDOW(wp
))
1144 /* For a location list window, use the referenced location list */
1145 return wp
->w_llist_ref
;
1148 * For a non-location list window, w_llist_ref should not point to a
1151 ll_free_all(&wp
->w_llist_ref
);
1153 if (wp
->w_llist
== NULL
)
1154 wp
->w_llist
= ll_new_list(); /* new location list */
1159 * Copy the location list from window "from" to window "to".
1162 copy_loclist(from
, to
)
1171 * When copying from a location list window, copy the referenced
1172 * location list. For other windows, copy the location list for
1175 if (IS_LL_WINDOW(from
))
1176 qi
= from
->w_llist_ref
;
1180 if (qi
== NULL
) /* no location list to copy */
1183 /* allocate a new location list */
1184 if ((to
->w_llist
= ll_new_list()) == NULL
)
1187 to
->w_llist
->qf_listcount
= qi
->qf_listcount
;
1189 /* Copy the location lists one at a time */
1190 for (idx
= 0; idx
< qi
->qf_listcount
; idx
++)
1192 qf_list_T
*from_qfl
;
1195 to
->w_llist
->qf_curlist
= idx
;
1197 from_qfl
= &qi
->qf_lists
[idx
];
1198 to_qfl
= &to
->w_llist
->qf_lists
[idx
];
1200 /* Some of the fields are populated by qf_add_entry() */
1201 to_qfl
->qf_nonevalid
= from_qfl
->qf_nonevalid
;
1202 to_qfl
->qf_count
= 0;
1203 to_qfl
->qf_index
= 0;
1204 to_qfl
->qf_start
= NULL
;
1205 to_qfl
->qf_ptr
= NULL
;
1206 if (from_qfl
->qf_title
)
1207 to_qfl
->qf_title
= (char *)vim_strsave((char_u
*)from_qfl
->qf_title
);
1209 to_qfl
->qf_title
= NULL
;
1211 if (from_qfl
->qf_user_title
)
1212 to_qfl
->qf_user_title
= (char *)vim_strsave((char_u
*)from_qfl
->qf_user_title
);
1214 to_qfl
->qf_user_title
= NULL
;
1215 to_qfl
->qf_use_user_title
= from_qfl
->qf_use_user_title
;
1217 if (from_qfl
->qf_count
)
1220 qfline_T
*prevp
= NULL
;
1222 /* copy all the location entries in this list */
1223 for (i
= 0, from_qfp
= from_qfl
->qf_start
; i
< from_qfl
->qf_count
;
1224 ++i
, from_qfp
= from_qfp
->qf_next
)
1226 if (qf_add_entry(to
->w_llist
, &prevp
,
1233 from_qfp
->qf_viscol
,
1234 from_qfp
->qf_pattern
,
1237 from_qfp
->qf_valid
) == FAIL
)
1243 * qf_add_entry() will not set the qf_num field, as the
1244 * directory and file names are not supplied. So the qf_fnum
1245 * field is copied here.
1247 prevp
->qf_fnum
= from_qfp
->qf_fnum
; /* file number */
1248 prevp
->qf_type
= from_qfp
->qf_type
; /* error type */
1249 if (from_qfl
->qf_ptr
== from_qfp
)
1250 to_qfl
->qf_ptr
= prevp
; /* current location */
1254 to_qfl
->qf_index
= from_qfl
->qf_index
; /* current index in the list */
1256 /* When no valid entries are present in the list, qf_ptr points to
1257 * the first item in the list */
1258 if (to_qfl
->qf_nonevalid
== TRUE
)
1259 to_qfl
->qf_ptr
= to_qfl
->qf_start
;
1262 to
->w_llist
->qf_curlist
= qi
->qf_curlist
; /* current list */
1266 * get buffer number for file "dir.name"
1269 qf_get_fnum(directory
, fname
)
1273 if (fname
== NULL
|| *fname
== NUL
) /* no file name */
1277 /* Name is reported as `main.c', but file is `c.main' */
1278 return ro_buflist_add(fname
);
1284 vms_remove_version(fname
);
1286 # ifdef BACKSLASH_IN_FILENAME
1287 if (directory
!= NULL
)
1288 slash_adjust(directory
);
1289 slash_adjust(fname
);
1291 if (directory
!= NULL
&& !vim_isAbsName(fname
)
1292 && (ptr
= concat_fnames(directory
, fname
, TRUE
)) != NULL
)
1295 * Here we check if the file really exists.
1296 * This should normally be true, but if make works without
1297 * "leaving directory"-messages we might have missed a
1300 if (mch_getperm(ptr
) < 0)
1303 directory
= qf_guess_filepath(fname
);
1305 ptr
= concat_fnames(directory
, fname
, TRUE
);
1307 ptr
= vim_strsave(fname
);
1309 /* Use concatenated directory name and file name */
1310 fnum
= buflist_add(ptr
, 0);
1314 return buflist_add(fname
, 0);
1320 * push dirbuf onto the directory stack and return pointer to actual dir or
1324 qf_push_dir(dirbuf
, stackptr
)
1326 struct dir_stack_T
**stackptr
;
1328 struct dir_stack_T
*ds_new
;
1329 struct dir_stack_T
*ds_ptr
;
1331 /* allocate new stack element and hook it in */
1332 ds_new
= (struct dir_stack_T
*)alloc((unsigned)sizeof(struct dir_stack_T
));
1336 ds_new
->next
= *stackptr
;
1339 /* store directory on the stack */
1340 if (vim_isAbsName(dirbuf
)
1341 || (*stackptr
)->next
== NULL
1342 || (*stackptr
&& dir_stack
!= *stackptr
))
1343 (*stackptr
)->dirname
= vim_strsave(dirbuf
);
1346 /* Okay we don't have an absolute path.
1347 * dirbuf must be a subdir of one of the directories on the stack.
1350 ds_new
= (*stackptr
)->next
;
1351 (*stackptr
)->dirname
= NULL
;
1354 vim_free((*stackptr
)->dirname
);
1355 (*stackptr
)->dirname
= concat_fnames(ds_new
->dirname
, dirbuf
,
1357 if (mch_isdir((*stackptr
)->dirname
) == TRUE
)
1360 ds_new
= ds_new
->next
;
1363 /* clean up all dirs we already left */
1364 while ((*stackptr
)->next
!= ds_new
)
1366 ds_ptr
= (*stackptr
)->next
;
1367 (*stackptr
)->next
= (*stackptr
)->next
->next
;
1368 vim_free(ds_ptr
->dirname
);
1372 /* Nothing found -> it must be on top level */
1375 vim_free((*stackptr
)->dirname
);
1376 (*stackptr
)->dirname
= vim_strsave(dirbuf
);
1380 if ((*stackptr
)->dirname
!= NULL
)
1381 return (*stackptr
)->dirname
;
1385 *stackptr
= (*stackptr
)->next
;
1393 * pop dirbuf from the directory stack and return previous directory or NULL if
1397 qf_pop_dir(stackptr
)
1398 struct dir_stack_T
**stackptr
;
1400 struct dir_stack_T
*ds_ptr
;
1402 /* TODO: Should we check if dirbuf is the directory on top of the stack?
1403 * What to do if it isn't? */
1405 /* pop top element and free it */
1406 if (*stackptr
!= NULL
)
1409 *stackptr
= (*stackptr
)->next
;
1410 vim_free(ds_ptr
->dirname
);
1414 /* return NEW top element as current dir or NULL if stack is empty*/
1415 return *stackptr
? (*stackptr
)->dirname
: NULL
;
1419 * clean up directory stack
1422 qf_clean_dir_stack(stackptr
)
1423 struct dir_stack_T
**stackptr
;
1425 struct dir_stack_T
*ds_ptr
;
1427 while ((ds_ptr
= *stackptr
) != NULL
)
1429 *stackptr
= (*stackptr
)->next
;
1430 vim_free(ds_ptr
->dirname
);
1436 * Check in which directory of the directory stack the given file can be
1438 * Returns a pointer to the directory name or NULL if not found
1439 * Cleans up intermediate directory entries.
1441 * TODO: How to solve the following problem?
1442 * If we have the this directory tree:
1452 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb.
1453 * qf_guess_filepath will return NULL.
1456 qf_guess_filepath(filename
)
1459 struct dir_stack_T
*ds_ptr
;
1460 struct dir_stack_T
*ds_tmp
;
1463 /* no dirs on the stack - there's nothing we can do */
1464 if (dir_stack
== NULL
)
1467 ds_ptr
= dir_stack
->next
;
1472 fullname
= concat_fnames(ds_ptr
->dirname
, filename
, TRUE
);
1474 /* If concat_fnames failed, just go on. The worst thing that can happen
1475 * is that we delete the entire stack.
1477 if ((fullname
!= NULL
) && (mch_getperm(fullname
) >= 0))
1480 ds_ptr
= ds_ptr
->next
;
1485 /* clean up all dirs we already left */
1486 while (dir_stack
->next
!= ds_ptr
)
1488 ds_tmp
= dir_stack
->next
;
1489 dir_stack
->next
= dir_stack
->next
->next
;
1490 vim_free(ds_tmp
->dirname
);
1494 return ds_ptr
==NULL
? NULL
: ds_ptr
->dirname
;
1499 * jump to a quickfix line
1500 * if dir == FORWARD go "errornr" valid entries forward
1501 * if dir == BACKWARD go "errornr" valid entries backward
1502 * if dir == FORWARD_FILE go "errornr" valid entries files backward
1503 * if dir == BACKWARD_FILE go "errornr" valid entries files backward
1504 * else if "errornr" is zero, redisplay the same line
1505 * else go to entry "errornr"
1508 qf_jump(qi
, dir
, errornr
, forceit
)
1516 qfline_T
*old_qf_ptr
;
1521 static char_u
*e_no_more_items
= (char_u
*)N_("E553: No more items");
1522 char_u
*err
= e_no_more_items
;
1530 char_u
*old_swb
= p_swb
;
1531 unsigned old_swb_flags
= swb_flags
;
1532 int opened_window
= FALSE
;
1537 win_T
*oldwin
= curwin
;
1538 int print_message
= TRUE
;
1541 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
1549 if (qi
->qf_curlist
>= qi
->qf_listcount
1550 || qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
1552 EMSG(_(e_quickfix
));
1556 qf_ptr
= qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
;
1557 old_qf_ptr
= qf_ptr
;
1558 qf_index
= qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
1559 old_qf_index
= qf_index
;
1560 if (dir
== FORWARD
|| dir
== FORWARD_FILE
) /* next valid entry */
1564 old_qf_ptr
= qf_ptr
;
1565 prev_index
= qf_index
;
1566 old_qf_fnum
= qf_ptr
->qf_fnum
;
1569 if (qf_index
== qi
->qf_lists
[qi
->qf_curlist
].qf_count
1570 || qf_ptr
->qf_next
== NULL
)
1572 qf_ptr
= old_qf_ptr
;
1573 qf_index
= prev_index
;
1583 qf_ptr
= qf_ptr
->qf_next
;
1584 } while ((!qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
1585 && !qf_ptr
->qf_valid
)
1586 || (dir
== FORWARD_FILE
&& qf_ptr
->qf_fnum
== old_qf_fnum
));
1590 else if (dir
== BACKWARD
|| dir
== BACKWARD_FILE
) /* prev. valid entry */
1594 old_qf_ptr
= qf_ptr
;
1595 prev_index
= qf_index
;
1596 old_qf_fnum
= qf_ptr
->qf_fnum
;
1599 if (qf_index
== 1 || qf_ptr
->qf_prev
== NULL
)
1601 qf_ptr
= old_qf_ptr
;
1602 qf_index
= prev_index
;
1612 qf_ptr
= qf_ptr
->qf_prev
;
1613 } while ((!qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
1614 && !qf_ptr
->qf_valid
)
1615 || (dir
== BACKWARD_FILE
&& qf_ptr
->qf_fnum
== old_qf_fnum
));
1619 else if (errornr
!= 0) /* go to specified number */
1621 while (errornr
< qf_index
&& qf_index
> 1 && qf_ptr
->qf_prev
!= NULL
)
1624 qf_ptr
= qf_ptr
->qf_prev
;
1626 while (errornr
> qf_index
&& qf_index
<
1627 qi
->qf_lists
[qi
->qf_curlist
].qf_count
1628 && qf_ptr
->qf_next
!= NULL
)
1631 qf_ptr
= qf_ptr
->qf_next
;
1636 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= qf_index
;
1637 if (qf_win_pos_update(qi
, old_qf_index
))
1638 /* No need to print the error message if it's visible in the error
1640 print_message
= FALSE
;
1643 * For ":helpgrep" find a help window or open one.
1645 if (qf_ptr
->qf_type
== 1 && (!curwin
->w_buffer
->b_help
|| cmdmod
.tab
!= 0))
1649 if (cmdmod
.tab
!= 0)
1652 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
1653 if (wp
->w_buffer
!= NULL
&& wp
->w_buffer
->b_help
)
1655 if (wp
!= NULL
&& wp
->w_buffer
->b_nwindows
> 0)
1656 win_enter(wp
, TRUE
);
1660 * Split off help window; put it at far top if no position
1661 * specified, the current window is vertically split and narrow.
1664 # ifdef FEAT_VERTSPLIT
1665 if (cmdmod
.split
== 0 && curwin
->w_width
!= Columns
1666 && curwin
->w_width
< 80)
1670 flags
|= WSP_NEWLOC
; /* don't copy the location list */
1672 if (win_split(0, flags
) == FAIL
)
1674 opened_window
= TRUE
; /* close it when fail */
1676 if (curwin
->w_height
< p_hh
)
1677 win_setheight((int)p_hh
);
1679 if (qi
!= &ql_info
) /* not a quickfix list */
1681 /* The new window should use the supplied location list */
1682 curwin
->w_llist
= qi
;
1688 restart_edit
= 0; /* don't want insert mode in help file */
1692 * If currently in the quickfix window, find another window to show the
1695 if (bt_quickfix(curbuf
) && !opened_window
)
1698 * If there is no file specified, we don't know where to go.
1699 * But do advance, otherwise ":cn" gets stuck.
1701 if (qf_ptr
->qf_fnum
== 0)
1704 /* Locate a window showing a normal buffer */
1706 FOR_ALL_WINDOWS(win
)
1707 if (win
->w_buffer
->b_p_bt
[0] == NUL
)
1714 * If no usable window is found and 'switchbuf' contains "usetab"
1715 * then search in other tabs.
1717 if (!usable_win
&& (swb_flags
& SWB_USETAB
))
1722 FOR_ALL_TAB_WINDOWS(tp
, wp
)
1724 if (wp
->w_buffer
->b_fnum
== qf_ptr
->qf_fnum
)
1726 goto_tabpage_win(tp
, wp
);
1735 * If there is only one window and it is the quickfix window, create a
1736 * new one above the quickfix window.
1738 if (((firstwin
== lastwin
) && bt_quickfix(curbuf
)) || !usable_win
)
1740 ll_ref
= curwin
->w_llist_ref
;
1744 flags
|= WSP_NEWLOC
;
1745 if (win_split(0, flags
) == FAIL
)
1746 goto failed
; /* not enough room for window */
1747 opened_window
= TRUE
; /* close it when fail */
1748 p_swb
= empty_option
; /* don't split again */
1750 # ifdef FEAT_SCROLLBIND
1751 curwin
->w_p_scb
= FALSE
;
1755 /* The new window should use the location list from the
1756 * location list window */
1757 curwin
->w_llist
= ll_ref
;
1758 ll_ref
->qf_refcount
++;
1763 if (curwin
->w_llist_ref
!= NULL
)
1765 /* In a location window */
1766 ll_ref
= curwin
->w_llist_ref
;
1768 /* Find the window with the same location list */
1769 FOR_ALL_WINDOWS(win
)
1770 if (win
->w_llist
== ll_ref
)
1774 /* Find the window showing the selected file */
1775 FOR_ALL_WINDOWS(win
)
1776 if (win
->w_buffer
->b_fnum
== qf_ptr
->qf_fnum
)
1780 /* Find a previous usable window */
1784 if (win
->w_buffer
->b_p_bt
[0] == NUL
)
1786 if (win
->w_prev
== NULL
)
1787 win
= lastwin
; /* wrap around the top */
1789 win
= win
->w_prev
; /* go to previous window */
1790 } while (win
!= curwin
);
1795 /* If the location list for the window is not set, then set it
1796 * to the location list from the location window */
1797 if (win
->w_llist
== NULL
)
1799 win
->w_llist
= ll_ref
;
1800 ll_ref
->qf_refcount
++;
1807 * Try to find a window that shows the right buffer.
1808 * Default to the window just above the quickfix buffer.
1814 if (win
->w_buffer
->b_fnum
== qf_ptr
->qf_fnum
)
1816 if (win
->w_prev
== NULL
)
1817 win
= lastwin
; /* wrap around the top */
1819 win
= win
->w_prev
; /* go to previous window */
1821 if (IS_QF_WINDOW(win
))
1823 /* Didn't find it, go to the window before the quickfix
1827 else if (curwin
->w_prev
!= NULL
)
1828 win
= curwin
->w_prev
;
1830 win
= curwin
->w_next
;
1834 /* Remember a usable window. */
1835 if (altwin
== NULL
&& !win
->w_p_pvw
1836 && win
->w_buffer
->b_p_bt
[0] == NUL
)
1847 * If there is a file name,
1848 * read the wanted file if needed, and check autowrite etc.
1850 old_curbuf
= curbuf
;
1851 old_lnum
= curwin
->w_cursor
.lnum
;
1853 if (qf_ptr
->qf_fnum
!= 0)
1855 if (qf_ptr
->qf_type
== 1)
1857 /* Open help file (do_ecmd() will set b_help flag, readfile() will
1858 * set b_p_ro flag). */
1859 if (!can_abandon(curbuf
, forceit
))
1861 EMSG(_(e_nowrtmsg
));
1865 ok
= do_ecmd(qf_ptr
->qf_fnum
, NULL
, NULL
, NULL
, (linenr_T
)1,
1866 ECMD_HIDE
+ ECMD_SET_HELP
,
1867 oldwin
== curwin
? curwin
: NULL
);
1870 ok
= buflist_getfile(qf_ptr
->qf_fnum
,
1871 (linenr_T
)1, GETF_SETMARK
| GETF_SWITCH
, forceit
);
1876 /* When not switched to another buffer, still need to set pc mark */
1877 if (curbuf
== old_curbuf
)
1880 if (qf_ptr
->qf_pattern
== NULL
)
1883 * Go to line with error, unless qf_lnum is 0.
1885 i
= qf_ptr
->qf_lnum
;
1888 if (i
> curbuf
->b_ml
.ml_line_count
)
1889 i
= curbuf
->b_ml
.ml_line_count
;
1890 curwin
->w_cursor
.lnum
= i
;
1892 if (qf_ptr
->qf_col
> 0)
1894 curwin
->w_cursor
.col
= qf_ptr
->qf_col
- 1;
1895 if (qf_ptr
->qf_viscol
== TRUE
)
1898 * Check each character from the beginning of the error
1899 * line up to the error column. For each tab character
1900 * found, reduce the error column value by the length of
1903 line
= ml_get_curline();
1905 for (char_col
= 0; char_col
< curwin
->w_cursor
.col
; ++char_col
)
1909 if (*line
++ == '\t')
1911 curwin
->w_cursor
.col
-= 7 - (screen_col
% 8);
1912 screen_col
+= 8 - (screen_col
% 8);
1921 beginline(BL_WHITE
| BL_FIX
);
1927 /* Move the cursor to the first line in the buffer */
1928 save_cursor
= curwin
->w_cursor
;
1929 curwin
->w_cursor
.lnum
= 0;
1930 if (!do_search(NULL
, '/', qf_ptr
->qf_pattern
, (long)1,
1932 curwin
->w_cursor
= save_cursor
;
1936 if ((fdo_flags
& FDO_QUICKFIX
) && old_KeyTyped
)
1941 /* Update the screen before showing the message */
1942 update_topline_redraw();
1943 sprintf((char *)IObuff
, _("(%d of %d)%s%s: "), qf_index
,
1944 qi
->qf_lists
[qi
->qf_curlist
].qf_count
,
1945 qf_ptr
->qf_cleared
? _(" (line deleted)") : "",
1946 (char *)qf_types(qf_ptr
->qf_type
, qf_ptr
->qf_nr
));
1947 /* Add the message, skipping leading whitespace and newlines. */
1948 len
= (int)STRLEN(IObuff
);
1949 qf_fmt_text(skipwhite(qf_ptr
->qf_text
), IObuff
+ len
, IOSIZE
- len
);
1951 /* Output the message. Overwrite to avoid scrolling when the 'O'
1952 * flag is present in 'shortmess'; But when not jumping, print the
1955 if (curbuf
== old_curbuf
&& curwin
->w_cursor
.lnum
== old_lnum
)
1957 else if (!msg_scrolled
&& shortmess(SHM_OVERALL
))
1959 msg_attr_keep(IObuff
, 0, TRUE
);
1967 win_close(curwin
, TRUE
); /* Close opened window */
1969 if (qf_ptr
->qf_fnum
!= 0)
1972 * Couldn't open file, so put index back where it was. This could
1973 * happen if the file was readonly and we changed something.
1978 qf_ptr
= old_qf_ptr
;
1979 qf_index
= old_qf_index
;
1983 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qf_ptr
;
1984 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= qf_index
;
1986 if (p_swb
!= old_swb
&& opened_window
)
1988 /* Restore old 'switchbuf' value, but not when an autocommand or
1989 * modeline has changed the value. */
1990 if (p_swb
== empty_option
)
1993 swb_flags
= old_swb_flags
;
1996 free_string_option(old_swb
);
2002 * ":clist": list all errors
2003 * ":llist": list all locations
2015 char_u
*arg
= eap
->arg
;
2016 int all
= eap
->forceit
; /* if not :cl!, only show
2017 recognised errors */
2018 qf_info_T
*qi
= &ql_info
;
2020 if (eap
->cmdidx
== CMD_llist
)
2022 qi
= GET_LOC_LIST(curwin
);
2030 if (qi
->qf_curlist
>= qi
->qf_listcount
2031 || qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
2033 EMSG(_(e_quickfix
));
2036 if (!get_list_range(&arg
, &idx1
, &idx2
) || *arg
!= NUL
)
2038 EMSG(_(e_trailing
));
2041 i
= qi
->qf_lists
[qi
->qf_curlist
].qf_count
;
2043 idx1
= (-idx1
> i
) ? 0 : idx1
+ i
+ 1;
2045 idx2
= (-idx2
> i
) ? 0 : idx2
+ i
+ 1;
2047 if (qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
)
2049 qfp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
2050 for (i
= 1; !got_int
&& i
<= qi
->qf_lists
[qi
->qf_curlist
].qf_count
; )
2052 if ((qfp
->qf_valid
|| all
) && idx1
<= i
&& i
<= idx2
)
2059 if (qfp
->qf_fnum
!= 0
2060 && (buf
= buflist_findnr(qfp
->qf_fnum
)) != NULL
)
2062 fname
= buf
->b_fname
;
2063 if (qfp
->qf_type
== 1) /* :helpgrep */
2064 fname
= gettail(fname
);
2067 sprintf((char *)IObuff
, "%2d", i
);
2069 vim_snprintf((char *)IObuff
, IOSIZE
, "%2d %s",
2071 msg_outtrans_attr(IObuff
, i
== qi
->qf_lists
[qi
->qf_curlist
].qf_index
2072 ? hl_attr(HLF_L
) : hl_attr(HLF_D
));
2073 if (qfp
->qf_lnum
== 0)
2075 else if (qfp
->qf_col
== 0)
2076 sprintf((char *)IObuff
, ":%ld", qfp
->qf_lnum
);
2078 sprintf((char *)IObuff
, ":%ld col %d",
2079 qfp
->qf_lnum
, qfp
->qf_col
);
2080 sprintf((char *)IObuff
+ STRLEN(IObuff
), "%s:",
2081 (char *)qf_types(qfp
->qf_type
, qfp
->qf_nr
));
2082 msg_puts_attr(IObuff
, hl_attr(HLF_N
));
2083 if (qfp
->qf_pattern
!= NULL
)
2085 qf_fmt_text(qfp
->qf_pattern
, IObuff
, IOSIZE
);
2086 STRCAT(IObuff
, ":");
2089 msg_puts((char_u
*)" ");
2091 /* Remove newlines and leading whitespace from the text. For an
2092 * unrecognized line keep the indent, the compiler may mark a word
2094 qf_fmt_text((fname
!= NULL
|| qfp
->qf_lnum
!= 0)
2095 ? skipwhite(qfp
->qf_text
) : qfp
->qf_text
,
2097 msg_prt_line(IObuff
, FALSE
);
2098 out_flush(); /* show one line at a time */
2108 * Remove newlines and leading whitespace from an error message.
2109 * Put the result in "buf[bufsize]".
2112 qf_fmt_text(text
, buf
, bufsize
)
2120 for (i
= 0; *p
!= NUL
&& i
< bufsize
- 1; ++i
)
2126 if (!vim_iswhite(*p
) && *p
!= '\n')
2136 * ":colder [count]": Up in the quickfix stack.
2137 * ":cnewer [count]": Down in the quickfix stack.
2138 * ":lolder [count]": Up in the location list stack.
2139 * ":lnewer [count]": Down in the location list stack.
2145 qf_info_T
*qi
= &ql_info
;
2148 if (eap
->cmdidx
== CMD_lolder
|| eap
->cmdidx
== CMD_lnewer
)
2150 qi
= GET_LOC_LIST(curwin
);
2158 if (eap
->addr_count
!= 0)
2164 if (eap
->cmdidx
== CMD_colder
|| eap
->cmdidx
== CMD_lolder
)
2166 if (qi
->qf_curlist
== 0)
2168 EMSG(_("E380: At bottom of quickfix stack"));
2175 if (qi
->qf_curlist
>= qi
->qf_listcount
- 1)
2177 EMSG(_("E381: At top of quickfix stack"));
2191 smsg((char_u
*)_("error list %d of %d; %d errors"),
2192 qi
->qf_curlist
+ 1, qi
->qf_listcount
,
2193 qi
->qf_lists
[qi
->qf_curlist
].qf_count
);
2195 qf_update_buffer(qi
);
2200 * Free error list "idx".
2209 while (qi
->qf_lists
[idx
].qf_count
)
2211 qfp
= qi
->qf_lists
[idx
].qf_start
->qf_next
;
2212 vim_free(qi
->qf_lists
[idx
].qf_start
->qf_text
);
2213 vim_free(qi
->qf_lists
[idx
].qf_start
->qf_pattern
);
2214 vim_free(qi
->qf_lists
[idx
].qf_start
);
2215 qi
->qf_lists
[idx
].qf_start
= qfp
;
2216 --qi
->qf_lists
[idx
].qf_count
;
2218 vim_free(qi
->qf_lists
[idx
].qf_title
);
2219 vim_free(qi
->qf_lists
[idx
].qf_user_title
);
2223 * qf_mark_adjust: adjust marks
2226 qf_mark_adjust(wp
, line1
, line2
, amount
, amount_after
)
2236 qf_info_T
*qi
= &ql_info
;
2240 if (wp
->w_llist
== NULL
)
2245 for (idx
= 0; idx
< qi
->qf_listcount
; ++idx
)
2246 if (qi
->qf_lists
[idx
].qf_count
)
2247 for (i
= 0, qfp
= qi
->qf_lists
[idx
].qf_start
;
2248 i
< qi
->qf_lists
[idx
].qf_count
; ++i
, qfp
= qfp
->qf_next
)
2249 if (qfp
->qf_fnum
== curbuf
->b_fnum
)
2251 if (qfp
->qf_lnum
>= line1
&& qfp
->qf_lnum
<= line2
)
2253 if (amount
== MAXLNUM
)
2254 qfp
->qf_cleared
= TRUE
;
2256 qfp
->qf_lnum
+= amount
;
2258 else if (amount_after
&& qfp
->qf_lnum
> line2
)
2259 qfp
->qf_lnum
+= amount_after
;
2264 * Make a nice message out of the error character and the error number:
2265 * char number message
2267 * w or W 0 " warning"
2271 * e or E n " error n"
2272 * w or W n " warning n"
2273 * i or I n " info n"
2282 static char_u buf
[20];
2283 static char_u cc
[3];
2286 if (c
== 'W' || c
== 'w')
2287 p
= (char_u
*)" warning";
2288 else if (c
== 'I' || c
== 'i')
2289 p
= (char_u
*)" info";
2290 else if (c
== 'E' || c
== 'e' || (c
== 0 && nr
> 0))
2291 p
= (char_u
*)" error";
2292 else if (c
== 0 || c
== 1)
2305 sprintf((char *)buf
, "%s %3d", (char *)p
, nr
);
2309 #if defined(FEAT_WINDOWS) || defined(PROTO)
2311 * ":cwindow": open the quickfix window if we have errors to display,
2313 * ":lwindow": open the location list window if we have locations to display,
2320 qf_info_T
*qi
= &ql_info
;
2323 if (eap
->cmdidx
== CMD_lwindow
)
2325 qi
= GET_LOC_LIST(curwin
);
2330 /* Look for an existing quickfix window. */
2331 win
= qf_find_win(qi
);
2334 * If a quickfix window is open but we have no errors to display,
2335 * close the window. If a quickfix window is not open, then open
2336 * it if we have errors; otherwise, leave it closed.
2338 if (qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
2339 || qi
->qf_curlist
>= qi
->qf_listcount
)
2344 else if (win
== NULL
)
2349 * ":cclose": close the window showing the list of errors.
2350 * ":lclose": close the window showing the location list
2357 qf_info_T
*qi
= &ql_info
;
2359 if (eap
->cmdidx
== CMD_lclose
|| eap
->cmdidx
== CMD_lwindow
)
2361 qi
= GET_LOC_LIST(curwin
);
2366 /* Find existing quickfix window and close it. */
2367 win
= qf_find_win(qi
);
2369 win_close(win
, FALSE
);
2373 * ":copen": open a window that shows the list of errors.
2374 * ":lopen": open a window that shows the location list.
2380 qf_info_T
*qi
= &ql_info
;
2383 tabpage_T
*prevtab
= curtab
;
2385 win_T
*oldwin
= curwin
;
2387 if (eap
->cmdidx
== CMD_lopen
|| eap
->cmdidx
== CMD_lwindow
)
2389 qi
= GET_LOC_LIST(curwin
);
2397 if (eap
->addr_count
!= 0)
2398 height
= eap
->line2
;
2400 height
= QF_WINHEIGHT
;
2403 reset_VIsual_and_resel(); /* stop Visual mode */
2406 need_mouse_correct
= TRUE
;
2410 * Find existing quickfix window, or open a new one.
2412 win
= qf_find_win(qi
);
2414 if (win
!= NULL
&& cmdmod
.tab
== 0)
2418 qf_buf
= qf_find_buf(qi
);
2420 /* The current window becomes the previous window afterwards. */
2423 if (eap
->cmdidx
== CMD_copen
|| eap
->cmdidx
== CMD_cwindow
)
2424 /* Create the new window at the very bottom. */
2426 if (win_split(height
, WSP_BELOW
| WSP_NEWLOC
) == FAIL
)
2427 return; /* not enough room for window */
2428 #ifdef FEAT_SCROLLBIND
2429 curwin
->w_p_scb
= FALSE
;
2432 if (eap
->cmdidx
== CMD_lopen
|| eap
->cmdidx
== CMD_lwindow
)
2435 * For the location list window, create a reference to the
2436 * location list from the window 'win'.
2438 curwin
->w_llist_ref
= win
->w_llist
;
2439 win
->w_llist
->qf_refcount
++;
2442 if (oldwin
!= curwin
)
2443 oldwin
= NULL
; /* don't store info when in another window */
2445 /* Use the existing quickfix buffer */
2446 (void)do_ecmd(qf_buf
->b_fnum
, NULL
, NULL
, NULL
, ECMD_ONE
,
2447 ECMD_HIDE
+ ECMD_OLDBUF
, oldwin
);
2450 /* Create a new quickfix buffer */
2451 (void)do_ecmd(0, NULL
, NULL
, NULL
, ECMD_ONE
, ECMD_HIDE
, oldwin
);
2452 /* switch off 'swapfile' */
2453 set_option_value((char_u
*)"swf", 0L, NULL
, OPT_LOCAL
);
2454 set_option_value((char_u
*)"bt", 0L, (char_u
*)"quickfix",
2456 set_option_value((char_u
*)"bh", 0L, (char_u
*)"wipe", OPT_LOCAL
);
2458 curwin
->w_p_diff
= FALSE
;
2461 set_option_value((char_u
*)"fdm", 0L, (char_u
*)"manual",
2466 /* Only set the height when still in the same tab page and there is no
2467 * window to the side. */
2468 if (curtab
== prevtab
2469 #ifdef FEAT_VERTSPLIT
2470 && curwin
->w_width
== Columns
2473 win_setheight(height
);
2474 curwin
->w_p_wfh
= TRUE
; /* set 'winfixheight' */
2480 * Fill the buffer with the quickfix list.
2484 curwin
->w_cursor
.lnum
= qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
2485 curwin
->w_cursor
.col
= 0;
2487 update_topline(); /* scroll to show the line */
2491 * Return the number of the current entry (line number in the quickfix
2495 qf_current_entry(wp
)
2498 qf_info_T
*qi
= &ql_info
;
2500 if (IS_LL_WINDOW(wp
))
2501 /* In the location list window, use the referenced location list */
2502 qi
= wp
->w_llist_ref
;
2504 return qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
2508 * Update the cursor position in the quickfix window to the current error.
2509 * Return TRUE if there is a quickfix window.
2512 qf_win_pos_update(qi
, old_qf_index
)
2514 int old_qf_index
; /* previous qf_index or zero */
2517 int qf_index
= qi
->qf_lists
[qi
->qf_curlist
].qf_index
;
2520 * Put the cursor on the current error in the quickfix window, so that
2523 win
= qf_find_win(qi
);
2525 && qf_index
<= win
->w_buffer
->b_ml
.ml_line_count
2526 && old_qf_index
!= qf_index
)
2528 win_T
*old_curwin
= curwin
;
2531 curbuf
= win
->w_buffer
;
2532 if (qf_index
> old_qf_index
)
2534 curwin
->w_redraw_top
= old_qf_index
;
2535 curwin
->w_redraw_bot
= qf_index
;
2539 curwin
->w_redraw_top
= qf_index
;
2540 curwin
->w_redraw_bot
= old_qf_index
;
2542 curwin
->w_cursor
.lnum
= qf_index
;
2543 curwin
->w_cursor
.col
= 0;
2544 update_topline(); /* scroll to show the line */
2545 redraw_later(VALID
);
2546 curwin
->w_redr_status
= TRUE
; /* update ruler */
2547 curwin
= old_curwin
;
2548 curbuf
= curwin
->w_buffer
;
2554 * Check whether the given window is displaying the specified quickfix/location
2563 * A window displaying the quickfix buffer will have the w_llist_ref field
2565 * A window displaying a location list buffer will have the w_llist_ref
2566 * pointing to the location list.
2568 if (bt_quickfix(win
->w_buffer
))
2569 if ((qi
== &ql_info
&& win
->w_llist_ref
== NULL
)
2570 || (qi
!= &ql_info
&& win
->w_llist_ref
== qi
))
2577 * Find a window displaying the quickfix/location list 'qi'
2578 * Searches in only the windows opened in the current tab.
2586 FOR_ALL_WINDOWS(win
)
2587 if (is_qf_win(win
, qi
))
2594 * Find a quickfix buffer.
2595 * Searches in windows opened in all the tabs.
2604 FOR_ALL_TAB_WINDOWS(tp
, win
)
2605 if (is_qf_win(win
, qi
))
2606 return win
->w_buffer
;
2612 * Find the quickfix buffer. If it exists, update the contents.
2615 qf_update_buffer(qi
)
2621 /* Check if a buffer for the quickfix list exists. Update it. */
2622 buf
= qf_find_buf(qi
);
2625 /* set curwin/curbuf to buf and save a few things */
2626 aucmd_prepbuf(&aco
, buf
);
2630 /* restore curwin/curbuf and a few other things */
2631 aucmd_restbuf(&aco
);
2633 (void)qf_win_pos_update(qi
, 0);
2638 * Fill current buffer with quickfix errors, replacing any previous contents.
2639 * curbuf must be the quickfix buffer!
2649 int old_KeyTyped
= KeyTyped
;
2651 /* delete all existing lines */
2652 while ((curbuf
->b_ml
.ml_flags
& ML_EMPTY
) == 0)
2653 (void)ml_delete((linenr_T
)1, FALSE
);
2655 /* Check if there is anything to display */
2656 if (qi
->qf_curlist
< qi
->qf_listcount
)
2658 /* Add one line for each error */
2659 qfp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
2660 for (lnum
= 0; lnum
< qi
->qf_lists
[qi
->qf_curlist
].qf_count
; ++lnum
)
2662 if (qfp
->qf_fnum
!= 0
2663 && (errbuf
= buflist_findnr(qfp
->qf_fnum
)) != NULL
2664 && errbuf
->b_fname
!= NULL
)
2666 if (qfp
->qf_type
== 1) /* :helpgrep */
2667 STRCPY(IObuff
, gettail(errbuf
->b_fname
));
2669 STRCPY(IObuff
, errbuf
->b_fname
);
2670 len
= (int)STRLEN(IObuff
);
2674 IObuff
[len
++] = '|';
2676 if (qfp
->qf_lnum
> 0)
2678 sprintf((char *)IObuff
+ len
, "%ld", qfp
->qf_lnum
);
2679 len
+= (int)STRLEN(IObuff
+ len
);
2681 if (qfp
->qf_col
> 0)
2683 sprintf((char *)IObuff
+ len
, " col %d", qfp
->qf_col
);
2684 len
+= (int)STRLEN(IObuff
+ len
);
2687 sprintf((char *)IObuff
+ len
, "%s",
2688 (char *)qf_types(qfp
->qf_type
, qfp
->qf_nr
));
2689 len
+= (int)STRLEN(IObuff
+ len
);
2691 else if (qfp
->qf_pattern
!= NULL
)
2693 qf_fmt_text(qfp
->qf_pattern
, IObuff
+ len
, IOSIZE
- len
);
2694 len
+= (int)STRLEN(IObuff
+ len
);
2696 IObuff
[len
++] = '|';
2697 IObuff
[len
++] = ' ';
2699 /* Remove newlines and leading whitespace from the text.
2700 * For an unrecognized line keep the indent, the compiler may
2701 * mark a word with ^^^^. */
2702 qf_fmt_text(len
> 3 ? skipwhite(qfp
->qf_text
) : qfp
->qf_text
,
2703 IObuff
+ len
, IOSIZE
- len
);
2705 if (ml_append(lnum
, IObuff
, (colnr_T
)STRLEN(IObuff
) + 1, FALSE
)
2710 /* Delete the empty line which is now at the end */
2711 (void)ml_delete(lnum
+ 1, FALSE
);
2714 /* correct cursor position */
2717 /* Set the 'filetype' to "qf" each time after filling the buffer. This
2718 * resembles reading a file into a buffer, it's more logical when using
2720 set_option_value((char_u
*)"ft", 0L, (char_u
*)"qf", OPT_LOCAL
);
2721 curbuf
->b_p_ma
= FALSE
;
2724 keep_filetype
= TRUE
; /* don't detect 'filetype' */
2725 apply_autocmds(EVENT_BUFREADPOST
, (char_u
*)"quickfix", NULL
,
2727 apply_autocmds(EVENT_BUFWINENTER
, (char_u
*)"quickfix", NULL
,
2729 keep_filetype
= FALSE
;
2732 /* make sure it will be redrawn */
2733 redraw_curbuf_later(NOT_VALID
);
2735 /* Restore KeyTyped, setting 'filetype' may reset it. */
2736 KeyTyped
= old_KeyTyped
;
2739 #endif /* FEAT_WINDOWS */
2742 * Return TRUE if "buf" is the quickfix buffer.
2748 return (buf
->b_p_bt
[0] == 'q');
2752 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer.
2753 * This means the buffer name is not a file name.
2759 return (buf
->b_p_bt
[0] == 'n' && buf
->b_p_bt
[2] == 'f')
2760 || buf
->b_p_bt
[0] == 'a';
2764 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer.
2770 return (buf
->b_p_bt
[0] == 'n');
2774 bt_dontwrite_msg(buf
)
2777 if (bt_dontwrite(buf
))
2779 EMSG(_("E382: Cannot write, 'buftype' option is set"));
2786 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide"
2793 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */
2794 switch (buf
->b_p_bh
[0])
2796 case 'u': /* "unload" */
2797 case 'w': /* "wipe" */
2798 case 'd': return FALSE
; /* "delete" */
2799 case 'h': return TRUE
; /* "hide" */
2801 return (p_hid
|| cmdmod
.hide
);
2805 * Return TRUE when using ":vimgrep" for ":grep".
2808 grep_internal(cmdidx
)
2811 return ((cmdidx
== CMD_grep
2812 || cmdidx
== CMD_lgrep
2813 || cmdidx
== CMD_grepadd
2814 || cmdidx
== CMD_lgrepadd
)
2815 && STRCMP("internal",
2816 *curbuf
->b_p_gp
== NUL
? p_gp
: curbuf
->b_p_gp
) == 0);
2820 * Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd"
2830 qf_info_T
*qi
= &ql_info
;
2833 char_u
*au_name
= NULL
;
2835 switch (eap
->cmdidx
)
2837 case CMD_make
: au_name
= (char_u
*)"make"; break;
2838 case CMD_lmake
: au_name
= (char_u
*)"lmake"; break;
2839 case CMD_grep
: au_name
= (char_u
*)"grep"; break;
2840 case CMD_lgrep
: au_name
= (char_u
*)"lgrep"; break;
2841 case CMD_grepadd
: au_name
= (char_u
*)"grepadd"; break;
2842 case CMD_lgrepadd
: au_name
= (char_u
*)"lgrepadd"; break;
2845 if (au_name
!= NULL
)
2847 apply_autocmds(EVENT_QUICKFIXCMDPRE
, au_name
,
2848 curbuf
->b_fname
, TRUE
, curbuf
);
2850 if (did_throw
|| force_abort
)
2856 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
2857 if (grep_internal(eap
->cmdidx
))
2863 if (eap
->cmdidx
== CMD_lmake
|| eap
->cmdidx
== CMD_lgrep
2864 || eap
->cmdidx
== CMD_lgrepadd
)
2868 fname
= get_mef_name();
2871 mch_remove(fname
); /* in case it's not unique */
2874 * If 'shellpipe' empty: don't redirect to 'errorfile'.
2876 len
= (unsigned)STRLEN(p_shq
) * 2 + (unsigned)STRLEN(eap
->arg
) + 1;
2878 len
+= (unsigned)STRLEN(p_sp
) + (unsigned)STRLEN(fname
) + 3;
2882 sprintf((char *)cmd
, "%s%s%s", (char *)p_shq
, (char *)eap
->arg
,
2885 append_redir(cmd
, len
, p_sp
, fname
);
2887 * Output a newline if there's something else than the :make command that
2888 * was typed (in which case the cursor is in column 0).
2894 msg_outtrans(cmd
); /* show what we are doing */
2896 /* let the shell know if we are redirecting output or not */
2897 do_shell(cmd
, *p_sp
!= NUL
? SHELL_DOOUT
: 0);
2901 /* read window status report and redraw before message */
2905 res
= qf_init(wp
, fname
, (eap
->cmdidx
!= CMD_make
2906 && eap
->cmdidx
!= CMD_lmake
) ? p_gefm
: p_efm
,
2907 (eap
->cmdidx
!= CMD_grepadd
2908 && eap
->cmdidx
!= CMD_lgrepadd
),
2909 (char *)*eap
->cmdlinep
);
2911 if (au_name
!= NULL
)
2912 apply_autocmds(EVENT_QUICKFIXCMDPOST
, au_name
,
2913 curbuf
->b_fname
, TRUE
, curbuf
);
2915 if (res
> 0 && !eap
->forceit
)
2918 qi
= GET_LOC_LIST(wp
);
2919 qf_jump(qi
, 0, 0, FALSE
); /* display first error */
2928 * Return the name for the errorfile, in allocated memory.
2929 * Find a new unique name when 'makeef' contains "##".
2930 * Returns NULL for error.
2937 static int start
= -1;
2945 name
= vim_tempname('e');
2951 for (p
= p_mef
; *p
; ++p
)
2952 if (p
[0] == '#' && p
[1] == '#')
2956 return vim_strsave(p_mef
);
2958 /* Keep trying until the name doesn't exist yet. */
2962 start
= mch_get_pid();
2966 name
= alloc((unsigned)STRLEN(p_mef
) + 30);
2969 STRCPY(name
, p_mef
);
2970 sprintf((char *)name
+ (p
- p_mef
), "%d%d", start
, off
);
2971 STRCAT(name
, p
+ 2);
2972 if (mch_getperm(name
) < 0
2974 /* Don't accept a symbolic link, its a security risk. */
2975 && mch_lstat((char *)name
, &sb
) < 0
2985 * ":cc", ":crewind", ":cfirst" and ":clast".
2986 * ":ll", ":lrewind", ":lfirst" and ":llast".
2992 qf_info_T
*qi
= &ql_info
;
2994 if (eap
->cmdidx
== CMD_ll
2995 || eap
->cmdidx
== CMD_lrewind
2996 || eap
->cmdidx
== CMD_lfirst
2997 || eap
->cmdidx
== CMD_llast
)
2999 qi
= GET_LOC_LIST(curwin
);
3010 : (eap
->cmdidx
== CMD_cc
|| eap
->cmdidx
== CMD_ll
)
3012 : (eap
->cmdidx
== CMD_crewind
|| eap
->cmdidx
== CMD_lrewind
3013 || eap
->cmdidx
== CMD_cfirst
|| eap
->cmdidx
== CMD_lfirst
)
3020 * ":cnext", ":cnfile", ":cNext" and ":cprevious".
3021 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile".
3027 qf_info_T
*qi
= &ql_info
;
3029 if (eap
->cmdidx
== CMD_lnext
3030 || eap
->cmdidx
== CMD_lNext
3031 || eap
->cmdidx
== CMD_lprevious
3032 || eap
->cmdidx
== CMD_lnfile
3033 || eap
->cmdidx
== CMD_lNfile
3034 || eap
->cmdidx
== CMD_lpfile
)
3036 qi
= GET_LOC_LIST(curwin
);
3044 qf_jump(qi
, (eap
->cmdidx
== CMD_cnext
|| eap
->cmdidx
== CMD_lnext
)
3046 : (eap
->cmdidx
== CMD_cnfile
|| eap
->cmdidx
== CMD_lnfile
)
3048 : (eap
->cmdidx
== CMD_cpfile
|| eap
->cmdidx
== CMD_lpfile
3049 || eap
->cmdidx
== CMD_cNfile
|| eap
->cmdidx
== CMD_lNfile
)
3052 eap
->addr_count
> 0 ? (int)eap
->line2
: 1, eap
->forceit
);
3056 * ":cfile"/":cgetfile"/":caddfile" commands.
3057 * ":lfile"/":lgetfile"/":laddfile" commands.
3064 qf_info_T
*qi
= &ql_info
;
3066 if (eap
->cmdidx
== CMD_lfile
|| eap
->cmdidx
== CMD_lgetfile
3067 || eap
->cmdidx
== CMD_laddfile
)
3070 if (*eap
->arg
!= NUL
)
3071 set_string_option_direct((char_u
*)"ef", -1, eap
->arg
, OPT_FREE
, 0);
3074 * This function is used by the :cfile, :cgetfile and :caddfile
3076 * :cfile always creates a new quickfix list and jumps to the
3078 * :cgetfile creates a new quickfix list but doesn't jump to the
3080 * :caddfile adds to an existing quickfix list. If there is no
3081 * quickfix list then a new list is created.
3083 if (qf_init(wp
, p_ef
, p_efm
, (eap
->cmdidx
!= CMD_caddfile
3084 && eap
->cmdidx
!= CMD_laddfile
),
3085 (char *)*eap
->cmdlinep
) > 0
3086 && (eap
->cmdidx
== CMD_cfile
3087 || eap
->cmdidx
== CMD_lfile
))
3090 qi
= GET_LOC_LIST(wp
);
3091 qf_jump(qi
, 0, 0, eap
->forceit
); /* display first error */
3096 * ":vimgrep {pattern} file(s)"
3097 * ":vimgrepadd {pattern} file(s)"
3098 * ":lvimgrep {pattern} file(s)"
3099 * ":lvimgrepadd {pattern} file(s)"
3105 regmmatch_T regmatch
;
3112 qf_info_T
*qi
= &ql_info
;
3113 qfline_T
*prevp
= NULL
;
3116 int duplicate_name
= FALSE
;
3118 int redraw_for_dummy
= FALSE
;
3120 buf_T
*first_match_buf
= NULL
;
3123 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3124 char_u
*save_ei
= NULL
;
3130 char_u dirname_start
[MAXPATHL
];
3131 char_u dirname_now
[MAXPATHL
];
3132 char_u
*target_dir
= NULL
;
3134 char_u
*au_name
= NULL
;
3136 switch (eap
->cmdidx
)
3138 case CMD_vimgrep
: au_name
= (char_u
*)"vimgrep"; break;
3139 case CMD_lvimgrep
: au_name
= (char_u
*)"lvimgrep"; break;
3140 case CMD_vimgrepadd
: au_name
= (char_u
*)"vimgrepadd"; break;
3141 case CMD_lvimgrepadd
: au_name
= (char_u
*)"lvimgrepadd"; break;
3144 if (au_name
!= NULL
)
3146 apply_autocmds(EVENT_QUICKFIXCMDPRE
, au_name
,
3147 curbuf
->b_fname
, TRUE
, curbuf
);
3148 if (did_throw
|| force_abort
)
3153 if (eap
->cmdidx
== CMD_lgrep
3154 || eap
->cmdidx
== CMD_lvimgrep
3155 || eap
->cmdidx
== CMD_lgrepadd
3156 || eap
->cmdidx
== CMD_lvimgrepadd
)
3158 qi
= ll_get_or_alloc_list(curwin
);
3163 if (eap
->addr_count
> 0)
3164 tomatch
= eap
->line2
;
3168 /* Get the search pattern: either white-separated or enclosed in // */
3169 regmatch
.regprog
= NULL
;
3170 p
= skip_vimgrep_pat(eap
->arg
, &s
, &flags
);
3173 EMSG(_(e_invalpat
));
3176 regmatch
.regprog
= vim_regcomp(s
, RE_MAGIC
);
3177 if (regmatch
.regprog
== NULL
)
3179 regmatch
.rmm_ic
= p_ic
;
3180 regmatch
.rmm_maxcol
= 0;
3185 EMSG(_("E683: File name missing or invalid pattern"));
3189 if ((eap
->cmdidx
!= CMD_grepadd
&& eap
->cmdidx
!= CMD_lgrepadd
&&
3190 eap
->cmdidx
!= CMD_vimgrepadd
&& eap
->cmdidx
!= CMD_lvimgrepadd
)
3191 || qi
->qf_curlist
== qi
->qf_listcount
)
3192 /* make place for a new list */
3193 qf_new_list(qi
, (char *)*eap
->cmdlinep
);
3194 else if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3195 /* Adding to existing list, find last entry. */
3196 for (prevp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3197 prevp
->qf_next
!= prevp
; prevp
= prevp
->qf_next
)
3200 /* parse the list of arguments */
3201 if (get_arglist_exp(p
, &fcount
, &fnames
) == FAIL
)
3209 /* Remember the current directory, because a BufRead autocommand that does
3210 * ":lcd %:p:h" changes the meaning of short path names. */
3211 mch_dirname(dirname_start
, MAXPATHL
);
3213 seconds
= (time_t)0;
3214 for (fi
= 0; fi
< fcount
&& !got_int
&& tomatch
> 0; ++fi
)
3216 fname
= shorten_fname1(fnames
[fi
]);
3217 if (time(NULL
) > seconds
)
3219 /* Display the file name every second or so, show the user we are
3221 seconds
= time(NULL
);
3223 p
= msg_strtrunc(fname
, TRUE
);
3225 msg_outtrans(fname
);
3232 msg_didout
= FALSE
; /* overwrite this message */
3233 msg_nowait
= TRUE
; /* don't wait for this message */
3238 buf
= buflist_findname_exp(fnames
[fi
]);
3239 if (buf
== NULL
|| buf
->b_ml
.ml_mfp
== NULL
)
3241 /* Remember that a buffer with this name already exists. */
3242 duplicate_name
= (buf
!= NULL
);
3244 redraw_for_dummy
= TRUE
;
3246 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3247 /* Don't do Filetype autocommands to avoid loading syntax and
3248 * indent scripts, a great speed improvement. */
3249 save_ei
= au_event_disable(",Filetype");
3251 /* Don't use modelines here, it's useless. */
3255 /* Load file into a buffer, so that 'fileencoding' is detected,
3256 * autocommands applied, etc. */
3257 buf
= load_dummy_buffer(fname
);
3259 /* When autocommands changed directory: go back. We assume it was
3261 mch_dirname(dirname_now
, MAXPATHL
);
3262 if (STRCMP(dirname_start
, dirname_now
) != 0)
3266 ea
.arg
= dirname_start
;
3267 ea
.cmdidx
= CMD_lcd
;
3272 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3273 au_event_restore(save_ei
);
3277 /* Use existing, loaded buffer. */
3278 using_dummy
= FALSE
;
3283 smsg((char_u
*)_("Cannot open file \"%s\""), fname
);
3287 /* Try for a match in all lines of the buffer.
3288 * For ":1vimgrep" look for first match only. */
3289 found_match
= FALSE
;
3290 for (lnum
= 1; lnum
<= buf
->b_ml
.ml_line_count
&& tomatch
> 0;
3294 while (vim_regexec_multi(®match
, curwin
, buf
, lnum
,
3298 if (qf_add_entry(qi
, &prevp
,
3303 regmatch
.startpos
[0].lnum
+ lnum
, FALSE
),
3304 regmatch
.startpos
[0].lnum
+ lnum
,
3305 regmatch
.startpos
[0].col
+ 1,
3306 FALSE
, /* vis_col */
3307 NULL
, /* search pattern */
3319 if ((flags
& VGR_GLOBAL
) == 0
3320 || regmatch
.endpos
[0].lnum
> 0)
3322 col
= regmatch
.endpos
[0].col
3323 + (col
== regmatch
.endpos
[0].col
);
3324 if (col
> (colnr_T
)STRLEN(ml_get_buf(buf
, lnum
, FALSE
)))
3334 if (found_match
&& first_match_buf
== NULL
)
3335 first_match_buf
= buf
;
3338 /* Never keep a dummy buffer if there is another buffer
3339 * with the same name. */
3340 wipe_dummy_buffer(buf
);
3343 else if (!cmdmod
.hide
3344 || buf
->b_p_bh
[0] == 'u' /* "unload" */
3345 || buf
->b_p_bh
[0] == 'w' /* "wipe" */
3346 || buf
->b_p_bh
[0] == 'd') /* "delete" */
3348 /* When no match was found we don't need to remember the
3349 * buffer, wipe it out. If there was a match and it
3350 * wasn't the first one or we won't jump there: only
3351 * unload the buffer.
3352 * Ignore 'hidden' here, because it may lead to having too
3353 * many swap files. */
3356 wipe_dummy_buffer(buf
);
3359 else if (buf
!= first_match_buf
|| (flags
& VGR_NOJUMP
))
3361 unload_dummy_buffer(buf
);
3368 /* If the buffer is still loaded we need to use the
3369 * directory we jumped to below. */
3370 if (buf
== first_match_buf
3371 && target_dir
== NULL
3372 && STRCMP(dirname_start
, dirname_now
) != 0)
3373 target_dir
= vim_strsave(dirname_now
);
3375 /* The buffer is still loaded, the Filetype autocommands
3376 * need to be done now, in that buffer. And the modelines
3377 * need to be done (again). But not the window-local
3379 aucmd_prepbuf(&aco
, buf
);
3380 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3381 apply_autocmds(EVENT_FILETYPE
, buf
->b_p_ft
,
3382 buf
->b_fname
, TRUE
, buf
);
3384 do_modelines(OPT_NOWIN
);
3385 aucmd_restbuf(&aco
);
3391 FreeWild(fcount
, fnames
);
3393 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
3394 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3395 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
3398 qf_update_buffer(qi
);
3402 if (au_name
!= NULL
)
3403 apply_autocmds(EVENT_QUICKFIXCMDPOST
, au_name
,
3404 curbuf
->b_fname
, TRUE
, curbuf
);
3407 /* Jump to first match. */
3408 if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3410 if ((flags
& VGR_NOJUMP
) == 0)
3413 qf_jump(qi
, 0, 0, eap
->forceit
);
3415 /* If we jumped to another buffer redrawing will already be
3417 redraw_for_dummy
= FALSE
;
3419 /* Jump to the directory used after loading the buffer. */
3420 if (curbuf
== first_match_buf
&& target_dir
!= NULL
)
3424 ea
.arg
= target_dir
;
3425 ea
.cmdidx
= CMD_lcd
;
3431 EMSG2(_(e_nomatch2
), s
);
3433 /* If we loaded a dummy buffer into the current window, the autocommands
3434 * may have messed up things, need to redraw and recompute folds. */
3435 if (redraw_for_dummy
)
3438 foldUpdateAll(curwin
);
3440 redraw_later(NOT_VALID
);
3445 vim_free(target_dir
);
3446 vim_free(regmatch
.regprog
);
3450 * Skip over the pattern argument of ":vimgrep /pat/[g][j]".
3451 * Put the start of the pattern in "*s", unless "s" is NULL.
3452 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP.
3453 * If "s" is not NULL terminate the pattern with a NUL.
3454 * Return a pointer to the char just past the pattern plus flags.
3457 skip_vimgrep_pat(p
, s
, flags
)
3466 /* ":vimgrep pattern fname" */
3470 if (s
!= NULL
&& *p
!= NUL
)
3475 /* ":vimgrep /pattern/[g][j] fname" */
3479 p
= skip_regexp(p
+ 1, c
, TRUE
, NULL
);
3483 /* Truncate the pattern. */
3488 /* Find the flags */
3489 while (*p
== 'g' || *p
== 'j')
3494 *flags
|= VGR_GLOBAL
;
3496 *flags
|= VGR_NOJUMP
;
3505 * Load file "fname" into a dummy buffer and return the buffer pointer.
3506 * Returns NULL if it fails.
3507 * Must call unload_dummy_buffer() or wipe_dummy_buffer() later!
3510 load_dummy_buffer(fname
)
3517 /* Allocate a buffer without putting it in the buffer list. */
3518 newbuf
= buflist_new(NULL
, NULL
, (linenr_T
)1, BLN_DUMMY
);
3522 /* Init the options. */
3523 buf_copy_options(newbuf
, BCO_ENTER
| BCO_NOHELP
);
3525 /* need to open the memfile before putting the buffer in a window */
3526 if (ml_open(newbuf
) == OK
)
3528 /* set curwin/curbuf to buf and save a few things */
3529 aucmd_prepbuf(&aco
, newbuf
);
3531 /* Need to set the filename for autocommands. */
3532 (void)setfname(curbuf
, fname
, NULL
, FALSE
);
3534 /* Create swap file now to avoid the ATTENTION message. */
3535 check_need_swap(TRUE
);
3537 /* Remove the "dummy" flag, otherwise autocommands may not
3539 curbuf
->b_flags
&= ~BF_DUMMY
;
3541 if (readfile(fname
, NULL
,
3542 (linenr_T
)0, (linenr_T
)0, (linenr_T
)MAXLNUM
,
3543 NULL
, READ_NEW
| READ_DUMMY
) == OK
3545 && !(curbuf
->b_flags
& BF_NEW
))
3548 if (curbuf
!= newbuf
)
3550 /* Bloody autocommands changed the buffer! */
3551 if (buf_valid(newbuf
))
3552 wipe_buffer(newbuf
, FALSE
);
3557 /* restore curwin/curbuf and a few other things */
3558 aucmd_restbuf(&aco
);
3561 if (!buf_valid(newbuf
))
3565 wipe_dummy_buffer(newbuf
);
3572 * Wipe out the dummy buffer that load_dummy_buffer() created.
3575 wipe_dummy_buffer(buf
)
3578 if (curbuf
!= buf
) /* safety check */
3580 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
3583 /* Reset the error/interrupt/exception state here so that aborting()
3584 * returns FALSE when wiping out the buffer. Otherwise it doesn't
3585 * work when got_int is set. */
3589 wipe_buffer(buf
, FALSE
);
3591 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
3592 /* Restore the error/interrupt/exception state if not discarded by a
3593 * new aborting error, interrupt, or uncaught exception. */
3600 * Unload the dummy buffer that load_dummy_buffer() created.
3603 unload_dummy_buffer(buf
)
3606 if (curbuf
!= buf
) /* safety check */
3607 close_buffer(NULL
, buf
, DOBUF_UNLOAD
);
3610 #if defined(FEAT_EVAL) || defined(PROTO)
3612 * Add each quickfix error to list "list" as a dictionary.
3615 get_errorlist(wp
, list
)
3619 qf_info_T
*qi
= &ql_info
;
3628 qi
= GET_LOC_LIST(wp
);
3633 if (qi
->qf_curlist
>= qi
->qf_listcount
3634 || qi
->qf_lists
[qi
->qf_curlist
].qf_count
== 0)
3637 qfp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3638 for (i
= 1; !got_int
&& i
<= qi
->qf_lists
[qi
->qf_curlist
].qf_count
; ++i
)
3640 /* Handle entries with a non-existing buffer number. */
3641 bufnum
= qfp
->qf_fnum
;
3642 if (bufnum
!= 0 && (buflist_findnr(bufnum
) == NULL
))
3645 if ((dict
= dict_alloc()) == NULL
)
3647 if (list_append_dict(list
, dict
) == FAIL
)
3650 buf
[0] = qfp
->qf_type
;
3652 if ( dict_add_nr_str(dict
, "bufnr", (long)bufnum
, NULL
) == FAIL
3653 || dict_add_nr_str(dict
, "lnum", (long)qfp
->qf_lnum
, NULL
) == FAIL
3654 || dict_add_nr_str(dict
, "col", (long)qfp
->qf_col
, NULL
) == FAIL
3655 || dict_add_nr_str(dict
, "vcol", (long)qfp
->qf_viscol
, NULL
) == FAIL
3656 || dict_add_nr_str(dict
, "nr", (long)qfp
->qf_nr
, NULL
) == FAIL
3657 || dict_add_nr_str(dict
, "pattern", 0L,
3658 qfp
->qf_pattern
== NULL
? (char_u
*)"" : qfp
->qf_pattern
) == FAIL
3659 || dict_add_nr_str(dict
, "text", 0L,
3660 qfp
->qf_text
== NULL
? (char_u
*)"" : qfp
->qf_text
) == FAIL
3661 || dict_add_nr_str(dict
, "type", 0L, buf
) == FAIL
3662 || dict_add_nr_str(dict
, "valid", (long)qfp
->qf_valid
, NULL
) == FAIL
)
3671 * Populate the quickfix list with the items supplied in the list
3675 set_errorlist(wp
, list
, action
)
3682 char_u
*filename
, *pattern
, *text
, *type
;
3687 qfline_T
*prevp
= NULL
;
3690 qf_info_T
*qi
= &ql_info
;
3691 int did_bufnr_emsg
= FALSE
;
3695 qi
= ll_get_or_alloc_list(wp
);
3700 if (action
== ' ' || qi
->qf_curlist
== qi
->qf_listcount
)
3701 /* make place for a new list */
3702 qf_new_list(qi
, NULL
);
3703 else if (action
== 'a' && qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
3704 /* Adding to existing list, find last entry. */
3705 for (prevp
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3706 prevp
->qf_next
!= prevp
; prevp
= prevp
->qf_next
)
3708 else if (action
== 'r')
3709 qf_free(qi
, qi
->qf_curlist
);
3711 for (li
= list
->lv_first
; li
!= NULL
; li
= li
->li_next
)
3713 if (li
->li_tv
.v_type
!= VAR_DICT
)
3714 continue; /* Skip non-dict items */
3716 d
= li
->li_tv
.vval
.v_dict
;
3720 filename
= get_dict_string(d
, (char_u
*)"filename", TRUE
);
3721 bufnum
= get_dict_number(d
, (char_u
*)"bufnr");
3722 lnum
= get_dict_number(d
, (char_u
*)"lnum");
3723 col
= get_dict_number(d
, (char_u
*)"col");
3724 vcol
= get_dict_number(d
, (char_u
*)"vcol");
3725 nr
= get_dict_number(d
, (char_u
*)"nr");
3726 type
= get_dict_string(d
, (char_u
*)"type", TRUE
);
3727 pattern
= get_dict_string(d
, (char_u
*)"pattern", TRUE
);
3728 text
= get_dict_string(d
, (char_u
*)"text", TRUE
);
3730 text
= vim_strsave((char_u
*)"");
3733 if ((filename
== NULL
&& bufnum
== 0) || (lnum
== 0 && pattern
== NULL
))
3736 /* Mark entries with non-existing buffer number as not valid. Give the
3737 * error message only once. */
3738 if (bufnum
!= 0 && (buflist_findnr(bufnum
) == NULL
))
3740 if (!did_bufnr_emsg
)
3742 did_bufnr_emsg
= TRUE
;
3743 EMSGN(_("E92: Buffer %ld not found"), bufnum
);
3749 status
= qf_add_entry(qi
, &prevp
,
3757 pattern
, /* search pattern */
3759 type
== NULL
? NUL
: *type
,
3774 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
3775 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
= qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
3776 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
3779 qf_update_buffer(qi
);
3787 * ":[range]cbuffer [bufnr]" command.
3788 * ":[range]caddbuffer [bufnr]" command.
3789 * ":[range]cgetbuffer [bufnr]" command.
3790 * ":[range]lbuffer [bufnr]" command.
3791 * ":[range]laddbuffer [bufnr]" command.
3792 * ":[range]lgetbuffer [bufnr]" command.
3799 qf_info_T
*qi
= &ql_info
;
3801 if (eap
->cmdidx
== CMD_lbuffer
|| eap
->cmdidx
== CMD_lgetbuffer
3802 || eap
->cmdidx
== CMD_laddbuffer
)
3804 qi
= ll_get_or_alloc_list(curwin
);
3809 if (*eap
->arg
== NUL
)
3811 else if (*skipwhite(skipdigits(eap
->arg
)) == NUL
)
3812 buf
= buflist_findnr(atoi((char *)eap
->arg
));
3815 else if (buf
->b_ml
.ml_mfp
== NULL
)
3816 EMSG(_("E681: Buffer is not loaded"));
3819 if (eap
->addr_count
== 0)
3822 eap
->line2
= buf
->b_ml
.ml_line_count
;
3824 if (eap
->line1
< 1 || eap
->line1
> buf
->b_ml
.ml_line_count
3825 || eap
->line2
< 1 || eap
->line2
> buf
->b_ml
.ml_line_count
)
3826 EMSG(_(e_invrange
));
3829 char *qf_title
= (char *)*eap
->cmdlinep
;
3832 vim_snprintf((char *)IObuff
, IOSIZE
, "%s (%s)", qf_title
,
3833 (char *)buf
->b_sfname
);
3834 qf_title
= (char *)IObuff
;
3837 if (qf_init_ext(qi
, NULL
, buf
, NULL
, p_efm
,
3838 (eap
->cmdidx
!= CMD_caddbuffer
3839 && eap
->cmdidx
!= CMD_laddbuffer
),
3840 eap
->line1
, eap
->line2
,
3842 && (eap
->cmdidx
== CMD_cbuffer
3843 || eap
->cmdidx
== CMD_lbuffer
))
3844 qf_jump(qi
, 0, 0, eap
->forceit
); /* display first error */
3849 #if defined(FEAT_EVAL) || defined(PROTO)
3851 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command.
3852 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command.
3859 qf_info_T
*qi
= &ql_info
;
3861 if (eap
->cmdidx
== CMD_lexpr
|| eap
->cmdidx
== CMD_lgetexpr
3862 || eap
->cmdidx
== CMD_laddexpr
)
3864 qi
= ll_get_or_alloc_list(curwin
);
3869 /* Evaluate the expression. When the result is a string or a list we can
3870 * use it to fill the errorlist. */
3871 tv
= eval_expr(eap
->arg
, NULL
);
3874 if ((tv
->v_type
== VAR_STRING
&& tv
->vval
.v_string
!= NULL
)
3875 || (tv
->v_type
== VAR_LIST
&& tv
->vval
.v_list
!= NULL
))
3877 if (qf_init_ext(qi
, NULL
, NULL
, tv
, p_efm
,
3878 (eap
->cmdidx
!= CMD_caddexpr
3879 && eap
->cmdidx
!= CMD_laddexpr
),
3880 (linenr_T
)0, (linenr_T
)0,
3881 (char *)*eap
->cmdlinep
) > 0
3882 && (eap
->cmdidx
== CMD_cexpr
3883 || eap
->cmdidx
== CMD_lexpr
))
3884 qf_jump(qi
, 0, 0, eap
->forceit
); /* display first error */
3887 EMSG(_("E777: String or List expected"));
3894 * ":helpgrep {pattern}"
3900 regmatch_T regmatch
;
3907 qfline_T
*prevp
= NULL
;
3909 #ifdef FEAT_MULTI_LANG
3912 qf_info_T
*qi
= &ql_info
;
3916 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
3918 p_cpo
= empty_option
;
3920 #ifdef FEAT_MULTI_LANG
3921 /* Check for a specified language */
3922 lang
= check_help_lang(eap
->arg
);
3925 if (eap
->cmdidx
== CMD_lhelpgrep
)
3927 /* Find an existing help window */
3929 if (wp
->w_buffer
!= NULL
&& wp
->w_buffer
->b_help
)
3932 if (wp
== NULL
) /* Help window not found */
3939 /* Allocate a new location list for help text matches */
3940 if ((qi
= ll_new_list()) == NULL
)
3946 regmatch
.regprog
= vim_regcomp(eap
->arg
, RE_MAGIC
+ RE_STRING
);
3947 regmatch
.rm_ic
= FALSE
;
3948 if (regmatch
.regprog
!= NULL
)
3950 /* create a new quickfix list */
3951 qf_new_list(qi
, (char *)*eap
->cmdlinep
);
3953 /* Go through all directories in 'runtimepath' */
3955 while (*p
!= NUL
&& !got_int
)
3957 copy_option_part(&p
, NameBuff
, MAXPATHL
, ",");
3959 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */
3960 add_pathsep(NameBuff
);
3961 STRCAT(NameBuff
, "doc/*.\\(txt\\|??x\\)");
3962 if (gen_expand_wildcards(1, &NameBuff
, &fcount
,
3963 &fnames
, EW_FILE
|EW_SILENT
) == OK
3966 for (fi
= 0; fi
< fcount
&& !got_int
; ++fi
)
3968 #ifdef FEAT_MULTI_LANG
3969 /* Skip files for a different language. */
3971 && STRNICMP(lang
, fnames
[fi
]
3972 + STRLEN(fnames
[fi
]) - 3, 2) != 0
3973 && !(STRNICMP(lang
, "en", 2) == 0
3974 && STRNICMP("txt", fnames
[fi
]
3975 + STRLEN(fnames
[fi
]) - 3, 3) == 0))
3978 fd
= mch_fopen((char *)fnames
[fi
], "r");
3982 while (!vim_fgets(IObuff
, IOSIZE
, fd
) && !got_int
)
3984 if (vim_regexec(®match
, IObuff
, (colnr_T
)0))
3986 int l
= (int)STRLEN(IObuff
);
3988 /* remove trailing CR, LF, spaces, etc. */
3989 while (l
> 0 && IObuff
[l
- 1] <= ' ')
3992 if (qf_add_entry(qi
, &prevp
,
3998 (int)(regmatch
.startp
[0] - IObuff
)
4000 FALSE
, /* vis_col */
4001 NULL
, /* search pattern */
4017 FreeWild(fcount
, fnames
);
4020 vim_free(regmatch
.regprog
);
4022 qi
->qf_lists
[qi
->qf_curlist
].qf_nonevalid
= FALSE
;
4023 qi
->qf_lists
[qi
->qf_curlist
].qf_ptr
=
4024 qi
->qf_lists
[qi
->qf_curlist
].qf_start
;
4025 qi
->qf_lists
[qi
->qf_curlist
].qf_index
= 1;
4028 if (p_cpo
== empty_option
)
4031 /* Darn, some plugin changed the value. */
4032 free_string_option(save_cpo
);
4035 qf_update_buffer(qi
);
4038 /* Jump to first match. */
4039 if (qi
->qf_lists
[qi
->qf_curlist
].qf_count
> 0)
4040 qf_jump(qi
, 0, 0, FALSE
);
4042 EMSG2(_(e_nomatch2
), eap
->arg
);
4044 if (eap
->cmdidx
== CMD_lhelpgrep
)
4046 /* If the help window is not opened or if it already points to the
4047 * correct location list, then free the new location list. */
4048 if (!curwin
->w_buffer
->b_help
|| curwin
->w_llist
== qi
)
4053 else if (curwin
->w_llist
== NULL
)
4054 curwin
->w_llist
= qi
;
4058 #endif /* FEAT_QUICKFIX */