RFC: Support for customizing the text displayed in the quickfix window

12 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Dec 30, 2019, 12:17:46 PM12/30/19
to vim_dev
Hi all,

I have seen several requests for customizing the text displayed
in the quickfix window. I am attaching the updates to the help text
for adding a new "qfbufexpr" option that will support this.
Any comments and suggestions on this approach?

Regards,
Yegappan

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 7d8e032cd..6b6614ef0 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -5883,6 +5883,62 @@ A jump table for the options with a short
description can be found at |Q_op|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

+ *'qfbufexpr'* *'qbe'*
+'qfbufexpr' 'qbe' string (default "")
+ global
+ {only available when compiled with the |+quickfix|
+ feature}
+ Expression for text to display in the quickfix and location list
+ window buffers. The supplied expression should be the name of a Vim
+ function that accepts three arguments. The first argument is set to
+ v:true if the expression is called for a quickfix list. The second
+ argument is the quickfix or location list list identifier. The third
+ argument is the index of the entry in the quickfix or location list.
+ The function should return the text to display in the quickfix buffer.
+ The function is called for each entry in the quickfix list.
+
+ This can be used to customize the information displayed in the
+ quickfix or location buffer for each entry in the corresponding
+ quickfix or location list.
+
+ This option can be overriden by using the |setqflist()| and
+ |setloclist()| functions and setting the 'qfbufexpr' attribute for
+ a quickfix/location list.
+
+ The example below tries to mimic the default behavior for the quickfix
+ and location list buffers.
+ Example: >
+ func MyQfExpr(is_qf, qfid, eidx)
+ if a:isqf
+ let qfl = getqflist({'id' : a:qfid, 'idx' : a:eidx,
+ \ 'items' : 1}).items
+ else
+ let qfl = getloclist(0, {'id' : a:qfid, 'idx' : a:eidx,
+ \ 'items' : 1}).items
+ endif
+ let e = qfl[0]
+ let s = ''
+ if e.bufnr != 0
+ let bname = bufname(e.bufnr)
+ let s ..= fnamemodify(bname, ':.')
+ endif
+ let s ..= '|'
+ if e.lnum > 0
+ let s ..= e.lnum
+ if e.col != 0
+ let s ..= ' col ' . e.col
+ endif
+ elseif e.pattern != ''
+ let s ..= e.pattern
+ endif
+ let s ..= '| '
+ let s ..= substitute(e.text, '^\s\+', '', '')
+ return s
+ endfunc
+ set qfbufexpr=MyQfExpr
+<
+ NOTE: This option is set to "" when 'compatible' is set.
+
*'quoteescape'* *'qe'*
'quoteescape' 'qe' string (default "\")
local to buffer
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index a20f56270..26b677eee 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -5438,8 +5438,9 @@ getqflist([{what}]) *getqflist()*
id get information for the quickfix list with
|quickfix-ID|; zero means the id for the
current list or the list specified by "nr"
- idx index of the current entry in the quickfix
- list specified by 'id' or 'nr'.
+ idx get information for the quickfix entry at this
+ index in the list specified by 'id' or 'nr'.
+ If set to zero, then uses the current entry.
See |quickfix-index|
items quickfix list entries
lines parse a list of lines using 'efm' and return
@@ -5475,7 +5476,7 @@ getqflist([{what}]) *getqflist()*
If not present, set to "".
id quickfix list ID |quickfix-ID|. If not
present, set to 0.
- idx index of the current entry in the list. If not
+ idx index of the quickfix entry in the list. If not
present, set to 0.
items quickfix list entries. If not present, set to
an empty list.
@@ -8658,6 +8659,13 @@ setqflist({list} [, {action} [, {what}]]) *setqflist()*
nr list number in the quickfix stack; zero
means the current quickfix list and "$" means
the last quickfix list.
+ qfbufexpr expression to get the text to display in the
+ quickfix buffer for each entry in the list.
+ This should be set to a Vim function that is
+ called for each entry in the list and should
+ return the text to display. Refer to
+ |'qfbufexpr'| for more information and an
+ example.
title quickfix list title text. See |quickfix-title|
Unsupported keys in {what} are ignored.
If the "nr" item is not present, then the current quickfix list

skywind3000

unread,
Dec 30, 2019, 1:20:37 PM12/30/19
to vim_dev
Please provide a `raw` reserved option for qfbufexpr, and if it is initialized as:

    set qbe=raw

Just keep the original text and don't run any filter function ?? for the speed purpose. And I don't need to write a 

    function! ReturnAsItIs(is_qf, qfid, eidx)
        if a:isqf
            let qfl = getqflist({'id' : a:qfid, 'idx' : a:eidx, 'items' : 1}).items
        else
            let qfl = getloclist(0, {'id' : a:qfid, 'idx' : a:eidx,  'items' : 1}).items
        endif
        let e = qfl[0]
        return e.text
    endfunc

    set qbe=ReturnAsItIs

It's totally unnecessary for every one to write such function, and it's too slow, so just a 

    set qbe=raw

can be much helpful.

skywind3000

unread,
Dec 30, 2019, 1:34:10 PM12/30/19
to vim_dev
Or use one of:

    set qbe=*
    set qbe=$
    set qbe=-
    set qbe=?

to distinguish from function names ??

在 2019年12月31日星期二 UTC+8上午2:20:37,skywind3000写道:
Reply all
Reply to author
Forward
0 new messages