Transformations: allow patterns

The type of g:startify_transformations has to be a list of lists now.
The inner lists contain 2 elements, a pattern and either a string or a
funcref.

Example:

function! s:foo(filename)
  return fnamemodify(a:filename, ':t')
endfunction

let g:startify_transformations = [
      \ ['.*vimrc$', 'vimrc'],
      \ ['.*', function('s:foo')],
      \ ]

References #209.
This commit is contained in:
Marco Hinz 2016-03-20 15:33:52 +01:00
parent 570ef9e11f
commit c381ab79fc

View file

@ -18,6 +18,7 @@ let s:delete_buffers = get(g:, 'startify_session_delete_buffers')
let s:relative_path = get(g:, 'startify_relative_path') ? ':.:~' : ':p:~'
let s:session_dir = resolve(expand(get(g:, 'startify_session_dir',
\ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
let s:tf = exists('g:startify_transformations')
let s:skiplist = get(g:, 'startify_skiplist', [
\ 'COMMIT_EDITMSG',
@ -25,17 +26,6 @@ let s:skiplist = get(g:, 'startify_skiplist', [
\ 'bundle/.*/doc',
\ ])
let s:transformations = {}
if exists('g:startify_transformations')
for [k,V] in items(g:startify_transformations)
call extend(s:transformations, { fnamemodify(resolve(expand(k)), ':p'): V })
unlet V " avoid type mismatch dict <-> string
endfor
let s:tf = 1
else
let s:tf = 0
endif
" Function: #get_separator {{{1
function! startify#get_separator() abort
return !exists('+shellslash') || &shellslash ? '/' : '\'
@ -859,10 +849,12 @@ endfunction
" Function: s:transform {{{1
function s:transform(absolute_path)
if has_key(s:transformations, a:absolute_path)
let V = s:transformations[a:absolute_path]
return type(V) == type('') ? V : V(a:absolute_path)
endif
for [k,V] in g:startify_transformations
if a:absolute_path =~ k
return type(V) == type('') ? V : V(a:absolute_path)
endif
unlet V
endfor
return a:absolute_path
endfunction