Merge pull request #3724 from ZyX-I/fix-3635

shada: Do not save unlisted and quickfix buffers
This commit is contained in:
Justin M. Keyes 2015-11-27 18:06:52 -05:00
commit b9139e009f
3 changed files with 51 additions and 7 deletions

View File

@ -5303,9 +5303,9 @@ A jump table for the options with a short description can be found at |Q_op|.
% When included, save and restore the buffer list. If Vim is % When included, save and restore the buffer list. If Vim is
started with a file name argument, the buffer list is not started with a file name argument, the buffer list is not
restored. If Vim is started without a file name argument, the restored. If Vim is started without a file name argument, the
buffer list is restored from the shada file. Buffers buffer list is restored from the shada file. Quickfix
without a file name and buffers for help files are not written ('buftype'), unlisted ('buflisted'), unnamed and buffers on
to the shada file. removable media (|shada-r|) are not saved.
When followed by a number, the number specifies the maximum When followed by a number, the number specifies the maximum
number of buffers that are stored. Without a number all number of buffers that are stored. Without a number all
buffers are stored. buffers are stored.

View File

@ -43,6 +43,7 @@
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/quickfix.h"
#include "nvim/lib/khash.h" #include "nvim/lib/khash.h"
#include "nvim/lib/kvec.h" #include "nvim/lib/kvec.h"
@ -2484,8 +2485,11 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
// Write buffer list // Write buffer list
if (find_shada_parameter('%') != NULL) { if (find_shada_parameter('%') != NULL) {
size_t buf_count = 0; size_t buf_count = 0;
#define IGNORE_BUF(buf)\
(buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
|| in_bufset(&removable_bufs, buf))
FOR_ALL_BUFFERS(buf) { FOR_ALL_BUFFERS(buf) {
if (buf->b_ffname != NULL && !in_bufset(&removable_bufs, buf)) { if (!IGNORE_BUF(buf)) {
buf_count++; buf_count++;
} }
} }
@ -2503,7 +2507,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
}; };
size_t i = 0; size_t i = 0;
FOR_ALL_BUFFERS(buf) { FOR_ALL_BUFFERS(buf) {
if (buf->b_ffname == NULL || in_bufset(&removable_bufs, buf)) { if (IGNORE_BUF(buf)) {
continue; continue;
} }
buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) { buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) {
@ -2519,6 +2523,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
goto shada_write_exit; goto shada_write_exit;
} }
xfree(buflist_entry.data.buffer_list.buffers); xfree(buflist_entry.data.buffer_list.buffers);
#undef IGNORE_BUF
} }
// Write some of the variables // Write some of the variables

View File

@ -1,7 +1,7 @@
-- ShaDa buffer list saving/reading support -- ShaDa buffer list saving/reading support
local helpers = require('test.functional.helpers') local helpers = require('test.functional.helpers')
local nvim_command, funcs, eq = local nvim_command, funcs, eq, curbufmeths =
helpers.command, helpers.funcs, helpers.eq helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths
local shada_helpers = require('test.functional.shada.helpers') local shada_helpers = require('test.functional.shada.helpers')
local reset, set_additional_cmd, clear = local reset, set_additional_cmd, clear =
@ -48,4 +48,43 @@ describe('ShaDa support code', function()
eq(1, funcs.bufnr('$')) eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1)) eq('', funcs.bufname(1))
end) end)
it('does not dump unlisted buffer', function()
set_additional_cmd('set shada+=%')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buflisted', false)
nvim_command('qall')
reset()
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
end)
it('does not dump quickfix buffer', function()
set_additional_cmd('set shada+=%')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buftype', 'quickfix')
nvim_command('qall')
reset()
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
end)
it('does not dump unnamed buffers', function()
set_additional_cmd('set shada+=% hidden')
reset()
curbufmeths.set_line(0, 'foo')
nvim_command('enew')
curbufmeths.set_line(0, 'bar')
eq(2, funcs.bufnr('$'))
nvim_command('qall!')
reset()
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
end)
end) end)