uniq_tail improved formatter added
This commit is contained in:
parent
233e3c60ce
commit
8d7c2ad830
|
@ -5,6 +5,7 @@ let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
|
||||||
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
||||||
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
||||||
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
||||||
|
let s:show_tab_nr = get(g:, 'airline#extensions#tabline#show_tab_nr', 1)
|
||||||
|
|
||||||
let s:builder_context = {
|
let s:builder_context = {
|
||||||
\ 'active' : 1,
|
\ 'active' : 1,
|
||||||
|
@ -103,7 +104,7 @@ function! airline#extensions#tabline#title(n)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#tabline#get_buffer_name(nr)
|
function! airline#extensions#tabline#get_buffer_name(nr)
|
||||||
return airline#extensions#tabline#formatters#{s:formatter}(a:nr, get(s:, 'current_buffer_list', []))
|
return airline#extensions#tabline#formatters#{s:formatter}(a:nr, get(s:, 'current_buffer_list', s:get_buffer_list()))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:get_buffer_list()
|
function! s:get_buffer_list()
|
||||||
|
@ -245,8 +246,10 @@ function! s:get_tabs()
|
||||||
if s:tab_nr_type == 0
|
if s:tab_nr_type == 0
|
||||||
let val .= ' %{len(tabpagebuflist('.i.'))}'
|
let val .= ' %{len(tabpagebuflist('.i.'))}'
|
||||||
else
|
else
|
||||||
|
if s:show_tab_nr
|
||||||
let val .= (g:airline_symbols.space).i
|
let val .= (g:airline_symbols.space).i
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)')
|
call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,90 @@ function! airline#extensions#tabline#formatters#unique_tail(bufnr, buffers)
|
||||||
return map[a:bufnr]
|
return map[a:bufnr]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buffers)
|
||||||
|
if len(a:buffers) <= 1 " don't need to compare bufnames if has less than one buffer opened
|
||||||
|
return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let curbuf_tail = fnamemodify(bufname(a:bufnr), ':t')
|
||||||
|
let do_deduplicate = 0
|
||||||
|
let path_tokens = {}
|
||||||
|
|
||||||
|
for nr in a:buffers
|
||||||
|
let name = bufname(nr)
|
||||||
|
if !empty(name) && nr != a:bufnr && fnamemodify(name, ':t') == curbuf_tail
|
||||||
|
let do_deduplicate = 1
|
||||||
|
let tokens = reverse(split(substitute(fnamemodify(name, ':p:.:h'), '\\', '/', 'g'), '/'))
|
||||||
|
let token_index = 0
|
||||||
|
for token in tokens
|
||||||
|
if token == '.' | break | endif
|
||||||
|
if !has_key(path_tokens, token_index)
|
||||||
|
let path_tokens[token_index] = {}
|
||||||
|
endif
|
||||||
|
let path_tokens[token_index][token] = 1
|
||||||
|
let token_index += 1
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
if do_deduplicate == 1
|
||||||
|
let path = []
|
||||||
|
let token_index = 0
|
||||||
|
for token in reverse(split(fnamemodify(bufname(a:bufnr), ':p:.:h'), '\'))
|
||||||
|
if token == '.' | break | endif
|
||||||
|
let duplicated = 0
|
||||||
|
let uniq = 1
|
||||||
|
let single = 1
|
||||||
|
if has_key(path_tokens, token_index)
|
||||||
|
let duplicated = 1
|
||||||
|
if len(keys(path_tokens[token_index])) > 1 | let single = 0 | endif
|
||||||
|
if has_key(path_tokens[token_index], token) | let uniq = 0 | endif
|
||||||
|
endif
|
||||||
|
call insert(path, {'token': token, 'duplicated': duplicated, 'uniq': uniq, 'single': single})
|
||||||
|
let token_index += 1
|
||||||
|
endfor
|
||||||
|
|
||||||
|
let buf_name = [curbuf_tail]
|
||||||
|
let has_uniq = 0
|
||||||
|
let has_skipped = 0
|
||||||
|
let skip_symbol = '…'
|
||||||
|
for token1 in reverse(path)
|
||||||
|
if !token1['duplicated'] && len(buf_name) > 1
|
||||||
|
call insert(buf_name, skip_symbol)
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_uniq == 1
|
||||||
|
call insert(buf_name, skip_symbol)
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
|
||||||
|
if token1['uniq'] == 0 && token1['single'] == 1
|
||||||
|
let has_skipped = 1
|
||||||
|
else
|
||||||
|
if has_skipped == 1
|
||||||
|
call insert(buf_name, skip_symbol)
|
||||||
|
let has_skipped = 0
|
||||||
|
endif
|
||||||
|
call insert(buf_name, token1['token'])
|
||||||
|
endif
|
||||||
|
|
||||||
|
if token1['uniq'] == 1
|
||||||
|
let has_uniq = 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return s:wrap_name(a:bufnr, join(buf_name, '/'))
|
||||||
|
else
|
||||||
|
return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:wrap_name(bufnr, buffer_name)
|
function! s:wrap_name(bufnr, buffer_name)
|
||||||
let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : ''
|
let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : ''
|
||||||
let _ .= a:buffer_name
|
let _ .= substitute(a:buffer_name, '\\', '/', 'g')
|
||||||
|
|
||||||
if getbufvar(a:bufnr, '&modified') == 1
|
if getbufvar(a:bufnr, '&modified') == 1
|
||||||
let _ .= s:buf_modified_symbol
|
let _ .= s:buf_modified_symbol
|
||||||
endif
|
endif
|
||||||
return _
|
return _
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue