From 2637e3ee58856f42cafa0f0094215e6d85d409dd Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Oct 2015 14:44:19 -0400 Subject: [PATCH] fix error from expanding snippets. resolves #862 --- autoload/airline/extensions/wordcount.vim | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/autoload/airline/extensions/wordcount.vim b/autoload/airline/extensions/wordcount.vim index ce753c9..6ea24f3 100644 --- a/autoload/airline/extensions/wordcount.vim +++ b/autoload/airline/extensions/wordcount.vim @@ -3,33 +3,38 @@ 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() +" adapted from http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim +function! s:update() + if &ft !~ g:airline#extensions#wordcount#filetypes + unlet! b:airline_wordcount + return + endif + let old_status = v:statusmsg let position = getpos(".") exe "silent normal g\" - let txt = '' let stat = v:statusmsg - if stat != '--No lines in buffer--' - let parts = split(v:statusmsg) - if len(parts) > 11 - let cnt = str2nr(split(v:statusmsg)[11]) - let spc = g:airline_symbols.space - let txt = cnt . spc . 'words' . spc . g:airline_right_alt_sep . spc - endif - end call setpos('.', position) let v:statusmsg = old_status - return txt + + let parts = split(stat) + if len(parts) > 11 + let cnt = str2nr(split(stat)[11]) + let spc = g:airline_symbols.space + let b:airline_wordcount = cnt . spc . 'words' . spc . g:airline_right_alt_sep . spc + else + unlet! b:airline_wordcount + endif endfunction function! airline#extensions#wordcount#apply(...) if &ft =~ g:airline#extensions#wordcount#filetypes - call airline#extensions#prepend_to_section('z', '%{airline#extensions#wordcount#count()}') + call airline#extensions#prepend_to_section('z', '%{get(b:, "airline_wordcount", "")}') endif endfunction function! airline#extensions#wordcount#init(ext) call a:ext.add_statusline_func('airline#extensions#wordcount#apply') + autocmd BufReadPost,CursorMoved,CursorMovedI * call s:update() endfunction