From 528f56472c52da68895482446dce557d6f117b02 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 7 Aug 2013 00:17:33 +0000 Subject: [PATCH] introduce new warning section, and refactor whitespace into an extension which uses it --- autoload/airline.vim | 3 +-- autoload/airline/extensions.vim | 4 ++++ autoload/airline/extensions/whitespace.vim | 11 +++++++++++ plugin/airline.vim | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 autoload/airline/extensions/whitespace.vim diff --git a/autoload/airline.vim b/autoload/airline.vim index f6dab68..2639806 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -105,8 +105,7 @@ function! s:get_statusline(winnr, active) let sl.=a:active ? g:airline_right_sep : g:airline_right_alt_sep let sl.=l:mode_color let sl.=s:get_section(a:winnr, 'z') - let sl.="%#Al3#" - let sl.='%{g:airline_detect_white_space && search(" $","nw") ? " ✹ " : ""}' + let sl.='%#Al3#'.s:getwinvar(a:winnr, 'airline_section_warning', '') endif return sl endfunction diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index f7b7402..82c6710 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -136,6 +136,10 @@ function! airline#extensions#load() call airline#extensions#bufferline#init(s:ext) endif + if g:airline_detect_whitespace + call airline#extensions#whitespace#init(s:ext) + endif + call airline#exec_funcrefs(g:airline_statusline_funcrefs, 0) endfunction diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim new file mode 100644 index 0000000..3c99300 --- /dev/null +++ b/autoload/airline/extensions/whitespace.vim @@ -0,0 +1,11 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#extensions#whitespace#check() + let w:airline_section_warning = '%{get(w:, "airline_active", 0) && search(" $", "nw")' + \ .'? " ".g:airline_whitespace_symbol." " : ""}' +endfunction + +function! airline#extensions#whitespace#init(ext) + call a:ext.add_statusline_funcref(function('airline#extensions#whitespace#check')) +endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index 36e7e66..2d47cc6 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -27,7 +27,8 @@ call s:check_defined('g:airline_enable_tagbar', 1) call s:check_defined('g:airline_detect_iminsert', 0) call s:check_defined('g:airline_detect_modified', 1) call s:check_defined('g:airline_detect_paste', 1) -call s:check_defined('g:airline_detect_white_space', 1) +call s:check_defined('g:airline_detect_whitespace', 1) +call s:check_defined('g:airline_whitespace_symbol', '✹') call s:check_defined('g:airline_branch_prefix', exists('g:airline_powerline_fonts')?' ':'') call s:check_defined('g:airline_readonly_symbol', exists('g:airline_powerline_fonts')?'':'RO') call s:check_defined('g:airline_linecolumn_prefix', exists('g:airline_powerline_fonts')?' ':':')