2016-01-15 02:38:38 +00:00
|
|
|
" MIT License. Copyright (c) 2013-2016 Bailey Ling.
|
2015-10-05 14:17:04 +00:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-04-05 12:14:48 +00:00
|
|
|
let s:filetypes = get(g:, 'airline#extensions#wordcount#filetypes', '\vhelp|markdown|rst|org|text|asciidoc')
|
2015-11-10 20:11:20 +00:00
|
|
|
let s:format = get(g:, 'airline#extensions#wordcount#format', '%d words')
|
2016-01-25 20:00:05 +00:00
|
|
|
let s:formatter = get(g:, 'airline#extensions#wordcount#formatter', 'default')
|
2015-10-05 14:17:04 +00:00
|
|
|
|
2015-10-06 18:44:19 +00:00
|
|
|
function! s:update()
|
2016-01-25 20:00:05 +00:00
|
|
|
if match(&ft, s:filetypes) > -1
|
2016-02-08 21:58:07 +00:00
|
|
|
let l:mode = mode()
|
|
|
|
if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S'
|
2016-01-25 20:00:05 +00:00
|
|
|
let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format()
|
|
|
|
let b:airline_change_tick = b:changedtick
|
2016-02-08 21:58:07 +00:00
|
|
|
else
|
|
|
|
if get(b:, 'airline_wordcount_cache', '') is# '' ||
|
|
|
|
\ b:airline_wordcount_cache isnot# get(b:, 'airline_wordcount', '') ||
|
|
|
|
\ get(b:, 'airline_change_tick', 0) != b:changedtick
|
|
|
|
" cache data
|
|
|
|
let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format()
|
|
|
|
let b:airline_wordcount_cache = b:airline_wordcount
|
|
|
|
let b:airline_change_tick = b:changedtick
|
|
|
|
endif
|
2016-01-15 11:54:46 +00:00
|
|
|
endif
|
2015-10-06 18:44:19 +00:00
|
|
|
endif
|
2015-10-05 14:17:04 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#wordcount#apply(...)
|
2015-10-08 00:44:34 +00:00
|
|
|
if &ft =~ s:filetypes
|
2015-10-06 18:44:19 +00:00
|
|
|
call airline#extensions#prepend_to_section('z', '%{get(b:, "airline_wordcount", "")}')
|
2015-10-05 14:17:04 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#wordcount#init(ext)
|
|
|
|
call a:ext.add_statusline_func('airline#extensions#wordcount#apply')
|
2015-10-06 18:44:19 +00:00
|
|
|
autocmd BufReadPost,CursorMoved,CursorMovedI * call s:update()
|
2015-10-05 14:17:04 +00:00
|
|
|
endfunction
|