From ccc4c9f43079f33f3ac2cbd1bb34c14b59e54354 Mon Sep 17 00:00:00 2001 From: Taikuh Date: Wed, 25 Oct 2017 20:54:50 +0800 Subject: [PATCH] Add option to change wordcount display for the default formatter --- .../extensions/wordcount/formatters/default.vim | 6 ++++-- doc/airline.txt | 14 +++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/autoload/airline/extensions/wordcount/formatters/default.vim b/autoload/airline/extensions/wordcount/formatters/default.vim index 059d06ea..5a25bcf9 100644 --- a/autoload/airline/extensions/wordcount/formatters/default.vim +++ b/autoload/airline/extensions/wordcount/formatters/default.vim @@ -4,6 +4,8 @@ scriptencoding utf-8 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()) if empty(words) 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 let words = substitute(words, '\d\@<=\(\(\d\{3\}\)\+\)$', separator.'&', 'g') endif - let result = printf("%s%s", words, " words"). result + let result = printf(fmt, words). result else - let result = printf("%s%s", words, "W"). result + let result = printf(fmt_short, words). result endif return result endfunction diff --git a/doc/airline.txt b/doc/airline.txt index 4f2cfcd0..18636292 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -465,7 +465,7 @@ syntastic * syntastic warning > let airline#extensions#syntastic#warning_symbol = 'W:' -< +< * syntastic statusline warning format (see |syntastic_stl_format|) > let airline#extensions#syntastic#stl_format_err = '%W{[%w(#%fw)]}' < @@ -559,14 +559,18 @@ eclim " create a file in the dir autoload/airline/extensions/wordcount/formatters/ " called foo.vim " 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' : \ wordcount()['words'] > 100 ? 'okay' : 'not enough') endfunction let g:airline#extensions#wordline#formatter = 'foo' -* defines how to display the wordcount statistics: > - let g:airline#extensions#wordcount#format = '%d words' +* defines how to display the wordcount statistics for the default formatter: > + " 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* * enable/disable detection of whitespace errors. > @@ -949,7 +953,7 @@ State indicators: * the current tex file is the main project file (nothing is shown by default) > let g:airline#extensions#vimtex#main = "" -* the current tex file is a subfile of the project +* the current tex file is a subfile of the project and the compilation is set for the main file > let g:airline#extensions#vimtex#sub_main = "m"