Skip to content

Commit

Permalink
patch 8.0.1353: QuickFixCmdPost is not used consistently
Browse files Browse the repository at this point in the history
Problem:    QuickFixCmdPost is not used consistently.
Solution:   Invoke QuickFixCmdPost consistently after QuickFixCmdPre.
            (Yegappan Lakshmanan, closes #2377)
  • Loading branch information
brammool committed Nov 28, 2017
1 parent f38c86e commit 1ed2276
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 43 deletions.
59 changes: 25 additions & 34 deletions src/quickfix.c
Expand Up @@ -4055,6 +4055,7 @@ ex_cfile(exarg_T *eap)
#ifdef FEAT_AUTOCMD
char_u *au_name = NULL;
#endif
int res;

if (eap->cmdidx == CMD_lfile || eap->cmdidx == CMD_lgetfile
|| eap->cmdidx == CMD_laddfile)
Expand Down Expand Up @@ -4102,28 +4103,18 @@ ex_cfile(exarg_T *eap)
* :caddfile adds to an existing quickfix list. If there is no
* quickfix list then a new list is created.
*/
if (qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile
&& eap->cmdidx != CMD_laddfile),
*eap->cmdlinep, enc) > 0
&& (eap->cmdidx == CMD_cfile
|| eap->cmdidx == CMD_lfile))
{
res = qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile
&& eap->cmdidx != CMD_laddfile), *eap->cmdlinep, enc);
#ifdef FEAT_AUTOCMD
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
#endif
if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile))
{
if (wp != NULL)
qi = GET_LOC_LIST(wp);
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
}

else
{
#ifdef FEAT_AUTOCMD
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
#endif
}
}

