@@ -191,10 +191,11 @@ command! CurrentLineWhitespaceOn call <SID>CurrentLineWhitespaceOn()
191191
192192" Process auto commands upon load, update local enabled on filetype change
193193autocmd FileType * let b: better_whitespace_enabled = ! <SID> ShouldSkipHighlight () | call <SID> SetupAutoCommands ()
194- autocmd WinEnter , BufWinEnter * call <SID> SetupAutoCommands ()
194+ autocmd BufWinEnter * call <SID> SetupAutoCommands ()
195195autocmd ColorScheme * call <SID> WhitespaceInit ()
196196
197197function ! s: PerformMatchHighlight (pattern)
198+ call s: InitVariable (' b:better_whitespace_enabled' , ! <SID> ShouldSkipHighlight ())
198199 if b: better_whitespace_enabled == 1
199200 exe ' match ExtraWhitespace ' . a: pattern
200201 else
@@ -204,6 +205,7 @@ endfunction
204205
205206function ! s: PerformSyntaxHighlight (pattern)
206207 syn clear ExtraWhitespace
208+ call s: InitVariable (' b:better_whitespace_enabled' , ! <SID> ShouldSkipHighlight ())
207209 if b: better_whitespace_enabled == 1
208210 exe ' syn match ExtraWhitespace excludenl ' . a: pattern
209211 endif
@@ -215,9 +217,6 @@ function! <SID>SetupAutoCommands()
215217 augroup better_whitespace
216218 autocmd !
217219
218- " make sure the local variable exists
219- call s: InitVariable (' b:better_whitespace_enabled' , ! <SID> ShouldSkipHighlight ())
220-
221220 if g: better_whitespace_enabled == 1
222221 if s: better_whitespace_initialized == 0
223222 call <SID> WhitespaceInit ()
@@ -227,7 +226,6 @@ function! <SID>SetupAutoCommands()
227226 if g: current_line_whitespace_disabled_soft == 0
228227 " Highlight all whitespace upon entering buffer
229228 call <SID> PerformMatchHighlight (' /\s\+$/' )
230- autocmd BufWinEnter * call <SID> PerformMatchHighlight (' /\s\+$/' )
231229 " Check if current line highglighting is disabled
232230 if g: current_line_whitespace_disabled_hard == 1
233231 " Never highlight whitespace on current line
0 commit comments