2018-01-05 04:37:59 -05:00
|
|
|
" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
|
2015-10-05 10:17:04 -04:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-23 20:16:30 -04:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2016-01-25 15:00:05 -05:00
|
|
|
let s:formatter = get(g:, 'airline#extensions#wordcount#formatter', 'default')
|
2016-12-13 15:27:53 -05:00
|
|
|
let g:airline#extensions#wordcount#filetypes = get(g:, 'airline#extensions#wordcount#filetypes',
|
|
|
|
\ '\vhelp|markdown|rst|org|text|asciidoc|tex|mail')
|
2015-10-05 10:17:04 -04:00
|
|
|
|
2017-02-26 04:24:08 -05:00
|
|
|
function! s:wordcount_update()
|
2017-02-26 04:25:21 -05:00
|
|
|
if empty(bufname(''))
|
|
|
|
return
|
|
|
|
endif
|
2016-12-13 15:27:53 -05:00
|
|
|
if match(&ft, get(g:, 'airline#extensions#wordcount#filetypes')) > -1
|
2016-02-08 16:58:07 -05:00
|
|
|
let l:mode = mode()
|
|
|
|
if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S'
|
2016-01-25 15:00:05 -05:00
|
|
|
let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format()
|
|
|
|
let b:airline_change_tick = b:changedtick
|
2016-02-08 16:58:07 -05:00
|
|
|
else
|
|
|
|
if get(b:, 'airline_wordcount_cache', '') is# '' ||
|
|
|
|
\ b:airline_wordcount_cache isnot# get(b:, 'airline_wordcount', '') ||
|
2017-02-24 12:24:30 -05:00
|
|
|
\ get(b:, 'airline_change_tick', 0) != b:changedtick ||
|
|
|
|
\ get(b:, 'airline_winwidth', 0) != winwidth(0)
|
2016-02-08 16:58:07 -05:00
|
|
|
" 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
|
2017-02-24 12:24:30 -05:00
|
|
|
let b:airline_winwidth = winwidth(0)
|
2016-02-08 16:58:07 -05:00
|
|
|
endif
|
2016-01-15 06:54:46 -05:00
|
|
|
endif
|
2015-10-06 14:44:19 -04:00
|
|
|
endif
|
2015-10-05 10:17:04 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#wordcount#apply(...)
|
2016-12-13 15:27:53 -05:00
|
|
|
if match(&ft, get(g:, 'airline#extensions#wordcount#filetypes')) > -1
|
2015-10-06 14:44:19 -04:00
|
|
|
call airline#extensions#prepend_to_section('z', '%{get(b:, "airline_wordcount", "")}')
|
2015-10-05 10:17:04 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#wordcount#init(ext)
|
|
|
|
call a:ext.add_statusline_func('airline#extensions#wordcount#apply')
|
2017-02-26 04:24:08 -05:00
|
|
|
autocmd BufReadPost,CursorMoved,CursorMovedI * call s:wordcount_update()
|
2015-10-05 10:17:04 -04:00
|
|
|
endfunction
|