@@ -152,20 +152,28 @@ if g:current_line_whitespace_disabled_soft == 1
152152 if <SID> ShouldHighlight ()
153153 exe ' syn match ExtraWhitespace excludenl "' . s: eol_whitespace_pattern . ' "'
154154 endif
155+ let w: better_whitespace_current_line = -1
155156 endfunction
156157
157158 " Match Whitespace on all lines except the current one
158159 function ! s: HighlightEOLWhitespaceExceptCurrentLine ()
159- call <SID> ClearHighlighting ()
160- if <SID> ShouldHighlight ()
160+ if ! <SID> ShouldHighlight ()
161+ call <SID> ClearHighlighting ()
162+ return
163+ endif
164+
165+ if ! exists (' w:better_whitespace_current_line' ) || w: better_whitespace_current_line !=# line (' .' )
166+ call <SID> ClearHighlighting ()
161167 exe ' syn match ExtraWhitespace excludenl "\%<' . line (' .' ) . ' l' . s: eol_whitespace_pattern .
162168 \ ' \|\%>' . line (' .' ) . ' l' . s: eol_whitespace_pattern . ' "'
169+ let w: better_whitespace_current_line = line (' .' )
163170 endif
164171 endfunction
165172
166173 " Remove Whitespace matching
167174 function ! s: ClearHighlighting ()
168175 syn clear ExtraWhitespace
176+ let w: better_whitespace_current_line = -1
169177 endfunction
170178else
171179 " Match Whitespace on all lines
@@ -175,15 +183,22 @@ else
175183 let w: better_whitespace_match_id = matchadd (' ExtraWhitespace' ,
176184 \ s: eol_whitespace_pattern , 10 , get (w: , ' better_whitespace_match_id' , -1 ))
177185 endif
186+ let w: better_whitespace_current_line = -1
178187 endfunction
179188
180189 " Match Whitespace on all lines except the current one
181190 function ! s: HighlightEOLWhitespaceExceptCurrentLine ()
182- call <SID> ClearHighlighting ()
183- if <SID> ShouldHighlight ()
191+ if ! <SID> ShouldHighlight ()
192+ call <SID> ClearHighlighting ()
193+ return
194+ endif
195+
196+ if ! exists (' w:better_whitespace_current_line' ) || w: better_whitespace_current_line !=# line (' .' )
197+ call <SID> ClearHighlighting ()
184198 let w: better_whitespace_match_id = matchadd (' ExtraWhitespace' ,
185199 \ ' \%<' . line (' .' ) . ' l' . s: eol_whitespace_pattern .
186200 \ ' \|\%>' . line (' .' ) . ' l' . s: eol_whitespace_pattern , 10 , get (w: , ' better_whitespace_match_id' , -1 ))
201+ let w: better_whitespace_current_line = line (' .' )
187202 endif
188203 endfunction
189204
194209 if match_id >= 0 && index (valid_ids, match_id) >= 0
195210 call matchdelete (match_id)
196211 endif
212+ let w: better_whitespace_current_line = -1
197213 endfunction
198214endif
199215
0 commit comments