To: vim_dev@googlegroups.com Subject: Patch 7.4.2050 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2050 Problem: When using ":vimgrep" may end up with duplicate buffers. Solution: When adding an error list entry pass the buffer number if possible. Files: src/quickfix.c, src/testdir/test_quickfix.vim *** ../vim-7.4.2049/src/quickfix.c 2016-07-16 16:54:18.330699629 +0200 --- src/quickfix.c 2016-07-16 18:24:29.268513435 +0200 *************** *** 1581,1587 **** static bufref_T qf_last_bufref = {NULL, 0}; /* ! * Get buffer number for file "dir.name". * Also sets the b_has_qf_entry flag. */ static int --- 1581,1587 ---- static bufref_T qf_last_bufref = {NULL, 0}; /* ! * Get buffer number for file "directory.fname". * Also sets the b_has_qf_entry flag. */ static int *************** *** 4109,4119 **** while (vim_regexec_multi(®match, curwin, buf, lnum, col, NULL) > 0) { ! ; if (qf_add_entry(qi, NULL, /* dir */ fname, ! 0, ml_get_buf(buf, regmatch.startpos[0].lnum + lnum, FALSE), regmatch.startpos[0].lnum + lnum, --- 4109,4121 ---- while (vim_regexec_multi(®match, 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, ! duplicate_name ? 0 : buf->b_fnum, ml_get_buf(buf, regmatch.startpos[0].lnum + lnum, FALSE), regmatch.startpos[0].lnum + lnum, *************** *** 4177,4188 **** --- 4179,4195 ---- 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 *** ../vim-7.4.2049/src/testdir/test_quickfix.vim 2016-07-16 16:54:18.338699549 +0200 --- src/testdir/test_quickfix.vim 2016-07-16 18:05:01.376283846 +0200 *************** *** 1462,1464 **** --- 1462,1479 ---- 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 *** ../vim-7.4.2049/src/version.c 2016-07-16 16:54:18.338699549 +0200 --- src/version.c 2016-07-16 17:36:56.217175177 +0200 *************** *** 760,761 **** --- 760,763 ---- { /* Add new patch number below this line */ + /**/ + 2050, /**/ -- You were lucky. We lived for three months in a brown paper bag in a septic tank. We used to have to get up at six o'clock in the morning, clean the bag, eat a crust of stale bread, go to work down mill for fourteen hours a day week in-week out. When we got home, our Dad would thrash us to sleep with his belt! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///