2018-01-05 17:37:59 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
|
2013-09-07 08:43:51 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2015-01-04 08:38:17 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2013-12-23 13:41:24 +08:00
|
|
|
let s:skip_symbol = '…'
|
2013-09-07 08:43:51 +08:00
|
|
|
|
2015-02-14 07:58:54 +08:00
|
|
|
function! airline#extensions#tabline#formatters#unique_tail_improved#format(bufnr, buffers)
|
2013-12-22 08:27:42 +08:00
|
|
|
if len(a:buffers) <= 1 " don't need to compare bufnames if has less than one buffer opened
|
2015-02-14 07:58:54 +08:00
|
|
|
return airline#extensions#tabline#formatters#default#format(a:bufnr, a:buffers)
|
2013-12-22 08:27:42 +08:00
|
|
|
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)
|
2014-05-22 17:29:35 +08:00
|
|
|
if !empty(name) && nr != a:bufnr && fnamemodify(name, ':t') == curbuf_tail " only perform actions if curbuf_tail isn't unique
|
2013-12-22 08:27:42 +08:00
|
|
|
let do_deduplicate = 1
|
2014-05-22 17:29:35 +08:00
|
|
|
let tokens = reverse(split(substitute(fnamemodify(name, ':p:h'), '\\', '/', 'g'), '/'))
|
2013-12-22 08:27:42 +08:00
|
|
|
let token_index = 0
|
|
|
|
for token in tokens
|
2014-03-10 19:13:18 +08:00
|
|
|
if token == '' | continue | endif
|
2013-12-22 08:27:42 +08:00
|
|
|
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
|
2014-05-22 17:29:35 +08:00
|
|
|
for token in reverse(split(substitute(fnamemodify(bufname(a:bufnr), ':p:h'), '\\', '/', 'g'), '/'))
|
2013-12-22 08:27:42 +08:00
|
|
|
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
|
|
|
|
for token1 in reverse(path)
|
|
|
|
if !token1['duplicated'] && len(buf_name) > 1
|
2013-12-23 13:41:24 +08:00
|
|
|
call insert(buf_name, s:skip_symbol)
|
2013-12-22 11:17:01 +08:00
|
|
|
let has_skipped = 0
|
2013-12-22 08:27:42 +08:00
|
|
|
break
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_uniq == 1
|
2013-12-23 13:41:24 +08:00
|
|
|
call insert(buf_name, s:skip_symbol)
|
2013-12-22 11:17:01 +08:00
|
|
|
let has_skipped = 0
|
2013-12-22 08:27:42 +08:00
|
|
|
break
|
|
|
|
endif
|
|
|
|
|
|
|
|
if token1['uniq'] == 0 && token1['single'] == 1
|
|
|
|
let has_skipped = 1
|
|
|
|
else
|
|
|
|
if has_skipped == 1
|
2013-12-23 13:41:24 +08:00
|
|
|
call insert(buf_name, s:skip_symbol)
|
2013-12-22 08:27:42 +08:00
|
|
|
let has_skipped = 0
|
|
|
|
endif
|
|
|
|
call insert(buf_name, token1['token'])
|
|
|
|
endif
|
|
|
|
|
|
|
|
if token1['uniq'] == 1
|
|
|
|
let has_uniq = 1
|
|
|
|
endif
|
|
|
|
endfor
|
2013-12-22 11:17:01 +08:00
|
|
|
|
|
|
|
if has_skipped == 1
|
2013-12-23 13:41:24 +08:00
|
|
|
call insert(buf_name, s:skip_symbol)
|
2013-12-22 11:17:01 +08:00
|
|
|
endif
|
|
|
|
|
2015-02-14 07:58:54 +08:00
|
|
|
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, join(buf_name, '/'))
|
2013-12-22 08:27:42 +08:00
|
|
|
else
|
2015-02-14 07:58:54 +08:00
|
|
|
return airline#extensions#tabline#formatters#default#format(a:bufnr, a:buffers)
|
2013-09-07 08:43:51 +08:00
|
|
|
endif
|
|
|
|
endfunction
|