Skip to content

Commit c0e82cc

Browse files
committed
Implement feature
1 parent 9e9a608 commit c0e82cc

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,32 @@ 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 save
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. This allows for raw modification of the actual
528+
session file contents, so use with care. In this example we persist the tab names
529+
previously assigned with [gcmt/taboo.vim](https://github.com/gcmt/taboo.vim):
530+
531+
```
532+
function! CustomFilter(commands)
533+
let currentTab = tabpagenr()
534+
let tabNames = []
535+
tabdo call add(tabNames, TabooTabName(tabpagenr()))
536+
exec 'tabn ' . currentTab
537+
let idx = match(a:commands, '^[^"]') - 1
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+
endfor
544+
endfunction
545+
call xolox#session#use_custom_filter(function('CustomFilter'))
546+
```
547+
522548
## Troubleshooting
523549

524550
### 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)