Skip to content

Commit ee85df3

Browse files
committed
patch 8.0.0484: :lhelpgrep does not fail after a successful one
Problem: Using :lhelpgrep with an argument that should fail does not produce an error if the previous :helpgrep worked. Solution: Use another way to detect that autocommands made the quickfix info invalid. (Yegappan Lakshmanan)
1 parent f79225e commit ee85df3

File tree

3 files changed

+150
-40
lines changed

3 files changed

+150
-40
lines changed

src/quickfix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5077,6 +5077,7 @@ ex_helpgrep(exarg_T *eap)
50775077
char_u *lang;
50785078
#endif
50795079
qf_info_T *qi = &ql_info;
5080+
qf_info_T *save_qi;
50805081
int new_qi = FALSE;
50815082
win_T *wp;
50825083
#ifdef FEAT_AUTOCMD
@@ -5130,6 +5131,9 @@ ex_helpgrep(exarg_T *eap)
51305131
}
51315132
}
51325133

5134+
/* Autocommands may change the list. Save it for later comparison */
5135+
save_qi = qi;
5136+
51335137
regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING);
51345138
regmatch.rm_ic = FALSE;
51355139
if (regmatch.regprog != NULL)
@@ -5262,7 +5266,7 @@ ex_helpgrep(exarg_T *eap)
52625266
{
52635267
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
52645268
curbuf->b_fname, TRUE, curbuf);
5265-
if (!new_qi && qi != &ql_info && qf_find_buf(qi) == NULL)
5269+
if (!new_qi && qi != save_qi && qf_find_buf(qi) == NULL)
52665270
/* autocommands made "qi" invalid */
52675271
return;
52685272
}

src/testdir/test_quickfix.vim

Lines changed: 143 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func s:setup_commands(cchar)
3131
command! -nargs=* -bang Xnfile <mods>cnfile<bang> <args>
3232
command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
3333
command! -nargs=* Xexpr <mods>cexpr <args>
34-
command! -nargs=* Xvimgrep <mods>vimgrep <args>
34+
command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args>
35+
command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args>
3536
command! -nargs=* Xgrep <mods> grep <args>
3637
command! -nargs=* Xgrepadd <mods> grepadd <args>
3738
command! -nargs=* Xhelpgrep helpgrep <args>
@@ -61,7 +62,8 @@ func s:setup_commands(cchar)
6162
command! -nargs=* -bang Xnfile <mods>lnfile<bang> <args>
6263
command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
6364
command! -nargs=* Xexpr <mods>lexpr <args>
64-
command! -nargs=* Xvimgrep <mods>lvimgrep <args>
65+
command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args>
66+
command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args>
6567
command! -nargs=* Xgrep <mods> lgrep <args>
6668
command! -nargs=* Xgrepadd <mods> lgrepadd <args>
6769
command! -nargs=* Xhelpgrep lhelpgrep <args>
@@ -85,57 +87,52 @@ func XlistTests(cchar)
8587
\ 'non-error 3', 'Xtestfile3:3:1:Line3']
8688

8789
" List only valid entries
88-
redir => result
89-
Xlist
90-
redir END
91-
let l = split(result, "\n")
90+
let l = split(execute('Xlist', ''), "\n")
9291
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
9392
\ ' 4 Xtestfile2:2 col 2: Line2',
9493
\ ' 6 Xtestfile3:3 col 1: Line3'], l)
9594

9695
" List all the entries
97-
redir => result
98-
Xlist!
99-
redir END
100-
let l = split(result, "\n")
96+
let l = split(execute('Xlist!', ''), "\n")
10197
call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
10298
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
10399
\ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
104100

105101
" List a range of errors
106-
redir => result
107-
Xlist 3,6
108-
redir END
109-
let l = split(result, "\n")
102+
let l = split(execute('Xlist 3,6', ''), "\n")
110103
call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
111104
\ ' 6 Xtestfile3:3 col 1: Line3'], l)
112105

113-
redir => result
114-
Xlist! 3,4
115-
redir END
116-
let l = split(result, "\n")
106+
let l = split(execute('Xlist! 3,4', ''), "\n")
117107
call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
118108

119-
redir => result
120-
Xlist -6,-4
121-
redir END
122-
let l = split(result, "\n")
109+
let l = split(execute('Xlist -6,-4', ''), "\n")
123110
call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
124111

125-
redir => result
126-
Xlist! -5,-3
127-
redir END
128-
let l = split(result, "\n")
112+
let l = split(execute('Xlist! -5,-3', ''), "\n")
129113
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
130114
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
131115

