aboutsummaryrefslogtreecommitdiff
path: root/.vim/autoload/airline/extensions/wordcount/formatters
diff options
context:
space:
mode:
authorYaroslav <contact@yaroslavps.com>2019-09-05 19:35:38 +0300
committerYaroslav <contact@yaroslavps.com>2019-09-05 19:35:38 +0300
commit212dcd0bf753f08c0127a26a71b673c734b45c02 (patch)
tree4a43e43c7c9b9ccfcaef4088ba9e5f52154994b5 /.vim/autoload/airline/extensions/wordcount/formatters
downloadvimrice-212dcd0bf753f08c0127a26a71b673c734b45c02.tar.gz
vimrice-212dcd0bf753f08c0127a26a71b673c734b45c02.zip
init commit, extracted vim config from i3rice
Diffstat (limited to '.vim/autoload/airline/extensions/wordcount/formatters')
-rw-r--r--.vim/autoload/airline/extensions/wordcount/formatters/default.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/.vim/autoload/airline/extensions/wordcount/formatters/default.vim b/.vim/autoload/airline/extensions/wordcount/formatters/default.vim
new file mode 100644
index 0000000..5682921
--- /dev/null
+++ b/.vim/autoload/airline/extensions/wordcount/formatters/default.vim
@@ -0,0 +1,39 @@
+" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
+" vim: et ts=2 sts=2 sw=2
+
+scriptencoding utf-8
+
+function! airline#extensions#wordcount#formatters#default#update_fmt(...)
+ 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
+call airline#extensions#wordcount#formatters#default#update_fmt()
+if index(g:airline_statusline_funcrefs, function('airline#extensions#wordcount#formatters#default#update_fmt')) == -1
+ " only add it, if not already done
+ call airline#add_statusline_funcref(function('airline#extensions#wordcount#formatters#default#update_fmt'))
+endif
+
+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)
+ if winwidth(0) >= 80
+ if a:wordcount > 999
+ " Format number according to locale, e.g. German: 1.245 or English: 1,245
+ let wordcount = substitute(a:wordcount, '\d\@<=\(\(\d\{3\}\)\+\)$', s:decimal_group.'&', 'g')
+ else
+ let wordcount = a:wordcount
+ endif
+ let str = printf(s:fmt, wordcount)
+ else
+ let str = printf(s:fmt_short, a:wordcount)
+ endif
+ return str . g:airline_symbols.space . g:airline_right_alt_sep . g:airline_symbols.space
+endfunction