Comments (15)
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
from persisted.nvim.
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.
from persisted.nvim.
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.
from persisted.nvim.
@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.
from persisted.nvim.
Will reopen when you can recreate with a minimal.lua
file
from persisted.nvim.
just tested with only two plugins telescope.nvim
and persisted.nvim
the issue still happnes, overlap/overwrite/mess up saved sessions.
prepare:
- clone persisted.nvim/, plenary.nvim/, telescope.nvim/ to ~/.local/share/nvim/site/pack/default/start
- vi init.lua
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:
- cd to folderA (can have path like /path/to/folderA) and open some files via :e filenames
- quit (:wq) to trigger auto save --> new session created and saved to ~/.local/share/nvim/sessions/
- cd to folderB and open some files
- quit to trigger auto save
- exit nvim
- cd to folderA
- switch to folderB using telescope
- quit to trigger auto save ---> Now saved session file from folderB will overwrite saved session file from folderA, switch between session A and B now only see session B
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
from persisted.nvim.
@olimorris can you re-open this?
from persisted.nvim.
Thanks, I'll play around and give it a try.
from persisted.nvim.
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.
from persisted.nvim.
but for example, when i switch to a session and start to open some buffers there like:
- at folderA (sessionA)
- switch to folderB (sessionB)
- start to open some buffers in this sessionB
- switch to folderC (sessionC)
- now switch back to folderB (sessionB) ---> opened buffers at step 3 did not registered to sessionB (they're not saved to sessionB)
How to have buffers in step 3 in sessionB between switch?
should I open new issue?
from persisted.nvim.
You'll need to manually save the session before you switch. In your steps above I can't see where you're saving it
from persisted.nvim.
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
from persisted.nvim.
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.
from persisted.nvim.
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.
from persisted.nvim.
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.
from persisted.nvim.
Related Issues (20)
- [Bug]: Getting "Could not find a session for" error on any new git repo or branch I open HOT 3
- [Bug]: Autoload not working HOT 3
- [Bug]: SessionLoad crashes HOT 12
- [Bug]: no-neck-pain.nvim `disable` doesn't work in `SavePre` hook HOT 9
- [Feature] Allow loading a session by name HOT 4
- Replace callbacks with user events HOT 30
- Startup time increased dramatically HOT 3
- [Bug] The cmdheight reset to 1 after SessionLoad HOT 12
- [Bug]: Unable to turn off autosaving HOT 6
- `string.gsub(session, save_dir, "")` will fail if special characters are not escaped HOT 3
- [Bug]: sessions dir is empty and nothing opened when :SessionLoad HOT 3
- `autosave` should not fires when opening single file in any directory HOT 3
- [Bug]: SessionSave / SessionLoad not working HOT 8
- [Bug]: Handle interaction with lazy.nvim HOT 1
- [Bug]: howto pin a buffer through sessions switching? HOT 1
- [Bug]: uv_close: Assertion `!uv__is_closing(handle' failed HOT 10
- [Bug]: Telescope extension doesn't work after neovim update HOT 4
- [Bug]: Autosave Not Triggered Without Existing Session File HOT 8
- [Bug]: Still running git commands when `use_git_branch=false` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from persisted.nvim.