vim-patch:8.0.1831: sometimes the quickfix title is incorrectly prefixed with ':'

Problem:    Sometimes the quickfix title is incorrectly prefixed with ':'.
Solution:   Prepend the colon in another way. (Yegappan Lakshmanan)

8b62e31003
This commit is contained in:
Marco Hinz 2019-04-08 17:00:11 +02:00
parent 446bfdd49f
commit daa82cbf69
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F
3 changed files with 117 additions and 8 deletions

View File

@ -14892,7 +14892,7 @@ static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
skip_args:
if (!title) {
title = (wp ? "setloclist()" : "setqflist()");
title = (wp ? ":setloclist()" : ":setqflist()");
}
recursive++;

View File

@ -1018,10 +1018,23 @@ static void qf_store_title(qf_info_T *qi, int qf_idx, char_u *title)
char_u *p = xmallocz(len);
qi->qf_lists[qf_idx].qf_title = p;
snprintf((char *)p, len + 1, ":%s", (char *)title);
xstrlcpy((char *)p, (char *)title, len + 1);
}
}
/// The title of a quickfix/location list is set, by default, to the command
/// that created the quickfix list with the ":" prefix.
/// Create a quickfix list title string by prepending ":" to a user command.
/// Returns a pointer to a static buffer with the title.
static char_u * qf_cmdtitle(char_u *cmd)
{
static char_u qftitle_str[IOSIZE];
snprintf((char *)qftitle_str, IOSIZE, ":%s", (char *)cmd);
return qftitle_str;
}
// Prepare for adding a new quickfix list. If the current list is in the
// middle of the stack, then all the following lists are freed and then
// the new list is added.
@ -1221,6 +1234,8 @@ static int qf_parse_get_fields(char_u *linebuf, size_t linelen, efm_T *fmt_ptr,
fields->type = 0;
*tail = NULL;
// Always ignore case when looking for a matching error.
regmatch.rm_ic = true;
regmatch.regprog = fmt_ptr->prog;
r = vim_regexec(&regmatch, linebuf, (colnr_T)0);
fmt_ptr->prog = regmatch.regprog;
@ -3417,7 +3432,7 @@ void ex_make(exarg_T *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->cmdlinep, enc);
qf_cmdtitle(*eap->cmdlinep), enc);
if (wp != NULL) {
qi = GET_LOC_LIST(wp);
}
@ -3776,7 +3791,7 @@ void ex_cfile(exarg_T *eap)
// quickfix list then a new list is created.
int res = qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile
&& eap->cmdidx != CMD_laddfile),
*eap->cmdlinep,enc);
qf_cmdtitle(*eap->cmdlinep), enc);
if (wp != NULL) {
qi = GET_LOC_LIST(wp);
}
@ -4044,7 +4059,7 @@ void ex_vimgrep(exarg_T *eap)
/* Get the search pattern: either white-separated or enclosed in // */
regmatch.regprog = NULL;
char_u *title = vim_strsave(*eap->cmdlinep);
char_u *title = vim_strsave(qf_cmdtitle(*eap->cmdlinep));
p = skip_vimgrep_pat(eap->arg, &s, &flags);
if (p == NULL) {
EMSG(_(e_invalpat));
@ -5216,7 +5231,7 @@ void ex_cbuffer(exarg_T *eap)
|| eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count)
EMSG(_(e_invrange));
else {
char_u *qf_title = *eap->cmdlinep;
char_u *qf_title = qf_cmdtitle(*eap->cmdlinep);
if (buf->b_sfname) {
vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)",
@ -5296,7 +5311,8 @@ void ex_cexpr(exarg_T *eap)
int res = qf_init_ext(qi, qi->qf_curlist, NULL, NULL, &tv, p_efm,
(eap->cmdidx != CMD_caddexpr
&& eap->cmdidx != CMD_laddexpr),
(linenr_T)0, (linenr_T)0, *eap->cmdlinep, NULL);
(linenr_T)0, (linenr_T)0,
qf_cmdtitle(*eap->cmdlinep), NULL);
if (res >= 0) {
qf_list_changed(qi, qi->qf_curlist);
}
@ -5386,7 +5402,7 @@ void ex_helpgrep(exarg_T *eap)
regmatch.rm_ic = FALSE;
if (regmatch.regprog != NULL) {
// Create a new quickfix list.
qf_new_list(qi, *eap->cmdlinep);
qf_new_list(qi, qf_cmdtitle(*eap->cmdlinep));
// Go through all the directories in 'runtimepath'
p = p_rtp;

View File

@ -2848,6 +2848,99 @@ func Test_shorten_fname()
call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
endfunc
" Quickfix title tests
" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
" Otherwise due to indentation, the title is set with spaces at the beginning
" of the command.
func Test_qftitle()
call writefile(["F1:1:Line1"], 'Xerr')
" :cexpr
exe "cexpr readfile('Xerr')"
call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
" :cgetexpr
exe "cgetexpr readfile('Xerr')"
call assert_equal(":cgetexpr readfile('Xerr')",
\ getqflist({'title' : 1}).title)
" :caddexpr
call setqflist([], 'f')
exe "caddexpr readfile('Xerr')"
call assert_equal(":caddexpr readfile('Xerr')",
\ getqflist({'title' : 1}).title)
" :cbuffer
new Xerr
exe "cbuffer"
call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
" :cgetbuffer
edit Xerr
exe "cgetbuffer"
call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
" :caddbuffer
call setqflist([], 'f')
edit Xerr
exe "caddbuffer"
call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
" :cfile
exe "cfile Xerr"
call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
" :cgetfile
exe "cgetfile Xerr"
call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
" :caddfile
call setqflist([], 'f')
exe "caddfile Xerr"
call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
" :grep
set grepprg=internal
exe "grep F1 Xerr"
call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
" :grepadd
call setqflist([], 'f')
exe "grepadd F1 Xerr"
call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
set grepprg&vim
" :vimgrep
exe "vimgrep F1 Xerr"
call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
" :vimgrepadd
call setqflist([], 'f')
exe "vimgrepadd F1 Xerr"
call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
call setqflist(['F1:10:L10'], ' ')
call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
call setqflist([], 'f')
call setqflist(['F1:10:L10'], 'a')
call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
call setqflist([], 'f')
call setqflist(['F1:10:L10'], 'r')
call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
close
call delete('Xerr')
call setqflist([], ' ', {'title' : 'Errors'})
copen
call assert_equal('Errors', w:quickfix_title)
call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
call assert_equal('Errors', w:quickfix_title)
cclose
endfunc
" Test for the position of the quickfix and location list window
func Test_qfwin_pos()
" Open two windows