]> granicus.if.org Git - vim/commitdiff
patch 7.4.2050 v7.4.2050
authorBram Moolenaar <Bram@vim.org>
Sat, 16 Jul 2016 16:24:56 +0000 (18:24 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 16 Jul 2016 16:24:56 +0000 (18:24 +0200)
Problem:    When using ":vimgrep" may end up with duplicate buffers.
Solution:   When adding an error list entry pass the buffer number if possible.

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

index 1fb47a00982b513813bda894c00b7370f9f6a63d..1145896e1ee99e8ead310bb0963c60b15a6fed60 100644 (file)
@@ -1581,7 +1581,7 @@ static char_u *qf_last_bufname = NULL;
 static bufref_T  qf_last_bufref = {NULL, 0};
 
 /*
- * Get buffer number for file "dir.name".
+ * Get buffer number for file "directory.fname".
  * Also sets the b_has_qf_entry flag.
  */
     static int
@@ -4109,11 +4109,13 @@ ex_vimgrep(exarg_T *eap)
                while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
                                                               col, NULL) > 0)
                {
-                   ;
+                   /* Pass the buffer number so that it gets used even for a
+                    * dummy buffer, unless duplicate_name is set, then the
+                    * buffer will be wiped out below. */
                    if (qf_add_entry(qi,
                                NULL,       /* dir */
                                fname,
-                               0,
+                               duplicate_name ? 0 : buf->b_fnum,
                                ml_get_buf(buf,
                                     regmatch.startpos[0].lnum + lnum, FALSE),
                                regmatch.startpos[0].lnum + lnum,
@@ -4177,12 +4179,17 @@ ex_vimgrep(exarg_T *eap)
                    else if (buf != first_match_buf || (flags & VGR_NOJUMP))
                    {
                        unload_dummy_buffer(buf, dirname_start);
+                       /* Keeping the buffer, remove the dummy flag. */
+                       buf->b_flags &= ~BF_DUMMY;
                        buf = NULL;
                    }
                }
 
                if (buf != NULL)
                {
+                   /* Keeping the buffer, remove the dummy flag. */
+                   buf->b_flags &= ~BF_DUMMY;
+
                    /* If the buffer is still loaded we need to use the
                     * directory we jumped to below. */
                    if (buf == first_match_buf
index 9fbef15f8f688e588c85dc4856572e362aa68b02..a4f8b35957e90fb6b58c43ec172d823dda19f3b6 100644 (file)
@@ -1462,3 +1462,18 @@ func Test_history()
   call HistoryTest('c')
   call HistoryTest('l')
 endfunc
+
+func Test_duplicate_buf()
+  " make sure we can get the highest buffer number
+  edit DoesNotExist
+  edit DoesNotExist2
+  let last_buffer = bufnr("$")
+
+  " make sure only one buffer is created
+  call writefile(['this one', 'that one'], 'Xgrepthis')
+  vimgrep one Xgrepthis
+  vimgrep one Xgrepthis
+  call assert_equal(last_buffer + 1, bufnr("$"))
+
+  call delete('Xgrepthis')
+endfunc
index f0df8480662829bc466a0d1230a83899d8b73cbb..f4d90907f092969e2825455b50d286968f8e62e8 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2050,
 /**/
     2049,
 /**/