barbar.nvim's is a &tabline plugin which has builtin integration with session files. Our implementation differs from bufferline.nvim's in that we do not keep a global variable synced with the state of the plugin, until it comes time to export it to a session.
Normally, it is advised to create a wrapper function around the :mksession (or plugin equivalent) command which runs :doautocmd with our User event pattern. However, this plugin (extremely conveniently) saves sessions without requiring user intervention. Thus, in order to ensure that our event runs first, a user of our plugin would have to clear the persistence augroup and recreate it, adding only one function call.
That solution seemed a bit hacky to me, so I wanted to see if creating a pre_save option would be a viable alternative. This implementation allows not just integration with barbar.nvim and user configurations, but it also allows new plugins to wait to sync global variables relevant to a session until necessary, which increases performance.
Feel free to request that the variable name or implementation details be changed. Also feel free to close the PR if this isn't something that aligns with the goals of the plugin.
About
This PR adds the
pre_save
option, which is afun()|nil
that will be called (if present) before saving the current session.Use cases include filtering buffers, executing autocmds, etc. Example config using lazy.nvim, for integration with barbar.nvim:
Motivation
barbar.nvim's is a
&tabline
plugin which has builtin integration with session files. Our implementation differs from bufferline.nvim's in that we do not keep a global variable synced with the state of the plugin, until it comes time to export it to a session.Normally, it is advised to create a wrapper function around the
:mksession
(or plugin equivalent) command which runs:doautocmd
with ourUser
event pattern. However, this plugin (extremely conveniently) saves sessions without requiring user intervention. Thus, in order to ensure that our event runs first, a user of our plugin would have to clear thepersistence
augroup and recreate it, adding only one function call.That solution seemed a bit hacky to me, so I wanted to see if creating a
pre_save
option would be a viable alternative. This implementation allows not just integration with barbar.nvim and user configurations, but it also allows new plugins to wait to sync global variables relevant to a session until necessary, which increases performance.Feel free to request that the variable name or implementation details be changed. Also feel free to close the PR if this isn't something that aligns with the goals of the plugin.