Skip to content

Commit 3653822

Browse files
committed
patch 8.0.1040: cannot use another error format in getqflist()
Problem: Cannot use another error format in getqflist(). Solution: Add the "efm" argument to getqflist(). (Yegappan Lakshmanan)
1 parent b31cf2b commit 3653822

4 files changed

Lines changed: 62 additions & 10 deletions

File tree

runtime/doc/eval.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4635,16 +4635,19 @@ getqflist([{what}]) *getqflist()*
46354635
returns only the items listed in {what} as a dictionary. The
46364636
following string items are supported in {what}:
46374637
context get the context stored with |setqflist()|
4638+
efm errorformat to use when parsing "lines". If
4639+
not present, then the 'erroformat' option
4640+
value is used.
46384641
id get information for the quickfix list with
46394642
|quickfix-ID|; zero means the id for the
4640-
current list or the list specifed by 'nr'
4643+
current list or the list specifed by "nr"
46414644
items quickfix list entries
46424645
lines use 'errorformat' to extract items from a list
46434646
of lines and return the resulting entries.
46444647
Only a |List| type is accepted. The current
46454648
quickfix list is not modified.
46464649
nr get information for this quickfix list; zero
4647-
means the current quickfix list and '$' means
4650+
means the current quickfix list and "$" means
46484651
the last quickfix list
46494652
title get the list title
46504653
winid get the |window-ID| (if opened)
@@ -7086,29 +7089,32 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
70867089
is created. The new quickfix list is added after the current
70877090
quickfix list in the stack and all the following lists are
70887091
freed. To add a new quickfix list at the end of the stack,
7089-
set "nr" in {what} to '$'.
7092+
set "nr" in {what} to "$".
70907093

70917094
If the optional {what} dictionary argument is supplied, then
70927095
only the items listed in {what} are set. The first {list}
70937096
argument is ignored. The following items can be specified in
70947097
{what}:
70957098
context any Vim type can be stored as a context
7099+
efm errorformat to use when parsing text from
7100+
"lines". If this is not present, then the
7101+
'errorformat' option value is used.
70967102
id quickfix list identifier |quickfix-ID|
70977103
items list of quickfix entries. Same as the {list}
70987104
argument.
70997105
lines use 'errorformat' to parse a list of lines and
71007106
add the resulting entries to the quickfix list
71017107
{nr} or {id}. Only a |List| value is supported.
71027108
nr list number in the quickfix stack; zero
7103-
means the current quickfix list and '$' means
7109+
means the current quickfix list and "$" means
71047110
the last quickfix list
71057111
title quickfix list title text
71067112
Unsupported keys in {what} are ignored.
71077113
If the "nr" item is not present, then the current quickfix list
71087114
is modified. When creating a new quickfix list, "nr" can be
71097115
set to a value one greater than the quickfix stack size.
71107116
When modifying a quickfix list, to guarantee that the correct
7111-
list is modified, 'id' should be used instead of 'nr' to
7117+
list is modified, "id" should be used instead of "nr" to
71127118
specify the list.
71137119

71147120
Examples: >

src/quickfix.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,16 +4643,29 @@ enum {
46434643
* Parse text from 'di' and return the quickfix list items
46444644
*/
46454645
static int
4646-
qf_get_list_from_lines(dictitem_T *di, dict_T *retdict)
4646+
qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict)
46474647
{
46484648
int status = FAIL;
46494649
qf_info_T *qi;
4650+
char_u *errorformat = p_efm;
4651+
dictitem_T *efm_di;
4652+
list_T *l;
46504653

46514654
/* Only a List value is supported */
46524655
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL)
46534656
{
4654-
list_T *l = list_alloc();
4657+
/* If errorformat is supplied then use it, otherwise use the 'efm'
4658+
* option setting
4659+
*/
4660+
if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL)
4661+
{
4662+
if (efm_di->di_tv.v_type != VAR_STRING ||
4663+
efm_di->di_tv.vval.v_string == NULL)
4664+
return FAIL;
4665+
errorformat = efm_di->di_tv.vval.v_string;
4666+
}
46554667

