implement customizable file name formatting (#230).

This commit is contained in:
Bailey Ling 2013-09-06 21:50:06 +00:00
parent b636c28ae2
commit 7a2f6525c3
3 changed files with 18 additions and 5 deletions

View File

@ -19,10 +19,11 @@ function! airline#deprecation#check()
\ [ 'g:airline_enable_branch', 'g:airline#extensions#branch#enabled' ],
\ [ 'g:airline_enable_bufferline', 'g:airline#extensions#bufferline#enabled' ],
\ [ 'g:airline_enable_syntastic', 'g:airline#extensions#syntastic#enabled' ],
\ [ 'g:airline#extensions#tabline#fnamemod', 'g:airline#extensions#tabline#fnamefunc' ],
\ ]
for test in tests
if exists(test[0])
echom printf('The variable %s is deprecated and may not work in the future. It has been replaced with %s', test[0], test[1])
echom printf('The variable %s is deprecated and may not work in the future. It has been replaced with %s. Please read the documentation.', test[0], test[1])
endif
endfor
endfunction

View File

@ -1,7 +1,7 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
let s:fnamefunc = get(g:, 'airline#extensions#tabline#fnamefunc', 'airline#extensions#tabline#fname_func')
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
@ -82,6 +82,11 @@ function! airline#extensions#tabline#title(n)
return airline#extensions#tabline#get_buffer_name(buflist[winnr - 1])
endfunction
function! airline#extensions#tabline#fname_func(name)
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
return substitute(fnamemodify(a:name, fmod), '\w\zs.\{-}\ze\/', '', 'g')
endfunction
function! airline#extensions#tabline#get_buffer_name(nr)
let _ = ''
let name = bufname(a:nr)
@ -93,7 +98,7 @@ function! airline#extensions#tabline#get_buffer_name(nr)
if empty(name)
let _ .= '[No Name]'
else
let _ .= fnamemodify(name, s:fmod)
let _ .= call(s:fnamefunc, [name])
endif
if getbufvar(a:nr, '&modified') == 1

View File

@ -305,8 +305,15 @@ virtualenv <https://github.com/jmcantrell/vim-virtualenv>
* enable/disable displaying buffers with a single tab. >
let g:airline#extensions#tabline#show_buffers = 1
<
* configure the formatting of filenames (see |filename-modifiers|). >
let g:airline#extensions#tabline#fnamemod = ':p:.'
* defines a function for how to format the file name. >
" the default renders /foo/bar/file.txt => /f/b/file.txt
let g:airline#extensions#tabline#fnamefunc
" here's a simple example to show only the file name:
function! MyFileFormat(file)
return fnamemodify(a:file, ':t')
endfunction
let g:airline#extensions#tabline#fnamefunc = 'MyFileFormat'
<
* configure filename match rules to exclude from the tabline. >
let g:airline#extensions#tabline#excludes = []