whitespace: Also check for Git conflict markers

This commit is contained in:
Christian Brabandt
2019-04-26 14:38:13 +02:00
parent d4f645777e
commit 538326ceac
2 changed files with 23 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ scriptencoding utf-8
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', 'mixed-indent-file']
let s:default_checks = ['indent', 'trailing', 'mixed-indent-file', 'conflicts']
let s:enabled = get(g:, 'airline#extensions#whitespace#enabled', 1)
let s:skip_check_ft = {'make': ['indent', 'mixed-indent-file']}
@@ -47,6 +47,14 @@ function! s:check_mixed_indent_file()
endif
endfunction
function! s:conflict_marker()
" Checks for git conflict markers
let annotation = '\%([0-9A-Za-z_.:]\+\)\?'
let pattern = '^\%(\%(<\{7} '.annotation. '\)\|\%(=\{7\}\)\|\%(>\{7\} '.annotation.'\)\)$'
let result = search(pattern, 'nw')
return result
endfunction
function! airline#extensions#whitespace#check()
let max_lines = get(g:, 'airline#extensions#whitespace#max_lines', 20000)
if &readonly || !&modifiable || !s:enabled || line('$') > max_lines
@@ -90,7 +98,12 @@ function! airline#extensions#whitespace#check()
let long = search('\%>'.&tw.'v.\+', 'nw')
endif
if trailing != 0 || mixed != 0 || long != 0 || !empty(mixed_file)
let conflicts = 0
if index(checks, 'conflicts') > -1
let conflicts = s:conflict_marker()
endif
if trailing != 0 || mixed != 0 || long != 0 || !empty(mixed_file) || conflicts != 0
let b:airline_whitespace_check = s:symbol
if strlen(s:symbol) > 0
let space = (g:airline_symbols.space)
@@ -115,6 +128,10 @@ function! airline#extensions#whitespace#check()
let mixed_indent_file_fmt = get(g:, 'airline#extensions#whitespace#mixed_indent_file_format', '[%s]mix-indent-file')
let b:airline_whitespace_check .= space.printf(mixed_indent_file_fmt, mixed_file)
endif
if !empty(conflicts)
let conflicts_fmt = get(g:, 'airline#extensions#whitespace#conflicts_format', '[%s]conflicts')
let b:airline_whitespace_check .= space.printf(conflicts_fmt, conflicts)
endif
endif
endif
endif