2020-06-11 04:18:30 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
|
2013-12-23 13:41:24 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2015-02-14 07:58:54 +08:00
|
|
|
function! airline#extensions#tabline#formatters#default#format(bufnr, buffers)
|
2020-11-26 17:01:36 +08:00
|
|
|
let fnametruncate = get(g:, 'airline#extensions#tabline#fnametruncate', 0)
|
2016-12-01 21:54:07 +08:00
|
|
|
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.')
|
2013-12-23 13:41:24 +08:00
|
|
|
let _ = ''
|
|
|
|
|
|
|
|
let name = bufname(a:bufnr)
|
|
|
|
if empty(name)
|
|
|
|
let _ .= '[No Name]'
|
2020-02-27 20:37:50 +08:00
|
|
|
elseif name =~ 'term://'
|
|
|
|
" Neovim Terminal
|
|
|
|
let _ = substitute(name, '\(term:\)//.*:\(.*\)', '\1 \2', '')
|
2013-12-23 13:41:24 +08:00
|
|
|
else
|
2020-11-26 17:01:36 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
|
2018-06-05 03:59:16 +08:00
|
|
|
" Does not handle non-ascii characters like Cyrillic: 'D/Учёба/t.c'
|
|
|
|
"let _ .= substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g')
|
|
|
|
let _ .= pathshorten(fnamemodify(name, fmod))
|
2013-12-23 13:41:24 +08:00
|
|
|
else
|
2016-12-01 21:54:07 +08:00
|
|
|
let _ .= fnamemodify(name, fmod)
|
2013-12-23 13:41:24 +08:00
|
|
|
endif
|
2020-11-26 17:01:36 +08:00
|
|
|
if a:bufnr != bufnr('%') && fnametruncate && strlen(_) > fnametruncate
|
2020-11-26 17:04:34 +08:00
|
|
|
if v:version > 802 || (v:version == 802 && has("patch1517"))
|
|
|
|
let _ = strpart(_, 0, fnametruncate, 1)
|
|
|
|
else
|
|
|
|
let _ = strpart(_, 0, fnametruncate)
|
|
|
|
endif
|
2015-03-21 07:37:36 +08:00
|
|
|
endif
|
2013-12-23 13:41:24 +08:00
|
|
|
endif
|
|
|
|
|
2015-02-14 07:58:54 +08:00
|
|
|
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, _)
|
2013-12-23 13:41:24 +08:00
|
|
|
endfunction
|
|
|
|
|
2015-02-14 07:58:54 +08:00
|
|
|
function! airline#extensions#tabline#formatters#default#wrap_name(bufnr, buffer_name)
|
2020-11-26 17:01:36 +08:00
|
|
|
let buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ')
|
|
|
|
let buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0)
|
|
|
|
let buf_modified_symbol = g:airline_symbols.modified
|
|
|
|
|
|
|
|
let _ = buf_nr_show ? printf(buf_nr_format, a:bufnr) : ''
|
2013-12-23 13:41:24 +08:00
|
|
|
let _ .= substitute(a:buffer_name, '\\', '/', 'g')
|
|
|
|
|
|
|
|
if getbufvar(a:bufnr, '&modified') == 1
|
2020-11-26 17:01:36 +08:00
|
|
|
let _ .= buf_modified_symbol
|
2013-12-23 13:41:24 +08:00
|
|
|
endif
|
|
|
|
return _
|
|
|
|
endfunction
|