length guard before extracting the word count (#861)

This commit is contained in:
Bailey Ling 2015-10-06 11:21:04 -04:00
parent e1ffd1cc30
commit a253b68812

View File

@ -8,21 +8,24 @@ function! airline#extensions#wordcount#count()
let old_status = v:statusmsg let old_status = v:statusmsg
let position = getpos(".") let position = getpos(".")
exe "silent normal g\<c-g>" exe "silent normal g\<c-g>"
let cnt = 0 let txt = ''
let stat = v:statusmsg let stat = v:statusmsg
if stat != '--No lines in buffer--' if stat != '--No lines in buffer--'
let parts = split(v:statusmsg)
if len(parts) > 11
let cnt = str2nr(split(v:statusmsg)[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 end
call setpos('.', position) call setpos('.', position)
let v:statusmsg = old_status let v:statusmsg = old_status
return cnt return txt
endfunction endfunction
function! airline#extensions#wordcount#apply(...) function! airline#extensions#wordcount#apply(...)
if &ft =~ g:airline#extensions#wordcount#filetypes if &ft =~ g:airline#extensions#wordcount#filetypes
let spc = g:airline_symbols.space call airline#extensions#prepend_to_section('z', '%{airline#extensions#wordcount#count()}')
call airline#extensions#prepend_to_section('z',
\ '%{airline#extensions#wordcount#count()}' . spc . 'words' . spc . g:airline_right_alt_sep .spc)
endif endif
endfunction endfunction