shada: Respect the optional buffer count for shada-%

Closes #5759
This commit is contained in:
James McCoy
2016-12-12 14:34:18 -05:00
parent 988ab5804a
commit 7eb91c781b
2 changed files with 17 additions and 1 deletions

View File

@@ -2424,12 +2424,13 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
// Write buffer list
if (find_shada_parameter('%') != NULL) {
int max_bufs = get_shada_parameter('%');
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) {
if (!IGNORE_BUF(buf)) {
if (!IGNORE_BUF(buf) && (max_bufs < 0 || buf_count < (size_t)max_bufs)) {
buf_count++;
}
}
@@ -2450,6 +2451,9 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
if (IGNORE_BUF(buf)) {
continue;
}
if (i >= buf_count) {
break;
}
buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) {
.pos = buf->b_last_cursor.mark,
.fname = (char *) buf->b_ffname,

View File

@@ -89,4 +89,16 @@ describe('ShaDa support code', function()
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
end)
it('restores 1 buffer with %1 in &shada, #5759', function()
set_additional_cmd('set shada+=%1')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
reset()
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
end)
end)