Use tabline builder for buffers tabline

This commit is contained in:
mrmr1993 2018-03-15 19:36:30 +00:00
parent d9e68039b8
commit 275ec4fe63
2 changed files with 42 additions and 23 deletions

View File

@ -69,24 +69,45 @@ function! airline#extensions#tabline#buffers#get()
if show_buf_label_first if show_buf_label_first
call airline#extensions#tabline#add_label(b, 'buffers') call airline#extensions#tabline#add_label(b, 'buffers')
endif endif
let pgroup = ''
for nr in s:get_visible_buffers() let b.tab_bufs = tabpagebuflist(tabpagenr())
if nr < 0
call b.add_raw('%#airline_tabhid#...') let b.overflow_group = 'airline_tabhid'
continue let b.buffers = airline#extensions#tabline#buflist#list()
if get(g:, 'airline#extensions#tabline#current_first', 0)
if index(b.buffers, cur) > -1
call remove(b.buffers, index(b.buffers, cur))
endif endif
let b.buffers = [cur] + b.buffers
endif
let group = airline#extensions#tabline#group_of_bufnr(tab_bufs, nr) function! b.get_group(i) dict
let bufnum = get(self.buffers, a:i, -1)
if nr == cur if bufnum == -1
return ''
endif
let group = airline#extensions#tabline#group_of_bufnr(self.tab_bufs, bufnum)
if bufnum == bufnr('%')
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0 let s:current_modified = (group == 'airline_tabmod') ? 1 : 0
endif endif
return group
endfunction
" Neovim feature: Have clickable buffers if has("tablineat")
if has("tablineat") function! b.get_pretitle(i) dict
call b.add_raw('%'.nr.'@airline#extensions#tabline#buffers#clickbuf@') let bufnum = get(self.buffers, a:i, -1)
endif return '%'.bufnum.'@airline#extensions#tabline#buffers#clickbuf@'
endfunction
function b.get_posttitle(i) dict
return '%X'
endfunction
endif
function! b.get_title(i) dict
let bufnum = get(self.buffers, a:i, -1)
let group = self.get_group(a:i)
let pgroup = self.get_group(a:i - 1)
if get(g:, 'airline_powerline_fonts', 0) if get(g:, 'airline_powerline_fonts', 0)
let space = s:spc let space = s:spc
else else
@ -95,20 +116,16 @@ function! airline#extensions#tabline#buffers#get()
if get(g:, 'airline#extensions#tabline#buffer_idx_mode', 0) if get(g:, 'airline#extensions#tabline#buffer_idx_mode', 0)
if len(s:number_map) > 0 if len(s:number_map) > 0
call b.add_section(group, space. get(s:number_map, index, '') . '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)' . s:spc) return space. get(s:number_map, a:i, '') . '%(%{airline#extensions#tabline#get_buffer_name('.bufnum.')}%)' . s:spc
else else
call b.add_section(group, '['.index.s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.']') return '['.a:i.s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.bufnum.')}%)'.']'
endif endif
let index += 1
else else
call b.add_section(group, space.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.s:spc) return space.'%(%{airline#extensions#tabline#get_buffer_name('.bufnum.')}%)'.s:spc
endif endif
endfunction
if has("tablineat") call b.insert_tabs(index(b.buffers, cur), 0, len(b.buffers) - 1)
call b.add_raw('%X')
endif
let pgroup=group
endfor
call b.add_section('airline_tabfill', '') call b.add_section('airline_tabfill', '')
call b.split() call b.split()

View File

@ -87,18 +87,20 @@ function! s:prototype.build() dict
if get(g:, 'airline#extensions#tabline#current_first', 0) if get(g:, 'airline#extensions#tabline#current_first', 0)
let self._left_position -= 1 let self._left_position -= 1
endif endif
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, self._left_position) call self.insert_raw('%#'.self.overflow_group.'#'.skipped_tabs_marker, self._left_position)
let self._right_position += 1 let self._right_position += 1
endif endif
if self._right_tab <= self._last_tab if self._right_tab <= self._last_tab
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, self._right_position) call self.insert_raw('%#'.self.overflow_group.'#'.skipped_tabs_marker, self._right_position)
endif endif
endif endif
return self._build() return self._build()
endfunction endfunction
let s:prototype.overflow_group = 'airline_tab'
function! s:evaluate_tabline(tabline) function! s:evaluate_tabline(tabline)
let tabline = a:tabline let tabline = a:tabline
let tabline = substitute(tabline, '%{\([^}]\+\)}', '\=eval(submatch(1))', 'g') let tabline = substitute(tabline, '%{\([^}]\+\)}', '\=eval(submatch(1))', 'g')