xolox / vim-session

Extended session management for Vim (:mksession on steroids)
http://peterodding.com/code/vim/session/
961 stars 80 forks source link

Generic mechanism for integrating with third party Vim plug-ins #98

Open xolox opened 10 years ago

xolox commented 10 years ago

The current situation is as follows:

  1. The vim-session plug-in knows how to persist and restore the types of Vim windows (buffers) that can be created with "stock Vim" (without using plug-ins not bundled with Vim's default run time). This is as things should be, without this the plug-in would be useless ;-)
  2. The vim-session plug-in also includes integrated support for persisting and restoring buffers created by a semi random subset of third party plug-ins. Either I was using those plug-ins myself when I added the integration or enough users bugged me to add integration :-)

This is how I would like things to be:

  1. The vim-session plug-in supports the types of Vim windows (buffers) that can be created with Vim's default feature set.
  2. The vim-session plug-in also includes a mechanism using which support can be added for buffers whose (dynamic) content was generated by third party Vim plug-ins.

The idea here is that the core of the plug-in won't have to focus on adding/keeping compatibility with random third party plug-ins, instead there's just the extension mechanism which should work properly.

Default integration with a bunch of third party plug-ins could still be included with the vim-session plug-in, but it could be kept in separate Vim script files. This would make it easier for users to contribute bits of integration.

This probably isn't going to be easy, it might even turn out that it's not possible to set something up which is simple & extensible yet reliable. But if I never try I'll never find out :-). Also I really don't want to be adding integration with third party Vim plug-ins until the end of time ;-).

rafi commented 10 years ago

Definitely the desired approach. Can we start with something "simple", like a list of buffer names to ignore? (Regexp patterns)

let g:xolox#session#ignore_window_patterns = [ '^\[unite\]', '^vimfiler\:' ]
xolox commented 10 years ago

@rafi: The vim-session plug-in uses Vim to generate most of the session script including the window layout. I don't think there's any way to prevent split windows from appearing in the session script, otherwise the window layout would be screwed up. So then the windows would have to be closed after the session is loaded. Either way it may screw up the window layout, the question is how much of a problem that is.

rafi commented 10 years ago

@xolox I've used the trick of yours with commenting out line patterns, it works for Vimfiler, but not for Unite. I'll try the other way around -- closing all Unite windows before saving session, and will test the Vimfiler workaround. Thanks!

rafi commented 10 years ago

I solved it on the other end. Patched up a unite-(menu)-source to manage the sessions and changed the action_table.save.is_quit: 1 to close the unite win and added these lines to close all Vimfilers wins in all tabs:

let current_tab = tabpagenr()
tabdo windo if &ft  == 'vimfiler' | bd | endif
execute 'tabnext '.current_tab
  1. Perhaps vim-session can offer an array of file-types to close before saving. e.g.: let g:xolox#session#wipe_filetypes = [ 'unite', 'vimfiler' ]
  2. Something more advanced could be commands to run on the original tab if it closed a certain window in it. e.g.:
let g:xolox#session#wipe_filetypes = [
  \ 'unite',
  \ { name: 'vimfiler', command: 'VimFilerExplorer' }
  \ ]

vim-session will iterate through tabs and close matching filetypes. When loading a session any command for a closed window will be executed in the original tab.

What say you?

chemzqm commented 9 years ago

Close the windows of vimfiler before session saving is fine for me, is there any way I can add the script instead of hacking the vim-session's code? I've tried with vim's autocmd, but never works.

mMontu commented 8 years ago

+1