diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index b1f2224b..4b1c80a1 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -206,6 +206,10 @@ function! airline#extensions#load() call airline#extensions#whitespace#init(s:ext) 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) call airline#extensions#tabline#init(s:ext) endif diff --git a/autoload/airline/extensions/wordcount.vim b/autoload/airline/extensions/wordcount.vim new file mode 100644 index 00000000..fe6eeb41 --- /dev/null +++ b/autoload/airline/extensions/wordcount.vim @@ -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\" + 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 + diff --git a/doc/airline.txt b/doc/airline.txt index 974f53ed..7f3d2264 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -401,6 +401,15 @@ eclim |airline-syntastic| extension. > 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* * enable/disable detection of whitespace errors. > let g:airline#extensions#whitespace#enabled = 1 @@ -490,8 +499,8 @@ exposed. let g:airline#extensions#tabline#formatter = 'foo' < - Note: the following variables are only used by the 'default' formatter. - When no disambiguation is needed, both 'unique_tail_improved' and + Note: the following variables are only used by the 'default' formatter. + When no disambiguation is needed, both 'unique_tail_improved' and 'unique_tail' delegate formatting to 'default', so these variables also control rendering of unique filenames when using these formatters.