Skip to content

Commit 4b27acb

Browse files
Cimbalintpeters
authored andcommitted
Simplify enabling/disabling to fix #87 (#88)
There is no harm in calling SetupAutoCommands() again, and WhitespaceInit() is called (only if necessary) from the former. Also, did not show up yet, but add a check so we don't get an error in the (unlikely) event that ShouldStripWhitespace() is called before ShouldHighlight().
1 parent de6caab commit 4b27acb

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

plugin/better-whitespace.vim

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,16 @@ endfunction
104104

105105
" Enable the whitespace highlighting
106106
function! s:EnableWhitespace()
107-
if b:better_whitespace_enabled != 1
108-
let b:better_whitespace_enabled = 1
109-
call <SID>WhitespaceInit()
110-
call <SID>SetupAutoCommands()
111-
call <SID>Echo("Whitespace Highlighting: Enabled")
112-
endif
107+
let b:better_whitespace_enabled = 1
108+
call <SID>Echo("Whitespace Highlighting: Enabled")
109+
call <SID>SetupAutoCommands()
113110
endfunction
114111

115112
" Disable the whitespace highlighting
116113
function! s:DisableWhitespace()
117-
if b:better_whitespace_enabled != 0
118-
let b:better_whitespace_enabled = 0
119-
call <SID>SetupAutoCommands()
120-
call <SID>Echo("Whitespace Highlighting: Disabled")
121-
endif
114+
let b:better_whitespace_enabled = 0
115+
call <SID>Echo("Whitespace Highlighting: Disabled")
116+
call <SID>SetupAutoCommands()
122117
endfunction
123118

124119
" Toggle whitespace highlighting on/off
@@ -277,7 +272,7 @@ endfunction
277272
function! s:ShouldStripWhitespace()
278273
call s:InitVariable('b:strip_whitespace_on_save', -1)
279274
if b:strip_whitespace_on_save < 0
280-
if b:better_whitespace_enabled < 0
275+
if !exists('b:better_whitespace_enabled') || b:better_whitespace_enabled < 0
281276
" We can't initialize buffer value properly yet, fall back to global one
282277
return g:strip_whitespace_on_save
283278
else

0 commit comments

Comments
 (0)