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 = ''
|
|
|
|
|
2016-02-22 14:32:36 +08:00
|
|
|
let s:buffers_label = get(g:, 'airline#extensions#tabline#buffers_label', 'buffers')
|
|
|
|
let s:tabs_label = get(g:, 'airline#extensions#tabline#tabs_label', 'tabs')
|
2016-02-25 18:19:52 +08:00
|
|
|
let s:switch_buffers_and_tabs = get(g:, 'airline#extensions#tabline#switch_buffers_and_tabs', 0)
|
|
|
|
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
2016-02-25 18:35:52 +08:00
|
|
|
let s:show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
|
2016-02-22 14:32:36 +08:00
|
|
|
|
2016-01-12 20:47:44 +08:00
|
|
|
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)
|
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-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
|
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-02-25 18:03:50 +08:00
|
|
|
call a:builder.add_section_spaced(group, tab.title.ctrlspace#api#TabBuffersNumber(tab.index))
|
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('%')
|
|
|
|
|
|
|
|
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
|
|
|
|
if s:show_buffers == 0
|
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0)
|
2016-02-25 18:35:52 +08:00
|
|
|
elseif s:show_tabs == 0
|
|
|
|
call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0)
|
2016-02-25 18:03:50 +08:00
|
|
|
else
|
2016-02-25 18:19:52 +08:00
|
|
|
if s:switch_buffers_and_tabs == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', s:buffers_label)
|
|
|
|
call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0)
|
|
|
|
else
|
|
|
|
call builder.add_section_spaced('airline_tabtype', s:tabs_label)
|
|
|
|
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
|
|
|
|
if s:show_buffers == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', s:tabs_label)
|
2016-02-25 18:35:52 +08:00
|
|
|
elseif s:show_tabs == 0
|
|
|
|
call builder.add_section_spaced('airline_tabtype', s:buffers_label)
|
2016-02-25 18:03:50 +08:00
|
|
|
else
|
2016-02-25 18:19:52 +08:00
|
|
|
if s:switch_buffers_and_tabs == 0
|
|
|
|
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1)
|
|
|
|
call builder.add_section_spaced('airline_tabtype', s:tabs_label)
|
|
|
|
else
|
|
|
|
call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 1)
|
|
|
|
call builder.add_section_spaced('airline_tabtype', s:buffers_label)
|
|
|
|
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
|