2013-08-28 09:51:54 -04:00
|
|
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2013-09-01 20:06:41 -04:00
|
|
|
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
|
2013-09-02 18:01:52 -04:00
|
|
|
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
2013-09-01 20:06:41 -04:00
|
|
|
|
2013-08-28 09:51:54 -04:00
|
|
|
function! airline#extensions#tabline#init(ext)
|
2013-09-03 10:13:58 -04:00
|
|
|
set showtabline=2
|
2013-08-28 09:51:54 -04:00
|
|
|
set tabline=%!airline#extensions#tabline#get()
|
2013-09-01 19:39:06 -04:00
|
|
|
|
|
|
|
call a:ext.add_theme_func('airline#extensions#tabline#load_theme')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#load_theme(palette)
|
2013-09-02 22:36:28 -04:00
|
|
|
call airline#highlighter#exec('airline_tab', a:palette.normal.airline_b)
|
|
|
|
call airline#highlighter#exec('airline_tabsel', a:palette.normal.airline_a)
|
|
|
|
call airline#highlighter#exec('airline_tabtype', a:palette.visual.airline_a)
|
|
|
|
call airline#highlighter#exec('airline_tabfill', a:palette.normal.airline_c)
|
|
|
|
call airline#highlighter#exec('airline_tabmod', a:palette.insert.airline_a)
|
2013-08-28 09:51:54 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#get()
|
|
|
|
if tabpagenr('$') == 1
|
2013-09-02 18:01:52 -04:00
|
|
|
return s:get_buffers()
|
2013-08-28 09:51:54 -04:00
|
|
|
else
|
2013-09-02 18:01:52 -04:00
|
|
|
return s:get_tabs()
|
2013-08-28 09:51:54 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#title(n)
|
|
|
|
let buflist = tabpagebuflist(a:n)
|
|
|
|
let winnr = tabpagewinnr(a:n)
|
2013-09-01 23:03:36 -04: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 09:51:54 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-09-02 18:01:52 -04:00
|
|
|
function! s:get_buffers()
|
|
|
|
let b = airline#builder#new({'active': 1})
|
|
|
|
let cur = bufnr('%')
|
|
|
|
for nr in range(1, bufnr('$'))
|
|
|
|
if buflisted(nr) && bufexists(nr)
|
|
|
|
for ex in s:excludes
|
|
|
|
if match(bufname(nr), ex)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
endfor
|
2013-09-02 22:36:28 -04:00
|
|
|
if cur == nr
|
|
|
|
if g:airline_detect_modified && getbufvar(nr, '&modified')
|
|
|
|
let group = 'airline_tabmod'
|
|
|
|
else
|
|
|
|
let group = 'airline_tabsel'
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let group = 'airline_tab'
|
|
|
|
endif
|
2013-09-02 18:01:52 -04:00
|
|
|
call b.add_section(group, '%( %{airline#extensions#tabline#get_buffer_name('.nr.')} %)')
|
|
|
|
endif
|
|
|
|
endfor
|
2013-09-02 22:36:28 -04:00
|
|
|
call b.add_section('airline_tabfill', '')
|
2013-09-02 18:01:52 -04:00
|
|
|
call b.split()
|
2013-09-02 22:36:28 -04:00
|
|
|
call b.add_section('airline_tabtype', ' buffers ')
|
2013-09-02 18:01:52 -04:00
|
|
|
return b.build()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:get_tabs()
|
|
|
|
let b = airline#builder#new({'active': 1})
|
|
|
|
for i in range(1, tabpagenr('$'))
|
2013-09-02 22:36:28 -04:00
|
|
|
let group = i == tabpagenr() ? 'airline_tabsel' : 'airline_tab'
|
2013-09-02 18:01:52 -04:00
|
|
|
call b.add_section(group, ' %{len(tabpagebuflist(tabpagenr()))}%( %'.i.'T %{airline#extensions#tabline#title('.i.')} %)')
|
|
|
|
endfor
|
|
|
|
call b.add_raw('%T')
|
2013-09-02 22:36:28 -04:00
|
|
|
call b.add_section('airline_tabfill', '')
|
2013-09-02 18:01:52 -04:00
|
|
|
call b.split()
|
2013-09-02 22:36:28 -04:00
|
|
|
call b.add_section('airline_tab', ' %999XX ')
|
|
|
|
call b.add_section('airline_tabtype', ' tabs ')
|
2013-09-02 18:01:52 -04:00
|
|
|
return b.build()
|
|
|
|
endfunction
|
|
|
|
|