From d7b36e0cf25684ce8eeadfd057d42cacc8b60d46 Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Thu, 13 Oct 2016 08:10:50 -0500 Subject: [PATCH] Make statusline initial updates more elegant --- autoload/ale/statusline.vim | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim index 48a51f1..8a31bc3 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)