docs updated, formatters moved to separate filenames

This commit is contained in:
zdm 2013-12-23 07:41:24 +02:00
parent 6c79004aaa
commit 50fd649110
5 changed files with 80 additions and 68 deletions

View File

@ -104,7 +104,7 @@ function! airline#extensions#tabline#title(n)
endfunction
function! airline#extensions#tabline#get_buffer_name(nr)
return airline#extensions#tabline#formatters#{s:formatter}(a:nr, get(s:, 'current_buffer_list', s:get_buffer_list()))
return airline#extensions#tabline#{s:formatter}#format(a:nr, get(s:, 'current_buffer_list', s:get_buffer_list()))
endfunction
function! s:get_buffer_list()

View File

@ -0,0 +1,35 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.')
let s:fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
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#default#format(bufnr, buffers)
let _ = ''
let name = bufname(a:bufnr)
if empty(name)
let _ .= '[No Name]'
else
if s:fnamecollapse
let _ .= substitute(fnamemodify(name, s:fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g')
else
let _ .= fnamemodify(name, s:fmod)
endif
endif
return airline#extensions#tabline#default#wrap_name(a:bufnr, _)
endfunction
function! airline#extensions#tabline#default#wrap_name(bufnr, buffer_name)
let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : ''
let _ .= substitute(a:buffer_name, '\\', '/', 'g')
if getbufvar(a:bufnr, '&modified') == 1
let _ .= s:buf_modified_symbol
endif
return _
endfunction

View File

@ -0,0 +1,27 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
function! airline#extensions#tabline#unique_tail#format(bufnr, buffers)
let duplicates = {}
let tails = {}
let map = {}
for nr in a:buffers
let name = bufname(nr)
if empty(name)
let map[nr] = '[No Name]'
else
let tail = fnamemodify(name, ':t')
if has_key(tails, tail)
let duplicates[nr] = nr
endif
let tails[tail] = 1
let map[nr] = airline#extensions#tabline#default#wrap_name(nr, tail)
endif
endfor
for nr in values(duplicates)
let map[nr] = airline#extensions#tabline#default#wrap_name(nr, fnamemodify(bufname(nr), ':p:.'))
endfor
return map[a:bufnr]
endfunction

View File

@ -1,57 +1,11 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.')
let s:fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
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
let s:skip_symbol = '…'
function! airline#extensions#tabline#formatters#default(bufnr, buffers)
let _ = ''
let name = bufname(a:bufnr)
if empty(name)
let _ .= '[No Name]'
else
if s:fnamecollapse
let _ .= substitute(fnamemodify(name, s:fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g')
else
let _ .= fnamemodify(name, s:fmod)
endif
endif
return s:wrap_name(a:bufnr, _)
endfunction
function! airline#extensions#tabline#formatters#unique_tail(bufnr, buffers)
let duplicates = {}
let tails = {}
let map = {}
for nr in a:buffers
let name = bufname(nr)
if empty(name)
let map[nr] = '[No Name]'
else
let tail = fnamemodify(name, ':t')
if has_key(tails, tail)
let duplicates[nr] = nr
endif
let tails[tail] = 1
let map[nr] = s:wrap_name(nr, tail)
endif
endfor
for nr in values(duplicates)
let map[nr] = s:wrap_name(nr, fnamemodify(bufname(nr), ':p:.'))
endfor
return map[a:bufnr]
endfunction
function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buffers)
function! airline#extensions#tabline#unique_tail_improved#format(bufnr, buffers)
if len(a:buffers) <= 1 " don't need to compare bufnames if has less than one buffer opened
return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers)
return airline#extensions#tabline#default#format(a:bufnr, a:buffers)
endif
let curbuf_tail = fnamemodify(bufname(a:bufnr), ':t')
@ -95,16 +49,15 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff
let buf_name = [curbuf_tail]
let has_uniq = 0
let has_skipped = 0
let skip_symbol = '…'
for token1 in reverse(path)
if !token1['duplicated'] && len(buf_name) > 1
call insert(buf_name, skip_symbol)
call insert(buf_name, s:skip_symbol)
let has_skipped = 0
break
endif
if has_uniq == 1
call insert(buf_name, skip_symbol)
call insert(buf_name, s:skip_symbol)
let has_skipped = 0
break
endif
@ -113,7 +66,7 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff
let has_skipped = 1
else
if has_skipped == 1
call insert(buf_name, skip_symbol)
call insert(buf_name, s:skip_symbol)
let has_skipped = 0
endif
call insert(buf_name, token1['token'])
@ -125,21 +78,11 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff
endfor
if has_skipped == 1
call insert(buf_name, skip_symbol)
call insert(buf_name, s:skip_symbol)
endif
return s:wrap_name(a:bufnr, join(buf_name, '/'))
return airline#extensions#tabline#default#wrap_name(a:bufnr, join(buf_name, '/'))
else
return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers)
return airline#extensions#tabline#default#format(a:bufnr, a:buffers)
endif
endfunction
function! s:wrap_name(bufnr, buffer_name)
let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : ''
let _ .= substitute(a:buffer_name, '\\', '/', 'g')
if getbufvar(a:bufnr, '&modified') == 1
let _ .= s:buf_modified_symbol
endif
return _
endfunction

View File

@ -379,11 +379,14 @@ eclim <https://eclim.org>
let g:airline#extensions#tabline#tab_nr_type = 0 " # of splits (default)
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
<
* enable/disable displaying tab number in tabs mode. >
let g:airline#extensions#tabline#show_tab_nr = 1
* 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, buffers)
function! airline#extensions#tabline#foo#format(bufnr, buffers)
return fnamemodify(bufname(a:bufnr), ':t')
endfunction
let g:airline#extensions#tabline#formatter = 'foo'
@ -406,6 +409,10 @@ eclim <https://eclim.org>
" there is another file of the same name, in which it will display it along
" with the containing parent directory.
let g:airline#extensions#tabline#formatter = 'unique_tail'
The `unique_tail_improved` - another algorithm, that will smartly uniqualise
buffers names with similar filename, suppressing common parts of paths.
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
<
* configure the minimum number of buffers needed to show the tabline. >
let g:airline#extensions#tabline#buffer_min_count = 0