]> granicus.if.org Git - vim/commitdiff
patch 8.1.2220: :cfile does not abort like other quickfix commands v8.1.2220
authorBram Moolenaar <Bram@vim.org>
Sat, 26 Oct 2019 14:48:44 +0000 (16:48 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Oct 2019 14:48:44 +0000 (16:48 +0200)
Problem:    :cfile does not abort like other quickfix commands.
Solution:   Abort when desired. Add tests for aborting. (Yegappan Lakshmanan,
            closes #5121)

src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index 067dbffd08c7b30a88d60986472f81d8acd2dde0..7b64f45640e89c41a108394b328afdbafcc58891 100644 (file)
@@ -5509,8 +5509,14 @@ ex_cfile(exarg_T *eap)
     int                res;
 
     au_name = cfile_get_auname(eap->cmdidx);
-    if (au_name != NULL)
-       apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf);
+    if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
+                                                       NULL, FALSE, curbuf))
+    {
+#ifdef FEAT_EVAL
+       if (aborting())
+           return;
+#endif
+    }
 
     enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc;
 #ifdef FEAT_BROWSE
index 84cdb6c916aea747cbe357d0623f0f61b52a2e29..f3f391cf658771c6cafd2afb4150aa10971a3c8e 100644 (file)
@@ -2701,7 +2701,7 @@ func Test_file_from_copen()
   cclose
 
   augroup! QF_Test
-endfunction
+endfunc
 
 func Test_resize_from_copen()
     augroup QF_Test
@@ -4304,3 +4304,93 @@ func Test_quickfix_count()
     call assert_fails('$' .. cmd, 'E16:')
   endfor
 endfunc
+
+" Test for aborting quickfix commands using QuickFixCmdPre
+func Xtest_qfcmd_abort(cchar)
+  call s:setup_commands(a:cchar)
+
+  call g:Xsetlist([], 'f')
+
+  " cexpr/lexpr
+  let e = ''
+  try
+    Xexpr ["F1:10:Line10", "F2:20:Line20"]
+  catch /.*/
+    let e = v:exception
+  endtry
+  call assert_equal('AbortCmd', e)
+  call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+
+  " cfile/lfile
+  call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
+  let e = ''
+  try
+    Xfile Xfile1
+  catch /.*/
+    let e = v:exception
+  endtry
+  call assert_equal('AbortCmd', e)
+  call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+  call delete('Xfile1')
+
+  " cgetbuffer/lgetbuffer
+  enew!
+  call append(0, ["F1:10:Line10", "F2:20:Line20"])
+  let e = ''
+  try
+    Xgetbuffer
+  catch /.*/
+    let e = v:exception
+  endtry
+  call assert_equal('AbortCmd', e)
+  call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+  enew!
+
+  " vimgrep/lvimgrep
+  let e = ''
+  try
+    Xvimgrep /func/ test_quickfix.vim
+  catch /.*/
+    let e = v:exception
+  endtry
+  call assert_equal('AbortCmd', e)
+  call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+
+  " helpgrep/lhelpgrep
+  let e = ''
+  try
+    Xhelpgrep quickfix
+  catch /.*/
+    let e = v:exception
+  endtry
+  call assert_equal('AbortCmd', e)
+  call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+
+  " grep/lgrep
+  if has('unix')
+    let e = ''
+    try
+      silent Xgrep func test_quickfix.vim
+    catch /.*/
+      let e = v:exception
+    endtry
+    call assert_equal('AbortCmd', e)
+    call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+  endif
+endfunc
+
+func Test_qfcmd_abort()
+  augroup QF_Test
+    au!
+    autocmd  QuickFixCmdPre * throw "AbortCmd"
+  augroup END
+
+  call Xtest_qfcmd_abort('c')
+  call Xtest_qfcmd_abort('l')
+
+  augroup QF_Test
+    au!
+  augroup END
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 345fc7ae0938140cde6b35bed60b379d6b0dfd09..e348c32bf638aa2e69944557e97911d8d2399753 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2220,
 /**/
     2219,
 /**/