From 27089517150e265687d515f80890f0772c5b4a9d Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:22:26 +0000 Subject: [PATCH 1/6] place hunks and branch extension into parts. --- autoload/airline/extensions/branch.vim | 2 +- autoload/airline/extensions/hunks.vim | 2 +- plugin/airline.vim | 19 ++++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 33a8e60..a746ea6 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -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 diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index aa70b8c..66403b1 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -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 diff --git a/plugin/airline.vim b/plugin/airline.vim index e06cd19..4a3984e 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -44,6 +44,8 @@ call extend(g:airline_parts, { \ 'paste': '%{airline#parts#paste()}', \ 'readonly': '%#airline_file#%{airline#parts#readonly()}', \ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}', + \ 'hunks': '', + \ 'branch': '', \ }, 'keep') call s:check_defined('g:airline_mode_map', {}) @@ -69,15 +71,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 +78,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', '%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_theme_defined = exists('g:airline_theme') if s:airline_theme_defined || !airline#switch_matching_theme() From 24a2035e4218320314278a1dd16f019288103355 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:24:01 +0000 Subject: [PATCH 2/6] place bufferline into parts. --- autoload/airline/extensions/bufferline.vim | 4 +--- plugin/airline.vim | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index db2eed8..8df5935 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -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 diff --git a/plugin/airline.vim b/plugin/airline.vim index 4a3984e..20c69a2 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -44,6 +44,7 @@ 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': '', \ }, 'keep') @@ -80,7 +81,7 @@ function! s:init() 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', '%f%m') + 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', '%{&filetype}') call s:check_defined('g:airline_section_y', g:airline_parts.ffenc) From f9718e6b656dadf4bc32c041aae774e66855d694 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:25:55 +0000 Subject: [PATCH 3/6] place tagbar into parts. --- autoload/airline/extensions/tagbar.vim | 4 ++-- plugin/airline.vim | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions/tagbar.vim b/autoload/airline/extensions/tagbar.vim index f1ad0e7..bf7efee 100644 --- a/autoload/airline/extensions/tagbar.vim +++ b/autoload/airline/extensions/tagbar.vim @@ -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 diff --git a/plugin/airline.vim b/plugin/airline.vim index 20c69a2..305fe38 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -47,6 +47,7 @@ call extend(g:airline_parts, { \ 'file': '%f%m', \ 'hunks': '', \ 'branch': '', + \ 'tagbar': '', \ }, 'keep') call s:check_defined('g:airline_mode_map', {}) @@ -83,7 +84,7 @@ function! s:init() 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', '%{&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_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c') call s:check_defined('g:airline_section_warning', '__') From 6fc8c00ef1f86379da7fa9a1ae15eaa506915d3a Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:38:34 +0000 Subject: [PATCH 4/6] place syntastic and whitespace into parts. --- autoload/airline/extensions.vim | 14 ++++++-------- autoload/airline/extensions/syntastic.vim | 10 +++++++--- autoload/airline/extensions/whitespace.vim | 16 ++++------------ plugin/airline.vim | 4 +++- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 4aac225..6ce8268 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -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 diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index 61edd8a..ef8d874 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -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 diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 7478a7e..a2029ac 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -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 diff --git a/plugin/airline.vim b/plugin/airline.vim index 305fe38..4c0f603 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -48,6 +48,8 @@ call extend(g:airline_parts, { \ 'hunks': '', \ 'branch': '', \ 'tagbar': '', + \ 'syntastic': '', + \ 'whitespace': '', \ }, 'keep') 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_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', '__') + 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() From ea4e0280fba21b435cce090cb873f15c3b537665 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:44:03 +0000 Subject: [PATCH 5/6] rename warningmsg to warning. --- autoload/airline.vim | 2 +- autoload/airline/extensions/default.vim | 2 +- autoload/airline/themes/solarized.vim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 33d19bc..63fc270 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -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 diff --git a/autoload/airline/extensions/default.vim b/autoload/airline/extensions/default.vim index 764d65d..3af84dd 100644 --- a/autoload/airline/extensions/default.vim +++ b/autoload/airline/extensions/default.vim @@ -39,7 +39,7 @@ function! airline#extensions#default#apply(builder, context) 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_section('airline_warning', s:get_section(winnr, 'warning', '', '')) call a:builder.add_raw('%)') endif endif diff --git a/autoload/airline/themes/solarized.vim b/autoload/airline/themes/solarized.vim index 521e46f..921ebac 100644 --- a/autoload/airline/themes/solarized.vim +++ b/autoload/airline/themes/solarized.vim @@ -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 = { From 39c3ba360e3bcdaa5930bd2cd6344749b4155495 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:57:18 +0000 Subject: [PATCH 6/6] support configurable layouts. --- autoload/airline/extensions/default.vim | 33 ++++++++++++++--------- autoload/airline/extensions/syntastic.vim | 2 +- plugin/airline.vim | 6 ++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/autoload/airline/extensions/default.vim b/autoload/airline/extensions/default.vim index 3af84dd..4821844 100644 --- a/autoload/airline/extensions/default.vim +++ b/autoload/airline/extensions/default.vim @@ -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 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_warning', s:get_section(winnr, 'warning', '', '')) - call a:builder.add_raw('%)') - endif + call build_sections(a:builder, s:layout[1], winnr) endif return 1 diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index ef8d874..24308c5 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -4,7 +4,7 @@ function! airline#extensions#syntastic#get_warnings() let errors = SyntasticStatuslineFlag() if strlen(errors) > 0 - return ' '.errors + return errors.' ' endif return '' endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index 4c0f603..f6ebe0c 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -84,12 +84,12 @@ function! s:init() 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_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)) + 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()