Closed idr4n closed 5 months ago
@idr4n The pre_save
function you described is a valid solution, which would look like this:
local function pre_save()
-- remove buffers whose files are located outside of cwd
local cwd = vim.fn.getcwd() .. '/'
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
local bufpath = vim.api.nvim_buf_get_name(buf) .. '/'
if not bufpath:match('^' .. vim.pesc(cwd)) then
vim.api.nvim_buf_delete(buf, {})
end
end
end
require('persistence').setup{
pre_save = pre_save,
}
Thanks @koonix. I'm closing this issue based on your solution.
Did you check the docs?
Is your feature request related to a problem? Please describe.
Yes, kind of. Buffers with files that are not part of the
cwd
seem to be persistent even after closing them.Describe the solution you'd like
At the moment (using LazyVim distro) buffers with files that are not part of the
cwd
are saved in the session. Furthermore, those buffers seem to be persistent, that is, even if I close them, quit neovim, reopen and restore the session, they show up again.Describe alternatives you've considered
I have consider implementing a function to pass to
pre_save
that close/delete the buffers with file paths that are no children of thecwd
. Would this be the approach to go with here?Thanks in advance!
Additional context
This is a session which
cwd
is~/.config/nvim
:As you can see, there is
~/.prettierrc.json
that was saved and it is not part of thecwd
.