]> granicus.if.org Git - vim/commitdiff
patch 8.2.1384: no ATTENTION prompt for :vimgrep first match file v8.2.1384
authorBram Moolenaar <Bram@vim.org>
Fri, 7 Aug 2020 16:12:18 +0000 (18:12 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 7 Aug 2020 16:12:18 +0000 (18:12 +0200)
Problem:    No ATTENTION prompt for :vimgrep first match file.
Solution:   When there is an existing swap file do not keep the dummy buffer.
            (closes #6649)

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

index 1901e3806df8f8eb24cd30fc1597ded5eb520836..99b0169ea5c39a028bbcd48066b3946b59520cad 100644 (file)
@@ -6015,6 +6015,23 @@ vgr_process_args(
     return OK;
 }
 
+/*
+ * Return TRUE if "buf" had an existing swap file, the current swap file does
+ * not end in ".swp".
+ */
+    static int
+existing_swapfile(buf_T *buf)
+{
+    if (buf->b_ml.ml_mfp != NULL)
+    {
+       char_u *fname = buf->b_ml.ml_mfp->mf_fname;
+       size_t len = STRLEN(fname);
+
+       return fname[len - 1] != 'p' || fname[len - 2] != 'w';
+    }
+    return FALSE;
+}
+
 /*
  * Search for a pattern in a list of files and populate the quickfix list with
  * the matches.
@@ -6125,7 +6142,8 @@ vgr_process_files(
                        buf = NULL;
                    }
                    else if (buf != *first_match_buf
-                                       || (cmd_args->flags & VGR_NOJUMP))
+                                       || (cmd_args->flags & VGR_NOJUMP)
+                                       || existing_swapfile(buf))
                    {
                        unload_dummy_buffer(buf, dirname_start);
                        // Keeping the buffer, remove the dummy flag.
index f3609f8514582f38fff1858f42752d83175c14b7..f431748e1e8dacdacbac121962bbb2a4d4ed8276 100644 (file)
@@ -91,6 +91,9 @@ set encoding=utf-8
 let s:test_script_fname = expand('%')
 au! SwapExists * call HandleSwapExists()
 func HandleSwapExists()
+  if exists('g:ignoreSwapExists')
+    return
+  endif
   " Ignore finding a swap file for the test script (the user might be
   " editing it and do ":make test_name") and the output file.
   " Report finding another swap file and chose 'q' to avoid getting stuck.
index 8ca55785d1e257a3425450bf75cf49a27bbb04a3..e71a3dfdec231744903e803d51e20b95d28a7629 100644 (file)
@@ -2837,6 +2837,26 @@ func Test_vimgrep_with_no_last_search_pat()
   call delete('Xresult')
 endfunc
 
+func Test_vimgrep_existing_swapfile()
+  call writefile(['match apple with apple'], 'Xapple')
+  call writefile(['swapfile'], '.Xapple.swp')
+  let g:foundSwap = 0
+  let g:ignoreSwapExists = 1
+  augroup grep
+    au SwapExists * let foundSwap = 1 | let v:swapchoice = 'e'
+  augroup END
+  vimgrep apple Xapple
+  call assert_equal(1, g:foundSwap)
+  call assert_match('.Xapple.swo', swapname(''))
+
+  call delete('Xapple')
+  call delete('Xapple.swp')
+  augroup grep
+    au! SwapExists
+  augroup END
+  unlet g:ignoreSwapExists
+endfunc
+
 func XfreeTests(cchar)
   call s:setup_commands(a:cchar)
 
index e6b8a893f1c7c292b7590c7d6bf1aa63be2ac588..98e408014bc49e11b310aca70517ae5a1cf3dc8e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1384,
 /**/
     1383,
 /**/