Closed Subjective closed 1 year ago
So there's two situations at work here
For 1, this is actually intentional and, I believe, the least confusing way to behave. In a perfect world, if I save a session and open it again, I expect Neovim to look the exact same as when I left. This means that we need to restore all windows. If there's a scratch buffer in one of those windows, then we have to restore it with something there, and I think that a new scratch buffer is less confusing that just picking a random buffer to fill it. Think also about tabs. If you open up a new tab (empty, with a scratch buffer) then save and restore the session, what should happen to that tab? Again I think the least confusing behavior is to recreate that tab with a new scratch buffer.
For 2, this is an interesting case. I don't expect this to be a common scenario, so this is something that would make sense as an addition to your own config. You can set the buf_filter
to ignore files that are not saved to disk. Probably something like this:
require("resession").setup({
buf_filter = function(bufnr)
local bufname = vim.api.nvim_buf_get_name(bufnr)
if vim.bo[bufnr].buftype == "" and bufname ~= "" then
if vim.fn.filereadable(bufname) == 0 then
return false
end
end
return require("resession").buf_filter(bufnr)
end
})
Thanks for the snippet in 2 :)
Regarding 1), I agree that it makes sense for everything to be restored to how it was previously (though it would be nice to have the option just restore the last active "real buffer"). My only qualm is that it doesn't work the same way it does with native :mksession
:
What I expect to happen:
The current behavior:
In any case, this a pretty minor nitpick - please don't feel obligated to make any changes, I just wanted to share my thoughts on this matter. Thanks for all the great plugins you've made!
Did you check the docs and existing issues?
Neovim version (nvim -v)
NVIM v0.10.0-dev-713+gf2ce31d3d
Operating system/version
MacOS 13.4
Describe the bug
When saving a session while in a "[No Name]" buffer, loading it up opens a scratch buffer. This doesn't happen when "[No Name]" buffer is opened but not in the active window when saving. Additionally, saving a session with named buffers (e.g.
:e testfile.txt)
that have not yet been written to a file recreates empty buffers with those names when loading the session.Steps To Reproduce
:enew
<leader>s
to save session while in the "[No Name]" buffer<leader>l
to load the saved sessionExpected Behavior
I would expect the session to load without a scratch buffer when a session is saved on a "[No Name]" buffer. And to not load named but unwritten buffers, or at least have the option of ignoring them when saving the session. Thanks for your time!
Directory structure
No response
Repro
Did you check the bug with a clean config?
nvim -u repro.lua
using the repro.lua file above.