Add an initial ALEGetStatusLine function with customizable output, #25

This commit is contained in:
Kabbaj Amine 2016-10-07 08:49:30 +03:00
parent c5d3cc5bc7
commit f128f7810d
2 changed files with 48 additions and 0 deletions

View File

@ -39,3 +39,12 @@ let g:ale_warn_about_trailing_whitespace =
" This flag can be set to 1 to keep sign gutter always open
let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0)
" String format for statusline
" Its a list where:
" * The 1st element is for errors
" * The 2nd element is for warnings
" * The 3rd element is when there are no errors
let g:ale_statusline_format = get(g:, 'ale_statusline_format',
\ ['%d error(s)', '%d warning(s)', 'OK']
\)

39
plugin/ale/statusline.vim Normal file
View File

@ -0,0 +1,39 @@
" Author: KabbAmine <amine.kabb@gmail.com>
" Description: Statusline related function(s)
function! ALEGetStatusLine() abort
" Returns a formatted string that can be integrated in the
" statusline
let buf = bufnr('%')
let bufLoclist = g:ale_buffer_loclist_map
if !has_key(bufLoclist, buf)
return ''
endif
let errors = 0
let warnings = 0
for e in bufLoclist[buf]
if e.type ==# 'E'
let errors += 1
else
let warnings += 1
endif
endfor
let errors = errors ? printf(g:ale_statusline_format[0], errors) : ''
let warnings = warnings ? printf(g:ale_statusline_format[1], warnings) : ''
let noErrors = g:ale_statusline_format[2]
" Different formats if no errors or no warnings
if empty(errors) && empty(warnings)
let res = noErrors
elseif !empty(errors) && !empty(warnings)
let res = printf('%s %s', errors, warnings)
else
let res = empty(errors) ? warnings : errors
endif
return res
endfunction