Skip to content

Commit b6fa30c

Browse files
committed
patch 8.0.0517: there is no way to remove quickfix lists
Problem: There is no way to remove quickfix lists (for testing). Solution: Add the 'f' action to setqflist(). Add tests. (Yegappan Lakshmanan)
1 parent e0720cb commit b6fa30c

5 files changed

Lines changed: 85 additions & 22 deletions

File tree

runtime/doc/eval.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6936,16 +6936,19 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
69366936
Note that the list is not exactly the same as what
69376937
|getqflist()| returns.
69386938

6939-
*E927*
6940-
If {action} is set to 'a', then the items from {list} are
6941-
added to the existing quickfix list. If there is no existing
6942-
list, then a new list is created.
6939+
{action} values: *E927*
6940+
'a' The items from {list} are added to the existing
6941+
quickfix list. If there is no existing list, then a
6942+
new list is created.
69436943

6944-
If {action} is set to 'r', then the items from the current
6945-
quickfix list are replaced with the items from {list}. This
6946-
can also be used to clear the list: >
6947-
:call setqflist([], 'r')
6944+
'r' The items from the current quickfix list are replaced
6945+
with the items from {list}. This can also be used to
6946+
clear the list: >
6947+
:call setqflist([], 'r')
69486948
<
6949+
'f' All the quickfix lists in the quickfix stack are
6950+
freed.
6951+
69496952
If {action} is not present or is set to ' ', then a new list
69506953
is created.
69516954

