vim-airline/autoload/airline/extensions/tabline.vim

73 lines
2.4 KiB
VimL
Raw Normal View History

2013-08-28 13:51:54 +00:00
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
2013-09-02 00:06:41 +00:00
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
2013-08-28 13:51:54 +00:00
function! airline#extensions#tabline#init(ext)
set tabline=%!airline#extensions#tabline#get()
call a:ext.add_theme_func('airline#extensions#tabline#load_theme')
endfunction
function! airline#extensions#tabline#load_theme(palette)
let fill = a:palette.normal.airline_c
let normal = a:palette.normal.airline_b
let selected = a:palette.normal.airline_a
let type = a:palette.visual.airline_a
call airline#highlighter#exec('airline_tabline', normal)
call airline#highlighter#exec('airline_tablinesel', selected)
call airline#highlighter#exec('airline_tablinetype', type)
call airline#highlighter#exec('airline_tablinefill', fill)
2013-08-28 13:51:54 +00:00
endfunction
function! airline#extensions#tabline#get()
let b = airline#builder#new({'active': 1})
let b._line = ''
if tabpagenr('$') == 1
let cur = bufnr('%')
for nr in range(1, bufnr('$'))
if buflisted(nr) && bufexists(nr)
if cur == nr
2013-09-02 03:03:36 +00:00
call b.add_section('airline_tablinesel', '%( %{airline#extensions#tabline#get_buffer_name('.nr.')} %)')
2013-08-28 13:51:54 +00:00
else
2013-09-02 03:03:36 +00:00
call b.add_section('airline_tabline', '%( %{airline#extensions#tabline#get_buffer_name('.nr.')} %)')
2013-08-28 13:51:54 +00:00
endif
endif
endfor
call b.add_section('airline_tablinefill', '')
2013-08-28 13:51:54 +00:00
call b.split()
call b.add_section('airline_tablinetype', ' buffers ')
2013-08-28 13:51:54 +00:00
else
let s = ''
for i in range(tabpagenr('$'))
if i + 1 == tabpagenr()
call b.add_section('airline_tablinesel', '%( %'.(i+1).'T %{airline#extensions#tabline#title('.(i+1).')} %)')
2013-08-28 13:51:54 +00:00
else
call b.add_section('airline_tabline', '%( %'.(i+1).'T %{airline#extensions#tabline#title('.(i+1).')} %)')
2013-08-28 13:51:54 +00:00
endif
endfor
call b.add_raw('%T')
call b.add_section('airline_tablinefill', '')
2013-08-28 13:51:54 +00:00
call b.split()
call b.add_section('airline_tabline', ' %999XX ')
call b.add_section('airline_tablinetype', ' tabs ')
2013-08-28 13:51:54 +00:00
endif
return b.build()
endfunction
function! airline#extensions#tabline#title(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
2013-09-02 03:03:36 +00:00
return airline#extensions#tabline#get_buffer_name(buflist[winnr - 1])
endfunction
function! airline#extensions#tabline#get_buffer_name(nr)
let name = bufname(a:nr)
if empty(name)
return '[No Name]'
endif
return fnamemodify(name, s:fmod)
2013-08-28 13:51:54 +00:00
endfunction