Merge branch 'dynamic' (#164)

This commit is contained in:
Bailey Ling 2013-08-28 00:00:42 +00:00
commit 4b9cda77dd
11 changed files with 59 additions and 53 deletions

View File

@ -26,7 +26,7 @@ function! airline#add_inactive_statusline_func(name)
endfunction
function! airline#load_theme()
highlight! default link airline_warningmsg WarningMsg
highlight! default link airline_warning WarningMsg
call airline#highlighter#load_theme()
call airline#extensions#load_theme()
endfunction

View File

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

View File

@ -31,6 +31,6 @@ function! airline#extensions#branch#get_head()
endfunction
function! airline#extensions#branch#init(ext)
let g:airline_section_b .= '%{airline#extensions#branch#get_head()}'
let g:airline_parts.branch = '%{airline#extensions#branch#get_head()}'
endfunction

View File

@ -10,7 +10,5 @@ function! airline#extensions#bufferline#init(ext)
let g:bufferline_active_buffer_right = ''
let g:bufferline_separator = ' '
if g:airline_section_c == '%f%m'
let g:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string()
endif
let g:airline_parts.file = '%{bufferline#refresh_status()}'.bufferline#get_status_string()
endfunction

View File

@ -7,6 +7,10 @@ let s:section_truncate_width = get(g:, 'airline#extensions#default#section_trunc
\ 'y': 88,
\ 'z': 45,
\ })
let s:layout = get(g:, 'airline#extensions#default#layout', [
\ [ 'a', 'b', 'c' ],
\ [ 'x', 'y', 'z', 'warning' ]
\ ])
function! s:get_section(winnr, key, ...)
if has_key(s:section_truncate_width, a:key)
@ -19,29 +23,34 @@ function! s:get_section(winnr, key, ...)
return empty(text) ? '' : prefix.text.suffix
endfunction
function! s:build_sections(builder, keys, winnr)
for key in a:keys
" i have no idea why the warning section needs special treatment, but it's
" needed to prevent separators from showing up
if key == 'warning'
call a:builder.add_raw('%(')
endif
call a:builder.add_section('airline_'.key, s:get_section(a:winnr, key))
if key == 'warning'
call a:builder.add_raw('%)')
endif
endfor
endfunction
function! airline#extensions#default#apply(builder, context)
let winnr = a:context.winnr
let active = a:context.active
if airline#util#getwinvar(winnr, 'airline_render_left', active || (!active && !g:airline_inactive_collapse))
call a:builder.add_section('airline_a', s:get_section(winnr, 'a'))
call a:builder.add_section('airline_b', s:get_section(winnr, 'b'))
call a:builder.add_section('airline_c', '%<'.s:get_section(winnr, 'c'))
call <sid>build_sections(a:builder, s:layout[0], winnr)
else
call a:builder.add_section('airline_c', '%f%m')
call a:builder.add_section('airline_a', '%f%m')
endif
call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
if airline#util#getwinvar(winnr, 'airline_render_right', 1)
call a:builder.add_section('airline_x', s:get_section(winnr, 'x'))
call a:builder.add_section('airline_y', s:get_section(winnr, 'y'))
call a:builder.add_section('airline_z', s:get_section(winnr, 'z'))
if active
call a:builder.add_raw('%(')
call a:builder.add_section('airline_warningmsg', s:get_section(winnr, 'warning', '', ''))
call a:builder.add_raw('%)')
endif
call <sid>build_sections(a:builder, s:layout[1], winnr)
endif
return 1

View File

@ -54,6 +54,6 @@ function! airline#extensions#hunks#get_hunks()
endfunction
function! airline#extensions#hunks#init(ext)
let g:airline_section_b .= '%{airline#extensions#hunks#get_hunks()}'
let g:airline_parts.hunks = '%{airline#extensions#hunks#get_hunks()}'
endfunction

View File

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

View File