132116
" Test for '+'
133-
redir => result
134-
Xlist! +2
135-
redir END
136-
let l = split(result, "\n")
117+
let l = split(execute('Xlist! +2', ''), "\n")
137118
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
138119
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
120+
121+
" Different types of errors
122+
call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
123+
\ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
124+
\ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
125+
\ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
126+
\ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
127+
let l = split(execute('Xlist', ""), "\n")
128+
call assert_equal([' 1:10 col 5 warning 11: Warning',
129+
\ ' 2:20 col 10 error 22: Error',
130+
\ ' 3:30 col 15 info 33: Info',
131+
\ ' 4:40 col 20 x 44: Other',
132+
\ ' 5:50 col 25 55: one'], l)
133+
134+
" Error cases
135+
call assert_fails('Xlist abc', 'E488:')
139136
endfunc
140137

141138
func Test_clist()
@@ -324,6 +321,23 @@ func XbufferTests(cchar)
324321
\ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
325322
enew!
326323

324+
" Check for invalid buffer
325+
call assert_fails('Xbuffer 199', 'E474:')
326+
327+
" Check for unloaded buffer
328+
edit Xtestfile1
329+
let bnr = bufnr('%')
330+
enew!
331+
call assert_fails('Xbuffer ' . bnr, 'E681:')
332+
333+
" Check for invalid range
334+
" Using Xbuffer will not run the range check in the cbuffer/lbuffer
335+
" commands. So directly call the commands.
336+
if (a:cchar == 'c')
337+
call assert_fails('900,999cbuffer', 'E16:')
338+
else
339+
call assert_fails('900,999lbuffer', 'E16:')
340+
endif
327341
endfunc
328342

329343
func Test_cbuffer()
@@ -372,6 +386,9 @@ func Xtest_browse(cchar)
372386
call assert_equal('Xqftestfile1', bufname('%'))
373387
call assert_equal(5, line('.'))
374388

389+
Xexpr ""
390+
call assert_fails('Xnext', 'E42:')
391+
375392
call delete('Xqftestfile1')
376393
call delete('Xqftestfile2')
377394
endfunc
@@ -411,6 +428,9 @@ func s:test_xhelpgrep(cchar)
411428
call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
412429
" This wipes out the buffer, make sure that doesn't cause trouble.
413430
Xclose
431+
432+
" Search for non existing help string
433+
call assert_fails('Xhelpgrep a1b2c3', 'E480:')
414434
endfunc
415435

416436
func Test_helpgrep()
@@ -604,7 +624,7 @@ func Test_locationlist()
604624
wincmd n | only
605625

606626
augroup! testgroup
607-
endfunc
627+
endfunc
608628

609629
func Test_locationlist_curwin_was_closed()
610630
augroup testgroup
@@ -623,7 +643,7 @@ func Test_locationlist_curwin_was_closed()
623643
call assert_fails('lrewind', 'E924:')
624644

625645
augroup! testgroup
626-
endfunc
646+
endfunc
627647

628648
func Test_locationlist_cross_tab_jump()
629649
call writefile(['loclistfoo'], 'loclistfoo')
@@ -760,7 +780,7 @@ func Test_efm1()
760780
call delete('Xerrorfile1')
761781
call delete('Xerrorfile2')
762782
call delete('Xtestfile')
763-
endfunc
783+
endfunc
764784

765785
" Test for quickfix directory stack support
766786
func s:dir_stack_tests(cchar)
@@ -919,20 +939,26 @@ func Test_efm2()
919939
call assert_equal(l[0].pattern, '^\VLine search text\$')
920940
call assert_equal(l[0].lnum, 0)
921941

942+
let l = split(execute('clist', ''), "\n")
943+
call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
944+
922945
" Test for %P, %Q and %t format specifiers
923946
let lines=["[Xtestfile1]",
924947
\ "(1,17) error: ';' missing",
925948
\ "(21,2) warning: variable 'z' not defined",
926949
\ "(67,3) error: end of file found before string ended",
950+
\ "--",
927951
\ "",
928952
\ "[Xtestfile2]",
953+
\ "--",
929954
\ "",
930955
\ "[Xtestfile3]",
931956
\ "NEW compiler v1.1",
932957
\ "(2,2) warning: variable 'x' not defined",
933-
\ "(67,3) warning: 's' already defined"
958+
\ "(67,3) warning: 's' already defined",
959+
\ "--"
934960
\]
935-
set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
961+
set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
936962
" To exercise the push/pop file functionality in quickfix, the test files
937963
" need to be created.
938964
call writefile(['Line1'], 'Xtestfile1')
@@ -943,7 +969,7 @@ func Test_efm2()
943969
caddexpr l
944970
endfor
945971
let l = getqflist()
946-
call assert_equal(9, len(l))
972+
call assert_equal(12, len(l))
947973
call assert_equal(21, l[2].lnum)
948974
call assert_equal(2, l[2].col)
949975
call assert_equal('w', l[2].type)
@@ -1098,6 +1124,13 @@ func SetXlistTests(cchar, bnum)
10981124
call g:Xsetlist([])
10991125
let l = g:Xgetlist()
11001126
call assert_equal(0, len(l))
1127+
1128+
" Error cases:
1129+
" Refer to a non-existing buffer and pass a non-dictionary type
1130+
call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1131+
\ " {'bufnr':999, 'lnum':5}])", 'E92:')
1132+
call g:Xsetlist([[1, 2,3]])
1133+
call assert_equal(0, len(g:Xgetlist()))
11011134
endfunc
11021135

