[vim/vim] :cexpr and :cgetexpr not included in QuickFixCmdPre/QuickFixCmdPost autocmd triggers (#1021)

69 views
Skip to first unread message

Mathias Stearn

unread,
Aug 29, 2016, 10:38:55 PM8/29/16
to vim/vim

QuickFixCmdPost can be used to automatically show the quickfix window whenever a command runs that affects the quickfix list. This seems to work for everything except for :cexpr, which looks like it was accidentally omitted from the list of triggering commands. If it was intentional, it may be worth mentioning explicitly in the docs.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Yegappan Lakshmanan

unread,
Aug 30, 2016, 12:05:14 AM8/30/16
to vim_dev, reply+00b1d19889e80d0772d78832b9d523f541b8b64...@reply.github.com
Hi,

On Mon, Aug 29, 2016 at 7:38 PM, Mathias Stearn
<vim-dev...@256bit.org> wrote:
>
> QuickFixCmdPost can be used to automatically show the quickfix window
> whenever a command runs that affects the quickfix list. This seems to work
> for everything except for :cexpr, which looks like it was accidentally
> omitted from the list of triggering commands. If it was intentional, it may
> be worth mentioning explicitly in the docs.
>

As mentioned in the help, the QuickFixCmdPre/Post autocmds are used
only for commands like grep, make, vimgrep and cscope that add/modify the
quickfix list. They are not used for commands like cfile, cbuffer and cexpr etc.
The help text for cexpr can be updated to state this.

- Yegappan

vim-dev ML

unread,
Aug 30, 2016, 12:05:42 AM8/30/16
to vim/vim, vim-dev ML, Your activity
Hi,

On Mon, Aug 29, 2016 at 7:38 PM, Mathias Stearn
<vim-dev...@256bit.org> wrote:
>
> QuickFixCmdPost can be used to automatically show the quickfix window
> whenever a command runs that affects the quickfix list. This seems to work
> for everything except for :cexpr, which looks like it was accidentally
> omitted from the list of triggering commands. If it was intentional, it may
> be worth mentioning explicitly in the docs.
>

As mentioned in the help, the QuickFixCmdPre/Post autocmds are used
only for commands like grep, make, vimgrep and cscope that add/modify the
quickfix list. They are not used for commands like cfile, cbuffer and cexpr etc.
The help text for cexpr can be updated to state this.

- Yegappan

Mathias Stearn

unread,
Aug 30, 2016, 9:26:02 AM8/30/16
to vim/vim, vim-dev ML, Comment

They are not used for commands like cfile, cbuffer and cexpr etc.

Actually, cfile is one of the commands that triggers QuickFixCmdPre/Post: https://github.com/vim/vim/blob/bc8801c/runtime/doc/autocmd.txt#L780-L801

Is there a better way to achieve the goal of always opening the quickfix window whenever I run a command that populates it?


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Aug 31, 2016, 12:09:50 AM8/31/16
to vim_dev, reply+00b1d19835b7b24ae3993aecc2b4e82d3a64da0...@reply.github.com
Hi,

On Tue, Aug 30, 2016 at 6:25 AM, Mathias Stearn
<vim-dev...@256bit.org> wrote:
> They are not used for commands like cfile, cbuffer and cexpr etc.
>
> Actually, cfile is one of the commands that triggers QuickFixCmdPre/Post:
> https://github.com/vim/vim/blob/bc8801c/runtime/doc/autocmd.txt#L780-L801
>

The attached patch fixes this problem. Now the pre/post autocmds are invoked
for the cexpr/cgetexpr/caddexpr/cbuffer/cgetbuffer/caddbuffer commands also.

- Yegappan
qfautocmd.diff

vim-dev ML

unread,
Aug 31, 2016, 12:10:13 AM8/31/16
to vim/vim, vim-dev ML, Your activity
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index e3ba3d7..e5dc741 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -784,7 +784,9 @@ QuickFixCmdPre Before a quickfix command is run (|:make|,
|:vimgrepadd|, |:lvimgrepadd|, |:cscope|,
|:cfile|, |:cgetfile|, |:caddfile|, |:lfile|,
|:lgetfile|, |:laddfile|, |:helpgrep|,
- |:lhelpgrep|).
+ |:lhelpgrep|, |:cexpr|, |:cgetexpr|,
+ |:caddexpr|, |:cbuffer|, |:cgetbuffer|,
+ |:caddbuffer|).
The pattern is matched against the command
being run. When |:grep| is used but 'grepprg'
is set to "internal" it still matches "grep".
diff --git a/src/quickfix.c b/src/quickfix.c
index d022061..2f5256b 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4845,6 +4845,9 @@ ex_cbuffer(exarg_T *eap)
{
buf_T *buf = NULL;
qf_info_T *qi = &ql_info;
+#ifdef FEAT_AUTOCMD
+ char_u *au_name = NULL;
+#endif

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

+#ifdef FEAT_AUTOCMD
+ switch (eap->cmdidx)
+ {
+ case CMD_cbuffer: au_name = (char_u *)"cbuffer"; break;
+ case CMD_cgetbuffer: au_name = (char_u *)"cgetbuffer"; break;
+ case CMD_caddbuffer: au_name = (char_u *)"caddbuffer"; break;
+ case CMD_lbuffer: au_name = (char_u *)"lbuffer"; break;
+ case CMD_lgetbuffer: au_name = (char_u *)"lgetbuffer"; break;
+ case CMD_laddbuffer: au_name = (char_u *)"laddbuffer"; break;
+ default: break;
+ }
+ if (au_name != NULL)
+ {
+ apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
+ curbuf->b_fname, TRUE, curbuf);
+# ifdef FEAT_EVAL
+ if (did_throw || force_abort)
+ return;
+# endif
+ }
+#endif
+
if (*eap->arg == NUL)
buf = curbuf;
else if (*skipwhite(skipdigits(eap->arg)) == NUL)
@@ -4887,10 +4912,16 @@ ex_cbuffer(exarg_T *eap)
(eap->cmdidx != CMD_caddbuffer
&& eap->cmdidx != CMD_laddbuffer),
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 */
+ qf_title) > 0)
+ {
+#ifdef FEAT_AUTOCMD
+ 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 */
+ }
}
}
}
@@ -4905,6 +4936,9 @@ ex_cexpr(exarg_T *eap)
{
typval_T *tv;
qf_info_T *qi = &ql_info;
+#ifdef FEAT_AUTOCMD
+ char_u *au_name = NULL;
+#endif

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

+#ifdef FEAT_AUTOCMD
+ switch (eap->cmdidx)
+ {
+ case CMD_cexpr: au_name = (char_u *)"cexpr"; break;
+ case CMD_cgetexpr: au_name = (char_u *)"cgetexpr"; break;
+ case CMD_caddexpr: au_name = (char_u *)"caddexpr"; break;
+ case CMD_lexpr: au_name = (char_u *)"lexpr"; break;
+ case CMD_lgetexpr: au_name = (char_u *)"lgetexpr"; break;
+ case CMD_laddexpr: au_name = (char_u *)"laddexpr"; break;
+ default: break;
+ }
+ if (au_name != NULL)
+ {
+ apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
+ curbuf->b_fname, TRUE, curbuf);
+# ifdef FEAT_EVAL
+ if (did_throw || force_abort)
+ return;
+# endif
+ }
+#endif
+
/* Evaluate the expression. When the result is a string or a list we can
* use it to fill the errorlist. */
tv = eval_expr(eap->arg, NULL);
@@ -4925,10 +4981,16 @@ ex_cexpr(exarg_T *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, *eap->cmdlinep) > 0
- && (eap->cmdidx == CMD_cexpr
- || eap->cmdidx == CMD_lexpr))
- qf_jump(qi, 0, 0, eap->forceit); /* display first error */
+ (linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0)
+ {
+#ifdef FEAT_AUTOCMD
+ 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 */
+ }
}
else
EMSG(_("E777: String or List expected"));
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 5c51477..affd8e6 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -1554,3 +1554,38 @@ function Test_qf_property()
call Xproperty_tests('c')
call Xproperty_tests('l')
endfunction
+
+" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
+function QfAutoCmdHandler(loc, cmd)
+ call add(g:acmds, a:loc . a:cmd)
+endfunction
+
+function Test_Autocmd()
+ autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
+ autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
+
+ let g:acmds = []
+ 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
+
+ let l = ['precexpr',
+ \ 'postcexpr',
+ \ 'precaddexpr',
+ \ 'postcaddexpr',
+ \ 'precgetexpr',
+ \ 'postcgetexpr',
+ \ 'precbuffer',
+ \ 'postcbuffer',
+ \ 'precgetbuffer',
+ \ 'postcgetbuffer',
+ \ 'precaddbuffer',
+ \ 'postcaddbuffer']
+ call assert_equal(l, g:acmds)
+endfunction

Christian Brabandt

unread,
Sep 2, 2016, 7:38:03 AM9/2/16
to vim/vim, vim-dev ML, Comment

fixed by 04c4ce6


You are receiving this because you commented.

Christian Brabandt

unread,
Sep 2, 2016, 7:38:12 AM9/2/16
to vim/vim, vim-dev ML, Comment

Closed #1021.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages