Skip to content

Commit 6a0cc91

Browse files
committed
patch 8.1.2220: :cfile does not abort like other quickfix commands
Problem: :cfile does not abort like other quickfix commands. Solution: Abort when desired. Add tests for aborting. (Yegappan Lakshmanan, closes #5121)
1 parent 28ed4df commit 6a0cc91

3 files changed

Lines changed: 101 additions & 3 deletions

File tree

src/quickfix.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5509,8 +5509,14 @@ ex_cfile(exarg_T *eap)
55095509
int res;
55105510

55115511
au_name = cfile_get_auname(eap->cmdidx);
5512-
if (au_name != NULL)
5513-
apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf);
5512+
if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
5513+
NULL, FALSE, curbuf))
5514+
{
5515+
#ifdef FEAT_EVAL
5516+
if (aborting())
5517+
return;
5518+
#endif
5519+
}
55145520

55155521
enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc;
55165522
#ifdef FEAT_BROWSE

src/testdir/test_quickfix.vim

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,7 @@ func Test_file_from_copen()
27012701
cclose
27022702

27032703
augroup! QF_Test
2704-
endfunction
2704+
endfunc
27052705

27062706
func Test_resize_from_copen()
27072707
augroup QF_Test
@@ -4304,3 +4304,93 @@ func Test_quickfix_count()
43044304
call assert_fails('$' .. cmd, 'E16:')
43054305
endfor
43064306
endfunc
4307+
4308+
" Test for aborting quickfix commands using QuickFixCmdPre
4309+
func Xtest_qfcmd_abort(cchar)
4310+
call s:setup_commands(a:cchar)
4311+
4312+
call g:Xsetlist([], 'f')
4313+
4314+
" cexpr/lexpr
4315+
let e = ''
4316+
try
4317+
Xexpr ["F1:10:Line10", "F2:20:Line20"]
4318+
catch /.*/
4319+
let e = v:exception
4320+
endtry
4321+
call assert_equal('AbortCmd', e)
4322+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4323+
4324+
" cfile/lfile
4325+
call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
4326+
let e = ''
4327+
try
4328+
Xfile Xfile1
4329+
catch /.*/
4330+
let e = v:exception
4331+
endtry
4332+
call assert_equal('AbortCmd', e)
4333+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4334+
call delete('Xfile1')
4335+
4336+
" cgetbuffer/lgetbuffer
4337+
enew!
4338+
call append(0, ["F1:10:Line10", "F2:20:Line20"])
4339+
let e = ''
4340+
try
4341+
Xgetbuffer
4342+
catch /.*/
4343+
let e = v:exception
4344+
endtry
4345+
call assert_equal('AbortCmd', e)
4346+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4347+
enew!
4348+
4349+
" vimgrep/lvimgrep
4350+
let e = ''
4351+
try
4352+
Xvimgrep /func/ test_quickfix.vim
4353+
catch /.*/
4354+
let e = v:exception
4355+
endtry
4356+
call assert_equal('AbortCmd', e)
4357+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4358+
4359+
" helpgrep/lhelpgrep
4360+
let e = ''
4361+
try
4362+
Xhelpgrep quickfix
4363+
catch /.*/
4364+
let e = v:exception
4365+
endtry
4366+
call assert_equal('AbortCmd', e)
4367+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4368+
4369+
" grep/lgrep
4370+
if has('unix')
4371+
let e = ''
4372+
try
4373+
silent Xgrep func test_quickfix.vim
4374+
catch /.*/
4375+
let e = v:exception
4376+
endtry
4377+
call assert_equal('AbortCmd', e)
4378+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4379+
endif
4380+
endfunc
4381+
4382+
func Test_qfcmd_abort()
4383+
augroup QF_Test
4384+
au!
4385+
autocmd QuickFixCmdPre * throw "AbortCmd"
4386+
augroup END
4387+
4388+
call Xtest_qfcmd_abort('c')
4389+
call Xtest_qfcmd_abort('l')
4390+
4391+
augroup QF_Test
4392+
au!
4393+
augroup END
4394+
endfunc
4395+
4396+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2220,
744746
/**/
745747
2219,
746748
/**/

0 commit comments

Comments
 (0)