Skip to content

Commit

Permalink
Implement feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nkgm committed Mar 12, 2017
1 parent 9e9a608 commit 759e021
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,33 @@ list with one string on success and an empty list on failure.

<!-- End of generated documentation -->

### Using a custom filter on `:SaveSession`

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

You can use this function to provide a `funcref` to filter the commands through
before `vim-session` saves them. In the following example we also persist the
tab names previously assigned with [gcmt/taboo.vim](https://github.com/gcmt/taboo.vim):

```
function! CustomFilter(commands)
let currentTab = tabpagenr()
let tabNames = []
tabdo call add(tabNames, TabooTabName(tabpagenr()))
exec 'tabn ' . currentTab
let idx = match(a:commands, '^[^"]') - 1
echom 'found ' . idx
for t in tabNames
if !empty(t)
call insert(a:commands, 'TabooRename ' . t, idx+1)
endif
let idx = match(a:commands, 'tabedit.*', idx+2)
" echom idx
endfor
endfunction
call xolox#session#use_custom_filter(function('CustomFilter'))
```

## Troubleshooting

### Using multiple platforms (multi boot, Cygwin, etc.)
Expand Down
11 changes: 11 additions & 0 deletions autoload/xolox/session.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ let g:xolox#session#version = '2.13.1'

" Public API for session persistence. {{{1

function! xolox#session#use_custom_filter(fn)
if type(a:fn) == 2
let s:custom_filter = a:fn
elseif exists('s:custom_filter')
unlet s:custom_filter
endif
endfunction

function! xolox#session#save_session(commands, filename) " {{{2
" Save the current Vim editing session to a Vim script using the
" [:mksession] [] command and some additional Vim magic provided by the
Expand Down Expand Up @@ -197,6 +205,9 @@ function! xolox#session#save_state(commands) " {{{2
call s:cleanup_after_plugin(a:commands, 's:wipebuf')
call add(a:commands, " endif")
call add(a:commands, "endif")
if exists('s:custom_filter') && type(s:custom_filter) == 2
call s:custom_filter(a:commands)
endif
return 1
finally
let &sessionoptions = ssop_save
Expand Down

0 comments on commit 759e021

Please sign in to comment.