Skip to content

Commit

Permalink
Simplify enabling/disabling to fix #87 (#88)
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
Cimbali authored and ntpeters committed May 24, 2018
1 parent de6caab commit 4b27acb
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions plugin/better-whitespace.vim
Expand Up @@ -104,21 +104,16 @@ endfunction

" Enable the whitespace highlighting
function! s:EnableWhitespace()
if b:better_whitespace_enabled != 1
let b:better_whitespace_enabled = 1
call <SID>WhitespaceInit()
call <SID>SetupAutoCommands()
call <SID>Echo("Whitespace Highlighting: Enabled")
endif
let b:better_whitespace_enabled = 1
call <SID>Echo("Whitespace Highlighting: Enabled")
call <SID>SetupAutoCommands()
endfunction

" Disable the whitespace highlighting
function! s:DisableWhitespace()
if b:better_whitespace_enabled != 0
let b:better_whitespace_enabled = 0
call <SID>SetupAutoCommands()
call <SID>Echo("Whitespace Highlighting: Disabled")
endif
let b:better_whitespace_enabled = 0
call <SID>Echo("Whitespace Highlighting: Disabled")
call <SID>SetupAutoCommands()
endfunction

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

0 comments on commit 4b27acb

Please sign in to comment.