0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)

This commit is contained in:
Bram Moolenaar
2010-07-25 16:58:46 +02:00
parent fa0ff9aedf
commit 7fd7320014
10 changed files with 115 additions and 34 deletions

View File

@@ -56,6 +56,8 @@ typedef struct qf_list_S
int qf_count; /* number of errors (0 means no error list) */
int qf_index; /* current index in the error list */
int qf_nonevalid; /* TRUE if not a single valid entry found */
char_u *qf_title; /* title derived from the command that created
* the error list */
} qf_list_T;
struct qf_info_S
@@ -104,8 +106,8 @@ struct efm_S
int conthere; /* %> used */
};
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));
static void qf_new_list __ARGS((qf_info_T *qi));
static int qf_init_ext __ARGS((qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast, char_u *qf_title));
static void qf_new_list __ARGS((qf_info_T *qi, char_u *qf_title));
static void ll_free_all __ARGS((qf_info_T **pqi));
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));
static qf_info_T *ll_new_list __ARGS((void));
@@ -144,15 +146,16 @@ static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *));
/*
* Read the errorfile "efile" into memory, line by line, building the error
* list.
* list. Set the error list's title to qf_title.
* Return -1 for error, number of errors for success.
*/
int
qf_init(wp, efile, errorformat, newlist)
qf_init(wp, efile, errorformat, newlist, qf_title)
win_T *wp;
char_u *efile;
char_u *errorformat;
int newlist; /* TRUE: start a new error list */
char_u *qf_title;
{
qf_info_T *qi = &ql_info;
@@ -167,7 +170,8 @@ qf_init(wp, efile, errorformat, newlist)
}
return qf_init_ext(qi, efile, curbuf, NULL, errorformat, newlist,
(linenr_T)0, (linenr_T)0);
(linenr_T)0, (linenr_T)0,
qf_title);
}
/*
@@ -175,11 +179,13 @@ qf_init(wp, efile, errorformat, newlist)
* list.
* Alternative: when "efile" is null read errors from buffer "buf".
* Always use 'errorformat' from "buf" if there is a local value.
* Then lnumfirst and lnumlast specify the range of lines to use.
* Then "lnumfirst" and "lnumlast" specify the range of lines to use.
* Set the title of the list to "qf_title".
* Return -1 for error, number of errors for success.
*/
static int
qf_init_ext(qi, efile, buf, tv, errorformat, newlist, lnumfirst, lnumlast)
qf_init_ext(qi, efile, buf, tv, errorformat, newlist, lnumfirst, lnumlast,
qf_title)
qf_info_T *qi;
char_u *efile;
buf_T *buf;
@@ -188,6 +194,7 @@ qf_init_ext(qi, efile, buf, tv, errorformat, newlist, lnumfirst, lnumlast)
int newlist; /* TRUE: start a new error list */
linenr_T lnumfirst; /* first line number to use */
linenr_T lnumlast; /* last line number to use */
char_u *qf_title;
{
char_u *namebuf;
char_u *errmsg;
@@ -257,11 +264,11 @@ qf_init_ext(qi, efile, buf, tv, errorformat, newlist, lnumfirst, lnumlast)
if (newlist || qi->qf_curlist == qi->qf_listcount)
/* make place for a new list */
qf_new_list(qi);
qf_new_list(qi, qf_title);
else if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
/* Adding to existing list, find last entry. */
for (qfprev = qi->qf_lists[qi->qf_curlist].qf_start;
qfprev->qf_next != qfprev; qfprev = qfprev->qf_next)
qfprev->qf_next != qfprev; qfprev = qfprev->qf_next)
;
/*
@@ -860,8 +867,9 @@ qf_init_end:
* Prepare for adding a new quickfix list.
*/
static void
qf_new_list(qi)
qf_new_list(qi, qf_title)
qf_info_T *qi;
char_u *qf_title;
{
int i;
@@ -888,6 +896,16 @@ qf_new_list(qi)
qi->qf_curlist = qi->qf_listcount++;
qi->qf_lists[qi->qf_curlist].qf_index = 0;
qi->qf_lists[qi->qf_curlist].qf_count = 0;
if (qf_title != NULL)
{
char_u *p = alloc(STRLEN(qf_title) + 2);
qi->qf_lists[qi->qf_curlist].qf_title = p;
if (p != NULL)
sprintf((char *)p, ":%s", (char *)qf_title);
}
else
qi->qf_lists[qi->qf_curlist].qf_title = NULL;
}
/*
@@ -1100,6 +1118,10 @@ copy_loclist(from, to)
to_qfl->qf_index = 0;
to_qfl->qf_start = NULL;
to_qfl->qf_ptr = NULL;
if (from_qfl->qf_title != NULL)
to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
else
to_qfl->qf_title = NULL;
if (from_qfl->qf_count)
{
@@ -2102,6 +2124,7 @@ qf_free(qi, idx)
qi->qf_lists[idx].qf_start = qfp;
--qi->qf_lists[idx].qf_count;
}
vim_free(qi->qf_lists[idx].qf_title);
}
/*
@@ -2366,6 +2389,10 @@ ex_copen(eap)
*/
qf_fill_buffer(qi);
if (qi->qf_lists[qi->qf_curlist].qf_title != NULL)
set_internal_string_var((char_u *)"w:quickfix_title",
qi->qf_lists[qi->qf_curlist].qf_title);
curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index;
curwin->w_cursor.col = 0;
check_cursor();
@@ -2790,7 +2817,8 @@ ex_make(eap)
res = qf_init(wp, fname, (eap->cmdidx != CMD_make
&& eap->cmdidx != CMD_lmake) ? p_gefm : p_efm,
(eap->cmdidx != CMD_grepadd
&& eap->cmdidx != CMD_lgrepadd));
&& eap->cmdidx != CMD_lgrepadd),
*eap->cmdlinep);
#ifdef FEAT_AUTOCMD
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
@@ -2977,7 +3005,8 @@ ex_cfile(eap)
* quickfix list then a new list is created.
*/
if (qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile
&& eap->cmdidx != CMD_laddfile)) > 0
&& eap->cmdidx != CMD_laddfile),
*eap->cmdlinep) > 0
&& (eap->cmdidx == CMD_cfile
|| eap->cmdidx == CMD_lfile))
{
@@ -3085,7 +3114,7 @@ ex_vimgrep(eap)
eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd)
|| qi->qf_curlist == qi->qf_listcount)
/* make place for a new list */
qf_new_list(qi);
qf_new_list(qi, *eap->cmdlinep);
else if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
/* Adding to existing list, find last entry. */
for (prevp = qi->qf_lists[qi->qf_curlist].qf_start;
@@ -3594,7 +3623,7 @@ set_errorlist(wp, list, action)
if (action == ' ' || qi->qf_curlist == qi->qf_listcount)
/* make place for a new list */
qf_new_list(qi);
qf_new_list(qi, NULL);
else if (action == 'a' && qi->qf_lists[qi->qf_curlist].qf_count > 0)
/* Adding to existing list, find last entry. */
for (prevp = qi->qf_lists[qi->qf_curlist].qf_start;
@@ -3725,10 +3754,20 @@ ex_cbuffer(eap)
EMSG(_(e_invrange));
else
{
char_u *qf_title = *eap->cmdlinep;
if (buf->b_sfname)
{
vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)",
(char *)qf_title, (char *)buf->b_sfname);
qf_title = IObuff;
}
if (qf_init_ext(qi, NULL, buf, NULL, p_efm,
(eap->cmdidx != CMD_caddbuffer
&& eap->cmdidx != CMD_laddbuffer),
eap->line1, eap->line2) > 0
eap->line1, eap->line2,
qf_title) > 0
&& (eap->cmdidx == CMD_cbuffer
|| eap->cmdidx == CMD_lbuffer))
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
@@ -3767,7 +3806,7 @@ ex_cexpr(eap)
if (qf_init_ext(qi, NULL, NULL, tv, p_efm,
(eap->cmdidx != CMD_caddexpr
&& eap->cmdidx != CMD_laddexpr),
(linenr_T)0, (linenr_T)0) > 0
(linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0
&& (eap->cmdidx == CMD_cexpr
|| eap->cmdidx == CMD_lexpr))
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
@@ -3837,7 +3876,7 @@ ex_helpgrep(eap)
if (regmatch.regprog != NULL)
{
/* create a new quickfix list */
qf_new_list(qi);
qf_new_list(qi, *eap->cmdlinep);
/* Go through all directories in 'runtimepath' */
p = p_rtp;