diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index e9c72f6..3f4aa31 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -178,14 +178,19 @@ function! airline#extensions#load() call airline#extensions#virtualenv#init(s:ext) endif - if (get(g:, 'airline#extensions#whitespace#enabled', 1) && get(g:, 'airline_detect_whitespace', 1)) - call airline#extensions#whitespace#init(s:ext) - endif if (get(g:, 'airline#extensions#syntastic#enabled', 1) && get(g:, 'airline_enable_syntastic', 1)) \ && exists(':SyntasticCheck') call airline#extensions#syntastic#init(s:ext) endif + if (get(g:, 'airline#extensions#whitespace#enabled', 1) && get(g:, 'airline_detect_whitespace', 1)) + call airline#extensions#whitespace#init(s:ext) + endif + + if get(g:, 'airline#extensions#tabline#enabled', 0) + call airline#extensions#tabline#init(s:ext) + endif + " load all other extensions not part of the default distribution for file in split(globpath(&rtp, "autoload/airline/extensions/*.vim"), "\n") " we have to check both resolved and unresolved paths, since it's possible diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim new file mode 100644 index 0000000..d33b42e --- /dev/null +++ b/autoload/airline/extensions/tabline.vim @@ -0,0 +1,49 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! airline#extensions#tabline#init(ext) + set tabline=%!airline#extensions#tabline#get() +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 + call b.add_section('TabLineSel', '%( %{fnamemodify(bufname('.nr.'), ":t")} %)') + else + call b.add_section('TabLine', '%( %{fnamemodify(bufname('.nr.'), ":t")} %)') + endif + endif + endfor + call b.add_section('TabLineFill', '') + call b.split() + call b.add_section('TabLineSel', ' buffers ') + else + let s = '' + for i in range(tabpagenr('$')) + if i + 1 == tabpagenr() + call b.add_section('TabLineSel', '%( %'.(i+1).'T %{airline#extensions#tabline#title('.(i+1).')} %)') + else + call b.add_section('TabLine', '%( %'.(i+1).'T %{airline#extensions#tabline#title('.(i+1).')} %)') + endif + endfor + call b.add_raw('%T') + call b.add_section('TabLineFill', '') + call b.split() + call b.add_section('TabLine', ' %999XX ') + call b.add_section('TabLineSel', ' tabs ') + endif + return b.build() +endfunction + +function! airline#extensions#tabline#title(n) + let buflist = tabpagebuflist(a:n) + let winnr = tabpagewinnr(a:n) + return fnamemodify(bufname(buflist[winnr - 1]), ':p:.') +endfunction +