Add option to change wordcount display for the default formatter

This commit is contained in:
Taikuh 2017-10-25 20:54:50 +08:00
parent 78ca75af6e
commit ccc4c9f430
2 changed files with 13 additions and 7 deletions

View File

@ -4,6 +4,8 @@
scriptencoding utf-8 scriptencoding utf-8
function! airline#extensions#wordcount#formatters#default#format() function! airline#extensions#wordcount#formatters#default#format()
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)
let words = string(s:wordcount()) let words = string(s:wordcount())
if empty(words) if empty(words)
return return
@ -15,9 +17,9 @@ function! airline#extensions#wordcount#formatters#default#format()
" Format number according to locale, e.g. German: 1.245 or English: 1,245 " Format number according to locale, e.g. German: 1.245 or English: 1,245
let words = substitute(words, '\d\@<=\(\(\d\{3\}\)\+\)$', separator.'&', 'g') let words = substitute(words, '\d\@<=\(\(\d\{3\}\)\+\)$', separator.'&', 'g')
endif endif
let result = printf("%s%s", words, " words"). result let result = printf(fmt, words). result
else else
let result = printf("%s%s", words, "W"). result let result = printf(fmt_short, words). result
endif endif
return result return result
endfunction endfunction

View File

@ -559,14 +559,18 @@ eclim <https://eclim.org>
" create a file in the dir autoload/airline/extensions/wordcount/formatters/ " create a file in the dir autoload/airline/extensions/wordcount/formatters/
" called foo.vim " called foo.vim
" this example needs at least Vim > 7.4.1042 " this example needs at least Vim > 7.4.1042
function! airline#extensions#wordcount#formatters#foo#format() function! airline#extensions#wordcount#formatters#foo#format(format,fmt)
return (wordcount()['words'] == 0 ? 'NONE' : return (wordcount()['words'] == 0 ? 'NONE' :
\ wordcount()['words'] > 100 ? 'okay' : 'not enough') \ wordcount()['words'] > 100 ? 'okay' : 'not enough')
endfunction endfunction
let g:airline#extensions#wordline#formatter = 'foo' let g:airline#extensions#wordline#formatter = 'foo'
* defines how to display the wordcount statistics: > * defines how to display the wordcount statistics for the default formatter: >
let g:airline#extensions#wordcount#format = '%d words' " Defaults are below. If fmt_short isn't defined, fmt is used.
" '%s' will be substituted by the word count
" fmt_short is displayed when window width is less than 80
let g:airline#extensions#wordcount#formatter#default#fmt = '%s words'
let g:airline#extensions#wordcount#formatter#default#fmt_short = '%sW'
< <
------------------------------------- *airline-whitespace* ------------------------------------- *airline-whitespace*
* enable/disable detection of whitespace errors. > * enable/disable detection of whitespace errors. >