improve buffer index mode and fix usages where there's overflow

This commit is contained in:
Bailey Ling 2014-09-17 09:52:08 -04:00
parent 8421f03178
commit 4dab93470f
2 changed files with 58 additions and 25 deletions

View File

@ -28,6 +28,21 @@ let s:buf_min_count = get(g:, 'airline#extensions#tabline#buffer_min_count', 0)
let s:tab_min_count = get(g:, 'airline#extensions#tabline#tab_min_count', 0)
let s:spc = g:airline_symbols.space
let s:number_map = &encoding == 'utf-8'
\ ? {
\ '0': '⁰',
\ '1': '¹',
\ '2': '²',
\ '3': '³',
\ '4': '⁴',
\ '5': '⁵',
\ '6': '⁶',
\ '7': '⁷',
\ '8': '⁸',
\ '9': '⁹'
\ }
\ : {}
function! airline#extensions#tabline#init(ext)
if has('gui_running')
set guioptions-=e
@ -198,6 +213,7 @@ function! s:get_visible_buffers()
endif
endif
let g:current_visible_buffers = buffers
return buffers
endfunction
@ -214,10 +230,7 @@ function! s:get_buffers()
endif
endif
if s:buffer_idx_mode
let s:buffer_idx_mode_buffers = []
let l:index = 1
endif
let b = airline#builder#new(s:builder_context)
let tab_bufs = tabpagebuflist(tabpagenr())
for nr in s:get_visible_buffers()
@ -225,6 +238,7 @@ function! s:get_buffers()
call b.add_raw('%#airline_tabhid#...')
continue
endif
if cur == nr
if g:airline_detect_modified && getbufvar(nr, '&modified')
let group = 'airline_tabmod'
@ -241,10 +255,14 @@ function! s:get_buffers()
let group = 'airline_tabhid'
endif
endif
if s:buffer_idx_mode
if len(s:number_map) > 0
call b.add_section(group, s:spc . get(s:number_map, l:index, '') . '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)' . s:spc)
else
call b.add_section(group, '['.l:index.s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.']')
endif
let l:index = l:index + 1
call add(s:buffer_idx_mode_buffers, nr)
else
call b.add_section(group, s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.s:spc)
endif
@ -264,21 +282,28 @@ function! s:select_tab(buf_index)
if exists('t:NERDTreeBufName') && bufname('%') == t:NERDTreeBufName
return
endif
if a:buf_index <= len(s:buffer_idx_mode_buffers)
exec "b!" . s:buffer_idx_mode_buffers[a:buf_index - 1]
let idx = a:buf_index
if g:current_visible_buffers[0] == -1
let idx = idx + 1
endif
let buf = get(g:current_visible_buffers, idx, 0)
if buf != 0
exec 'b!' . buf
endif
endfunction
function! s:define_buffer_idx_mode_mappings()
noremap <unique> <Plug>AirlineSelectTab1 :call <SID>select_tab(1)<CR>
noremap <unique> <Plug>AirlineSelectTab2 :call <SID>select_tab(2)<CR>
noremap <unique> <Plug>AirlineSelectTab3 :call <SID>select_tab(3)<CR>
noremap <unique> <Plug>AirlineSelectTab4 :call <SID>select_tab(4)<CR>
noremap <unique> <Plug>AirlineSelectTab5 :call <SID>select_tab(5)<CR>
noremap <unique> <Plug>AirlineSelectTab6 :call <SID>select_tab(6)<CR>
noremap <unique> <Plug>AirlineSelectTab7 :call <SID>select_tab(7)<CR>
noremap <unique> <Plug>AirlineSelectTab8 :call <SID>select_tab(8)<CR>
noremap <unique> <Plug>AirlineSelectTab9 :call <SID>select_tab(9)<CR>
noremap <unique> <Plug>AirlineSelectTab1 :call <SID>select_tab(0)<CR>
noremap <unique> <Plug>AirlineSelectTab2 :call <SID>select_tab(1)<CR>
noremap <unique> <Plug>AirlineSelectTab3 :call <SID>select_tab(2)<CR>
noremap <unique> <Plug>AirlineSelectTab4 :call <SID>select_tab(3)<CR>
noremap <unique> <Plug>AirlineSelectTab5 :call <SID>select_tab(4)<CR>
noremap <unique> <Plug>AirlineSelectTab6 :call <SID>select_tab(5)<CR>
noremap <unique> <Plug>AirlineSelectTab7 :call <SID>select_tab(6)<CR>
noremap <unique> <Plug>AirlineSelectTab8 :call <SID>select_tab(7)<CR>
noremap <unique> <Plug>AirlineSelectTab9 :call <SID>select_tab(8)<CR>
endfunction
function! s:get_tabs()

View File

@ -405,15 +405,23 @@ eclim <https://eclim.org>
let g:airline#extensions#tabline#show_tab_type = 1
* enable/disable displaying index of the buffer.
" When enabled, a map between buffer index and buffer number
" will be maintained. Up to nine mappings will be defined to
" allow switching to a buffer using its index easily.
" The mappings have the form <Plug>AirlineSelectTab{x}
" where x is a number from 1 to 9. One can defining mappings like this
" nmap <leader>1 <Plug>AirlineSelectTab1
" Note that buffering switching won't happen if the current buffer
" is a NERDTree buffer.
When enabled, numbers will be displayed in the tabline and mappings will be
exposed to allow you to select a buffer directly. Up to 9 mappings will be
exposed.
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
Note: Mappings will be ignored within a NERDTree buffer.
* defines the name of a formatter for how buffer names are displayed. >
let g:airline#extensions#tabline#formatter = 'default'