-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Overhauled vim cmds and percent encoding session file names #334
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BREAKING CHANGE: Removed DisableAutoSave as it didn't follow the naming convention
All commands and functions now expect a session name, which is either just a string (e.g. `:SessionSave mysession`) or a path (usually the cwd, `:SessionSave` with no argument is the same as `:SessionSave .. vim.fn.getcwd()`). This should not impact most people but you can now no longer do something like `SessionSave /some/dir/session.vim` and expect it to save to `/some/dir`. What will happen now is that it will save a session with the name '/some/dir/session'. Also introducing some new cmds: - `:SessionSearch` (pops a picker, eitherTelescope or vim.ui.select) - `:SesssionEnableAutoSave` enables autosave on exit, subject to all of the normal filters in the config - `:SesssionEnableAutoSave!` disable autosave on exit - `:SesssionToggleAutoSave` toggles autosave on exit Also fixed autocomplete for session names for Restore/Delete
BREAKING CHANGE: This is listed as a break change but there is code to handle working with the old session file names. In theory, it should be seamless but it's worth highlighting what's changed in case you run into any trouble.
Also updated Telescope section
Only check for last session at `auto_restore_session_at_vim_enter` to make sure it's only ever run once as cwd handling calls AutoRestore
That way a you can delete legacy files directly vs it deleting the non-legacy session first. We're still restoring sessions by name rather than file, mostly to handle dynamic conversion
Shouldn't change the code at all, just cleaner to not have to deal with nil
I think it's cleaner not to expose them as vim cmds as they clutter the cmd space for what is a pretty niche use case. That functionality is available in Lua, tho, as SaveSessionToDir, RestoreSessionFromDir, DeleteSessionFromDir for anyone that might want to use it.
This enables handling session names that end in .vim (as you might find in a vim plugin name)
cameronr
changed the title
Overhauled vim cmds and percent encoding sessions
Overhauled vim cmds and percent encoding session file names
Jul 28, 2024
If it's marked as defaultConf, then it will create a diagnostic for missing fields and we don't want that.
If launched with a single directory argument but there's no session for that directory, don't save a session in the cwd for that directory (unless it the single directory argument matches the cwd)
If we don't delete the args when saving the session, the session will keep adding those files back in when the session is reloaded, even if those buffers had been closed
Mainly useful for Lualine
rmagatti
approved these changes
Jul 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While this PR is largely compatible with existing setups, it does include some breaking changes (as discussed in #257) with how vim commands work with arguments. It also includes a new session filename format (percent encoding some characters) but it transparently handles converting between the old format (e.g.
%some%dir
on *nix/MacOS andC++-some-dir
on Windows) and the new percent encoding (%2Fsome%2Fdir
format on both on all platforms)Command Overhaul
How the commands work with arguments has been updated. The argument to any function (Save/Restore/Delete) is strictly a session name, which means either a named session (e.g mysession) or a path (e.g. /my/proj). It is no longer possible to specify a directory to save in and a session name all in one argument. That was necessary because it was impossible to make that consistent in all cases. The benefit is that arguments to the commands and what you see in the session picker are all consistent. See "/my/proj" as the session name in the session picker? Great, you can restore it with
:SessionRestore /my/proj
I also added a
:SessionSearch
command that will pop the Telescope picker if it's installed and vim.ui.select otherwise. DisableAutoSave was renamed to SessionDisableAutoSave to make it consistent with the rest of the commands and I added a toggle cmd useful for a keymap:In addition,
RestoreSessionFromFile
has been removed as a vim command because it's no longer necessary.I decided not to expose
SessionSaveToDir
/SessionRestoreFromDir
/SessionDeleteFromDir
versions as vim cmds as they seem like more niche uses cases and they clutter the autocomplete list. That functionality is available in Lua, tho, asSaveSessionToDir
,RestoreSessionFromDir
,DeleteSessionFromDir
.As a little bonus,
:SessionRestore
/:SessionDelete
also now get session name completion when you're typing.New session filename format
Session file names are now percent encoded rather than the custom and different escaping methods used between *nix/MacOS and Windows. The new format is the same across all platforms and will percent encode all
/\:*?"'<>+ |.%
characters. The immediate benefit is supporting session names with dashes on windows and some slightly better git branch naming. This should mean fewer encoding related issues going forward.When restoring a session, it will transparently move an old format session file to the new format and all places the search/delete sessions are able to read both formats.
current_session_name
The return from require('auto-session.lib').current_session_name is now the full session name, consistent with what is displayed in session search and used for save/restore. That means if it's a session that was automatically named after the cwd, it will be longer than was previously returned. To get just the last part of the session name (like the previous behavior), just pass
true
as an argument. For example, for the session named/some/dir/myproj
, thenrequire('auto-session.lib').current_session_name(true)
will return justmyproj
Fixes
Fixes: #55, #73, #148, #195, #204, #242, #250, #257, #262
#116: Addresses 1-4 but not 5 or 6.
#273: Doesn't fully address, especially the way we're handling git branches, but the simplicity of just having a session file without requiring a mapping table is desirable enough that I think it's worth seeing if this is good enough. If not, we can add a mapping layer on top.
Closing Thoughts
Even with the unit test coverage, it could make sense to integrate this into a another branch and get a few other people testing. Or we can just integrate it into main and I'll make sure to respond quickly to any reported issues.
Lastly, assuming that this PR is approved, I'll update the breaking changes issue with the text above.