Skip to content

Commit 1f9bb68

Browse files
committed
Support for sessions with multiple TagList windows
See issue #66 on GitHub: #66
1 parent 7186722 commit 1f9bb68

3 files changed

Lines changed: 44 additions & 31 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ This variable isn't really an option but if you want to avoid loading the vim-se
223223

224224
## Compatibility with other plug-ins
225225

226-
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:
226+
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:
227227

228-
* [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;
228+
* [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;
229229
* When [shell.vim](http://peterodding.com/code/vim/shell/) is installed Vim's full-screen state is persisted;
230-
* 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.
230+
* The [netrw](http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw-start) plug-in supports sessions out of the box.
231231

232232
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.
233233

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

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

245-
### Public API for the vim-notes plug-in
245+
### Public API for the vim-session plug-in
246246

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

autoload/xolox/session.vim

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
" Public API for the vim-notes plug-in.
1+
" Public API for the vim-session plug-in.
22
"
33
" Author: Peter Odding
4-
" Last Change: July 4, 2013
4+
" Last Change: July 5, 2013
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.4.6'
7+
let g:xolox#session#version = '2.4.7'
88

99
" Public API for session persistence. {{{1
1010

@@ -189,11 +189,8 @@ function! xolox#session#save_state(commands) " {{{2
189189
call extend(a:commands, map(lines, 's:state_filter(v:val)'))
190190
" Re-implement Vim's special handling of the initial, empty buffer.
191191
call add(a:commands, "if exists('s:wipebuf')")
192-
call add(a:commands, " if empty(bufname(s:wipebuf)) && !getbufvar(s:wipebuf, '&modified')")
193-
call add(a:commands, " let s:wipebuflines = getbufline(s:wipebuf, 1, '$')")
194-
call add(a:commands, " if len(s:wipebuflines) <= 1 && empty(get(s:wipebuflines, 0, ''))")
195-
call add(a:commands, " silent exe 'bwipe ' . s:wipebuf")
196-
call add(a:commands, " endif")
192+
call add(a:commands, " if empty(bufname(s:wipebuf))")
193+
call s:cleanup_after_plugin(a:commands, 's:wipebuf')
197194
call add(a:commands, " endif")
198195
call add(a:commands, "endif")
199196
return 1
@@ -244,6 +241,9 @@ function! s:state_filter(line) " {{{3
244241
elseif a:line =~ '^file .\{-}\[BufExplorer\]$'
245242
" Same trick (about the E95) for BufExplorer.
246243
return '" ' . a:line
244+
elseif a:line =~ '^file .\{-}__Tag_List__$'
245+
" Same trick (about the E95) for TagList.
246+
return '" ' . a:line
247247
elseif a:line =~ '^args '
248248
" The :mksession command adds an :args line to the session file, but when
249249
" :args is executed during a session restore it edits the first file it is
@@ -273,6 +273,11 @@ function! xolox#session#save_special_windows(session) " {{{2
273273
let tabpage = tabpagenr()
274274
let window = winnr()
275275
let s:nerdtrees = {}
276+
call add(a:session, '')
277+
call add(a:session, '" Support for special windows like quick-fix and plug-in windows.')
278+
call add(a:session, '" Everything down here is generated by vim-session (not supported')
279+
call add(a:session, '" by :mksession out of the box).')
280+
call add(a:session, '')
276281
try
277282
if xolox#session#include_tabs()
278283
tabdo call s:check_special_tabpage(a:session)
@@ -299,6 +304,7 @@ function! s:check_special_window(session)
299304
" If we detected a special window and the argument to the command is not a
300305
" pathname, this variable should be set to false to disable normalization.
301306
let do_normalize_path = 1
307+
let bufname = expand('%:t')
302308
if exists('b:NERDTreeRoot')
303309
if !has_key(s:nerdtrees, bufnr('%'))
304310
let command = 'NERDTree'
@@ -308,9 +314,12 @@ function! s:check_special_window(session)
308314
let command = 'NERDTreeMirror'
309315
let argument = ''
310316
endif
311-
elseif expand('%:t') == '[BufExplorer]'
317+
elseif bufname == '[BufExplorer]'
312318
let command = 'BufExplorer'
313319
let argument = ''
320+
elseif bufname == '__Tag_List__'
321+
let command = 'Tlist'
322+
let argument = ''
314323
elseif exists('g:proj_running') && g:proj_running == bufnr('%')
315324
let command = 'Project'
316325
let argument = expand('%:p')
@@ -340,9 +349,7 @@ function! s:check_special_window(session)
340349
endif
341350
call add(a:session, command . ' ' . fnameescape(argument))
342351
endif
343-
call add(a:session, 'if bufnr("%") != s:bufnr_save')
344-
call add(a:session, ' execute "bwipeout" s:bufnr_save')
345-
call add(a:session, 'endif')
352+
call s:cleanup_after_plugin(a:session, 's:bufnr_save')
346353
call add(a:session, 'execute "cd" fnameescape(s:cwd_save)')
347354
return 1
348355
endif
@@ -364,6 +371,15 @@ function! s:nerdtree_persist()
364371
endif
365372
endfunction
366373

374+
function! s:cleanup_after_plugin(commands, bufnr_var)
375+
call add(a:commands, "if !getbufvar(" . a:bufnr_var . ", '&modified')")
376+
call add(a:commands, " let s:wipebuflines = getbufline(" . a:bufnr_var . ", 1, '$')")
377+
call add(a:commands, " if len(s:wipebuflines) <= 1 && empty(get(s:wipebuflines, 0, ''))")
378+
call add(a:commands, " silent execute 'bwipeout' " . a:bufnr_var)
379+
call add(a:commands, " endif")
380+
call add(a:commands, "endif")
381+
endfunction
382+
367383
" Automatic commands to manage the default session. {{{1
368384

369385
function! xolox#session#auto_load() " {{{2

doc/session.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Contents ~
3535
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
3636
6. Known issues |session-known-issues|
3737
7. Function reference |session-function-reference|
38-
1. Public API for the vim-notes plug-in |session-public-api-for-vim-notes-plug-in|
38+
1. Public API for the vim-session plug-in |public-api-for-vim-session-plug-in|
3939
1. The |xolox#session#save_session()| function
4040
2. The |xolox#session#save_globals()| function
4141
3. The |xolox#session#save_features()| function
@@ -453,15 +453,12 @@ Compatibility with other plug-ins ~
453453

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

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

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

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

489486
-------------------------------------------------------------------------------
490-
*session-public-api-for-vim-notes-plug-in*
491-
Public API for the vim-notes plug-in ~
487+
*public-api-for-vim-session-plug-in*
488+
Public API for the vim-session plug-in ~
492489

493490
-------------------------------------------------------------------------------
494491
The *xolox#session#save_session()* function
@@ -820,8 +817,8 @@ References ~
820817
[12] http://www.vim.org/scripts/script.php?script_id=2771
821818
[13] http://www.vim.org/scripts/script.php?script_id=1658
822819
[14] http://www.vim.org/scripts/script.php?script_id=69
823-
[15] http://peterodding.com/code/vim/shell/
824-
[16] http://www.vim.org/scripts/script.php?script_id=273
820+
[15] http://www.vim.org/scripts/script.php?script_id=273
821+
[16] http://peterodding.com/code/vim/shell/
825822
[17] http://peterodding.com/code/vim/session
826823
[18] http://peterodding.com/code/vim/shell
827824
[19] http://www.vim.org/scripts/script.php?script_id=3150

0 commit comments

Comments
 (0)