natecraddock / sessions.nvim Goto Github PK
View Code? Open in Web Editor NEWa simple session manager plugin
License: MIT License
a simple session manager plugin
License: MIT License
Hi! I hope you are all doing well!
I no longer use Neovim regularly, but I really would like to keep this plugin alive. It's been really simple to maintain, but I worry about the long-term.
So I'm looking for someone willing to step in and maintain this plugin. Either
I think the second is the simplest, and no one has to update their configs to point to a new repository.
If no one steps up, I will try my best to make sure this works for as long as possible. But I won't make any promises. If a future Neovim release would cause an unreasonable amount of work for me to update this plugin, I probably wouldn't update it.
Sorry if that's sad news for anyone, and I apologize if this breaks someone's workflow someday. I don't think this plugin will stop working anytime soon, but if it does... ๐ฌ
Hello @natecraddock, I know you said you don't use neovim anymore but I have a few questions and I was hoping you could please help me.
I'm using workspaces.nvim and sessions.nvim to manage my projects in neovim. So far I've had no real issues until today. This is what I'm using as a trigger to save the session.
require("sessions").setup({
events = { "BufEnter" },
session_filepath = vim.fn.stdpath("data") .. "/sessions",
absolute = true
})
This works most of the time but is not the best solution. I want to save the session when a new buffer is added and when a buffer is deleted. So far I can save the session when adding buffers without any issues. The problem is when deleting the buffers, there is no actual way in neovim to know if a buffer has been deleted with an autocmd event.
This is where https://github.com/famiu/bufdelete.nvim comes in handy. It has an autocmd User event called BDeletePre and BDeletePost.
User autocommands
bufdelete.nvim triggers the following User autocommands (see :help User for more information):
BDeletePre {range_start,range_end} - Prior to deleting a buffer.
BDeletePost {range_start,range_end} - After deleting a buffer.
In both of these cases, range_start and range_end are replaced by the start and end of the buffer range, respectively.
For example, if you use require('bufdelete').bufdelete({1, 42}), the autocommand patterns will be BDeletePre {1,42} and BDeletePost {1,42}.
Now, if I add the "User" event like this:
require("sessions").setup({
events = { "BufEnter", "User" },
session_filepath = vim.fn.stdpath("data") .. "/sessions",
absolute = true
})
That won't work.
If I add this code to sessions.nvim/lua/sessions/init.lua
then it does work:
-- start autosaving changes to the session file
local start_autosave = function()
-- save future changes
local events = vim.fn.join(config.events, ",")
local augroup = vim.api.nvim_create_augroup("sessions.nvim", {})
vim.api.nvim_create_autocmd(
string.format("%s", events),
{
group = augroup,
pattern = "*",
callback = write_session_file,
}
)
vim.api.nvim_create_autocmd(
string.format("%s", "User"),
{
group = augroup,
pattern = "*",
callback = write_session_file,
}
)
-- save now
write_session_file()
end
Do you know what I need to do to make it work without editing the plugin's source code? I'm a total noob when it comes to plugins or autocmds so any help is really appreciated. Thank you.
P.S. I loved your work on blender's outliner BTW ;)
A quick rationale coming straight from my current session config. I want any new directory I open to automatically register as a session. At the moment it requires doing a manual save if a load fails:
vim.api.nvim_create_autocmd('VimEnter', {
callback = function (data)
local is_directory = vim.fn.isdirectory(data.file) == 1
if not is_directory then
return
end
vim.cmd.cd(data.file)
local sessions_api = require('sessions')
local session_found = sessions_api.load(nil, { silent = true })
-- currently this is the way to start a new session if none was detected
if not session_found then
sessions_api.save()
end
-- other code omitted
end,
})
If the sessions.start_autosave
function was public (after a small refactoring to separate off writing session files), it would be slightly more convenient bc the user can delay the first save to an actual event like WinEnter
.
On the other hand this might feel nitpicky, and I don't want to introduce new API if it feels unnecessary.
Hi @natecraddock,
Thanks for creating this plugin. I'm happily using it in conjunction with workspaces and but noticed that the session file is always stored relative to the current cwd. I'd rather not pollute my workspace with neovim session information. It's not something I will commit nor will it be of interested to my fellow colleagues.
Is there a way to have sessions stored the same way as workspaces? Meaning that the 'data' + $SOMEDIR directory will be used to write session files, with filenames that match the current cwd?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.