From f128f7810dee652dec02349fcacb78b26a515559 Mon Sep 17 00:00:00 2001 From: Kabbaj Amine Date: Fri, 7 Oct 2016 08:49:30 +0300 Subject: [PATCH] Add an initial ALEGetStatusLine function with customizable output, #25 --- plugin/ale/aaflags.vim | 9 +++++++++ plugin/ale/statusline.vim | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 plugin/ale/statusline.vim diff --git a/plugin/ale/aaflags.vim b/plugin/ale/aaflags.vim index f0c0bb7..10d8212 100644 --- a/plugin/ale/aaflags.vim +++ b/plugin/ale/aaflags.vim @@ -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'] +\) diff --git a/plugin/ale/statusline.vim b/plugin/ale/statusline.vim new file mode 100644 index 0000000..def7db6 --- /dev/null +++ b/plugin/ale/statusline.vim @@ -0,0 +1,39 @@ +" Author: KabbAmine +" 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