Merge pull request #1413 from chrisbra/wordformat
Improvements to wordcount formatting
This commit is contained in:
commit
52c0afadb9
@ -3,12 +3,14 @@
|
|||||||
|
|
||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
|
|
||||||
let s:format = get(g:, 'airline#extensions#wordcount#format', '%d words')
|
|
||||||
let s:formatter = get(g:, 'airline#extensions#wordcount#formatter', 'default')
|
let s:formatter = get(g:, 'airline#extensions#wordcount#formatter', 'default')
|
||||||
let g:airline#extensions#wordcount#filetypes = get(g:, 'airline#extensions#wordcount#filetypes',
|
let g:airline#extensions#wordcount#filetypes = get(g:, 'airline#extensions#wordcount#filetypes',
|
||||||
\ '\vhelp|markdown|rst|org|text|asciidoc|tex|mail')
|
\ '\vhelp|markdown|rst|org|text|asciidoc|tex|mail')
|
||||||
|
|
||||||
function! s:update()
|
function! s:wordcount_update()
|
||||||
|
if empty(bufname(''))
|
||||||
|
return
|
||||||
|
endif
|
||||||
if match(&ft, get(g:, 'airline#extensions#wordcount#filetypes')) > -1
|
if match(&ft, get(g:, 'airline#extensions#wordcount#filetypes')) > -1
|
||||||
let l:mode = mode()
|
let l:mode = mode()
|
||||||
if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S'
|
if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S'
|
||||||
@ -17,11 +19,13 @@ function! s:update()
|
|||||||
else
|
else
|
||||||
if get(b:, 'airline_wordcount_cache', '') is# '' ||
|
if get(b:, 'airline_wordcount_cache', '') is# '' ||
|
||||||
\ b:airline_wordcount_cache isnot# get(b:, 'airline_wordcount', '') ||
|
\ b:airline_wordcount_cache isnot# get(b:, 'airline_wordcount', '') ||
|
||||||
\ get(b:, 'airline_change_tick', 0) != b:changedtick
|
\ get(b:, 'airline_change_tick', 0) != b:changedtick ||
|
||||||
|
\ get(b:, 'airline_winwidth', 0) != winwidth(0)
|
||||||
" cache data
|
" cache data
|
||||||
let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format()
|
let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format()
|
||||||
let b:airline_wordcount_cache = b:airline_wordcount
|
let b:airline_wordcount_cache = b:airline_wordcount
|
||||||
let b:airline_change_tick = b:changedtick
|
let b:airline_change_tick = b:changedtick
|
||||||
|
let b:airline_winwidth = winwidth(0)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@ -35,5 +39,5 @@ endfunction
|
|||||||
|
|
||||||
function! airline#extensions#wordcount#init(ext)
|
function! airline#extensions#wordcount#init(ext)
|
||||||
call a:ext.add_statusline_func('airline#extensions#wordcount#apply')
|
call a:ext.add_statusline_func('airline#extensions#wordcount#apply')
|
||||||
autocmd BufReadPost,CursorMoved,CursorMovedI * call s:update()
|
autocmd BufReadPost,CursorMoved,CursorMovedI * call s:wordcount_update()
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -8,14 +8,18 @@ function! airline#extensions#wordcount#formatters#default#format()
|
|||||||
if empty(words)
|
if empty(words)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let separator = s:get_decimal_group()
|
let result = g:airline_symbols.space . g:airline_right_alt_sep . g:airline_symbols.space
|
||||||
if words > 999 && !empty(separator)
|
if winwidth(0) >= 80
|
||||||
" Format number according to locale, e.g. German: 1.245 or English: 1,245
|
let separator = s:get_decimal_group()
|
||||||
let a = join(reverse(split(words, '.\zs')),'')
|
if words > 999 && !empty(separator)
|
||||||
let a = substitute(a, '...', '&'.separator, 'g')
|
" Format number according to locale, e.g. German: 1.245 or English: 1,245
|
||||||
let words = join(reverse(split(a, '.\zs')),'')
|
let words = substitute(words, '\d\@<=\(\(\d\{3\}\)\+\)$', separator.'&', 'g')
|
||||||
|
endif
|
||||||
|
let result = printf("%s%s", words, " words"). result
|
||||||
|
else
|
||||||
|
let result = printf("%s%s", words, "W"). result
|
||||||
endif
|
endif
|
||||||
return words . " words" . g:airline_symbols.space . g:airline_right_alt_sep . g:airline_symbols.space
|
return result
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:wordcount()
|
function! s:wordcount()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user