Skip to content

Commit

Permalink
Support for sessions with multiple TagList windows
Browse files Browse the repository at this point in the history
See issue #66 on GitHub:
  #66
  • Loading branch information
xolox committed Jul 4, 2013
1 parent 7186722 commit 1f9bb68
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -223,11 +223,11 @@ This variable isn't really an option but if you want to avoid loading the vim-se

## Compatibility with other plug-ins

Vim's [:mksession][mksession] command isn't really compatible with plug-ins that create buffers with generated content and because of this the vim-session plug-in includes specific workarounds for such plug-ins:
Vim's [:mksession][mksession] command isn't really compatible with plug-ins that create buffers with generated content and because of this the vim-session plug-in includes specific workarounds for a couple of popular plug-ins:

* [BufExplorer](http://www.vim.org/scripts/script.php?script_id=42), [Conque Shell](http://www.vim.org/scripts/script.php?script_id=2771), [NERD tree](http://www.vim.org/scripts/script.php?script_id=1658) and [Project](http://www.vim.org/scripts/script.php?script_id=69) windows are supported;
* [BufExplorer](http://www.vim.org/scripts/script.php?script_id=42), [Conque Shell](http://www.vim.org/scripts/script.php?script_id=2771), [NERD tree](http://www.vim.org/scripts/script.php?script_id=1658), [Project](http://www.vim.org/scripts/script.php?script_id=69) and [taglist](http://www.vim.org/scripts/script.php?script_id=273) windows are supported;
* When [shell.vim](http://peterodding.com/code/vim/shell/) is installed Vim's full-screen state is persisted;
* The [netrw](http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw-start) and [taglist.vim](http://www.vim.org/scripts/script.php?script_id=273) plug-ins support sessions out of the box.
* The [netrw](http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw-start) plug-in supports sessions out of the box.

If your favorite plug-in doesn't work with the vim-session plug-in drop me a mail and I'll see what I can do. Please include a link to the plug-in in your e-mail so that I can install and test the plug-in.

Expand All @@ -240,9 +240,9 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
<!-- Start of generated documentation -->

The documentation of the 34 functions below was extracted from
1 Vim scripts on July 4, 2013 at 01:25.
1 Vim scripts on July 5, 2013 at 00:31.

### Public API for the vim-notes plug-in
### Public API for the vim-session plug-in

#### The `xolox#session#save_session()` function

Expand Down
40 changes: 28 additions & 12 deletions autoload/xolox/session.vim
@@ -1,10 +1,10 @@
" Public API for the vim-notes plug-in.
" Public API for the vim-session plug-in.
"
" Author: Peter Odding
" Last Change: July 4, 2013
" Last Change: July 5, 2013
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '2.4.6'
let g:xolox#session#version = '2.4.7'

" Public API for session persistence. {{{1

Expand Down Expand Up @@ -189,11 +189,8 @@ function! xolox#session#save_state(commands) " {{{2
call extend(a:commands, map(lines, 's:state_filter(v:val)'))
" Re-implement Vim's special handling of the initial, empty buffer.
call add(a:commands, "if exists('s:wipebuf')")
call add(a:commands, " if empty(bufname(s:wipebuf)) && !getbufvar(s:wipebuf, '&modified')")
call add(a:commands, " let s:wipebuflines = getbufline(s:wipebuf, 1, '$')")
call add(a:commands, " if len(s:wipebuflines) <= 1 && empty(get(s:wipebuflines, 0, ''))")
call add(a:commands, " silent exe 'bwipe ' . s:wipebuf")
call add(a:commands, " endif")
call add(a:commands, " if empty(bufname(s:wipebuf))")
call s:cleanup_after_plugin(a:commands, 's:wipebuf')
call add(a:commands, " endif")
call add(a:commands, "endif")
return 1
Expand Down Expand Up @@ -244,6 +241,9 @@ function! s:state_filter(line) " {{{3
elseif a:line =~ '^file .\{-}\[BufExplorer\]$'
" Same trick (about the E95) for BufExplorer.
return '" ' . a:line
elseif a:line =~ '^file .\{-}__Tag_List__$'
" Same trick (about the E95) for TagList.
return '" ' . a:line
elseif a:line =~ '^args '
" The :mksession command adds an :args line to the session file, but when
" :args is executed during a session restore it edits the first file it is
Expand Down Expand Up @@ -273,6 +273,11 @@ function! xolox#session#save_special_windows(session) " {{{2
let tabpage = tabpagenr()
let window = winnr()
let s:nerdtrees = {}
call add(a:session, '')
call add(a:session, '" Support for special windows like quick-fix and plug-in windows.')
call add(a:session, '" Everything down here is generated by vim-session (not supported')
call add(a:session, '" by :mksession out of the box).')
call add(a:session, '')
try
if xolox#session#include_tabs()
tabdo call s:check_special_tabpage(a:session)
Expand All @@ -299,6 +304,7 @@ function! s:check_special_window(session)
" If we detected a special window and the argument to the command is not a
" pathname, this variable should be set to false to disable normalization.
let do_normalize_path = 1
let bufname = expand('%:t')
if exists('b:NERDTreeRoot')
if !has_key(s:nerdtrees, bufnr('%'))
let command = 'NERDTree'
Expand All @@ -308,9 +314,12 @@ function! s:check_special_window(session)
let command = 'NERDTreeMirror'
let argument = ''
endif
elseif expand('%:t') == '[BufExplorer]'
elseif bufname == '[BufExplorer]'
let command = 'BufExplorer'
let argument = ''
elseif bufname == '__Tag_List__'
let command = 'Tlist'
let argument = ''
elseif exists('g:proj_running') && g:proj_running == bufnr('%')
let command = 'Project'
let argument = expand('%:p')
Expand Down Expand Up @@ -340,9 +349,7 @@ function! s:check_special_window(session)
endif
call add(a:session, command . ' ' . fnameescape(argument))
endif
call add(a:session, 'if bufnr("%") != s:bufnr_save')
call add(a:session, ' execute "bwipeout" s:bufnr_save')
call add(a:session, 'endif')
call s:cleanup_after_plugin(a:session, 's:bufnr_save')
call add(a:session, 'execute "cd" fnameescape(s:cwd_save)')
return 1
endif
Expand All @@ -364,6 +371,15 @@ function! s:nerdtree_persist()
endif
endfunction

function! s:cleanup_after_plugin(commands, bufnr_var)
call add(a:commands, "if !getbufvar(" . a:bufnr_var . ", '&modified')")
call add(a:commands, " let s:wipebuflines = getbufline(" . a:bufnr_var . ", 1, '$')")
call add(a:commands, " if len(s:wipebuflines) <= 1 && empty(get(s:wipebuflines, 0, ''))")
call add(a:commands, " silent execute 'bwipeout' " . a:bufnr_var)
call add(a:commands, " endif")
call add(a:commands, "endif")
endfunction

" Automatic commands to manage the default session. {{{1

function! xolox#session#auto_load() " {{{2
Expand Down
25 changes: 11 additions & 14 deletions doc/session.txt
Expand Up @@ -35,7 +35,7 @@ Contents ~
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
6. Known issues |session-known-issues|
7. Function reference |session-function-reference|
1. Public API for the vim-notes plug-in |session-public-api-for-vim-notes-plug-in|
1. Public API for the vim-session plug-in |public-api-for-vim-session-plug-in|
1. The |xolox#session#save_session()| function
2. The |xolox#session#save_globals()| function
3. The |xolox#session#save_features()| function
Expand Down Expand Up @@ -453,15 +453,12 @@ Compatibility with other plug-ins ~

Vim's |:mksession| command isn't really compatible with plug-ins that create
buffers with generated content and because of this the vim-session plug-in
includes specific workarounds for such plug-ins:
includes specific workarounds for a couple of popular plug-ins:

- BufExplorer [11], Conque Shell [12], NERD tree [13] and Project [14]
windows are supported;

- When shell.vim [15] is installed Vim's full-screen state is persisted;

- The netrw (see |netrw-start|) and taglist.vim [16] plug-ins support
sessions out of the box.
- BufExplorer [11], Conque Shell [12], NERD tree [13], Project [14] and
taglist [15] windows are supported;
- When shell.vim [16] is installed Vim's full-screen state is persisted;
- The netrw (see |netrw-start|) plug-in supports sessions out of the box.

If your favorite plug-in doesn't work with the vim-session plug-in drop me a
mail and I'll see what I can do. Please include a link to the plug-in in your
Expand All @@ -484,11 +481,11 @@ might take a while...)
Function reference ~

The documentation of the 34 functions below was extracted from 1 Vim scripts on
July 4, 2013 at 01:25.
July 5, 2013 at 00:31.

-------------------------------------------------------------------------------
*session-public-api-for-vim-notes-plug-in*
Public API for the vim-notes plug-in ~
*public-api-for-vim-session-plug-in*
Public API for the vim-session plug-in ~

-------------------------------------------------------------------------------
The *xolox#session#save_session()* function
Expand Down Expand Up @@ -820,8 +817,8 @@ References ~
[12] http://www.vim.org/scripts/script.php?script_id=2771
[13] http://www.vim.org/scripts/script.php?script_id=1658
[14] http://www.vim.org/scripts/script.php?script_id=69
[15] http://peterodding.com/code/vim/shell/
[16] http://www.vim.org/scripts/script.php?script_id=273
[15] http://www.vim.org/scripts/script.php?script_id=273
[16] http://peterodding.com/code/vim/shell/
[17] http://peterodding.com/code/vim/session
[18] http://peterodding.com/code/vim/shell
[19] http://www.vim.org/scripts/script.php?script_id=3150
Expand Down

0 comments on commit 1f9bb68

Please sign in to comment.