2016-01-12 07:47:44 -05: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 05:03:50 -05: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 07:47:44 -05:00
|
|
|
endif
|
|
|
|
|
2016-02-25 05:03:50 -05:00
|
|
|
let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab)
|
2017-08-08 03:01:24 -04: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 07:47:44 -05:00
|
|
|
for buffer in s:buffer_list
|
2016-02-25 05:03:50 -05:00
|
|
|
if a:cur_buf == buffer.index
|
2016-01-12 07:47:44 -05:00
|
|
|
if buffer.modified
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabmod'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
else
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabsel'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
if buffer.modified
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabmod_unsel'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
elseif buffer.visible
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tab'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
else
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabhid'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)'
|
2016-03-19 12:38:53 -04:00
|
|
|
|
|
|
|
if has("tablineat")
|
2016-06-02 10:00:00 -04:00
|
|
|
let buf_name = '%'.buffer.index.'@airline#extensions#tabline#buffers#clickbuf@'.buf_name.'%X'
|
2016-03-19 12:38:53 -04:00
|
|
|
endif
|
|
|
|
|
2016-02-25 05:03:50 -05:00
|
|
|
call a:builder.add_section_spaced(group, buf_name)
|
2016-01-12 07:47:44 -05:00
|
|
|
endfor
|
2017-08-08 03:01:24 -04:00
|
|
|
" add by tenfy(tenfyzhong@qq.com)
|
|
|
|
" if the selected buffer was updated
|
|
|
|
" return true
|
|
|
|
return 1
|
2016-02-25 05:03:50 -05:00
|
|
|
endfunction
|
2016-01-12 07:47:44 -05:00
|
|
|
|
2016-02-25 05:03:50 -05: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 07:47:44 -05:00
|
|
|
|
|
|
|
for tab in s:tab_list
|
|
|
|
if tab.current
|
|
|
|
if tab.modified
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabmod'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
else
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabsel'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
if tab.modified
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabmod_unsel'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
else
|
2016-02-25 05:03:50 -05:00
|
|
|
let group = 'airline_tabhid'.pos_extension
|
2016-01-12 07:47:44 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-03-19 12:38:53 -04:00
|
|
|
call a:builder.add_section_spaced(group, '%'.tab.index.'T'.tab.title.ctrlspace#api#TabBuffersNumber(tab.index).'%T')
|
2016-01-12 07:47:44 -05:00
|
|
|
endfor
|
2016-02-25 05:03:50 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#ctrlspace#get()
|
|
|
|
let cur_buf = bufnr('%')
|
2018-01-04 11:27:34 -05: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 05:03:50 -05:00
|
|
|
|
2016-07-03 15:09:42 -04:00
|
|
|
call airline#extensions#tabline#tabs#map_keys()
|
2016-02-25 05:03:50 -05: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 05:19:52 -05:00
|
|
|
" Add left tabline content
|
2018-01-04 11:27:34 -05:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0
|
2016-02-25 05:19:52 -05:00
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0)
|
2018-01-04 11:27:34 -05:00
|
|
|
elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0
|
2017-08-08 03:01:24 -04: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 05:03:50 -05:00
|
|
|
else
|
2018-01-04 11:27:34 -05:00
|
|
|
if switch_buffers_and_tabs == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', buffer_label)
|
2017-08-08 03:01:24 -04: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 05:19:52 -05:00
|
|
|
else
|
2018-01-04 11:27:34 -05:00
|
|
|
call builder.add_section_spaced('airline_tabtype', tab_label)
|
2016-02-25 05:19:52 -05:00
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0)
|
|
|
|
endif
|
2016-02-25 05:03:50 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
call builder.add_section('airline_tabfill', '')
|
|
|
|
call builder.split()
|
|
|
|
call builder.add_section('airline_tabfill', '')
|
|
|
|
|
2016-02-25 05:19:52 -05:00
|
|
|
" Add right tabline content
|
2018-01-04 11:27:34 -05: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 05:03:50 -05:00
|
|
|
else
|
2018-01-04 11:27:34 -05:00
|
|
|
if switch_buffers_and_tabs == 0
|
2016-02-25 05:19:52 -05:00
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1)
|
2018-01-04 11:27:34 -05:00
|
|
|
call builder.add_section_spaced('airline_tabtype', tab_label)
|
2016-02-25 05:19:52 -05:00
|
|
|
else
|
2017-08-08 03:01:24 -04: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
|
2018-01-04 11:27:34 -05:00
|
|
|
call builder.add_section_spaced('airline_tabtype', buffer_label)
|
2016-02-25 05:19:52 -05:00
|
|
|
endif
|
2016-02-25 05:03:50 -05:00
|
|
|
endif
|
2016-01-12 07:47:44 -05:00
|
|
|
|
|
|
|
let s:current_bufnr = cur_buf
|
|
|
|
let s:current_tabnr = cur_tab
|
2016-02-25 05:03:50 -05:00
|
|
|
let s:current_tabline = builder.build()
|
2016-01-12 07:47:44 -05:00
|
|
|
return s:current_tabline
|
|
|
|
endfunction
|