Make statusline initial updates more elegant

This commit is contained in:
Bjorn Neergaard 2016-10-13 08:10:50 -05:00
parent dc58db7640
commit d7b36e0cf2
No known key found for this signature in database
GPG Key ID: D8F4DB0CE841305D

View File

@ -17,16 +17,11 @@ function! ale#statusline#Update(buffer, loclist) abort
let g:ale_buffer_count_map[a:buffer] = [l:errors, l:warnings]
endfunction
" Returns a tuple of errors and warnings (or false if no data exists)
" for use in third-party integrations.
" Returns a tuple of errors and warnings for use in third-party integrations.
function! ale#statusline#Count(buffer) abort
" Cache is cold, so manually ask for an update.
if !has_key(g:ale_buffer_count_map, a:buffer)
if has_key(g:ale_buffer_loclist_map, a:buffer)
call ale#statusline#Update(a:buffer, g:ale_buffer_loclist_map[a:buffer])
return ale#statusline#Count(a:buffer)
else
return 0
endif
call ale#statusline#Update(a:buffer, get(g:ale_buffer_loclist_map, a:buffer, []))
endif
return g:ale_buffer_count_map[a:buffer]
@ -36,22 +31,19 @@ endfunction
function! ale#statusline#Status() abort
let l:buffer = bufnr('%')
" Cache is cold, so manually ask for an update.
if !has_key(g:ale_buffer_count_map, l:buffer)
if has_key(g:ale_buffer_loclist_map, l:buffer)
call ale#statusline#Update(l:buffer, g:ale_buffer_loclist_map[l:buffer])
return ale#statusline#Status()
else
return ''
endif
call ale#statusline#Update(l:buffer, get(g:ale_buffer_loclist_map, l:buffer, []))
endif
" Build strings based on user formatting preferences.
let l:errors = g:ale_buffer_count_map[l:buffer][0] ?
\ printf(g:ale_statusline_format[0], g:ale_buffer_count_map[l:buffer][0]) : ''
let l:warnings = g:ale_buffer_count_map[l:buffer][1] ?
\ printf(g:ale_statusline_format[1], g:ale_buffer_count_map[l:buffer][1]) : ''
let l:no_errors = g:ale_statusline_format[2]
" Different formats if no errors or no warnings
" Different formats based on the combination of errors and warnings.
if empty(l:errors) && empty(l:warnings)
let l:res = l:no_errors
elseif !empty(l:errors) && !empty(l:warnings)