@@ -65,6 +65,12 @@ call s:InitVariable('strip_max_file_size', 1000)
6565" Disable verbosity by default
6666call s: InitVariable (' better_whitespace_verbosity' , 0 )
6767
68+ " Bypass the aliases set for diff by default
69+ if has (" win32" ) || has (" win16" )
70+ call s: InitVariable (' diff_binary' , ' diff.exe' )
71+ else
72+ call s: InitVariable (' diff_binary' , ' command diff' )
73+ endif
6874
6975" Section: Whitespace matching setup
7076
@@ -95,18 +101,18 @@ function! s:WhitespaceInit()
95101endfunction
96102
97103" Diff command returning a space-separated list of ranges of new/modified lines (as first,last)
98- let s: diff_cmd= ' diff -a --unchanged-group-format="" --old-group-format="" --new-group-format="%dF,%dL " --changed-group-format="%dF,%dL " '
104+ let s: diff_cmd= g: diff_binary . ' -a --unchanged-group-format="" --old-group-format="" --new-group-format="%dF,%dL " --changed-group-format="%dF,%dL " '
99105
100106" Section: Actual work functions
101107
102- " Function to implement trim() fro vim < 8.0.1630
103- if v: version > 800 || ( v: version == 800 && has ( ' patch-1630 ' ) )
108+ " Function to implement trim() if it does not exist
109+ if exists ( ' *trim ' )
104110 function ! s: Trim (s )
105111 return trim (a: s )
106112 endfunction
107113else
108114 function ! s: Trim (s )
109- return substitute (a: s , ' ^\s *\(.\{-}\)\s *$' , ' \1' , ' ' )
115+ return substitute (a: s , ' ^\_s *\(.\{-}\)\_s *$' , ' \1' , ' ' )
110116 endfunction
111117endif
112118
@@ -155,26 +161,25 @@ if g:current_line_whitespace_disabled_soft == 1
155161else
156162 " Match Whitespace on all lines
157163 function ! s: HighlightEOLWhitespace ()
164+ call <SID> ClearHighlighting ()
158165 if <SID> ShouldHighlight ()
159- exe ' match ExtraWhitespace "' . s: eol_whitespace_pattern . ' "'
160- else
161- call <SID> ClearHighlighting ()
166+ let s: match_id = matchadd (' ExtraWhitespace' , s: eol_whitespace_pattern , 10 , get (s: , ' match_id' , -1 ))
162167 endif
163168 endfunction
164169
165170 " Match Whitespace on all lines except the current one
166171 function ! s: HighlightEOLWhitespaceExceptCurrentLine ()
172+ call <SID> ClearHighlighting ()
167173 if <SID> ShouldHighlight ()
168- exe ' match ExtraWhitespace "\%<' . line (' .' ) . ' l' . s: eol_whitespace_pattern .
169- \ ' \|\%>' . line (' .' ) . ' l' . s: eol_whitespace_pattern . ' "'
170- else
171- call <SID> ClearHighlighting ()
174+ let s: match_id = matchadd (' ExtraWhitespace' ,
175+ \ ' \%<' . line (' .' ) . ' l' . s: eol_whitespace_pattern .
176+ \ ' \|\%>' . line (' .' ) . ' l' . s: eol_whitespace_pattern , 10 , get (s: , ' match_id' , -1 ))
172177 endif
173178 endfunction
174179
175180 " Remove Whitespace matching
176181 function ! s: ClearHighlighting ()
177- match ExtraWhitespace ' '
182+ silent ! call matchdelete ( get ( s: , ' match_id ' , -1 ))
178183 endfunction
179184endif
180185
0 commit comments