-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Auto save manually named sessions #386
Comments
Thanks for filling the new issue! Just to make sure we're on the same page, I don't think it would hard to add the ability for manually named sessions to be autosaved on exit (but there isn't currently a way to autoload them on start). That would look like this:
Would that work for your workflow? |
I should be the one thanking you for taking the time to consider this feature.
Exactly. Ff named sessions would be be auto-updated, would that allow loading/reading single separate files e.g., shell profiles, separate singular config files, etc.? |
Ok, I think I have it working the way I described above. If you want to test it, you can temporary change the top of your -- 'rmagatti/auto-session',
'cameronr/auto-session', After changing the config, you'll have to open Lazy (or whatever plugin manager you use) and update the plugin to actually pull it down (and restart nvim just to be sure).
I'm not quite sure what that means. You could have a manually named session for whatever file(s) you wanted to. The only issue is you'll have to manually load them since they're not named after the cwd. But once loaded, they should update when you exit (if you use my fork above). I'm curious, though, why you'd want a session for a single file? |
I did test out yesterday, and noticed flakey behavior that i've been trying to reproduce.
The ideal workflow for me would be having a mix of CWD and named sessions for entire projects/dir that I explicitly |
Hmm, When you say you have "multiple named sessions opened", do you mean in multiple instances of nvim or something else? I really want to make sure I understand your use case. When you run Is it possible for you to describe your desired setup with actual examples, maybe with this template: Session #n
For example: Session 1:
Session 2:
|
Having multiple nvim instances, yes. {
-- 'rmagatti/auto-session',
'cameronr/auto-session',
lazy = false,
---enables autocomplete for opts
---@module "auto-session"
---@type AutoSession.Config
opts = {
enabled = true, -- Enables/disables auto creating, saving and restoring
root_dir = vim.fn.stdpath "data" .. "/sessions/", -- Root dir where sessions will be stored
auto_save = true, -- Enables/disables auto saving session on exit
auto_restore = false, -- Enables/disables auto restoring session on start
auto_create = false, -- Enables/disables auto creating new session files. Can take a function that should return true/false if a new session file should be created or not
suppressed_dirs = nil, -- Suppress session restore/create in certain directories
-- suppressed_dirs = { '~/', '~/Projects', '~/Downloads', '/' },
allowed_dirs = nil, -- Allow session restore/create in certain directories
auto_restore_last_session = false, -- On startup, loads the last saved session if session for cwd does not exist
use_git_branch = false, -- Include git branch name in session name
lazy_support = true, -- Automatically detect if Lazy.nvim is being used and wait until Lazy is done to make sure session is restored correctly. Does nothing if Lazy isn't being used. Can be disabled if a problem is suspected or for debugging
bypass_save_filetypes = { 'alpha', 'dashboard' }, -- -- List of file types to bypass auto save when the only buffer open is one of the file types listed, useful to ignore dashboards (or whatever dashboard you use)
close_unsupported_windows = true, -- Close windows that aren't backed by normal file before autosaving a session
args_allow_single_directory = true, -- Follow normal sesion save/load logic if launched with a single directory as the only argument
args_allow_files_auto_save = false, -- Allow saving a session even when launched with a file argument (or multiple files/dirs). It does not load any existing session first. While you can just set this to true, you probably want to set it to a function that decides when to save a session when launched with file args. See documentation for more detail
continue_restore_on_error = false, -- Keep loading the session even if there's an error
cwd_change_handling = true, -- Follow cwd changes, saving a session before change and restoring after
log_level = "info", -- Sets the log level of the plugin (debug, info, warn, error).
session_lens = {
load_on_setup = true, -- Initialize on startup (requires Telescope)
theme_conf = { -- Pass through for Telescope theme options
-- layout_config = { -- As one example, can change width/height of picker
-- width = 0.8, -- percent of window
-- height = 0.5,
-- },
},
previewer = false, -- File preview for session picker
mappings = {
-- Mode can be a string or a table, e.g. {"i", "n"} for both insert and normal mode
delete_session = { "i", "<C-D>" },
alternate_session = { "i", "<C-S>" },
copy_session = { "i", "<C-Y>" },
},
session_control = {
control_dir = vim.fn.stdpath "data" .. "/auto_session/", -- Auto session control dir, for control files, like alternating between two sessions with session-lens
control_filename = "session_control.json", -- File name of the session control file
},
},
}
-- log_level = 'debug',
},
Session 1
Session 2
Mind you that individual files would be loaded automatically without even having designated session names for them in |
Thanks for the detailed response! I'll break my response into sections:
While it's not necessary, you don't have to include the default values in your config so you could trim your config to: auto_restore = false, -- Enables/disables auto restoring session on start
auto_create = false, -- Enables/disables auto creating new session files. Can take a function that should return true/false if a new session file should be created or not
bypass_save_filetypes = { 'alpha', 'dashboard' }, -- -- List of file types to bypass auto save when the only buffer open is one of the file types listed, useful to ignore dashboards (or whatever dashboard you use)
continue_restore_on_error = false, -- Keep loading the session even if there's an error
cwd_change_handling = true, -- Follow cwd changes, saving a session before change and restoring after
log_level = "info", -- Sets the log level of the plugin (debug, info, warn, error). Also, I'm curious why you have
-- from: https://www.reddit.com/r/neovim/comments/1abd2cq/what_are_your_favorite_tricks_using_neovim/
vim.api.nvim_create_autocmd('BufReadPost', {
desc = 'Open file at the last position it was edited earlier',
command = 'silent! normal! g`"zv',
}) Beyond remembering your cursor position, is there other data you're trying to restore with single file sessions? |
I usually copy-paste the default config explicitly, just in case I ever wanted to fiddle with it later on.
I've just keep toggling different options on/off thinking it could be the reason why this odd behavior.
unfortunately It's still not working for me. I've tried to lazy load auto-session as the singly plugin, and still to no avail. I've tried a minimal session with only two tabs, and still without much like. I know that's now quite informative, but i really don't know what's wrong
Thank you. It works just fine. I initially thought that was the responsibility of the session manager |
Ok, I think we're making progress. So I think the only issue now is that named sessions aren't saving your changes on exit? Is that right? Can you describe in as much detail as possible what's not working? You don't have to worry about why it's not working (that's my job :) ), I just need to know what you're doing and what you're seeing that doesn't look right. You described your workflow as:
Is the problem that when go back to "step $1", the session you restored from |
Exactly. I have to update it manually for it take effect using
|
Thank you, that's very helpful. That sounds like it might not actually be using my fork as that's how the code worked before my changes and that work flow is working for me in my fork. Can you do the following:
|
Ok, great, so we can rule that out. Next step is to turn on some logging. Can you do the following:
|
auto-session DEBUG: Config at start of setup {
args_allow_files_auto_save = false,
args_allow_single_directory = true,
auto_create = false,
auto_restore = false,
auto_restore_last_session = false,
auto_save = true,
bypass_save_filetypes = { "alpha", "dashboard" },
close_unsupported_windows = true,
continue_restore_on_error = false,
cwd_change_handling = true,
enabled = true,
lazy_support = true,
log_level = "debug",
root_dir = "/home/keinvanity/.local/share/nvim/sessions/",
session_lens = {
load_on_setup = true,
mappings = {
alternate_session = { "i", "<C-S>" },
copy_session = { "i", "<C-Y>" },
delete_session = { "i", "<C-D>" }
},
previewer = false,
session_control = {
control_dir = "/home/keinvanity/.local/share/nvim/auto_session/",
control_filename = "session_control.json"
},
theme_conf = {}
},
use_git_branch = false
}
auto-session WARN: vim.o.sessionoptions is missing localoptions.
Use `:checkhealth autosession` for more info.
auto-session DEBUG: Root dir set to: /home/keinvanity/.local/share/nvim/sessions/
auto-session DEBUG: Loading session lens
auto-session DEBUG: Lazy is loaded, but not visible, will try to restore session
auto-session DEBUG: enabled_for_command_line_argv, launch_argv: {}
auto-session DEBUG: No arguments, saving/restoring enabled
auto-session DEBUG: No session restored, call no_restore hooks
false
|
Thanks for that logging but I need the logging after you have restored a session and run the auto save function i mentioned in my previous message. please do the following:
|
I did exactly that the last time, but now it's returning more output. After running 08:18:35 PM msg_show auto-session DEBUG: Config at start of setup {
args_allow_files_auto_save = false,
args_allow_single_directory = true,
auto_create = false,
auto_restore = false,
auto_restore_last_session = false,
auto_save = true,
bypass_save_filetypes = { "alpha", "dashboard" },
close_unsupported_windows = true,
continue_restore_on_error = false,
cwd_change_handling = true,
enabled = true,
lazy_support = true,
log_level = "debug",
root_dir = "/home/keinvanity/.local/share/nvim/sessions/",
session_lens = {
load_on_setup = true,
mappings = {
alternate_session = { "i", "<C-S>" },
copy_session = { "i", "<C-Y>" },
delete_session = { "i", "<C-D>" }
},
previewer = false,
session_control = {
control_dir = "/home/keinvanity/.local/share/nvim/auto_session/",
control_filename = "session_control.json"
},
theme_conf = {}
},
use_git_branch = false
}
auto-session WARN: vim.o.sessionoptions is missing localoptions.
Use `:checkhealth autosession` for more info.
auto-session DEBUG: Root dir set to: /home/keinvanity/.local/share/nvim/sessions/
auto-session DEBUG: Loading session lens
auto-session DEBUG: Lazy is loaded, but not visible, will try to restore session
auto-session DEBUG: enabled_for_command_line_argv, launch_argv: {}
auto-session DEBUG: No arguments, saving/restoring enabled
auto-session DEBUG: No session restored, call no_restore hooks
08:19:02 PM msg_show.echo Notifications 2024-10-14T20:18:48 Messages INFO 2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: get_session_file_name no session_name, using cwd: /home/keinvanity
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: Autosaving before restoring {
cwd = "/home/keinvanity",
session_name = "dis2"
}
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: enabled_for_command_line_argv, launch_argv: {}
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: No arguments, saving/restoring enabled
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: find_matching_directory {
dirToFind = "/home/keinvanity",
dirsToCheck = {}
}
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: suppress_session didn't find a match, returning false
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: bypass_save_by_filetype: false
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: auto_save_conditions_met: returning true
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: get_session_file_name no session_name, using cwd: /home/keinvanity
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: Create not enabled and no existing session, not creating session
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: RestoreSessionFromDir start { "/home/keinvanity/.local/share/nvim/sessions/", "dis2" }
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: RestoreSessionFromDir validated session_dir: /home/keinvanity/.local/share/nvim/sessions/
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: RestoreSessionFromDir escaped session name: dis2.vim
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: get_session_file_name no session_name, using cwd: /home/keinvanity
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: Session is manually named
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: RestoreSessionFile restoring session from: /home/keinvanity/.local/share/nvim/sessions/dis2.vim
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: DirChangedPre
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: {
["changed window"] = "false",
cwd = "/home/keinvanity",
scope = "global",
target = "~"
}
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: DirChangedPre: restore_in_progress/vim.g.SessionLoad is true, ignoring this event
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: DirChanged
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: cwd: /home/keinvanity
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: changed window: false
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: scope: global
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: DirChangedPre: restore_in_progress/vim.g.SessionLoad is true, ignoring this event
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: Restored session: dis2
2024-10-14T20:18:38 Notify INFO Restored session: dis2
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: Loaded session control data: {
alternate = "/home/keinvanity/.local/share/nvim/sessions/navi.vim",
current = "/home/keinvanity/.local/share/nvim/sessions/dis2.vim"
}
2024-10-14T20:18:38 Notify DEBUG auto-session DEBUG: Not writing to session control file, current is same as session_file_name: /home/keinvanity/.local/share/nvim/sessions/dis2.vim
2024-10-14T20:18:43 Messages INFO false
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: launch_argv is nil, saving/restoring enabled
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: find_matching_directory {
dirToFind = "/home/keinvanity",
dirsToCheck = {}
}
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: suppress_session didn't find a match, returning false
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: bypass_save_by_filetype: false
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: auto_save_conditions_met: returning true
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: get_session_file_name no session_name, using cwd: /home/keinvanity
2024-10-14T20:18:43 Notify DEBUG auto-session DEBUG: Create not enabled and no existing session, not creating session
|
Ahh, I see the bug now. When |
When auto-saving, if the session has been manually named use that session name instead of the cwd session name. Fixes manually named session not auto-saving on exit.
Ok, just committed a fix. Can you try the updating my fork of |
Thank you so much for the time and your detailed guidance! Please just notify me when this PR would get merged to revert back to the original repo. Thanks! |
Glad it's working now! I'll reopen the issue and it'll get closed when the code is merged in. |
Great back and forth here btw! Thanks for making auto-session better! 🙏 |
@kqvanity changes are merged in now. You can switch back to the main fork |
Is your feature request related to a problem? Please describe.
SessionSave
manually will save the content in a new session named after the CWD (withauto_create
set or not)Describe the solution you'd like
I'd favor support for named sessions for multiple reasons
Describe alternatives you've considered
I've tried setting up hooks to named of the current session when a session-save event is triggered, but it became recursive
Additional context
N/A
The text was updated successfully, but these errors were encountered: