extract buffer name logic into a formatter.

hold off on deprecation warnings for now...
This commit is contained in:
Bailey Ling 2013-09-07 00:43:51 +00:00
parent 65efb89145
commit 0ac25ecc30
5 changed files with 49 additions and 40 deletions

View File

@ -19,11 +19,13 @@ 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' ],
\ [ 'g:airline#extensions#tabline#fnamemod', 'g:airline#extensions#tabline#formatter' ],
\ ]
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. Please read the documentation.', test[0], test[1])
let max = winwidth(0) - 16
let msg = 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])
echom msg[:max].'...'
endif
endfor
endfunction

View File

@ -1,13 +1,10 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:fnamefunc = get(g:, 'airline#extensions#tabline#fnamefunc', 'airline#extensions#tabline#fname_func')
let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
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)
let s:buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0)
let s:buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ')
let s:buf_modified_symbol = g:airline_symbols.modified
let s:builder_context = {
\ 'active' : 1,
@ -82,30 +79,8 @@ 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)
if s:buf_nr_show
let _ .= printf(s:buf_nr_format, a:nr)
endif
if empty(name)
let _ .= '[No Name]'
else
let _ .= call(s:fnamefunc, [name])
endif
if getbufvar(a:nr, '&modified') == 1
let _ .= s:buf_modified_symbol
endif
return _
return airline#extensions#tabline#formatters#{s:formatter}(a:nr)
endfunction
function! s:get_buffer_list()

View File

@ -0,0 +1,29 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ')
let s:buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0)
let s:buf_modified_symbol = g:airline_symbols.modified
function! airline#extensions#tabline#formatters#default(bufnr)
let _ = ''
if s:buf_nr_show
let _ .= printf(s:buf_nr_format, a:bufnr)
endif
let name = bufname(a:bufnr)
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
if empty(name)
let _ .= '[No Name]'
else
let _ .= substitute(fnamemodify(name, fmod), '\w\zs.\{-}\ze\/', '', 'g')
endif
if getbufvar(a:bufnr, '&modified') == 1
let _ .= s:buf_modified_symbol
endif
return _
endfunction

View File

@ -305,16 +305,6 @@ virtualenv <https://github.com/jmcantrell/vim-virtualenv>
* enable/disable displaying buffers with a single tab. >
let g:airline#extensions#tabline#show_buffers = 1
<
* 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 = []
<
@ -322,12 +312,25 @@ virtualenv <https://github.com/jmcantrell/vim-virtualenv>
let g:airline#extensions#tabline#tab_nr_type = 0 " # of splits (default)
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
<
* defines the name of a formatter for how buffer names are displayed. >
let g:airline#extensions#tabline#formatter = 'default'
" here is how you can define a 'foo' formatter:
function! airline#extensions#tabline#formatters#foo(bufnr)
return fnamemodify(bufname(a:bufnr), ':t')
endfunction
let g:airline#extensions#tabline#formatter = 'foo'
<
* configure whether buffer numbers should be shown. >
let g:airline#extensions#tabline#buffer_nr_show = 0
<
Note: this is only valid when the formatter is 'default'.
* configure how buffer numbers should be formatted with |printf|. >
let g:airline#extensions#tabline#buffer_nr_format = '%s: '
<
Note: this is only valid when the formatter is 'default'.
* configure the minimum number of buffers needed to show the tabline. >
let g:airline#extensions#tabline#buffer_min_count = 0
<

View File

@ -6,7 +6,7 @@ if &cp || v:version < 702 || (exists('g:loaded_airline') && g:loaded_airline)
endif
let g:loaded_airline = 1
autocmd VimEnter * call airline#deprecation#check()
" autocmd VimEnter * call airline#deprecation#check()
let s:airline_initialized = 0
let s:airline_theme_defined = 0