mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-12-05 16:34:13 +08:00
97e204f3b6
1) allow for custom formatting of the output of the wordcount formatter This allows for formatting numbers correctly e.g. 1,042 in English locale and 1.042 in German locale. 2) cache values, so that no on every cursor move the wordcount needs to be recalculated.
49 lines
1.2 KiB
VimL
49 lines
1.2 KiB
VimL
" MIT License. Copyright (c) 2013-2016 Bailey Ling.
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
function! airline#extensions#wordcount#formatters#default#format()
|
|
let words = string(s:wordcount())
|
|
if empty(words)
|
|
return
|
|
endif
|
|
let separator = s:get_decimal_group()
|
|
if words > 999 && !empty(separator)
|
|
" Format number according to locale, e.g. German: 1.245 or English: 1,245
|
|
let a = join(reverse(split(words, '.\zs')),'')
|
|
let a = substitute(a, '...', '&'.separator, 'g')
|
|
let words = join(reverse(split(a, '.\zs')),'')
|
|
endif
|
|
return words . " words" . g:airline_symbols.space . g:airline_right_alt_sep . g:airline_symbols.space
|
|
endfunction
|
|
|
|
function! s:wordcount()
|
|
if exists("*wordcount")
|
|
return wordcount()['words']
|
|
else if mode() =~? 's'
|
|
return
|
|
else
|
|
let old_status = v:statusmsg
|
|
let position = getpos(".")
|
|
exe "silent normal! g\<c-g>"
|
|
let stat = v:statusmsg
|
|
call setpos('.', position)
|
|
let v:statusmsg = old_status
|
|
|
|
let parts = split(stat)
|
|
if len(parts) > 11
|
|
return str2nr(parts[11])
|
|
else
|
|
return
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
function s:get_decimal_group()
|
|
if match(v:lang, '\v\cC|en') > -1
|
|
return ','
|
|
elseif match(v:lang, '\v\cde|dk|fr') > -1
|
|
return '.'
|
|
endif
|
|
return ''
|
|
endfunction
|