From 538326ceacc60da86fab0978ab10a0bf308dacd1 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Fri, 26 Apr 2019 14:38:13 +0200 Subject: [PATCH] whitespace: Also check for Git conflict markers --- autoload/airline/extensions/whitespace.vim | 21 +++++++++++++++++++-- doc/airline.txt | 6 ++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 23916cb..453f0aa 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -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 diff --git a/doc/airline.txt b/doc/airline.txt index 2fdc358..d92b621 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -1145,10 +1145,11 @@ virtualenv " 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' ] + " conflicts: checks for conflict markers + let g:airline#extensions#whitespace#checks = [ 'indent', 'trailing', 'long', 'mixed-indent-file', 'conflicts' ] " this can also be configured for an individual buffer - let b:airline_whitespace_checks = [ 'indent', 'trailing', 'long', 'mixed-indent-file' ] + let b:airline_whitespace_checks = [ 'indent', 'trailing', 'long', 'mixed-indent-file', 'conflicts ] < * configure the maximum number of lines where whitespace checking is enabled. > let g:airline#extensions#whitespace#max_lines = 20000 @@ -1161,6 +1162,7 @@ virtualenv 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]' + let g:airline#extensions#whitespace#conflicts_format = 'conflicts[%s]' * configure custom trailing whitespace regexp rule > let g:airline#extensions#whitespace#trailing_regexp = '\s$'