add wordcount extension

resolves #761
This commit is contained in:
Bailey Ling 2015-10-05 10:17:04 -04:00
parent bb4be0095d
commit e59c3ecd6e
3 changed files with 47 additions and 2 deletions

View File

@ -206,6 +206,10 @@ function! airline#extensions#load()
call airline#extensions#whitespace#init(s:ext) call airline#extensions#whitespace#init(s:ext)
endif endif
if get(g:, 'airline#extensions#wordcount#enabled', 1)
call airline#extensions#wordcount#init(s:ext)
endif
if get(g:, 'airline#extensions#tabline#enabled', 0) if get(g:, 'airline#extensions#tabline#enabled', 0)
call airline#extensions#tabline#init(s:ext) call airline#extensions#tabline#init(s:ext)
endif endif

View File

@ -0,0 +1,32 @@
" MIT License. Copyright (c) 2013-2015 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let g:airline#extensions#wordcount#filetypes = '\vhelp|markdown|rst|org'
" http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim
function! airline#extensions#wordcount#count()
let old_status = v:statusmsg
let position = getpos(".")
exe "silent normal g\<c-g>"
let cnt = 0
let stat = v:statusmsg
if stat != '--No lines in buffer--'
let cnt = str2nr(split(v:statusmsg)[11])
end
call setpos('.', position)
let v:statusmsg = old_status
return cnt
endfunction
function! airline#extensions#wordcount#apply(...)
if &ft =~ g:airline#extensions#wordcount#filetypes
let spc = g:airline_symbols.space
call airline#extensions#prepend_to_section('z',
\ '%{airline#extensions#wordcount#count()}' . spc . 'words' . spc . g:airline_right_alt_sep .spc)
endif
endfunction
function! airline#extensions#wordcount#init(ext)
call a:ext.add_statusline_func('airline#extensions#wordcount#apply')
endfunction

View File

@ -401,6 +401,15 @@ eclim <https://eclim.org>
|airline-syntastic| extension. > |airline-syntastic| extension. >
let g:airline#extensions#eclim#enabled = 1 let g:airline#extensions#eclim#enabled = 1
------------------------------------- *airline-wordcount*
* enable/disable word counting. >
let g:airline#extensions#wordcount#enabled = 1
<
* regex of filetypes to enable word counting. >
" the default value matches filetypes typically used for documentation
" such as markdown and help files.
let g:airline#extensions#wordcount#filetypes = ...
<
------------------------------------- *airline-whitespace* ------------------------------------- *airline-whitespace*
* enable/disable detection of whitespace errors. > * enable/disable detection of whitespace errors. >
let g:airline#extensions#whitespace#enabled = 1 let g:airline#extensions#whitespace#enabled = 1
@ -490,8 +499,8 @@ exposed.
let g:airline#extensions#tabline#formatter = 'foo' let g:airline#extensions#tabline#formatter = 'foo'
< <
Note: the following variables are only used by the 'default' formatter. Note: the following variables are only used by the 'default' formatter.
When no disambiguation is needed, both 'unique_tail_improved' and When no disambiguation is needed, both 'unique_tail_improved' and
'unique_tail' delegate formatting to 'default', so these variables also 'unique_tail' delegate formatting to 'default', so these variables also
control rendering of unique filenames when using these formatters. control rendering of unique filenames when using these formatters.