Skip to content

Commit 858ba06

Browse files
committed
patch 8.2.0869: it is not possible to customize the quickfix window contents
Problem: It is not possible to customize the quickfix window contents. Solution: Add 'quickfixtextfunc'. (Yegappan Lakshmanan, closes #5465)
1 parent 2245ae1 commit 858ba06

File tree

8 files changed

+367
-71
lines changed

8 files changed

+367
-71
lines changed

runtime/doc/eval.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5508,8 +5508,9 @@ getqflist([{what}]) *getqflist()*
55085508
id get information for the quickfix list with
55095509
|quickfix-ID|; zero means the id for the
55105510
current list or the list specified by "nr"
5511-
idx index of the current entry in the quickfix
5512-
list specified by 'id' or 'nr'.
5511+
idx get information for the quickfix entry at this
5512+
index in the list specified by 'id' or 'nr'.
5513+
If set to zero, then uses the current entry.
55135514
See |quickfix-index|
55145515
items quickfix list entries
55155516
lines parse a list of lines using 'efm' and return
@@ -5545,7 +5546,7 @@ getqflist([{what}]) *getqflist()*
55455546
If not present, set to "".
55465547
id quickfix list ID |quickfix-ID|. If not
55475548
present, set to 0.
5548-
idx index of the current entry in the list. If not
5549+
idx index of the quickfix entry in the list. If not
55495550
present, set to 0.
55505551
items quickfix list entries. If not present, set to
55515552
an empty list.
@@ -8841,6 +8842,11 @@ setqflist({list} [, {action} [, {what}]]) *setqflist()*
88418842
nr list number in the quickfix stack; zero
88428843
means the current quickfix list and "$" means
88438844
the last quickfix list.
8845+
quickfixtextfunc
8846+
function to get the text to display in the
8847+
quickfix window. Refer to
8848+
|quickfix-window-function| for an explanation
8849+
of how to write the function and an example.
88448850
title quickfix list title text. See |quickfix-title|
88458851
Unsupported keys in {what} are ignored.
88468852
If the "nr" item is not present, then the current quickfix list

runtime/doc/options.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5898,6 +5898,21 @@ A jump table for the options with a short description can be found at |Q_op|.
58985898
'pyxversion' has no effect. The pyx* functions and commands are
58995899
always the same as the compiled version.
59005900

5901+
This option cannot be set from a |modeline| or in the |sandbox|, for
5902+
security reasons.
5903+
5904+
*'quickfixtextfunc'* *'qftf'*
5905+
'quickfixtextfunc' 'qftf' string (default "")
5906+
global
5907+
{only available when compiled with the |+quickfix|
5908+
feature}
5909+
This option specifies a function to be used to get the text to display
5910+
in the quickfix and location list windows. This can be used to
5911+
customize the information displayed in the quickfix or location window
5912+
for each entry in the corresponding quickfix or location list. See
5913+
|quickfix-window-function| for an explanation of how to write the
5914+
function and an example.
5915+
59015916
This option cannot be set from a |modeline| or in the |sandbox|, for
59025917
security reasons.
59035918

runtime/doc/quickfix.txt

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This subject is introduced in section |30.1| of the user manual.
1515
7. The error format |error-file-format|
1616
8. The directory stack |quickfix-directory-stack|
1717
9. Specific error file formats |errorformats|
18+
10. Customizing the quickfix window |quickfix-window-function|
1819

1920
The quickfix commands are not available when the |+quickfix| feature was
2021
disabled at compile time.
@@ -1921,6 +1922,59 @@ error messages into a format that quickfix mode will understand. See the
19211922
start of the file about how to use it. (This script is deprecated, see
19221923
|compiler-perl|.)
19231924

1924-
1925+
=============================================================================
1926+
10. Customizing the quickfix window *quickfix-window-function*
1927+
1928+
The default format for the lines displayed in the quickfix window and location
1929+
list window is:
1930+
1931+
<filename>|<lnum> col <col>|<text>
1932+
1933+
The values displayed in each line correspond to the "bufnr", "lnum", "col" and
1934+
"text" fields returned by the |getqflist()| function.
1935+
1936+
For some quickfix/location lists, the displayed text need to be customized.
1937+
For example, if only the filename is present for a quickfix entry, then the
1938+
two "|" field separator characters after the filename are not needed. Another
1939+
use case is to customize the path displayed for a filename. By default, the
1940+
complete path (which may be too long) is displayed for files which are not
1941+
under the current directory tree. The file path may need to be simplified to a
1942+
common parent directory.
1943+
1944+
The displayed text can be customized by setting the 'quickfixtextfunc' option
1945+
to a Vim function. This function will be called with a dict argument for
1946+
every entry in a quickfix or a location list. The dict argument will have the
1947+
following fields:
1948+
1949+
quickfix set to 1 when called for a quickfix list and 0 when called for
1950+
a location list.
1951+
id quickfix or location list identifier
1952+
idx index of the entry in the quickfix or location list
1953+
1954+
The function should return a single line of text to display in the quickfix
1955+
window for the entry identified by idx. The function can obtain information
1956+
about the current entry using the |getqflist()| function and specifying the
1957+
quickfix list identifier "id" and the entry index "idx".
1958+
1959+
If a quickfix or location list specific customization is needed, then the
1960+
'quickfixtextfunc' attribute of the list can be set using the |setqflist()| or
1961+
|setloclist()| function. This overrides the global 'quickfixtextfunc' option.
1962+
1963+
The example below displays the list of old files (|v:oldfiles|) in a quickfix
1964+
window. As there is no line, column number and error text information
1965+
associated with each entry, the 'quickfixtextfunc' function returns only the
1966+
filename.
1967+
Example: >
1968+
" create a quickfix list from v:oldfiles
1969+
call setqflist([], ' ', {'lines' : v:oldfiles, 'efm' : '%f',
1970+
\ 'quickfixtextfunc' : 'QfOldFiles'})
1971+
func QfOldFiles(info)
1972+
" get information about the specific quickfix entry
1973+
let e = getqflist({'id' : a:info.id, 'idx' : a:info.idx,
1974+
\ 'items' : 1}).items[0]
1975+
" return the simplified file name
1976+
return fnamemodify(bufname(e.bufnr), ':p:.')
1977+
endfunc
1978+
<
19251979

19261980
vim:tw=78:ts=8:noet:ft=help:norl:

src/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ EXTERN int p_ru; // 'ruler'
820820
EXTERN char_u *p_ruf; // 'rulerformat'
821821
#endif
822822
EXTERN char_u *p_pp; // 'packpath'
823+
EXTERN char_u *p_qftf; // 'quickfixtextfunc'
823824
EXTERN char_u *p_rtp; // 'runtimepath'
824825
EXTERN long p_sj; // 'scrolljump'
825826
#if defined(MSWIN) && defined(FEAT_GUI)

src/optiondefs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,15 @@ static struct vimoption options[] =
20452045
#endif
20462046
{(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
20472047
SCTX_INIT},
2048+
{"quickfixtextfunc", "qftf", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_SECURE,
2049+
#if defined(FEAT_QUICKFIX) && defined(FEAT_EVAL)
2050+
(char_u *)&p_qftf, PV_NONE,
2051+
{(char_u *)"", (char_u *)0L}
2052+
#else
2053+
(char_u *)NULL, PV_NONE,
2054+
{(char_u *)NULL, (char_u *)NULL}
2055+
#endif
2056+
SCTX_INIT},
20482057
{"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
20492058
#ifdef FEAT_TEXTOBJ
20502059
(char_u *)&p_qe, PV_QE,

0 commit comments

Comments
 (0)