summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorBjorn Neergaard <bjorn@neersighted.com>2016-10-13 08:10:50 -0500
committerBjorn Neergaard <bjorn@neersighted.com>2016-10-13 08:51:40 -0500
commitd7b36e0cf25684ce8eeadfd057d42cacc8b60d46 (patch)
tree86ccb4f84cefcd521dd44c6d651552df72c35a19 /autoload
parentdc58db764064ec924b78c43acff32607845edac5 (diff)
downloadale-d7b36e0cf25684ce8eeadfd057d42cacc8b60d46.zip
Make statusline initial updates more elegant
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/statusline.vim22
1 files changed, 7 insertions, 15 deletions
diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim
index 48a51f19..8a31bc39 100644
--- a/autoload/ale/statusline.vim
+++ b/autoload/ale/statusline.vim
@@ -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)