commit b98eefd8030c398735f4069ddc05b3e5b7a511a5
parent 93925fe0208fcd640eb6c5f2822f994a427f3795
Author: glepnir <glephunter@gmail.com>
Date: Tue, 10 Jun 2025 21:50:16 +0800
fix(shada): prevent 'nobuflisted' buffers in v:oldfiles #34373
Problem: 'nobuflisted' buffers are incorrectly added to v:oldfiles.
Solution: Use ignore_buf() consistently in shada_write() for buffer
marks processing.
Diffstat:
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
@@ -2027,7 +2027,7 @@ static inline ShaDaWriteResult shada_read_when_writing(FileDescriptor *const sd_
static inline bool ignore_buf(const buf_T *const buf, Set(ptr_t) *const removable_bufs)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
{
- return (buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
+ return (buf == NULL || buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
|| bt_terminal(buf) || set_has(ptr_t, removable_bufs, (ptr_t)buf));
}
@@ -2489,8 +2489,7 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
fname = fm.fname;
} else {
const buf_T *const buf = buflist_findnr(fm.fmark.fnum);
- if (buf == NULL || buf->b_ffname == NULL
- || set_has(ptr_t, &removable_bufs, (ptr_t)buf)) {
+ if (ignore_buf(buf, &removable_bufs)) {
continue;
}
fname = buf->b_ffname;
@@ -2526,7 +2525,7 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
// Initialize buffers
if (num_marked_files > 0) {
FOR_ALL_BUFFERS(buf) {
- if (buf->b_ffname == NULL || set_has(ptr_t, &removable_bufs, buf)) {
+ if (ignore_buf(buf, &removable_bufs)) {
continue;
}
const void *local_marks_iter = NULL;
diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua
@@ -91,4 +91,18 @@ describe('shada support code', function()
eq('', fn.bufname(1))
eq(testfilename, fn.bufname(2))
end)
+
+ it("does not add 'nobuflisted' buffers to v:oldfiles", function()
+ reset("set shada='100")
+ nvim_command('edit ' .. testfilename)
+ nvim_command('setlocal nobuflisted')
+ nvim_command('edit ' .. testfilename_2)
+ nvim_command('setlocal buflisted')
+ nvim_command('write')
+ expect_exit(nvim_command, 'qall')
+ reset("set shada='100")
+ local oldfiles = api.nvim_get_vvar('oldfiles')
+ eq(1, #oldfiles)
+ t.matches(vim.pesc(testfilename_2), oldfiles[1])
+ end)
end)