From 7fb9bcf2c94c465f3e0331df8264396504df4f5a Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 7 Aug 2013 00:48:53 +0000 Subject: [PATCH] improve whitespace detection; add support for mixed indents --- autoload/airline/extensions/whitespace.vim | 31 +++++++++++++++++++--- doc/airline.txt | 23 +++++++++++----- plugin/airline.vim | 1 + 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 3c99300..fe842c2 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -2,10 +2,35 @@ " 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." " : ""}' + if line('$') > g:airline_whitespace_max_lines + return '' + endif + + let trailing = search(' $', 'nw') != 0 + let mixed = search('^ ', 'nw') != 0 && search('^\t', 'nw') != 0 + + if trailing || mixed + let text = " ".g:airline_whitespace_symbol." " + if g:airline_detect_whitespace == 1 + if trailing + let text .= 'trailing ' + endif + if mixed + let text .= 'mixed-indent ' + endif + endif + return text + endif + return '' +endfunction! + +function! airline#extensions#whitespace#apply() + if exists('w:airline_active') && w:airline_active + let w:airline_section_warning = '%{airline#extensions#whitespace#check()}' + endif endfunction function! airline#extensions#whitespace#init(ext) - call a:ext.add_statusline_funcref(function('airline#extensions#whitespace#check')) + call a:ext.add_statusline_funcref(function('airline#extensions#whitespace#apply')) endfunction + diff --git a/doc/airline.txt b/doc/airline.txt index 83db705..df003e6 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -73,6 +73,13 @@ values): let g:airline_detect_iminsert=1 < +* enable whitespace detection +> + let g:airline_detect_whitespace=0 "disabled + let g:airline_detect_whitespace=1 "icon and message (default) + let g:airline_detect_whitespace=2 "icon only +< + * change the default theme > let g:airline_theme='dark' @@ -132,6 +139,7 @@ separators, as well as the powerline font glyths. let g:airline_paste_symbol = 'ρ' let g:airline_paste_symbol = 'Þ' let g:airline_paste_symbol = '∥' + let g:airline_whitespace_symbol = 'Ξ' " powerline symbols let g:airline_left_sep = '' @@ -157,13 +165,14 @@ with the usual statusline syntax. > " here are the the default values - let g:airline_section_a (the mode/paste indicator) - let g:airline_section_b (the fugitive/lawrencium branch indicator) - let g:airline_section_c (bufferline or filename) - let g:airline_section_gutter (syntastic, readonly flag) - let g:airline_section_x (tagbar, filetype) - let g:airline_section_y (fileencoding, fileformat) - let g:airline_section_z (percentage, line number, column number) + let g:airline_section_a (the mode/paste indicator) + let g:airline_section_b (the fugitive/lawrencium branch indicator) + let g:airline_section_c (bufferline or filename) + let g:airline_section_gutter (syntastic, readonly flag) + let g:airline_section_x (tagbar, filetype) + let g:airline_section_y (fileencoding, fileformat) + let g:airline_section_z (percentage, line number, column number) + let g:airline_section_warning (special section that only appears sometimes) " here is an example of how you could replace the branch indicator with " the current working directory, followed by the filename. diff --git a/plugin/airline.vim b/plugin/airline.vim index 2d47cc6..6df2204 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -29,6 +29,7 @@ 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_whitespace', 1) call s:check_defined('g:airline_whitespace_symbol', '✹') +call s:check_defined('g:airline_whitespace_max_lines', 3000) 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')?' ':':')