Skip to content

Commit 110a9fd

Browse files
committed
A little lighter on the events. Initialize buffer variable just in time to avoid hassle with its initialization.
1 parent 7aa5f31 commit 110a9fd

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

plugin/better-whitespace.vim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ command! CurrentLineWhitespaceOn call <SID>CurrentLineWhitespaceOn()
191191

192192
" Process auto commands upon load, update local enabled on filetype change
193193
autocmd FileType * let b:better_whitespace_enabled = !<SID>ShouldSkipHighlight() | call <SID>SetupAutoCommands()
194-
autocmd WinEnter,BufWinEnter * call <SID>SetupAutoCommands()
194+
autocmd BufWinEnter * call <SID>SetupAutoCommands()
195195
autocmd ColorScheme * call <SID>WhitespaceInit()
196196

197197
function! 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

205206
function! 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

Comments
 (0)