Merge pull request #1005 from chrisbra/mixed_indent
Detect inconsistent mixed indentation in a file
This commit is contained in:
commit
9e6a917c52
@ -5,11 +5,12 @@
|
||||
|
||||
let s:show_message = get(g:, 'airline#extensions#whitespace#show_message', 1)
|
||||
let s:symbol = get(g:, 'airline#extensions#whitespace#symbol', g:airline_symbols.whitespace)
|
||||
let s:default_checks = ['indent', 'trailing']
|
||||
let s:default_checks = ['indent', 'trailing', 'mixed-indent-file']
|
||||
|
||||
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:long_format = get(g:, 'airline#extensions#whitespace#long_format', 'long[%s]')
|
||||
let s:mixed_indent_file_format = get(g:, 'airline#extensions#whitespace#mixed_indent_file_format', 'mix-indent-file[%s]')
|
||||
let s:indent_algo = get(g:, 'airline#extensions#whitespace#mixed_indent_algo', 0)
|
||||
|
||||
let s:max_lines = get(g:, 'airline#extensions#whitespace#max_lines', 20000)
|
||||
@ -32,6 +33,16 @@ function! s:check_mixed_indent()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:check_mixed_indent_file()
|
||||
let indent_tabs = search('\v(^\t+)', 'nw')
|
||||
let indent_spc = search('\v(^ +)', 'nw')
|
||||
if indent_tabs > 0 && indent_spc > 0
|
||||
return printf("%d:%d", indent_tabs, indent_spc)
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#whitespace#check()
|
||||
if &readonly || !&modifiable || !s:enabled || line('$') > s:max_lines
|
||||
return ''
|
||||
@ -58,12 +69,17 @@ function! airline#extensions#whitespace#check()
|
||||
let mixed = s:check_mixed_indent()
|
||||
endif
|
||||
|
||||
let mixed_file = ''
|
||||
if index(checks, 'mixed-indent-file') > -1
|
||||
let mixed_file = s:check_mixed_indent_file()
|
||||
endif
|
||||
|
||||
let long = 0
|
||||
if index(checks, 'long') > -1 && &tw > 0
|
||||
let long = search('\%>'.&tw.'v.\+', 'nw')
|
||||
endif
|
||||
|
||||
if trailing != 0 || mixed != 0 || long != 0
|
||||
if trailing != 0 || mixed != 0 || long != 0 || !empty(mixed_file)
|
||||
let b:airline_whitespace_check = s:symbol
|
||||
if s:show_message
|
||||
if trailing != 0
|
||||
@ -75,6 +91,9 @@ function! airline#extensions#whitespace#check()
|
||||
if long != 0
|
||||
let b:airline_whitespace_check .= (g:airline_symbols.space).printf(s:long_format, long)
|
||||
endif
|
||||
if !empty(mixed_file)
|
||||
let b:airline_whitespace_check .= (g:airline_symbols.space).printf(s:mixed_indent_file_format, mixed_file)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
@ -467,7 +467,11 @@ eclim <https://eclim.org>
|
||||
let g:airline#extensions#whitespace#symbol = '!'
|
||||
<
|
||||
* configure which whitespace checks to enable. >
|
||||
let g:airline#extensions#whitespace#checks = [ 'indent', 'trailing', 'long' ]
|
||||
" indent: mixed indent within a line
|
||||
" long: overlong lines
|
||||
" trailing: trailing whitespace
|
||||
" mixed-indent-file: different indentation in different lines
|
||||
let g:airline#extensions#whitespace#checks = [ 'indent', 'trailing', 'long', 'mixed-indent-file' ]
|
||||
<
|
||||
* configure the maximum number of lines where whitespace checking is enabled. >
|
||||
let g:airline#extensions#whitespace#max_lines = 20000
|
||||
@ -479,6 +483,7 @@ eclim <https://eclim.org>
|
||||
let g:airline#extensions#whitespace#trailing_format = 'trailing[%s]'
|
||||
let g:airline#extensions#whitespace#mixed_indent_format = 'mixed-indent[%s]'
|
||||
let g:airline#extensions#whitespace#long_format = 'long[%s]'
|
||||
let g:airline#extensions#whitespace#mixed_indent_file_format = 'mix-indent-file[%s]'
|
||||
|
||||
* configure custom trailing whitespace regexp rule >
|
||||
let g:airline#extensions#whitespace#trailing_regexp = '\s$'
|
||||
|
Loading…
Reference in New Issue
Block a user