From 2e3055541e88676a32439063f1f660166028c6ce Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Tue, 20 Jun 2017 22:26:22 +0200 Subject: [PATCH] syntastic: distinguis errors and warnings Currently the syntastic results are simply dumped into the error section, however syntastic does internally distinguish between error and warning sections. Therefore change the syntastic extension to dump errors into the error section and warnings into the warning section. closes #1480 --- autoload/airline/extensions/syntastic.vim | 37 ++++++++++++++++++----- autoload/airline/init.vim | 11 ++++--- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index adf54602..338e8e58 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -7,15 +7,38 @@ if !exists(':SyntasticCheck') finish endif -function! airline#extensions#syntastic#get_warnings() - let errors = SyntasticStatuslineFlag() - if strlen(errors) > 0 - return errors.(g:airline_symbols.space) +let s:error_symbol = get(g:, 'airline#extensions#syntastic#error_symbol', 'E:') +let s:warning_symbol = get(g:, 'airline#extensions#syntastic#warning_symbol', 'W:') + +function! airline#extensions#syntastic#get_warning() + return airline#extensions#syntastic#get('warning') +endfunction + +function! airline#extensions#syntastic#get_error() + return airline#extensions#syntastic#get('error') +endfunction + +function! airline#extensions#syntastic#get(type) + let _backup = get(g:, 'syntastic_stl_format', '') + let is_err = (a:type is# 'error') + let res = '' + if is_err + let g:syntastic_stl_format = '%E{%e}' + else + let g:syntastic_stl_format = '%W{%w}' + endif + let cnt = SyntasticStatuslineFlag() + if !empty(_backup) + let g:syntastic_stl_format = _backup + endif + if cnt == 0 + return '' + else + return (is_err ? s:error_symbol : s:warning_symbol).cnt endif - return '' endfunction function! airline#extensions#syntastic#init(ext) - call airline#parts#define_function('syntastic', 'airline#extensions#syntastic#get_warnings') + call airline#parts#define_function('syntastic-warn', 'airline#extensions#syntastic#get_warning') + call airline#parts#define_function('syntastic-err', 'airline#extensions#syntastic#get_error') endfunction - diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 67d44369..d718a245 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -142,9 +142,10 @@ function! airline#init#bootstrap() \ 'raw': '/%L%{g:airline_symbols.maxlinenr}', \ 'accent': 'bold'}) call airline#parts#define_function('ffenc', 'airline#parts#ffenc') - call airline#parts#define_empty(['hunks', 'branch', 'obsession', 'tagbar', 'syntastic', - \ 'eclim', 'whitespace','windowswap', 'ycm_error_count', 'ycm_warning_count', - \ 'neomake_error_count', 'neomake_warning_count', 'ale_error_count', 'ale_warning_count']) + call airline#parts#define_empty(['hunks', 'branch', 'obsession', 'tagbar', + \ 'syntastic-warn', 'syntastic-err', 'eclim', 'whitespace','windowswap', + \ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count', + \ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count']) call airline#parts#define_text('capslock', '') call airline#parts#define_text('xkblayout', '') @@ -189,9 +190,9 @@ function! airline#init#sections() endif endif if !exists('g:airline_section_error') - let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic', 'eclim', 'neomake_error_count', 'ale_error_count']) + let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic-err', 'eclim', 'neomake_error_count', 'ale_error_count']) endif if !exists('g:airline_section_warning') - let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'neomake_warning_count', 'ale_warning_count', 'whitespace']) + let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic-warn', 'neomake_warning_count', 'ale_warning_count', 'whitespace']) endif endfunction