2016-01-12 20:47:44 +08:00
|
|
|
" MIT License. Copyright (c) 2016 Kevin Sapper
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
|
|
|
let s:current_bufnr = -1
|
|
|
|
let s:current_tabnr = -1
|
|
|
|
let s:current_tabline = ''
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#ctrlspace#off()
|
|
|
|
augroup airline_tabline_ctrlspace
|
|
|
|
autocmd!
|
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#ctrlspace#on()
|
|
|
|
augroup airline_tabline_ctrlspace
|
|
|
|
autocmd!
|
|
|
|
autocmd BufDelete * call airline#extensions#tabline#ctrlspace#invalidate()
|
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#ctrlspace#invalidate()
|
|
|
|
let s:current_bufnr = -1
|
|
|
|
let s:current_tabnr = -1
|
|
|
|
endfunction
|
|
|
|
|
2016-02-25 18:03:50 +08:00
|
|
|
function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pos)
|
|
|
|
if a:pos == 0
|
|
|
|
let pos_extension = ''
|
|
|
|
else
|
|
|
|
let pos_extension = '_right'
|
2016-01-12 20:47:44 +08:00
|
|
|
endif
|
|
|
|
|
2016-02-25 18:03:50 +08:00
|
|
|
let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab)
|
2017-08-08 15:01:24 +08:00
|
|
|
" add by tenfy(tenfyzhong@qq.com)
|
|
|
|
" if the current buffer no in the buffer list
|
|
|
|
" return false and no redraw tabline.
|
|
|
|
" Fixes #1515. if there a BufEnter autocmd execute redraw. The tabline may no update.
|
|
|
|
let bufnr_list = map(copy(s:buffer_list), 'v:val["index"]')
|
|
|
|
if index(bufnr_list, a:cur_buf) == -1
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2016-01-12 20:47:44 +08:00
|
|
|
for buffer in s:buffer_list
|
2016-02-25 18:03:50 +08:00
|
|
|
if a:cur_buf == buffer.index
|
2016-01-12 20:47:44 +08:00
|
|
|
if buffer.modified
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabmod'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
else
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabsel'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
if buffer.modified
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabmod_unsel'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
elseif buffer.visible
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tab'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
else
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabhid'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)'
|
2016-03-20 00:38:53 +08:00
|
|
|
|
|
|
|
if has("tablineat")
|
2016-06-02 22:00:00 +08:00
|
|
|
let buf_name = '%'.buffer.index.'@airline#extensions#tabline#buffers#clickbuf@'.buf_name.'%X'
|
2016-03-20 00:38:53 +08:00
|
|
|
endif
|
|
|
|
|
2016-02-25 18:03:50 +08:00
|
|
|
call a:builder.add_section_spaced(group, buf_name)
|
2016-01-12 20:47:44 +08:00
|
|
|
endfor
|
2017-08-08 15:01:24 +08:00
|
|
|
" add by tenfy(tenfyzhong@qq.com)
|
|
|
|
" if the selected buffer was updated
|
|
|
|
" return true
|
|
|
|
return 1
|
2016-02-25 18:03:50 +08:00
|
|
|
endfunction
|
2016-01-12 20:47:44 +08:00
|
|
|
|
2016-02-25 18:03:50 +08:00
|
|
|
function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos)
|
|
|
|
if a:pos == 0
|
|
|
|
let pos_extension = ''
|
|
|
|
else
|
|
|
|
let pos_extension = '_right'
|
|
|
|
endif
|
2016-01-12 20:47:44 +08:00
|
|
|
|
|
|
|
for tab in s:tab_list
|
|
|
|
if tab.current
|
|
|
|
if tab.modified
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabmod'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
else
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabsel'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
if tab.modified
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabmod_unsel'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
else
|
2016-02-25 18:03:50 +08:00
|
|
|
let group = 'airline_tabhid'.pos_extension
|
2016-01-12 20:47:44 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-03-20 00:38:53 +08:00
|
|
|
call a:builder.add_section_spaced(group, '%'.tab.index.'T'.tab.title.ctrlspace#api#TabBuffersNumber(tab.index).'%T')
|
2016-01-12 20:47:44 +08:00
|
|
|
endfor
|
2016-02-25 18:03:50 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#ctrlspace#get()
|
|
|
|
let cur_buf = bufnr('%')
|
2018-01-05 00:27:34 +08:00
|
|
|
let buffer_label = get(g:, 'airline#extensions#tabline#buffers_label', 'buffers')
|
|
|
|
let tab_label = get(g:, 'airline#extensions#tabline#tabs_label', 'tabs')
|
|
|
|
let switch_buffers_and_tabs = get(g:, 'airline#extensions#tabline#switch_buffers_and_tabs', 0)
|
2016-02-25 18:03:50 +08:00
|
|
|
|
2018-01-05 01:15:40 +08:00
|
|
|
try
|
|
|
|
call airline#extensions#tabline#tabs#map_keys()
|
|
|
|
catch
|
|
|
|
" no-op
|
|
|
|
endtry
|
2016-02-25 18:03:50 +08:00
|
|
|
let s:tab_list = ctrlspace#api#TabList()
|
|
|
|
for tab in s:tab_list
|
|
|
|
if tab.current
|
|
|
|
let cur_tab = tab.index
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if cur_buf == s:current_bufnr && cur_tab == s:current_tabnr
|
|
|
|
return s:current_tabline
|
|
|
|
endif
|
|
|
|
|
|
|
|
let builder = airline#extensions#tabline#new_builder()
|
|
|
|
|
2016-02-25 18:19:52 +08:00
|
|
|
" Add left tabline content
|
2018-01-05 00:27:34 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0
|
2016-02-25 18:19:52 +08:00
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0)
|
2018-01-05 00:27:34 +08:00
|
|
|
elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0
|
2017-08-08 15:01:24 +08:00
|
|
|
" add by tenfy(tenfyzhong@qq.com)
|
|
|
|
" if current buffer no in the buffer list, does't update tabline
|
|
|
|
if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) == 0
|
|
|
|
return s:current_tabline
|
|
|
|
endif
|
2016-02-25 18:03:50 +08:00
|
|
|
else
|
2018-01-05 00:27:34 +08:00
|
|
|
if switch_buffers_and_tabs == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', buffer_label)
|
2017-08-08 15:01:24 +08:00
|
|
|
" add by tenfy(tenfyzhong@qq.com)
|
|
|
|
" if current buffer no in the buffer list, does't update tabline
|
|
|
|
if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) == 0
|
|
|
|
return s:current_tabline
|
|
|
|
endif
|
2016-02-25 18:19:52 +08:00
|
|
|
else
|
2018-01-05 00:27:34 +08:00
|
|
|
call builder.add_section_spaced('airline_tabtype', tab_label)
|
2016-02-25 18:19:52 +08:00
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0)
|
|
|
|
endif
|
2016-02-25 18:03:50 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
call builder.add_section('airline_tabfill', '')
|
|
|
|
call builder.split()
|
|
|
|
call builder.add_section('airline_tabfill', '')
|
|
|
|
|
2016-02-25 18:19:52 +08:00
|
|
|
" Add right tabline content
|
2018-01-05 00:27:34 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', tab_label)
|
|
|
|
elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', buffer_label)
|
2016-02-25 18:03:50 +08:00
|
|
|
else
|
2018-01-05 00:27:34 +08:00
|
|
|
if switch_buffers_and_tabs == 0
|
2016-02-25 18:19:52 +08:00
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1)
|
2018-01-05 00:27:34 +08:00
|
|
|
call builder.add_section_spaced('airline_tabtype', tab_label)
|
2016-02-25 18:19:52 +08:00
|
|
|
else
|
2017-08-08 15:01:24 +08:00
|
|
|
" add by tenfy(tenfyzhong@qq.com)
|
|
|
|
" if current buffer no in the buffer list, does't update tabline
|
2018-01-05 00:58:36 +08:00
|
|
|
if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 1) == 0
|
2017-08-08 15:01:24 +08:00
|
|
|
return s:current_tabline
|
|
|
|
endif
|
2018-01-05 00:27:34 +08:00
|
|
|
call builder.add_section_spaced('airline_tabtype', buffer_label)
|
2016-02-25 18:19:52 +08:00
|
|
|
endif
|
2016-02-25 18:03:50 +08:00
|
|
|
endif
|
2016-01-12 20:47:44 +08:00
|
|
|
|
|
|
|
let s:current_bufnr = cur_buf
|
|
|
|
let s:current_tabnr = cur_tab
|
2016-02-25 18:03:50 +08:00
|
|
|
let s:current_tabline = builder.build()
|
2016-01-12 20:47:44 +08:00
|
|
|
return s:current_tabline
|
|
|
|
endfunction
|