2018-01-05 17:37:59 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2018 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
|
|
|
|
|
2016-01-26 04:00:05 +08:00
|
|
|
function! airline#extensions#wordcount#formatters#default#format()
|
2017-10-25 20:54:50 +08:00
|
|
|
let fmt = get(g:, 'airline#extensions#wordcount#formatter#default#fmt', '%s words')
|
|
|
|
let fmt_short = get(g:, 'airline#extensions#wordcount#formatter#default#fmt_short', fmt == '%s words' ? '%sW' : fmt)
|
2016-01-26 04:00:05 +08:00
|
|
|
let words = string(s:wordcount())
|
|
|
|
if empty(words)
|
|
|
|
return
|
|
|
|
endif
|
2017-02-25 01:25:29 +08:00
|
|
|
let result = g:airline_symbols.space . g:airline_right_alt_sep . g:airline_symbols.space
|
|
|
|
if winwidth(0) >= 80
|
|
|
|
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
|
2017-02-25 01:28:48 +08:00
|
|
|
let words = substitute(words, '\d\@<=\(\(\d\{3\}\)\+\)$', separator.'&', 'g')
|
2017-02-25 01:25:29 +08:00
|
|
|
endif
|
2017-10-25 20:54:50 +08:00
|
|
|
let result = printf(fmt, words). result
|
2017-02-25 01:25:29 +08:00
|
|
|
else
|
2017-10-25 20:54:50 +08:00
|
|
|
let result = printf(fmt_short, words). result
|
2016-01-26 04:00:05 +08:00
|
|
|
endif
|
2017-02-25 01:25:29 +08:00
|
|
|
return result
|
2016-01-26 04:00:05 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:wordcount()
|
|
|
|
if exists("*wordcount")
|
2016-02-09 05:58:07 +08:00
|
|
|
let l:mode = mode()
|
|
|
|
if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S'
|
|
|
|
let l:visual_words = wordcount()['visual_words']
|
|
|
|
if l:visual_words != ''
|
|
|
|
return l:visual_words
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
return wordcount()['words']
|
|
|
|
endif
|
2016-01-28 04:21:12 +08:00
|
|
|
elseif mode() =~? 's'
|
2016-01-26 04:00:05 +08:00
|
|
|
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
|
|
|
|
|
2016-04-21 03:10:28 +08:00
|
|
|
function! s:get_decimal_group()
|
2018-06-05 03:45:46 +08:00
|
|
|
if match(get(v:, 'lang', ''), '\v\cC|en') > -1
|
2016-01-26 04:00:05 +08:00
|
|
|
return ','
|
2018-06-05 03:45:46 +08:00
|
|
|
elseif match(get(v:, 'lang', ''), '\v\cde|dk|fr|pt') > -1
|
2016-01-26 04:00:05 +08:00
|
|
|
return '.'
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|