11031136
func Test_setqflist()
@@ -1116,7 +1149,8 @@ func Xlist_empty_middle(cchar)
11161149
call s:setup_commands(a:cchar)
11171150

11181151
" create three quickfix lists
1119-
Xvimgrep Test_ test_quickfix.vim
1152+
let @/ = 'Test_'
1153+
Xvimgrep // test_quickfix.vim
11201154
let testlen = len(g:Xgetlist())
11211155
call assert_true(testlen > 0)
11221156
Xvimgrep empty test_quickfix.vim
@@ -1609,23 +1643,41 @@ func Xproperty_tests(cchar)
16091643
call g:Xsetlist([], ' ', {'title' : 'N3'})
16101644
call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
16111645

1646+
" Changing the title of an earlier quickfix list
1647+
call g:Xsetlist([], ' ', {'title' : 'NewTitle', 'nr' : 2})
1648+
call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1649+
1650+
" Changing the title of an invalid quickfix list
1651+
call assert_equal(-1, g:Xsetlist([], ' ',
1652+
\ {'title' : 'SomeTitle', 'nr' : 99}))
1653+
call assert_equal(-1, g:Xsetlist([], ' ',
1654+
\ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1655+
1656+
if a:cchar == 'c'
1657+
copen
1658+
call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1659+
cclose
1660+
endif
1661+
16121662
" Invalid arguments
16131663
call assert_fails('call g:Xgetlist([])', 'E715')
16141664
call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
16151665
let s = g:Xsetlist([], 'a', {'abc':1})
16161666
call assert_equal(-1, s)
16171667

16181668
call assert_equal({}, g:Xgetlist({'abc':1}))
1669+
call assert_equal({}, g:Xgetlist({'nr':99, 'title':1}))
1670+
call assert_equal({}, g:Xgetlist({'nr':[], 'title':1}))
16191671

16201672
if a:cchar == 'l'
16211673
call assert_equal({}, getloclist(99, {'title': 1}))
16221674
endif
1623-
endfunc
1675+
endfunc
16241676

16251677
func Test_qf_property()
16261678
call Xproperty_tests('c')
16271679
call Xproperty_tests('l')
1628-
endfunc
1680+
endfunc
16291681

16301682
" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
16311683
func QfAutoCmdHandler(loc, cmd)
@@ -1774,3 +1826,55 @@ func Test_cwindow_jump()
17741826
enew | only
17751827
set efm&vim
17761828
endfunc
1829+
1830+
func XvimgrepTests(cchar)
1831+
call s:setup_commands(a:cchar)
1832+
1833+
call writefile(['Editor:VIM vim',
1834+
\ 'Editor:Emacs EmAcS',
1835+
\ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
1836+
call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
1837+
1838+
" Error cases
1839+
call assert_fails('Xvimgrep /abc *', 'E682:')
1840+
1841+
let @/=''
1842+
call assert_fails('Xvimgrep // *', 'E35:')
1843+
1844+
call assert_fails('Xvimgrep abc', 'E683:')
1845+
call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
1846+
call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
1847+
1848+
Xexpr ""
1849+
Xvimgrepadd Notepad Xtestfile1
1850+
Xvimgrepadd MacOS Xtestfile2
1851+
let l = g:Xgetlist()
1852+
call assert_equal(2, len(l))
1853+
call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
1854+
1855+
Xvimgrep #\cvim#g Xtestfile?
1856+
let l = g:Xgetlist()
1857+
call assert_equal(2, len(l))
1858+
call assert_equal(8, l[0].col)
1859+
call assert_equal(12, l[1].col)
1860+
1861+
1Xvimgrep ?Editor? Xtestfile*
1862+
let l = g:Xgetlist()
1863+
call assert_equal(1, len(l))
1864+
call assert_equal('Editor:VIM vim', l[0].text)
1865+
1866+
edit +3 Xtestfile2
1867+
Xvimgrep +\cemacs+j Xtestfile1
1868+
let l = g:Xgetlist()
1869+
call assert_equal('Xtestfile2', bufname(''))
1870+
call assert_equal('Editor:Emacs EmAcS', l[0].text)
1871+
1872+
call delete('Xtestfile1')
1873+
call delete('Xtestfile2')
1874+
endfunc
1875+
1876+
" Tests for the :vimgrep command
1877+
func Test_vimgrep()
1878+
call XvimgrepTests('c')
1879+
call XvimgrepTests('l')
1880+
endfunc

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+
484,
767769
/**/
768770
483,
769771
/**/

0 commit comments

Comments
 (0)