2015-10-05 10:17:04 -04:00
|
|
|
" MIT License. Copyright (c) 2013-2015 Bailey Ling.
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2015-10-07 20:44:34 -04:00
|
|
|
let s:filetypes = get(g:, 'airline#extensions#wordcount#filetypes', '\vhelp|markdown|rst|org')
|
2015-11-10 15:11:20 -05:00
|
|
|
let s:format = get(g:, 'airline#extensions#wordcount#format', '%d words')
|
2015-10-05 10:17:04 -04:00
|
|
|
|
2015-10-06 14:44:19 -04:00
|
|
|
" adapted from http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim
|
|
|
|
function! s:update()
|
2015-10-07 20:44:34 -04:00
|
|
|
if &ft !~ s:filetypes
|
2015-10-06 14:44:19 -04:00
|
|
|
unlet! b:airline_wordcount
|
|
|
|
return
|
2015-11-10 15:20:53 -05:00
|
|
|
elseif mode() =~? 's'
|
|
|
|
" Bail on select mode
|
|
|
|
return
|
2015-10-06 14:44:19 -04:00
|
|
|
endif
|
|
|
|
|
2015-10-05 10:17:04 -04:00
|
|
|
let old_status = v:statusmsg
|
|
|
|
let position = getpos(".")
|
2015-10-16 18:22:53 -04:00
|
|
|
exe "silent normal! g\<c-g>"
|
2015-10-05 10:17:04 -04:00
|
|
|
let stat = v:statusmsg
|
|
|
|
call setpos('.', position)
|
|
|
|
let v:statusmsg = old_status
|
2015-10-06 14:44:19 -04:00
|
|
|
|
|
|
|
let parts = split(stat)
|
|
|
|
if len(parts) > 11
|
|
|
|
let cnt = str2nr(split(stat)[11])
|
|
|
|
let spc = g:airline_symbols.space
|
2015-11-10 15:11:20 -05:00
|
|
|
let b:airline_wordcount = printf(s:format, cnt) . spc . g:airline_right_alt_sep . spc
|
2015-10-06 14:44:19 -04:00
|
|
|
else
|
|
|
|
unlet! b:airline_wordcount
|
|
|
|
endif
|
2015-10-05 10:17:04 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#wordcount#apply(...)
|
2015-10-07 20:44:34 -04:00
|
|
|
if &ft =~ s:filetypes
|
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')
|
2015-10-06 14:44:19 -04:00
|
|
|
autocmd BufReadPost,CursorMoved,CursorMovedI * call s:update()
|
2015-10-05 10:17:04 -04:00
|
|
|
endfunction
|
|
|
|
|