@ -20,7 +20,7 @@ function! airline#extensions#tagbar#init(ext)
call a:ext.add_inactive_statusline_func('airline#extensions#tagbar#inactive_apply')
let g:tagbar_status_func = 'airline#extensions#tagbar#get_status'
let g:airline_section_x = '%(%{get(w:,"airline_active",0) ? tagbar#currenttag("%s","") : ""} '
\ .g:airline_right_alt_sep.' %)'.g:airline_section_x
let g:airline_parts.tagbar = '%(%{get(w:,"airline_active",0) ? tagbar#currenttag("%s","") : ""} '
\ .g:airline_right_alt_sep.' %)'
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:mixed_indent_format = get(g:, 'airline#extensions#whitespace#mixed_indent_format', 'mixed-indent[%s]')
let s:initialized = 0
let s:enabled = 1
function! airline#extensions#whitespace#check()
@ -39,14 +38,14 @@ function! airline#extensions#whitespace#check()
endif
if trailing != 0 || mixed
let b:airline_whitespace_check = s:symbol." "
let b:airline_whitespace_check = s:symbol.' '
if s:show_message
if trailing != 0
let b:airline_whitespace_check .= printf(s:trailing_format, trailing).' '
let b:airline_whitespace_check .= printf(s:trailing_format, trailing)
endif
if mixed
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
@ -54,10 +53,6 @@ function! airline#extensions#whitespace#check()
return b:airline_whitespace_check
endfunction!
function! airline#extensions#whitespace#apply(...)
call airline#extensions#append_to_section('warning', ' %{airline#extensions#whitespace#check()}')
endfunction
function! airline#extensions#whitespace#toggle()
if s:enabled
autocmd! airline_whitespace CursorHold,BufWritePost
@ -69,10 +64,7 @@ function! airline#extensions#whitespace#toggle()
endfunction
function! airline#extensions#whitespace#init(...)
if !s:initialized
let s:initialized = 1
call airline#add_statusline_func('airline#extensions#whitespace#apply')
endif
let g:airline_parts.whitespace = '%{airline#extensions#whitespace#check()}'
unlet! b:airline_whitespace_check
augroup airline_whitespace

View File

@ -112,7 +112,7 @@ function! s:generate()
\ [s:N3[0].g, s:N3[1].g, s:N3[0].t, s:N3[1].t, s:N3[2]],
\ s:NFa)
let g:airline#themes#solarized#palette.normal.airline_warningmsg = [
let g:airline#themes#solarized#palette.normal.airline_warning = [
\ s:NW[0].g, s:NW[1].g, s:NW[0].t, s:NW[1].t, s:NW[2]]
let g:airline#themes#solarized#palette.normal_modified = {

View File

@ -44,6 +44,12 @@ call extend(g:airline_parts, {
\ 'paste': '%{airline#parts#paste()}',
\ 'readonly': '%#airline_file#%{airline#parts#readonly()}',
\ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}',
\ 'file': '%f%m',
\ 'hunks': '',
\ 'branch': '',
\ 'tagbar': '',
\ 'syntastic': '',
\ 'whitespace': '',
\ }, 'keep')
call s:check_defined('g:airline_mode_map', {})
@ -69,15 +75,6 @@ call extend(g:airline_theme_map, {
\ '.*solarized.*': 'solarized',
\ }, 'keep')
call s:check_defined('g:airline_section_a', (g:airline_parts.mode).(g:airline_parts.paste).(g:airline_parts.iminsert))
call s:check_defined('g:airline_section_b', '')
call s:check_defined('g:airline_section_c', '%f%m')
call s:check_defined('g:airline_section_gutter', ' '.(g:airline_parts.readonly).'%=')
call s:check_defined('g:airline_section_x', '%{&filetype}')
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_warning', '__')
let s:airline_initialized = 0
let s:airline_theme_defined = 0
function! s:init()
@ -85,6 +82,14 @@ function! s:init()
let s:airline_initialized = 1
call airline#extensions#load()
call s:check_defined('g:airline_section_a', (g:airline_parts.mode).(g:airline_parts.paste).(g:airline_parts.iminsert))
call s:check_defined('g:airline_section_b', (g:airline_parts.hunks).(g:airline_parts.branch))
call s:check_defined('g:airline_section_c', '%<'.(g:airline_parts.file))
call s:check_defined('g:airline_section_gutter', ' '.(g:airline_parts.readonly).'%=')
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_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c ')
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')
if s:airline_theme_defined || !airline#switch_matching_theme()