Closed tmpm697 closed 1 year ago
If i remove pcall(vim.cmd, "SessionSave")
, it seems to work
but i.e: you had sesison of folder1 with two buffers buf1,buf2
then nvim
under folder1 will restore two buffers as expected, then you open buf3 and call :Telescope persisted
to switch to another session --> now session folder1 still only have two buffers --> show be 3.
My setup works
before and current idk from neovim or persisted, it stop working or become junky.
@tmpm697 can you use the minimal.lua
file in the initial bug report and share it so I can try and recreate it.
It's like searching for a needle in a haystack without it.
Will reopen when you can recreate with a minimal.lua
file
just tested with only two plugins telescope.nvim
and persisted.nvim
the issue still happnes, overlap/overwrite/mess up saved sessions.
prepare:
minimal init.lua:
-- other require() for mapping, options and autocmd
autocmd({ "User" }, {
pattern = "PersistedTelescopeLoadPre",
group = augroup,
callback = function()
vim.schedule(function()
pcall(vim.cmd, "silent %bd!")
end)
end,
})
-- require for telescope.nvim
require("persisted").setup({
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
silent = true, -- silent nvim message when sourcing session file
use_git_branch = false, -- create session files based on the branch of the git enabled repository
autosave = true, -- automatically save session files when exiting Neovim
autoload = true, -- automatically load the session for the cwd on Neovim startup
on_autoload_no_session = nil, -- function to run when `autoload = true` but there is no session to load
follow_cwd = true, -- change session file name to match current working directory if it changes
allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
ignored_dirs = { "/tmp" }, -- table of dirs that are ignored when auto-saving and auto-loading
should_autosave = nill
telescope = { -- options for the telescope extension
reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted
},
})
require("telescope").load_extension("persisted") -- To load the telescope extension
and default telescope.nvim
setup (if you also need it, please let me know)
steps:
both follow_cwd = true
or follow_cwd = false
give same result
expected: with above settings, switch session will clean up current buffers and restore switching session, switch back and forth does not messup saved sessions.
I did not observe this issue until recent refactor that introduce: https://github.com/olimorris/persisted.nvim#events--callbacks @olimorris
@olimorris can you re-open this?
This is my hook:
{
name = "PersistedHooks",
{
"User",
function(session)
require("persisted").save()
-- Delete all of the open buffers
vim.api.nvim_input("<ESC>:%bd!<CR>")
-- Don't start saving the session yet
require("persisted").stop()
end,
opts = { pattern = "PersistedTelescopeLoadPre" },
},
},
That seems to do everything you're asking. It's in a different format as I use the legendary.nvim
plugin
Thanks, I'll play around and give it a try.
yes, the only need to change to make this work is:
require("persisted").stop()
have no idea but if not this cause so much trouble for me. overlapping session make it unusable for a quit of time.
thanks.
but for example, when i switch to a session and start to open some buffers there like:
How to have buffers in step 3 in sessionB between switch?
should I open new issue?
You'll need to manually save the session before you switch. In your steps above I can't see where you're saving it
You'll need to manually save the session before you switch. In your steps above I can't see where you're saving it
can i autosave it when i switch session at step 4? manually save session is not ideal for me.
if yes, what should this can be changed to?
function(session)
require("persisted").save()
vim.api.nvim_input("<ESC>:%bd!<CR>")
require("persisted").stop()
end,
EDIT: afiak if autosave look for current cwd to save session, the target
session will be overwrite by current one --> this is the #1 issue
Autosave will only work when you exit Neovim.
But I've just pushed a commit through as you were right it won't actually save the correct session. If you try this:
function(session)
require("persisted").save({ session = session.data.file_path })
-- Delete all of the open buffers
vim.api.nvim_input("<ESC>:%bd!<CR>")
-- Don't start saving the session yet
require("persisted").stop()
end,
It should now work.
Does not work for me, use 06946ed
commit and
function(session)
require("persisted").save({ session = session.data.file_path })
-- Delete all of the open buffers
vim.api.nvim_input("<ESC>:%bd!<CR>")
-- Don't start saving the session yet
require("persisted").stop()
end,
clean up all sessions, switch from sessionB to sessionA will overwrite sessionA by sessionB.
Think I've solved it. If you update the plugin and try require("persisted").save({ session = vim.g.persisted_loaded_session })
After a session loads, the global variable gets updated with the path to that session allowing you to manually save it.
Think I've solved it. If you update the plugin and try
require("persisted").save({ session = vim.g.persisted_loaded_session })
After a session loads, the global variable gets updated with the path to that session allowing you to manually save it.
thank you!, this save me a ton, probably others.
Your Persisted.nvim config
return { "olimorris/persisted.nvim", lazy = false,
}
autocmd.lua
Error messages
No response
Describe the bug
Reproduce the bug
Expected here that when under folder1 or folder2, start nvim will restore session of each. when switch via telescope, all current buffers of current session will be tried to del if not having un-saved/modifed files and then switch cwd and restore the selecting session from telescope. Do not overwrite current session next session (currently it did)
NVIM v0.9.0-dev-1260+ga7b537c7 latest persisted.nvim
Final checks
minimal.lua
config file above and still get the issueSessionSave
to save the session before restarting Neovim and usingSessionLoad