Skip to content

Commit 759e021

Browse files
committed
Implement feature
1 parent 9e9a608 commit 759e021

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,33 @@ list with one string on success and an empty list on failure.
519519

520520
<!-- End of generated documentation -->
521521

522+
### Using a custom filter on `:SaveSession`
523+
524+
#### The `xolox#session#use_custom_filter()` function
525+
526+
You can use this function to provide a `funcref` to filter the commands through
527+
before `vim-session` saves them. In the following example we also persist the
528+
tab names previously assigned with [gcmt/taboo.vim](https://github.com/gcmt/taboo.vim):
529+
530+
```
531+
function! CustomFilter(commands)
532+
let currentTab = tabpagenr()
533+
let tabNames = []
534+
tabdo call add(tabNames, TabooTabName(tabpagenr()))
535+
exec 'tabn ' . currentTab
536+
let idx = match(a:commands, '^[^"]') - 1
537+
echom 'found ' . idx
538+
for t in tabNames
539+
if !empty(t)
540+
call insert(a:commands, 'TabooRename ' . t, idx+1)
541+
endif
542+
let idx = match(a:commands, 'tabedit.*', idx+2)
543+
" echom idx
544+
endfor
545+
endfunction
546+
call xolox#session#use_custom_filter(function('CustomFilter'))
547+
```
548+
522549
## Troubleshooting
523550

524551
### Using multiple platforms (multi boot, Cygwin, etc.)

autoload/xolox/session.vim

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ let g:xolox#session#version = '2.13.1'
88

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

11+
function! xolox#session#use_custom_filter(fn)
12+
if type(a:fn) == 2
13+
let s:custom_filter = a:fn
14+
elseif exists('s:custom_filter')
15+
unlet s:custom_filter
16+
endif
17+
endfunction
18+
1119
function! xolox#session#save_session(commands, filename) " {{{2
1220
" Save the current Vim editing session to a Vim script using the
1321
" [:mksession] [] command and some additional Vim magic provided by the
@@ -197,6 +205,9 @@ function! xolox#session#save_state(commands) " {{{2
197205
call s:cleanup_after_plugin(a:commands, 's:wipebuf')
198206
call add(a:commands, " endif")
199207
call add(a:commands, "endif")
208+
if exists('s:custom_filter') && type(s:custom_filter) == 2
209+
call s:custom_filter(a:commands)
210+
endif
200211
return 1
201212
finally
202213
let &sessionoptions = ssop_save

0 commit comments

Comments
 (0)