4668+
l = list_alloc();
46564669
if (l == NULL)
46574670
return FAIL;
46584671

@@ -4662,7 +4675,7 @@ qf_get_list_from_lines(dictitem_T *di, dict_T *retdict)
46624675
vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
46634676
qi->qf_refcount++;
46644677

4665-
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, p_efm,
4678+
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
46664679
TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
46674680
{
46684681
(void)get_errorlist(qi, NULL, 0, l);
@@ -4692,7 +4705,7 @@ get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
46924705
int flags = QF_GETLIST_NONE;
46934706

46944707
if ((di = dict_find(what, (char_u *)"lines", -1)) != NULL)
4695-
return qf_get_list_from_lines(di, retdict);
4708+
return qf_get_list_from_lines(what, di, retdict);
46964709

46974710
if (wp != NULL)
46984711
qi = GET_LOC_LIST(wp);
@@ -4962,6 +4975,7 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action, char_u *title)
49624975
int retval = FAIL;
49634976
int qf_idx;
49644977
int newlist = FALSE;
4978+
char_u *errorformat = p_efm;
49654979

49664980
if (action == ' ' || qi->qf_curlist == qi->qf_listcount)
49674981
newlist = TRUE;
@@ -5039,6 +5053,7 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action, char_u *title)
50395053
retval = OK;
50405054
}
50415055
}
5056+
50425057
if ((di = dict_find(what, (char_u *)"items", -1)) != NULL)
50435058
{
50445059
if (di->di_tv.v_type == VAR_LIST)
@@ -5051,14 +5066,21 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action, char_u *title)
50515066
}
50525067
}
50535068

5069+
if ((di = dict_find(what, (char_u *)"efm", -1)) != NULL)
5070+
{
5071+
if (di->di_tv.v_type != VAR_STRING || di->di_tv.vval.v_string == NULL)
5072+
return FAIL;
5073+
errorformat = di->di_tv.vval.v_string;
5074+
}
5075+
50545076
if ((di = dict_find(what, (char_u *)"lines", -1)) != NULL)
50555077
{
50565078
/* Only a List value is supported */
50575079
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL)
50585080
{
50595081
if (action == 'r')
50605082
qf_free_items(qi, qf_idx);
5061-
if (qf_init_ext(qi, qf_idx, NULL, NULL, &di->di_tv, p_efm,
5083+
if (qf_init_ext(qi, qf_idx, NULL, NULL, &di->di_tv, errorformat,
50625084
FALSE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
50635085
retval = OK;
50645086
}

src/testdir/test_quickfix.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,17 @@ func Xsetexpr_tests(cchar)
23212321
call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
23222322
call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
23232323
call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
2324+
2325+
" Adding entries using a custom efm
2326+
set efm&
2327+
call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2328+
\ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2329+
call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2330+
call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2331+
call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2332+
call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2333+
call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2334+
\ 'lines' : ['F1:10:L10']}))
23242335
endfunc
23252336

23262337
func Test_setexpr()
@@ -2537,6 +2548,17 @@ func XgetListFromLines(cchar)
25372548
call assert_equal([], g:Xgetlist({'lines' : []}).items)
25382549
call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
25392550

2551+
" Parse text using a custom efm
2552+
set efm&
2553+
let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
2554+
call assert_equal('Line30', l[0].text)
2555+
let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
2556+
call assert_equal('File3:30:Line30', l[0].text)
2557+
let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
2558+
call assert_equal({}, l)
2559+
call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
2560+
call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
2561+
25402562
" Make sure that the quickfix stack is not modified
25412563
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
25422564
endfunc

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1040,
772774
/**/
773775
1039,
774776
/**/

0 commit comments

Comments
 (0)