2021-01-01 20:57:00 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
|
2016-01-26 04:00:05 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2018-09-22 10:34:27 +08:00
|
|
|
function! airline#extensions#wordcount#formatters#default#update_fmt(...)
|
2018-09-19 03:09:22 +08:00
|
|
|
let s:fmt = get(g:, 'airline#extensions#wordcount#formatter#default#fmt', '%s words')
|
|
|
|
let s:fmt_short = get(g:, 'airline#extensions#wordcount#formatter#default#fmt_short', s:fmt == '%s words' ? '%sW' : s:fmt)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Reload format when statusline is rebuilt
|
2018-09-22 10:34:27 +08:00
|
|
|
call airline#extensions#wordcount#formatters#default#update_fmt()
|
2020-07-09 06:30:31 +08:00
|
|
|
|
2018-09-22 10:34:27 +08:00
|
|
|
if index(g:airline_statusline_funcrefs, function('airline#extensions#wordcount#formatters#default#update_fmt')) == -1
|
2018-09-20 16:41:50 +08:00
|
|
|
" only add it, if not already done
|
2018-09-22 10:34:27 +08:00
|
|
|
call airline#add_statusline_funcref(function('airline#extensions#wordcount#formatters#default#update_fmt'))
|
2018-09-20 16:41:50 +08:00
|
|
|
endif
|
2018-07-01 01:34:12 +08:00
|
|
|
|
2018-09-18 09:04:35 +08:00
|
|
|
if match(get(v:, 'lang', ''), '\v\cC|en') > -1
|
|
|
|
let s:decimal_group = ','
|
|
|
|
elseif match(get(v:, 'lang', ''), '\v\cde|dk|fr|pt') > -1
|
|
|
|
let s:decimal_group = '.'
|
|
|
|
else
|
|
|
|
let s:decimal_group = ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
function! airline#extensions#wordcount#formatters#default#to_string(wordcount)
|
2019-10-02 20:50:35 +08:00
|
|
|
if airline#util#winwidth() > 85
|
2018-09-18 09:04:35 +08:00
|
|
|
if a:wordcount > 999
|
2017-02-25 01:25:29 +08:00
|
|
|
" Format number according to locale, e.g. German: 1.245 or English: 1,245
|
2018-09-18 09:04:35 +08:00
|
|
|
let wordcount = substitute(a:wordcount, '\d\@<=\(\(\d\{3\}\)\+\)$', s:decimal_group.'&', 'g')
|
2016-02-09 05:58:07 +08:00
|
|
|
else
|
2018-09-18 09:04:35 +08:00
|
|
|
let wordcount = a:wordcount
|
2016-02-09 05:58:07 +08:00
|
|
|
endif
|
2018-09-18 09:04:35 +08:00
|
|
|
let str = printf(s:fmt, wordcount)
|
2016-01-26 04:00:05 +08:00
|
|
|
else
|
2018-09-18 09:04:35 +08:00
|
|
|
let str = printf(s:fmt_short, a:wordcount)
|
2016-01-26 04:00:05 +08:00
|
|
|
endif
|
2020-07-09 06:30:31 +08:00
|
|
|
|
|
|
|
let str .= g:airline_symbols.space
|
|
|
|
|
|
|
|
if !empty(g:airline_right_alt_sep)
|
|
|
|
let str .= g:airline_right_alt_sep . g:airline_symbols.space
|
|
|
|
endif
|
|
|
|
|
|
|
|
return str
|
2016-01-26 04:00:05 +08:00
|
|
|
endfunction
|