add whitespace toggle command

This commit is contained in:
Bailey Ling 2013-08-08 14:42:27 +00:00
parent 57955b3b86
commit 4485b03e51
4 changed files with 21 additions and 4 deletions

View File

@ -137,7 +137,7 @@ function! airline#extensions#load()
endif
if g:airline_detect_whitespace
call airline#extensions#whitespace#init(s:ext)
call airline#extensions#whitespace#init()
endif
call airline#exec_funcrefs(g:airline_statusline_funcrefs, 0)

View File

@ -4,7 +4,7 @@
" http://got-ravings.blogspot.com/2008/10/vim-pr0n-statusline-whitespace-flags.html
function! airline#extensions#whitespace#check()
if &readonly
if &readonly || !g:airline_detect_whitespace
return ''
endif
@ -37,8 +37,21 @@ function! airline#extensions#whitespace#apply()
endif
endfunction
function! airline#extensions#whitespace#init(ext)
call a:ext.add_statusline_funcref(function('airline#extensions#whitespace#apply'))
function! airline#extensions#whitespace#toggle()
let g:airline_detect_whitespace = !g:airline_detect_whitespace
if g:airline_detect_whitespace
call airline#extensions#whitespace#init()
else
autocmd! airline_whitespace CursorHold,BufWritePost
endif
endfunction
let s:initialized = 0
function! airline#extensions#whitespace#init()
if !s:initialized
let s:initialized = 1
call add(g:airline_statusline_funcrefs, function('airline#extensions#whitespace#apply'))
endif
augroup airline_whitespace
autocmd!

View File

@ -120,6 +120,9 @@ COMMANDS *airline-commands*
:AirlineTheme {theme-name} *:AirlineTheme*
Displays or changes the current theme.
:AirlineToggleWhitespace *:AirlineToggleWhitespace*
Toggles whitespace detection.
==============================================================================
CUSTOMIZATION *airline-customization*

View File

@ -80,6 +80,7 @@ function! s:airline_theme(...)
endif
endfunction
command! -nargs=? -complete=customlist,<sid>get_airline_themes AirlineTheme call <sid>airline_theme(<f-args>)
command! AirlineToggleWhitespace call airline#extensions#whitespace#toggle()
augroup airline
autocmd!