2020-06-11 04:18:30 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
|
2015-02-19 10:24:05 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2016-01-28 12:11:11 +08:00
|
|
|
let s:spc = g:airline_symbols.space
|
2015-02-19 10:24:05 +08:00
|
|
|
let s:current_bufnr = -1
|
|
|
|
let s:current_tabnr = -1
|
|
|
|
let s:current_modified = 0
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#tabs#off()
|
|
|
|
augroup airline_tabline_tabs
|
|
|
|
autocmd!
|
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#tabs#on()
|
|
|
|
augroup airline_tabline_tabs
|
|
|
|
autocmd!
|
2015-02-19 10:37:13 +08:00
|
|
|
autocmd BufDelete * call airline#extensions#tabline#tabs#invalidate()
|
2015-02-19 10:24:05 +08:00
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
2015-02-19 10:37:13 +08:00
|
|
|
function! airline#extensions#tabline#tabs#invalidate()
|
|
|
|
let s:current_bufnr = -1
|
|
|
|
endfunction
|
|
|
|
|
2015-02-19 10:24:05 +08:00
|
|
|
function! airline#extensions#tabline#tabs#get()
|
|
|
|
let curbuf = bufnr('%')
|
|
|
|
let curtab = tabpagenr()
|
2018-01-05 01:15:40 +08:00
|
|
|
try
|
|
|
|
call airline#extensions#tabline#tabs#map_keys()
|
|
|
|
catch
|
|
|
|
" no-op
|
|
|
|
endtry
|
2018-03-14 23:25:03 +08:00
|
|
|
if curbuf == s:current_bufnr && curtab == s:current_tabnr && &columns == s:column_width
|
2015-02-19 10:24:05 +08:00
|
|
|
if !g:airline_detect_modified || getbufvar(curbuf, '&modified') == s:current_modified
|
|
|
|
return s:current_tabline
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
let b = airline#extensions#tabline#new_builder()
|
2016-01-28 12:11:11 +08:00
|
|
|
|
2019-04-17 15:04:56 +08:00
|
|
|
call airline#extensions#tabline#add_label(b, 'tabs', 0)
|
2018-03-13 04:27:52 +08:00
|
|
|
|
2018-03-16 01:04:19 +08:00
|
|
|
function! b.get_group(i) dict
|
|
|
|
let curtab = tabpagenr()
|
|
|
|
let group = 'airline_tab'
|
|
|
|
if a:i == curtab
|
2016-04-12 06:22:42 +08:00
|
|
|
let group = 'airline_tabsel'
|
2015-02-19 10:24:05 +08:00
|
|
|
if g:airline_detect_modified
|
2018-03-16 01:04:19 +08:00
|
|
|
for bi in tabpagebuflist(curtab)
|
2015-02-19 10:24:05 +08:00
|
|
|
if getbufvar(bi, '&modified')
|
2016-04-12 06:22:42 +08:00
|
|
|
let group = 'airline_tabmod'
|
2015-02-19 10:24:05 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
2016-04-12 06:22:42 +08:00
|
|
|
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0
|
2015-02-19 10:24:05 +08:00
|
|
|
endif
|
2018-03-16 01:04:19 +08:00
|
|
|
return group
|
|
|
|
endfunction
|
|
|
|
|
2018-03-16 02:14:50 +08:00
|
|
|
function! b.get_title(i) dict
|
2016-02-16 03:01:34 +08:00
|
|
|
let val = '%('
|
2018-01-05 01:20:25 +08:00
|
|
|
|
|
|
|
if get(g:, 'airline#extensions#tabline#show_tab_nr', 1)
|
2018-03-16 02:14:50 +08:00
|
|
|
let tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
|
|
|
let val .= airline#extensions#tabline#tabs#tabnr_formatter(tab_nr_type, a:i)
|
2016-02-16 03:01:34 +08:00
|
|
|
endif
|
2018-03-16 01:04:19 +08:00
|
|
|
|
|
|
|
return val.'%'.a:i.'T %{airline#extensions#tabline#title('.a:i.')} %)'
|
|
|
|
endfunction
|
|
|
|
|
2018-03-19 22:27:06 +08:00
|
|
|
call b.insert_titles(curtab, 1, tabpagenr('$'))
|
2015-02-19 10:24:05 +08:00
|
|
|
|
2016-02-22 04:03:55 +08:00
|
|
|
call b.add_section('airline_tabfill', '')
|
|
|
|
call b.split()
|
|
|
|
call b.add_section('airline_tabfill', '')
|
|
|
|
|
2018-01-05 01:20:25 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_close_button', 1)
|
|
|
|
call b.add_section('airline_tab_right', ' %999X'.
|
|
|
|
\ get(g:, 'airline#extensions#tabline#close_symbol', 'X').' ')
|
2016-02-22 04:03:55 +08:00
|
|
|
endif
|
|
|
|
|
2018-01-05 01:20:25 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_splits', 1) == 1
|
2016-02-22 04:03:55 +08:00
|
|
|
let buffers = tabpagebuflist(curtab)
|
|
|
|
for nr in buffers
|
2016-04-12 06:22:42 +08:00
|
|
|
let group = airline#extensions#tabline#group_of_bufnr(buffers, nr) . "_right"
|
2016-02-22 04:03:55 +08:00
|
|
|
call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)')
|
|
|
|
endfor
|
2018-03-19 22:06:55 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
2019-04-17 15:04:56 +08:00
|
|
|
call airline#extensions#tabline#add_label(b, 'buffers', 1)
|
2018-03-19 22:06:55 +08:00
|
|
|
endif
|
2018-01-05 01:34:48 +08:00
|
|
|
endif
|
2019-03-08 21:05:38 +08:00
|
|
|
call airline#extensions#tabline#add_tab_label(b)
|
2015-02-19 10:24:05 +08:00
|
|
|
|
|
|
|
let s:current_bufnr = curbuf
|
|
|
|
let s:current_tabnr = curtab
|
2018-03-14 23:25:03 +08:00
|
|
|
let s:column_width = &columns
|
2015-02-19 10:24:05 +08:00
|
|
|
let s:current_tabline = b.build()
|
|
|
|
return s:current_tabline
|
|
|
|
endfunction
|
2016-01-21 03:22:12 +08:00
|
|
|
|
2016-07-04 03:09:42 +08:00
|
|
|
function! airline#extensions#tabline#tabs#map_keys()
|
2018-07-14 03:33:03 +08:00
|
|
|
if maparg('<Plug>AirlineSelectTab1', 'n') is# ':1tabn<CR>'
|
2017-06-27 20:44:03 +08:00
|
|
|
return
|
|
|
|
endif
|
2019-02-07 15:17:33 +08:00
|
|
|
let bidx_mode = get(g:, 'airline#extensions#tabline#buffer_idx_mode', 1)
|
|
|
|
if bidx_mode == 1
|
|
|
|
for i in range(1, 9)
|
|
|
|
exe printf('noremap <silent> <Plug>AirlineSelectTab%d :%dtabn<CR>', i, i)
|
|
|
|
endfor
|
|
|
|
else
|
2019-02-08 14:55:35 +08:00
|
|
|
for i in range(11, 99)
|
|
|
|
exe printf('noremap <silent> <Plug>AirlineSelectTab%d :%dtabn<CR>', i, i-10)
|
2019-02-07 15:17:33 +08:00
|
|
|
endfor
|
|
|
|
endif
|
2016-01-21 03:22:12 +08:00
|
|
|
noremap <silent> <Plug>AirlineSelectPrevTab gT
|
|
|
|
" tabn {count} goes to count tab does not go {count} tab pages forward!
|
2016-02-05 02:03:25 +08:00
|
|
|
noremap <silent> <Plug>AirlineSelectNextTab :<C-U>exe repeat(':tabn\|', v:count1)<cr>
|
2016-01-21 03:22:12 +08:00
|
|
|
endfunction
|
2018-01-05 03:41:55 +08:00
|
|
|
|
2019-02-03 00:45:55 +08:00
|
|
|
function! airline#extensions#tabline#tabs#tabnr_formatter(nr, i) abort
|
2018-01-05 03:41:55 +08:00
|
|
|
let formatter = get(g:, 'airline#extensions#tabline#tabnr_formatter', 'tabnr')
|
2019-02-03 00:45:55 +08:00
|
|
|
try
|
2019-02-03 04:57:15 +08:00
|
|
|
return airline#extensions#tabline#formatters#{formatter}#format(a:nr, a:i)
|
2019-02-03 00:45:55 +08:00
|
|
|
catch /^Vim\%((\a\+)\)\=:E117/ " catch E117, unknown function
|
|
|
|
" Function not found
|
|
|
|
return call(formatter, [a:nr, a:i])
|
|
|
|
catch
|
|
|
|
" something went wrong, return an empty string
|
|
|
|
return ""
|
|
|
|
endtry
|
2018-01-05 03:41:55 +08:00
|
|
|
endfunction
|