From 56eaf3733fecbf01553e7e978054370071402551 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 4 Sep 2013 19:53:04 +0000 Subject: [PATCH] add support to show tabline based on minimum buffer count (#220). --- autoload/airline/extensions/tabline.vim | 58 +++++++++++++++++++------ doc/airline.txt | 3 ++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 12188cd2..53d9a737 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -16,13 +16,22 @@ let s:builder_context = { \ 'right_alt_sep' : get(g:, 'airline#extensions#tabline#right_alt_sep', g:airline_right_alt_sep), \ } +let s:buf_min_count = get(g:, 'airline#extensions#tabline#buffer_min_count', 0) +let s:buf_len = 0 + function! airline#extensions#tabline#init(ext) if has('gui_running') set guioptions-=e endif - set showtabline=2 + set tabline=%!airline#extensions#tabline#get() + if s:buf_min_count <= 0 + set showtabline=2 + else + autocmd CursorMoved * call cursormove() + endif + call a:ext.add_theme_func('airline#extensions#tabline#load_theme') endfunction @@ -40,6 +49,19 @@ function! airline#extensions#tabline#load_theme(palette) call airline#highlighter#exec('airline_tabmod', l:tabmod) endfunction +function! s:cursormove() + let c = len(s:get_buffer_list()) + if c > s:buf_min_count + if &showtabline != 2 + set showtabline=2 + endif + else + if &showtabline != 0 + set showtabline=0 + endif + endif +endfunction + function! airline#extensions#tabline#get() if tabpagenr('$') == 1 return s:get_buffers() @@ -75,8 +97,8 @@ function! airline#extensions#tabline#get_buffer_name(nr) return _ endfunction -function! s:get_buffers() - let b = airline#builder#new(s:builder_context) +function! s:get_buffer_list() + let buffers = [] let cur = bufnr('%') for nr in range(1, bufnr('$')) if buflisted(nr) && bufexists(nr) @@ -85,18 +107,28 @@ function! s:get_buffers() continue endif endfor - 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 - call b.add_section(group, '%( %{airline#extensions#tabline#get_buffer_name('.nr.')} %)') + call add(buffers, nr) endif endfor + return buffers +endfunction + +function! s:get_buffers() + let b = airline#builder#new(s:builder_context) + let cur = bufnr('%') + for nr in s:get_buffer_list() + 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 + call b.add_section(group, '%( %{airline#extensions#tabline#get_buffer_name('.nr.')} %)') + endfor + call b.add_section('airline_tabfill', '') call b.split() call b.add_section('airline_tabtype', ' buffers ') diff --git a/doc/airline.txt b/doc/airline.txt index abe8ce0e..db39877e 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -312,6 +312,9 @@ virtualenv * configure how buffer numbers should be formatted with |printf|. > let g:airline#extensions#tabline#buffer_nr_format = '%s: ' < +* configure the minimum number of buffers needed to show the tabline. > + let g:airline#extensions#tabline#buffer_min_count = 0 +< * configure separators for the tabline only. > let g:airline#extensions#tabline#left_sep = '' let g:airline#extensions#tabline#left_alt_sep = ''