src/evalfunc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10038,7 +10038,8 @@ set_qf_ll_list(
1003810038
act = get_tv_string_chk(action_arg);
1003910039
if (act == NULL)
1004010040
return; /* type error; errmsg already given */
10041-
if ((*act == 'a' || *act == 'r' || *act == ' ') && act[1] == NUL)
10041+
if ((*act == 'a' || *act == 'r' || *act == ' ' || *act == 'f') &&
10042+
act[1] == NUL)
1004210043
action = *act;
1004310044
else
1004410045
EMSG2(_(e_invact), act);

src/quickfix.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ qf_get_next_file_line(qfstate_T *state)
717717

718718
#ifdef FEAT_MBYTE
719719
/* Convert a line if it contains a non-ASCII character. */
720-
if (state->vc.vc_type != CONV_NONE && has_non_ascii(state->linebuf)) {
720+
if (state->vc.vc_type != CONV_NONE && has_non_ascii(state->linebuf))
721+
{
721722
char_u *line;
722723

723724
line = string_convert(&state->vc, state->linebuf, &state->linelen);
@@ -917,7 +918,8 @@ qf_parse_line(
917918
}
918919
if (fmt_ptr->flags == '+' && !qi->qf_multiscan) /* %+ */
919920
{
920-
if (linelen > fields->errmsglen) {
921+
if (linelen > fields->errmsglen)
922+
{
921923
/* linelen + null terminator */
922924
if ((fields->errmsg = vim_realloc(fields->errmsg,
923925
linelen + 1)) == NULL)
@@ -931,7 +933,8 @@ qf_parse_line(
931933
if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
932934
continue;
933935
len = (int)(regmatch.endp[i] - regmatch.startp[i]);
934-
if (len > fields->errmsglen) {
936+
if (len > fields->errmsglen)
937+
{
935938
/* len + null terminator */
936939
if ((fields->errmsg = vim_realloc(fields->errmsg, len + 1))
937940
== NULL)
@@ -1013,7 +1016,8 @@ qf_parse_line(
10131016
fields->namebuf[0] = NUL; /* no match found, remove file name */
10141017
fields->lnum = 0; /* don't jump to this line */
10151018
fields->valid = FALSE;
1016-
if (linelen > fields->errmsglen) {
1019+
if (linelen > fields->errmsglen)
1020+
{
10171021
/* linelen + null terminator */
10181022
if ((fields->errmsg = vim_realloc(fields->errmsg,
10191023
linelen + 1)) == NULL)
@@ -4798,7 +4802,8 @@ qf_add_entries(
47984802
qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE;
47994803
else
48004804
qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
4801-
if (action != 'a') {
4805+
if (action != 'a')
4806+
{
48024807
qi->qf_lists[qi->qf_curlist].qf_ptr =
48034808
qi->qf_lists[qi->qf_curlist].qf_start;
48044809
if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
@@ -4861,6 +4866,18 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action)
48614866
return retval;
48624867
}
48634868

4869+
static void
4870+
qf_free_stack(win_T *wp, qf_info_T *qi)
4871+
{
4872+
qf_free_all(wp);
4873+
if (wp == NULL)
4874+
{
4875+
/* quickfix list */
4876+
qi->qf_curlist = 0;
4877+
qi->qf_listcount = 0;
4878+
}
4879+
}
4880+
48644881
/*
48654882
* Populate the quickfix list with the items supplied in the list
48664883
* of dictionaries. "title" will be copied to w:quickfix_title.
@@ -4884,7 +4901,12 @@ set_errorlist(
48844901
return FAIL;
48854902
}
48864903

4887-
if (what != NULL)
4904+
if (action == 'f')
4905+
{
4906+
/* Free the entire quickfix or location list stack */
4907+
qf_free_stack(wp, qi);
4908+
}
4909+
else if (what != NULL)
48884910
retval = qf_set_properties(qi, what, action);
48894911
else
48904912
retval = qf_add_entries(qi, list, title, action);
@@ -5187,7 +5209,8 @@ ex_helpgrep(exarg_T *eap)
51875209
/* Convert a line if 'encoding' is not utf-8 and
51885210
* the line contains a non-ASCII character. */
51895211
if (vc.vc_type != CONV_NONE
5190-
&& has_non_ascii(IObuff)) {
5212+
&& has_non_ascii(IObuff))
5213+
{
51915214
line = string_convert(&vc, IObuff, NULL);
51925215
if (line == NULL)
51935216
line = IObuff;

src/testdir/test_quickfix.vim

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func s:setup_commands(cchar)
3838
command! -nargs=* Xhelpgrep helpgrep <args>
3939
let g:Xgetlist = function('getqflist')
4040
let g:Xsetlist = function('setqflist')
41+
call setqflist([], 'f')
4142
else
4243
command! -nargs=* -bang Xlist <mods>llist<bang> <args>
4344
command! -nargs=* Xgetexpr <mods>lgetexpr <args>
@@ -69,13 +70,17 @@ func s:setup_commands(cchar)
6970
command! -nargs=* Xhelpgrep lhelpgrep <args>
7071
let g:Xgetlist = function('getloclist', [0])
7172
let g:Xsetlist = function('setloclist', [0])
73+
call setloclist(0, [], 'f')
7274
endif
7375
endfunc
7476

7577
" Tests for the :clist and :llist commands
7678
func XlistTests(cchar)
7779
call s:setup_commands(a:cchar)
7880

81+
if a:cchar == 'l'
82+
call assert_fails('llist', 'E776:')
83+
endif
7984
" With an empty list, command should return error
8085
Xgetexpr []
8186
silent! Xlist
@@ -146,6 +151,9 @@ endfunc
146151
func XageTests(cchar)
147152
call s:setup_commands(a:cchar)
148153

154+
let list = [{'bufnr': 1, 'lnum': 1}]
155+
call g:Xsetlist(list)
156+
149157
" Jumping to a non existent list should return error
150158
silent! Xolder 99
151159
call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
@@ -179,11 +187,7 @@ func XageTests(cchar)
179187
endfunc
180188

181189
func Test_cage()
182-
let list = [{'bufnr': 1, 'lnum': 1}]
183-
call setqflist(list)
184190
call XageTests('c')
185-
186-
call setloclist(0, list)
187191
call XageTests('l')
188192
endfunc
189193

@@ -192,6 +196,11 @@ endfunc
192196
func XwindowTests(cchar)
193197
call s:setup_commands(a:cchar)
194198

199+
" Opening the location list window without any errors should fail
200+
if a:cchar == 'l'
201+
call assert_fails('lopen', 'E776:')
202+
endif
203+
195204
" Create a list with no valid entries
196205
Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
197206

@@ -232,6 +241,19 @@ func XwindowTests(cchar)
232241
" Calling cwindow should close the quickfix window with no valid errors
233242
Xwindow
234243
call assert_true(winnr('$') == 1)
244+
245+
if a:cchar == 'c'
246+
" Opening the quickfix window in multiple tab pages should reuse the
247+
" quickfix buffer
248+
Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
249+
\ 'Xtestfile3:3:1:Line3']
250+
Xopen
251+
let qfbufnum = bufnr('%')
252+
tabnew
253+
Xopen
254+
call assert_equal(qfbufnum, bufnr('%'))
255+
new | only | tabonly
256+
endif
235257
endfunc
236258

237259
func Test_cwindow()
@@ -360,6 +382,13 @@ endfunc
360382
func Xtest_browse(cchar)
361383
call s:setup_commands(a:cchar)
362384

385+
" Jumping to first or next location list entry without any error should
386+
" result in failure
387+
if a:cchar == 'l'
388+
call assert_fails('lfirst', 'E776:')
389+
call assert_fails('lnext', 'E776:')
390+
endif
391+
363392
call s:create_test_file('Xqftestfile1')
364393
call s:create_test_file('Xqftestfile2')
365394

@@ -1550,6 +1579,11 @@ endfunc
15501579
func XbottomTests(cchar)
15511580
call s:setup_commands(a:cchar)
15521581

1582+
" Calling lbottom without any errors should fail
1583+
if a:cchar == 'l'
1584+
call assert_fails('lbottom', 'E776:')
1585+
endif
1586+
15531587
call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
15541588
Xopen
15551589
let wid = win_getid()
@@ -1571,10 +1605,9 @@ endfunc
15711605
func HistoryTest(cchar)
15721606
call s:setup_commands(a:cchar)
15731607

1574-
call assert_fails(a:cchar . 'older 99', 'E380:')
15751608
" clear all lists after the first one, then replace the first one.
15761609
call g:Xsetlist([])
1577-
Xolder
1610+
call assert_fails('Xolder 99', 'E380:')
15781611
let entry = {'filename': 'foo', 'lnum': 42}
15791612
call g:Xsetlist([entry], 'r')
15801613
call g:Xsetlist([entry, entry])
@@ -1617,6 +1650,7 @@ func Xproperty_tests(cchar)
16171650
call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
16181651

16191652
" Set and get the title
1653+
call g:Xsetlist([])
16201654
Xopen
16211655
wincmd p
16221656
call g:Xsetlist([{'filename':'foo', 'lnum':27}])

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
517,
767769
/**/
768770
516,
769771
/**/

0 commit comments

Comments
 (0)