2019-03-25 07:27:10 -04:00
|
|
|
" MIT License. Copyright (c) 2013-2019 Bailey Ling et al.
|
2015-02-18 21:37:13 -05:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
|
|
|
let s:spc = g:airline_symbols.space
|
|
|
|
|
|
|
|
let s:current_bufnr = -1
|
|
|
|
let s:current_modified = 0
|
|
|
|
let s:current_tabline = ''
|
|
|
|
let s:current_visible_buffers = []
|
|
|
|
|
2016-11-25 12:36:55 -05:00
|
|
|
let s:number_map = {
|
2015-02-18 21:37:13 -05:00
|
|
|
\ '0': '⁰',
|
|
|
|
\ '1': '¹',
|
|
|
|
\ '2': '²',
|
|
|
|
\ '3': '³',
|
|
|
|
\ '4': '⁴',
|
|
|
|
\ '5': '⁵',
|
|
|
|
\ '6': '⁶',
|
|
|
|
\ '7': '⁷',
|
|
|
|
\ '8': '⁸',
|
|
|
|
\ '9': '⁹'
|
|
|
|
\ }
|
2016-11-25 12:36:55 -05:00
|
|
|
let s:number_map = &encoding == 'utf-8'
|
|
|
|
\ ? get(g:, 'airline#extensions#tabline#buffer_idx_format', s:number_map)
|
2015-02-18 21:37:13 -05:00
|
|
|
\ : {}
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#buffers#off()
|
|
|
|
augroup airline_tabline_buffers
|
|
|
|
autocmd!
|
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#buffers#on()
|
2019-02-03 04:36:07 -05:00
|
|
|
let terminal_event = has("nvim") ? 'TermOpen' : 'TerminalOpen'
|
2015-02-18 21:37:13 -05:00
|
|
|
augroup airline_tabline_buffers
|
|
|
|
autocmd!
|
2018-07-13 16:29:34 -04:00
|
|
|
autocmd BufDelete * call airline#extensions#tabline#buflist#clean()
|
2019-02-03 04:43:23 -05:00
|
|
|
if exists("##".terminal_event)
|
|
|
|
exe 'autocmd '. terminal_event. ' * call airline#extensions#tabline#buflist#clean()'
|
|
|
|
endif
|
2018-07-13 16:29:34 -04:00
|
|
|
autocmd User BufMRUChange call airline#extensions#tabline#buflist#clean()
|
2015-02-18 21:37:13 -05:00
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#buffers#invalidate()
|
|
|
|
let s:current_bufnr = -1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#buffers#get()
|
2018-01-04 07:59:47 -05:00
|
|
|
try
|
|
|
|
call <sid>map_keys()
|
|
|
|
catch
|
|
|
|
" no-op
|
|
|
|
endtry
|
2015-02-18 21:37:13 -05:00
|
|
|
let cur = bufnr('%')
|
2018-03-15 16:40:36 -04:00
|
|
|
if cur == s:current_bufnr && &columns == s:column_width
|
2015-02-18 21:37:13 -05:00
|
|
|
if !g:airline_detect_modified || getbufvar(cur, '&modified') == s:current_modified
|
|
|
|
return s:current_tabline
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
let b = airline#extensions#tabline#new_builder()
|
|
|
|
let tab_bufs = tabpagebuflist(tabpagenr())
|
2018-01-04 13:37:45 -05:00
|
|
|
let show_buf_label_first = 0
|
|
|
|
|
|
|
|
if get(g:, 'airline#extensions#tabline#buf_label_first', 0)
|
|
|
|
let show_buf_label_first = 1
|
|
|
|
endif
|
|
|
|
if show_buf_label_first
|
2019-04-17 03:04:56 -04:00
|
|
|
call airline#extensions#tabline#add_label(b, 'buffers', 0)
|
2018-01-04 13:37:45 -05:00
|
|
|
endif
|
2015-02-18 21:37:13 -05:00
|
|
|
|
2018-03-15 15:36:30 -04:00
|
|
|
let b.tab_bufs = tabpagebuflist(tabpagenr())
|
2016-02-24 19:45:17 -05:00
|
|
|
|
2018-03-15 15:36:30 -04:00
|
|
|
let b.overflow_group = 'airline_tabhid'
|
|
|
|
let b.buffers = airline#extensions#tabline#buflist#list()
|
|
|
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
|
|
|
if index(b.buffers, cur) > -1
|
|
|
|
call remove(b.buffers, index(b.buffers, cur))
|
2016-02-24 19:45:17 -05:00
|
|
|
endif
|
2018-03-15 15:36:30 -04:00
|
|
|
let b.buffers = [cur] + b.buffers
|
|
|
|
endif
|
2016-02-24 19:45:17 -05:00
|
|
|
|
2018-03-15 15:36:30 -04:00
|
|
|
function! b.get_group(i) dict
|
|
|
|
let bufnum = get(self.buffers, a:i, -1)
|
|
|
|
if bufnum == -1
|
|
|
|
return ''
|
2016-02-09 15:54:27 -05:00
|
|
|
endif
|
2018-03-15 15:36:30 -04:00
|
|
|
let group = airline#extensions#tabline#group_of_bufnr(self.tab_bufs, bufnum)
|
|
|
|
if bufnum == bufnr('%')
|
|
|
|
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0
|
|
|
|
endif
|
|
|
|
return group
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
if has("tablineat")
|
|
|
|
function! b.get_pretitle(i) dict
|
|
|
|
let bufnum = get(self.buffers, a:i, -1)
|
|
|
|
return '%'.bufnum.'@airline#extensions#tabline#buffers#clickbuf@'
|
|
|
|
endfunction
|
|
|
|
|
2018-06-13 12:52:13 -04:00
|
|
|
function! b.get_posttitle(i) dict
|
2018-03-15 15:36:30 -04:00
|
|
|
return '%X'
|
|
|
|
endfunction
|
|
|
|
endif
|
2018-01-04 08:30:16 -05:00
|
|
|
|
2018-03-15 15:36:30 -04:00
|
|
|
function! b.get_title(i) dict
|
|
|
|
let bufnum = get(self.buffers, a:i, -1)
|
|
|
|
let group = self.get_group(a:i)
|
|
|
|
let pgroup = self.get_group(a:i - 1)
|
2018-04-15 04:16:28 -04:00
|
|
|
" always add a space when powerline_fonts are used
|
|
|
|
" or for the very first item
|
|
|
|
if get(g:, 'airline_powerline_fonts', 0) || a:i == 0
|
2018-02-08 22:02:35 -05:00
|
|
|
let space = s:spc
|
|
|
|
else
|
|
|
|
let space= (pgroup == group ? s:spc : '')
|
|
|
|
endif
|
2018-01-08 03:48:36 -05:00
|
|
|
|
2018-01-07 03:51:08 -05:00
|
|
|
if get(g:, 'airline#extensions#tabline#buffer_idx_mode', 0)
|
2015-02-18 21:37:13 -05:00
|
|
|
if len(s:number_map) > 0
|
2019-02-07 02:11:47 -05:00
|
|
|
return space. s:get_number(a:i) . '%(%{airline#extensions#tabline#get_buffer_name('.bufnum.')}%)' . s:spc
|
2015-02-18 21:37:13 -05:00
|
|
|
else
|
2018-04-01 20:00:54 -04:00
|
|
|
return '['.(a:i+1).s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.bufnum.')}%)'.']'
|
2015-02-18 21:37:13 -05:00
|
|
|
endif
|
|
|
|
else
|
2018-03-15 15:36:30 -04:00
|
|
|
return space.'%(%{airline#extensions#tabline#get_buffer_name('.bufnum.')}%)'.s:spc
|
2015-02-18 21:37:13 -05:00
|
|
|
endif
|
2018-03-15 15:36:30 -04:00
|
|
|
endfunction
|
2018-01-04 08:30:16 -05:00
|
|
|
|
2018-03-31 20:16:20 -04:00
|
|
|
let current_buffer = max([index(b.buffers, cur), 0])
|
2018-03-15 16:29:25 -04:00
|
|
|
let last_buffer = len(b.buffers) - 1
|
2018-03-31 20:16:20 -04:00
|
|
|
call b.insert_titles(current_buffer, 0, last_buffer)
|
2015-02-18 21:37:13 -05:00
|
|
|
|
|
|
|
call b.add_section('airline_tabfill', '')
|
|
|
|
call b.split()
|
|
|
|
call b.add_section('airline_tabfill', '')
|
2018-01-04 13:37:45 -05:00
|
|
|
if !show_buf_label_first
|
2019-04-17 03:04:56 -04:00
|
|
|
call airline#extensions#tabline#add_label(b, 'buffers', 1)
|
2018-01-04 13:37:45 -05:00
|
|
|
endif
|
2018-01-04 08:30:16 -05:00
|
|
|
|
2019-03-08 08:05:38 -05:00
|
|
|
call airline#extensions#tabline#add_tab_label(b)
|
2015-02-18 21:37:13 -05:00
|
|
|
|
|
|
|
let s:current_bufnr = cur
|
2018-03-15 16:40:36 -04:00
|
|
|
let s:column_width = &columns
|
2015-02-18 21:37:13 -05:00
|
|
|
let s:current_tabline = b.build()
|
2018-03-15 16:29:25 -04:00
|
|
|
let s:current_visible_buffers = copy(b.buffers)
|
2019-02-06 16:42:10 -05:00
|
|
|
" Do not remove from s:current_visible_buffers, this breaks s:select_tab()
|
|
|
|
"if b._right_title <= last_buffer
|
|
|
|
" call remove(s:current_visible_buffers, b._right_title, last_buffer)
|
|
|
|
"endif
|
|
|
|
"if b._left_title > 0
|
|
|
|
" call remove(s:current_visible_buffers, 0, b._left_title)
|
|
|
|
"endif
|
2018-03-15 16:29:25 -04:00
|
|
|
return s:current_tabline
|
2015-02-18 21:37:13 -05:00
|
|
|
endfunction
|
|
|
|
|
2019-02-07 02:11:47 -05:00
|
|
|
function! s:get_number(index)
|
|
|
|
if len(s:number_map) == 0
|
|
|
|
return a:index
|
|
|
|
endif
|
|
|
|
let bidx_mode = get(g:, 'airline#extensions#tabline#buffer_idx_mode', 0)
|
|
|
|
if bidx_mode > 1
|
2019-02-08 01:55:35 -05:00
|
|
|
return join(map(split(a:index+11, '\zs'), 'get(s:number_map, v:val, "")'), '')
|
2019-02-07 02:11:47 -05:00
|
|
|
else
|
|
|
|
return get(s:number_map, a:index+1, '')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2015-02-18 21:37:13 -05:00
|
|
|
function! s:select_tab(buf_index)
|
2017-08-24 11:22:16 -04:00
|
|
|
" no-op when called in 'keymap_ignored_filetypes'
|
2018-01-04 08:35:10 -05:00
|
|
|
if count(get(g:, 'airline#extensions#tabline#keymap_ignored_filetypes',
|
|
|
|
\ ['vimfiler', 'nerdtree']), &ft)
|
2015-02-18 21:37:13 -05:00
|
|
|
return
|
|
|
|
endif
|
2019-02-06 16:42:10 -05:00
|
|
|
let idx = a:buf_index
|
|
|
|
if s:current_visible_buffers[0] == -1
|
|
|
|
let idx = idx + 1
|
2015-02-18 21:37:13 -05:00
|
|
|
endif
|
2019-02-06 16:42:10 -05:00
|
|
|
|
|
|
|
let buf = get(s:current_visible_buffers, idx, 0)
|
|
|
|
if buf != 0
|
|
|
|
exec 'b!' . buf
|
|
|
|
endif
|
2015-02-18 21:37:13 -05:00
|
|
|
endfunction
|
|
|
|
|
2015-02-28 19:18:02 -05:00
|
|
|
function! s:jump_to_tab(offset)
|
2017-02-28 10:54:03 -05:00
|
|
|
let l = airline#extensions#tabline#buflist#list()
|
2015-02-28 19:18:02 -05:00
|
|
|
let i = index(l, bufnr('%'))
|
|
|
|
if i > -1
|
2017-02-28 10:54:03 -05:00
|
|
|
exec 'b!' . l[(i + a:offset) % len(l)]
|
2015-02-28 19:18:02 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2016-04-20 15:10:28 -04:00
|
|
|
function! s:map_keys()
|
2019-02-07 02:11:47 -05:00
|
|
|
let bidx_mode = get(g:, 'airline#extensions#tabline#buffer_idx_mode', 1)
|
|
|
|
if bidx_mode > 0
|
|
|
|
if bidx_mode == 1
|
|
|
|
for i in range(1, 9)
|
|
|
|
exe printf('noremap <silent> <Plug>AirlineSelectTab%d :call <SID>select_tab(%d)<CR>', i, i-1)
|
|
|
|
endfor
|
|
|
|
else
|
2019-02-08 01:55:35 -05:00
|
|
|
for i in range(11, 99)
|
|
|
|
exe printf('noremap <silent> <Plug>AirlineSelectTab%d :call <SID>select_tab(%d)<CR>', i, i-11)
|
2019-02-07 02:11:47 -05:00
|
|
|
endfor
|
|
|
|
endif
|
2016-01-20 14:22:12 -05:00
|
|
|
noremap <silent> <Plug>AirlineSelectPrevTab :<C-u>call <SID>jump_to_tab(-v:count1)<CR>
|
|
|
|
noremap <silent> <Plug>AirlineSelectNextTab :<C-u>call <SID>jump_to_tab(v:count1)<CR>
|
2019-02-04 15:47:11 -05:00
|
|
|
" Enable this for debugging
|
|
|
|
" com! AirlineBufferList :echo map(copy(s:current_visible_buffers), {i,k -> k.": ".bufname(k)})
|
2016-01-20 14:22:12 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
2016-02-09 15:54:27 -05:00
|
|
|
|
2016-04-20 15:10:28 -04:00
|
|
|
function! airline#extensions#tabline#buffers#clickbuf(minwid, clicks, button, modifiers) abort
|
2016-04-07 06:46:46 -04:00
|
|
|
" Clickable buffers
|
2016-02-09 15:54:27 -05:00
|
|
|
" works only in recent NeoVim with has('tablineat')
|
2016-04-07 06:46:46 -04:00
|
|
|
|
|
|
|
" single mouse button click without modifiers pressed
|
|
|
|
if a:clicks == 1 && a:modifiers !~# '[^ ]'
|
|
|
|
if a:button is# 'l'
|
|
|
|
" left button - switch to buffer
|
|
|
|
silent execute 'buffer' a:minwid
|
|
|
|
elseif a:button is# 'm'
|
|
|
|
" middle button - delete buffer
|
2016-10-19 19:19:43 -04:00
|
|
|
|
2019-01-11 04:43:06 -05:00
|
|
|
if get(g:, 'airline#extensions#tabline#middle_click_preserves_windows', 0) == 0 || winnr('$') == 1
|
2016-10-19 19:19:43 -04:00
|
|
|
" just simply delete the clicked buffer. This will cause windows
|
|
|
|
" associated with the clicked buffer to be closed.
|
|
|
|
silent execute 'bdelete' a:minwid
|
|
|
|
else
|
|
|
|
" find windows displaying the clicked buffer and open an new
|
|
|
|
" buffer in them.
|
|
|
|
let current_window = bufwinnr("%")
|
|
|
|
let window_number = bufwinnr(a:minwid)
|
|
|
|
let last_window_visited = -1
|
|
|
|
|
|
|
|
" Set to 1 if the clicked buffer was open in any windows.
|
|
|
|
let buffer_in_window = 0
|
|
|
|
|
|
|
|
" Find the next window with the clicked buffer open. If bufwinnr()
|
|
|
|
" returns the same window number, this is because we clicked a new
|
|
|
|
" buffer, and then tried editing a new buffer. Vim won't create a
|
|
|
|
" new empty buffer for the same window, so we get the same window
|
|
|
|
" number from bufwinnr(). In this case we just give up and don't
|
|
|
|
" delete the buffer.
|
|
|
|
" This could be made cleaner if we could check if the clicked buffer
|
|
|
|
" is a new buffer, but I don't know if there is a way to do that.
|
|
|
|
while window_number != -1 && window_number != last_window_visited
|
|
|
|
let buffer_in_window = 1
|
|
|
|
silent execute window_number . 'wincmd w'
|
|
|
|
silent execute 'enew'
|
|
|
|
let last_window_visited = window_number
|
|
|
|
let window_number = bufwinnr(a:minwid)
|
|
|
|
endwhile
|
|
|
|
silent execute current_window . 'wincmd w'
|
|
|
|
if window_number != last_window_visited || buffer_in_window == 0
|
|
|
|
silent execute 'bdelete' a:minwid
|
|
|
|
endif
|
|
|
|
endif
|
2016-04-07 06:46:46 -04:00
|
|
|
endif
|
2016-02-09 15:54:27 -05:00
|
|
|
endif
|
|
|
|
endfunction
|