feat(alt file): save and restore alternate file.#82
Open
josh-nz wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
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.
This change causes Resession to save and restore the alternate file for each window, if one is set. It is backwards compatible by guarding against the existence of
altfilein the session data before attempting to set the alternate file, and the set call is wrapped in apcallso any errors, such as if the alternate buffer no longer exists due to the file being deleted or renamed, won't affect the rest of the plugin from functioning.I initially tried to implement this as an extension, but the alternate file is a little strange. While it is stored in the global
#register, it is tracked per window. (changing windows must cause neo/vim to update this register). There is no reference to this alternate file on the window itself (eg viavim.fn.getwininfo(winid)) so it's unclear how neo/vim tracks this. So while an extension can iterate over all windows (eg viavim.api.nvim_list_wins()) and store them in a list, there is no reference back to any meaningful window identifier, since window ids can differ per session. There is also no guarantee that I can find thatvim.api.nvim_list_wins()will list the windows in the same order asvim.fn.winlayout(tabnr)as used by Recession, or that the order still holds across multiple tabs.Using the extension window hooks (
save/load_win) doesn't work, it appears those are intended exclusively for non-file windows and if an extension is attempting to do something here, then Resession skips loading the file buffer.So the only reliable way for an extension to implement this feature would be to copy a good chunk of the tab/window recursive code to ensure the alternate files are saved and loaded in the correct order as the windows. While feels not great. It also feels like this is a nice feature to have in the core library, it's sort of a property of the window even if internally in neo/vim it might be handled strangely. I don't feel like this needs to be a user option, but it could be added if you felt strongly about it.
The new API used,
vim.api.nvim_win_call, has existed since neovim 0.5.0.