Skip to content

Commit 04c4ce6

Browse files
committed
patch 7.4.2299
Problem: QuickFixCmdPre and QuickFixCmdPost autocommands are not always triggered. Solution: Also trigger on ":expr", ":cbuffer", etc. (Yegappan Lakshmanan)
1 parent 0874a83 commit 04c4ce6

3 files changed

Lines changed: 107 additions & 8 deletions

File tree

src/quickfix.c

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,6 +4845,9 @@ ex_cbuffer(exarg_T *eap)
48454845
{
48464846
buf_T *buf = NULL;
48474847
qf_info_T *qi = &ql_info;
4848+
#ifdef FEAT_AUTOCMD
4849+
char_u *au_name = NULL;
4850+
#endif
48484851

48494852
if (eap->cmdidx == CMD_lbuffer || eap->cmdidx == CMD_lgetbuffer
48504853
|| eap->cmdidx == CMD_laddbuffer)
@@ -4854,6 +4857,28 @@ ex_cbuffer(exarg_T *eap)
48544857
return;
48554858
}
48564859

4860+
#ifdef FEAT_AUTOCMD
4861+
switch (eap->cmdidx)
4862+
{
4863+
case CMD_cbuffer: au_name = (char_u *)"cbuffer"; break;
4864+
case CMD_cgetbuffer: au_name = (char_u *)"cgetbuffer"; break;
4865+
case CMD_caddbuffer: au_name = (char_u *)"caddbuffer"; break;
4866+
case CMD_lbuffer: au_name = (char_u *)"lbuffer"; break;
4867+
case CMD_lgetbuffer: au_name = (char_u *)"lgetbuffer"; break;
4868+
case CMD_laddbuffer: au_name = (char_u *)"laddbuffer"; break;
4869+
default: break;
4870+
}
4871+
if (au_name != NULL)
4872+
{
4873+
apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
4874+
curbuf->b_fname, TRUE, curbuf);
4875+
# ifdef FEAT_EVAL
4876+
if (did_throw || force_abort)
4877+
return;
4878+
# endif
4879+
}
4880+
#endif
4881+
48574882
if (*eap->arg == NUL)
48584883
buf = curbuf;
48594884
else if (*skipwhite(skipdigits(eap->arg)) == NUL)
@@ -4887,10 +4912,16 @@ ex_cbuffer(exarg_T *eap)
48874912
(eap->cmdidx != CMD_caddbuffer
48884913
&& eap->cmdidx != CMD_laddbuffer),
48894914
eap->line1, eap->line2,
4890-
qf_title) > 0
4891-
&& (eap->cmdidx == CMD_cbuffer
4892-
|| eap->cmdidx == CMD_lbuffer))
4893-
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
4915+
qf_title) > 0)
4916+
{
4917+
#ifdef FEAT_AUTOCMD
4918+
if (au_name != NULL)
4919+
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
4920+
curbuf->b_fname, TRUE, curbuf);
4921+
#endif
4922+
if (eap->cmdidx == CMD_cbuffer || eap->cmdidx == CMD_lbuffer)
4923+
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
4924+
}
48944925
}
48954926
}
48964927
}
@@ -4905,6 +4936,9 @@ ex_cexpr(exarg_T *eap)
49054936
{
49064937
typval_T *tv;
49074938
qf_info_T *qi = &ql_info;
4939+
#ifdef FEAT_AUTOCMD
4940+
char_u *au_name = NULL;
4941+
#endif
49084942

49094943
if (eap->cmdidx == CMD_lexpr || eap->cmdidx == CMD_lgetexpr
49104944
|| eap->cmdidx == CMD_laddexpr)
@@ -4914,6 +4948,28 @@ ex_cexpr(exarg_T *eap)
49144948
return;
49154949
}
49164950

4951+
#ifdef FEAT_AUTOCMD
4952+
switch (eap->cmdidx)
4953+
{
4954+
case CMD_cexpr: au_name = (char_u *)"cexpr"; break;
4955+
case CMD_cgetexpr: au_name = (char_u *)"cgetexpr"; break;
4956+
case CMD_caddexpr: au_name = (char_u *)"caddexpr"; break;
4957+
case CMD_lexpr: au_name = (char_u *)"lexpr"; break;
4958+
case CMD_lgetexpr: au_name = (char_u *)"lgetexpr"; break;
4959+
case CMD_laddexpr: au_name = (char_u *)"laddexpr"; break;
4960+
default: break;
4961+
}
4962+
if (au_name != NULL)
4963+
{
4964+
apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
4965+
curbuf->b_fname, TRUE, curbuf);
4966+
# ifdef FEAT_EVAL
4967+
if (did_throw || force_abort)
4968+
return;
4969+
# endif
4970+
}
4971+
#endif
4972+
49174973
/* Evaluate the expression. When the result is a string or a list we can
49184974
* use it to fill the errorlist. */
49194975
tv = eval_expr(eap->arg, NULL);
@@ -4925,10 +4981,16 @@ ex_cexpr(exarg_T *eap)
49254981
if (qf_init_ext(qi, NULL, NULL, tv, p_efm,
49264982
(eap->cmdidx != CMD_caddexpr
49274983
&& eap->cmdidx != CMD_laddexpr),
4928-
(linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0
4929-
&& (eap->cmdidx == CMD_cexpr
4930-
|| eap->cmdidx == CMD_lexpr))
4931-
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
4984+
(linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0)
4985+
{
4986+
#ifdef FEAT_AUTOCMD
4987+
if (au_name != NULL)
4988+
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
4989+
curbuf->b_fname, TRUE, curbuf);
4990+
#endif
4991+
if (eap->cmdidx == CMD_cexpr || eap->cmdidx == CMD_lexpr)
4992+
qf_jump(qi, 0, 0, eap->forceit); /* display first error */
4993+
}
49324994
}
49334995
else
49344996
EMSG(_("E777: String or List expected"));

src/testdir/test_quickfix.vim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,38 @@ function Test_qf_property()
15541554
call Xproperty_tests('c')
15551555
call Xproperty_tests('l')
15561556
endfunction
1557+
1558+
" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
1559+
function QfAutoCmdHandler(loc, cmd)
1560+
call add(g:acmds, a:loc . a:cmd)
1561+
endfunction
1562+
1563+
function Test_Autocmd()
1564+
autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
1565+
autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
1566+
1567+
let g:acmds = []
1568+
cexpr "F1:10:Line 10"
1569+
caddexpr "F1:20:Line 20"
1570+
cgetexpr "F1:30:Line 30"
1571+
enew! | call append(0, "F2:10:Line 10")
1572+
cbuffer!
1573+
enew! | call append(0, "F2:20:Line 20")
1574+
cgetbuffer
1575+
enew! | call append(0, "F2:30:Line 30")
1576+
caddbuffer
1577+
1578+
let l = ['precexpr',
1579+
\ 'postcexpr',
1580+
\ 'precaddexpr',
1581+
\ 'postcaddexpr',
1582+
\ 'precgetexpr',
1583+
\ 'postcgetexpr',
1584+
\ 'precbuffer',
1585+
\ 'postcbuffer',
1586+
\ 'precgetbuffer',
1587+
\ 'postcgetbuffer',
1588+
\ 'precaddbuffer',
1589+
\ 'postcaddbuffer']
1590+
call assert_equal(l, g:acmds)
1591+
endfunction

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2299,
766768
/**/
767769
2298,
768770
/**/

0 commit comments

Comments
 (0)