commit 71455173b482b9787340505151995da9e2b8f38f
parent c1d21492a66c8bc3cdb390b5f4cb24ad16516853
Author: Andre Toerien <andre.toerien8@gmail.com>
Date: Sat, 19 Apr 2025 14:47:44 +0200
feat(shada): don't store jumplist if '0 in 'shada'
Diffstat:
5 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
@@ -5187,8 +5187,8 @@ A jump table for the options with a short description can be found at |Q_op|.
' Maximum number of previously edited files for which the marks
are remembered. This parameter must always be included when
'shada' is non-empty.
- Including this item also means that the |jumplist| and the
- |changelist| are stored in the shada file.
+ If non-zero, then the |jumplist| and the |changelist| are also
+ stored in the shada file.
*shada-/*
/ Maximum number of items in the search pattern history to be
saved. If non-zero, then the previous search and substitute
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
@@ -5441,8 +5441,8 @@ vim.go.ssop = vim.go.sessionoptions
--- ' Maximum number of previously edited files for which the marks
--- are remembered. This parameter must always be included when
--- 'shada' is non-empty.
---- Including this item also means that the `jumplist` and the
---- `changelist` are stored in the shada file.
+--- If non-zero, then the `jumplist` and the `changelist` are also
+--- stored in the shada file.
--- *shada-/*
--- / Maximum number of items in the search pattern history to be
--- saved. If non-zero, then the previous search and substitute
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
@@ -7296,8 +7296,8 @@ local options = {
' Maximum number of previously edited files for which the marks
are remembered. This parameter must always be included when
'shada' is non-empty.
- Including this item also means that the |jumplist| and the
- |changelist| are stored in the shada file.
+ If non-zero, then the |jumplist| and the |changelist| are also
+ stored in the shada file.
*shada-/*
/ Maximum number of items in the search pattern history to be
saved. If non-zero, then the previous search and substitute
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
@@ -2396,8 +2396,10 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
} while (var_iter != NULL);
}
- // Initialize jump list
- wms->jumps_size = shada_init_jumps(wms->jumps, &removable_bufs);
+ if (num_marked_files > 0) { // Skip if '0 in 'shada'
+ // Initialize jump list
+ wms->jumps_size = shada_init_jumps(wms->jumps, &removable_bufs);
+ }
const bool search_highlighted = !(no_hlsearch
|| find_shada_parameter('h') != NULL);
diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua
@@ -152,6 +152,37 @@ describe('ShaDa support code', function()
eq(saved, exec_capture('jumps'))
end)
+ it("does not dump jumplist if `'0` in shada", function()
+ local empty_jumps = exec_capture('jumps')
+ nvim_command("set shada='0")
+ nvim_command('edit ' .. testfilename_2)
+ nvim_command('normal! G')
+ nvim_command('normal! gg')
+ nvim_command('edit ' .. testfilename)
+ nvim_command('normal! G')
+ nvim_command('normal! gg')
+ nvim_command('enew')
+ nvim_command('normal! gg')
+ expect_exit(nvim_command, 'qall')
+ reset()
+ eq(empty_jumps, exec_capture('jumps'))
+ end)
+
+ it("does read back jumplist even with `'0` in shada", function()
+ nvim_command('edit ' .. testfilename_2)
+ nvim_command('normal! G')
+ nvim_command('normal! gg')
+ nvim_command('edit ' .. testfilename)
+ nvim_command('normal! G')
+ nvim_command('normal! gg')
+ nvim_command('enew')
+ nvim_command('normal! gg')
+ local saved = exec_capture('jumps')
+ expect_exit(nvim_command, 'qall')
+ reset("set shada='0")
+ eq(saved, exec_capture('jumps'))
+ end)
+
it('when dumping jump list also dumps current position', function()
nvim_command('edit ' .. testfilename)
nvim_command('normal! G')