/*
Expand Down Expand Up @@ -5450,6 +5441,7 @@ ex_cbuffer(exarg_T *eap)
#ifdef FEAT_AUTOCMD
char_u *au_name = NULL;
#endif
int res;

if (eap->cmdidx == CMD_lbuffer || eap->cmdidx == CMD_lgetbuffer
|| eap->cmdidx == CMD_laddbuffer)
Expand Down Expand Up @@ -5509,20 +5501,19 @@ ex_cbuffer(exarg_T *eap)
qf_title = IObuff;
}

if (qf_init_ext(qi, qi->qf_curlist, NULL, buf, NULL, p_efm,
res = qf_init_ext(qi, qi->qf_curlist, NULL, buf, NULL, p_efm,
(eap->cmdidx != CMD_caddbuffer
&& eap->cmdidx != CMD_laddbuffer),
eap->line1, eap->line2,
qf_title, NULL) > 0)
{
qf_title, NULL);
#ifdef FEAT_AUTOCMD
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
#endif
if (eap->cmdidx == CMD_cbuffer || eap->cmdidx == CMD_lbuffer)
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
}
if (res > 0 && (eap->cmdidx == CMD_cbuffer ||
eap->cmdidx == CMD_lbuffer))
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
}
}
}
Expand All @@ -5540,6 +5531,7 @@ ex_cexpr(exarg_T *eap)
#ifdef FEAT_AUTOCMD
char_u *au_name = NULL;
#endif
int res;

if (eap->cmdidx == CMD_lexpr || eap->cmdidx == CMD_lgetexpr
|| eap->cmdidx == CMD_laddexpr)
Expand Down Expand Up @@ -5578,20 +5570,19 @@ ex_cexpr(exarg_T *eap)
if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL)
|| (tv->v_type == VAR_LIST && tv->vval.v_list != NULL))
{
if (qf_init_ext(qi, qi->qf_curlist, NULL, NULL, tv, p_efm,
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) > 0)
{
NULL);
#ifdef FEAT_AUTOCMD
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
#endif
if (eap->cmdidx == CMD_cexpr || eap->cmdidx == CMD_lexpr)
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
}
if (res > 0 && (eap->cmdidx == CMD_cexpr ||
eap->cmdidx == CMD_lexpr))
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
}
else
EMSG(_("E777: String or List expected"));
Expand Down
128 changes: 119 additions & 9 deletions src/testdir/test_quickfix.vim
Expand Up @@ -1966,26 +1966,136 @@ func Test_Autocmd()
cexpr "F1:10:Line 10"
caddexpr "F1:20:Line 20"
cgetexpr "F1:30:Line 30"
enew! | call append(0, "F2:10:Line 10")
cbuffer!
enew! | call append(0, "F2:20:Line 20")
cgetbuffer
enew! | call append(0, "F2:30:Line 30")
caddbuffer

cexpr ""
caddexpr ""
cgetexpr ""
silent! cexpr non_existing_func()
silent! caddexpr non_existing_func()
silent! cgetexpr non_existing_func()
let l = ['precexpr',
\ 'postcexpr',
\ 'precaddexpr',
\ 'postcaddexpr',
\ 'precgetexpr',
\ 'postcgetexpr',
\ 'precbuffer',
\ 'precexpr',
\ 'postcexpr',
\ 'precaddexpr',
\ 'postcaddexpr',
\ 'precgetexpr',
\ 'postcgetexpr',
\ 'precexpr',
\ 'precaddexpr',
\ 'precgetexpr']
call assert_equal(l, g:acmds)

let g:acmds = []
enew! | call append(0, "F2:10:Line 10")
cbuffer!
enew! | call append(0, "F2:20:Line 20")
cgetbuffer
enew! | call append(0, "F2:30:Line 30")
caddbuffer
new
let bnum = bufnr('%')
bunload
exe 'silent! cbuffer! ' . bnum
exe 'silent! cgetbuffer ' . bnum
exe 'silent! caddbuffer ' . bnum
enew!
let l = ['precbuffer',
\ 'postcbuffer',
\ 'precgetbuffer',
\ 'postcgetbuffer',
\ 'precaddbuffer',
\ 'postcaddbuffer']
\ 'postcaddbuffer',
\ 'precbuffer',
\ 'precgetbuffer',
\ 'precaddbuffer']
call assert_equal(l, g:acmds)

call writefile(['Xtest:1:Line1'], 'Xtest')
call writefile([], 'Xempty')
let g:acmds = []
cfile Xtest
caddfile Xtest
cgetfile Xtest
cfile Xempty
caddfile Xempty
cgetfile Xempty
silent! cfile do_not_exist
silent! caddfile do_not_exist
silent! cgetfile do_not_exist
let l = ['precfile',
\ 'postcfile',
\ 'precaddfile',
\ 'postcaddfile',
\ 'precgetfile',
\ 'postcgetfile',
\ 'precfile',
\ 'postcfile',
\ 'precaddfile',
\ 'postcaddfile',
\ 'precgetfile',
\ 'postcgetfile',
\ 'precfile',
\ 'postcfile',
\ 'precaddfile',
\ 'postcaddfile',
\ 'precgetfile',
\ 'postcgetfile']
call assert_equal(l, g:acmds)

let g:acmds = []
helpgrep quickfix
silent! helpgrep non_existing_help_topic
vimgrep test Xtest
vimgrepadd test Xtest
silent! vimgrep non_existing_test Xtest
silent! vimgrepadd non_existing_test Xtest
set makeprg=
silent! make
set makeprg&
let l = ['prehelpgrep',
\ 'posthelpgrep',
\ 'prehelpgrep',
\ 'posthelpgrep',
\ 'previmgrep',
\ 'postvimgrep',
\ 'previmgrepadd',
\ 'postvimgrepadd',
\ 'previmgrep',
\ 'postvimgrep',
\ 'previmgrepadd',
\ 'postvimgrepadd',
\ 'premake',
\ 'postmake']
call assert_equal(l, g:acmds)

if has('unix')
" Run this test only on Unix-like systems. The grepprg may not be set on
" non-Unix systems.
" The following lines are used for the grep test. Don't remove.
" Grep_Autocmd_Text: Match 1
" GrepAdd_Autocmd_Text: Match 2
let g:acmds = []
silent grep Grep_Autocmd_Text test_quickfix.vim
silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
silent grep abc123def Xtest
silent grepadd abc123def Xtest
let l = ['pregrep',
\ 'postgrep',
\ 'pregrepadd',
\ 'postgrepadd',
\ 'pregrep',
\ 'postgrep',
\ 'pregrepadd',
\ 'postgrepadd']
call assert_equal(l, g:acmds)
endif

call delete('Xtest')
call delete('Xempty')
endfunc

func Test_Autocmd_Exception()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -771,6 +771,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1353,
/**/
1352,
/**/
Expand Down

0 comments on commit 1ed2276

Please sign in to comment.