From 105e9daaf71d1493cdf342a2cc736cbb513cc1a5 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 4 Feb 2019 21:47:11 +0100 Subject: [PATCH] tabline: Make the PlugAirlineSelectTab buffers work as expected for bufferlist. fixes #1857 --- .../airline/extensions/tabline/buffers.vim | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/autoload/airline/extensions/tabline/buffers.vim b/autoload/airline/extensions/tabline/buffers.vim index fb6043b3..8e9e9345 100644 --- a/autoload/airline/extensions/tabline/buffers.vim +++ b/autoload/airline/extensions/tabline/buffers.vim @@ -164,14 +164,19 @@ function! s:select_tab(buf_index) return endif - let idx = a:buf_index - if s:current_visible_buffers[0] == -1 - let idx = idx + 1 - endif - - let buf = get(s:current_visible_buffers, idx, 0) - if buf != 0 - exec 'b!' . buf + let buf = index(s:current_visible_buffers, a:buf_index) + if buf >= 0 + try + exec 'b!' . s:current_visible_buffers[buf] + catch /^Vim\%((\a\+)\)\=:E939/ + " buffer 0 does not exist + catch /^Vim\%((\a\+)\)\=:E86/ + " should not happen hopefully ;) + call airline#util#warning(printf("Buffer Number %d does not exist", a:buf_index)) + catch + " catch all, something broken... :| + call airline#util#warning("Exception not handled: ". v:exception) + endtry endif endfunction @@ -185,17 +190,19 @@ endfunction function! s:map_keys() if get(g:, 'airline#extensions#tabline#buffer_idx_mode', 1) - noremap AirlineSelectTab1 :call select_tab(0) - noremap AirlineSelectTab2 :call select_tab(1) - noremap AirlineSelectTab3 :call select_tab(2) - noremap AirlineSelectTab4 :call select_tab(3) - noremap AirlineSelectTab5 :call select_tab(4) - noremap AirlineSelectTab6 :call select_tab(5) - noremap AirlineSelectTab7 :call select_tab(6) - noremap AirlineSelectTab8 :call select_tab(7) - noremap AirlineSelectTab9 :call select_tab(8) + noremap AirlineSelectTab1 :call select_tab(1) + noremap AirlineSelectTab2 :call select_tab(2) + noremap AirlineSelectTab3 :call select_tab(3) + noremap AirlineSelectTab4 :call select_tab(4) + noremap AirlineSelectTab5 :call select_tab(5) + noremap AirlineSelectTab6 :call select_tab(6) + noremap AirlineSelectTab7 :call select_tab(7) + noremap AirlineSelectTab8 :call select_tab(8) + noremap AirlineSelectTab9 :call select_tab(9) noremap AirlineSelectPrevTab :call jump_to_tab(-v:count1) noremap AirlineSelectNextTab :call jump_to_tab(v:count1) + " Enable this for debugging + " com! AirlineBufferList :echo map(copy(s:current_visible_buffers), {i,k -> k.": ".bufname(k)}) endif endfunction