place syntastic and whitespace into parts.

This commit is contained in:
Bailey Ling 2013-08-27 23:38:34 +00:00
parent f9718e6b65
commit 6fc8c00ef1
4 changed files with 20 additions and 24 deletions

View File

@ -185,14 +185,12 @@ function! airline#extensions#load()
call airline#extensions#virtualenv#init(s:ext) call airline#extensions#virtualenv#init(s:ext)
endif endif
if g:airline_section_warning == '__' if (get(g:, 'airline#extensions#whitespace#enabled', 1) && get(g:, 'airline_detect_whitespace', 1))
if (get(g:, 'airline#extensions#whitespace#enabled', 1) && get(g:, 'airline_detect_whitespace', 1)) call airline#extensions#whitespace#init(s:ext)
call airline#extensions#whitespace#init(s:ext) endif
endif if (get(g:, 'airline#extensions#syntastic#enabled', 1) && get(g:, 'airline_enable_syntastic', 1))
if (get(g:, 'airline#extensions#syntastic#enabled', 1) && get(g:, 'airline_enable_syntastic', 1)) \ && exists(':SyntasticCheck')
\ && exists(':SyntasticCheck') call airline#extensions#syntastic#init(s:ext)
call airline#extensions#syntastic#init(s:ext)
endif
endif endif
" load all other extensions not part of the default distribution " load all other extensions not part of the default distribution

View File

@ -1,11 +1,15 @@
" MIT License. Copyright (c) 2013 Bailey Ling. " MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2 " vim: et ts=2 sts=2 sw=2
function! airline#extensions#syntastic#apply(...) function! airline#extensions#syntastic#get_warnings()
call airline#extensions#append_to_section('warning', '%{SyntasticStatuslineFlag()}') let errors = SyntasticStatuslineFlag()
if strlen(errors) > 0
return ' '.errors
endif
return ''
endfunction endfunction
function! airline#extensions#syntastic#init(ext) function! airline#extensions#syntastic#init(ext)
call a:ext.add_statusline_func('airline#extensions#syntastic#apply') let g:airline_parts.syntastic = '%{airline#extensions#syntastic#get_warnings()}'
endfunction endfunction

View File

@ -16,7 +16,6 @@ let s:checks = get(g:, 'airline#extensions#whitespace#checks', ['indent', 'trail
let s:trailing_format = get(g:, 'airline#extensions#whitespace#trailing_format', 'trailing[%s]') let s:trailing_format = get(g:, 'airline#extensions#whitespace#trailing_format', 'trailing[%s]')
let s:mixed_indent_format = get(g:, 'airline#extensions#whitespace#mixed_indent_format', 'mixed-indent[%s]') let s:mixed_indent_format = get(g:, 'airline#extensions#whitespace#mixed_indent_format', 'mixed-indent[%s]')
let s:initialized = 0
let s:enabled = 1 let s:enabled = 1
function! airline#extensions#whitespace#check() function! airline#extensions#whitespace#check()
@ -39,14 +38,14 @@ function! airline#extensions#whitespace#check()
endif endif
if trailing != 0 || mixed if trailing != 0 || mixed
let b:airline_whitespace_check = s:symbol." " let b:airline_whitespace_check = s:symbol.' '
if s:show_message if s:show_message
if trailing != 0 if trailing != 0
let b:airline_whitespace_check .= printf(s:trailing_format, trailing).' ' let b:airline_whitespace_check .= printf(s:trailing_format, trailing)
endif endif
if mixed if mixed
let mixnr = indents[0] == indents[1] ? indents[0] : indents[2] let mixnr = indents[0] == indents[1] ? indents[0] : indents[2]
let b:airline_whitespace_check .= printf(s:mixed_indent_format, mixnr).' ' let b:airline_whitespace_check .= printf(s:mixed_indent_format, mixnr)
endif endif
endif endif
endif endif
@ -54,10 +53,6 @@ function! airline#extensions#whitespace#check()
return b:airline_whitespace_check return b:airline_whitespace_check
endfunction! endfunction!
function! airline#extensions#whitespace#apply(...)
call airline#extensions#append_to_section('warning', ' %{airline#extensions#whitespace#check()}')
endfunction
function! airline#extensions#whitespace#toggle() function! airline#extensions#whitespace#toggle()
if s:enabled if s:enabled
autocmd! airline_whitespace CursorHold,BufWritePost autocmd! airline_whitespace CursorHold,BufWritePost
@ -69,10 +64,7 @@ function! airline#extensions#whitespace#toggle()
endfunction endfunction
function! airline#extensions#whitespace#init(...) function! airline#extensions#whitespace#init(...)
if !s:initialized let g:airline_parts.whitespace = '%{airline#extensions#whitespace#check()}'
let s:initialized = 1
call airline#add_statusline_func('airline#extensions#whitespace#apply')
endif
unlet! b:airline_whitespace_check unlet! b:airline_whitespace_check
augroup airline_whitespace augroup airline_whitespace

View File

@ -48,6 +48,8 @@ call extend(g:airline_parts, {
\ 'hunks': '', \ 'hunks': '',
\ 'branch': '', \ 'branch': '',
\ 'tagbar': '', \ 'tagbar': '',
\ 'syntastic': '',
\ 'whitespace': '',
\ }, 'keep') \ }, 'keep')
call s:check_defined('g:airline_mode_map', {}) call s:check_defined('g:airline_mode_map', {})
@ -87,7 +89,7 @@ function! s:init()
call s:check_defined('g:airline_section_x', (g:airline_parts.tagbar).'%{&filetype}') call s:check_defined('g:airline_section_x', (g:airline_parts.tagbar).'%{&filetype}')
call s:check_defined('g:airline_section_y', g:airline_parts.ffenc) call s:check_defined('g:airline_section_y', g:airline_parts.ffenc)
call s:check_defined('g:airline_section_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c') call s:check_defined('g:airline_section_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c')
call s:check_defined('g:airline_section_warning', '__') call s:check_defined('g:airline_section_warning', (g:airline_parts.syntastic).' '.(g:airline_parts.whitespace))
let s:airline_theme_defined = exists('g:airline_theme') let s:airline_theme_defined = exists('g:airline_theme')
if s:airline_theme_defined || !airline#switch_matching_theme() if s:airline_theme_defined || !airline#switch_matching_theme()