@@ -163,21 +163,22 @@ endfunction
163163
164164" Strip whitespace on file save
165165function ! s: EnableStripWhitespaceOnSave ()
166- let g : strip_whitespace_on_save = 1
166+ let b : strip_whitespace_on_save = 1
167167 call <SID> Echo (" Strip Whitespace On Save: Enabled" )
168168 call <SID> SetupAutoCommands ()
169169endfunction
170170
171171" Don't strip whitespace on file save
172172function ! s: DisableStripWhitespaceOnSave ()
173- let g : strip_whitespace_on_save = 0
173+ let b : strip_whitespace_on_save = 0
174174 call <SID> Echo (" Strip Whitespace On Save: Disabled" )
175175 call <SID> SetupAutoCommands ()
176176endfunction
177177
178178" Strips whitespace on file save
179179function ! s: ToggleStripWhitespaceOnSave ()
180- if g: strip_whitespace_on_save == 1
180+ call <SID> ShouldSkipHighlight ()
181+ if b: strip_whitespace_on_save == 1
181182 call <SID> DisableStripWhitespaceOnSave ()
182183 else
183184 call <SID> EnableStripWhitespaceOnSave ()
@@ -186,7 +187,12 @@ endfunction
186187
187188" Determines if whitespace highlighting should currently be skipped
188189function ! s: ShouldSkipHighlight ()
189- return &buftype == ' nofile' || index (g: better_whitespace_filetypes_blacklist , &ft ) >= 0
190+ if ! exists (' b:better_whitespace_enabled' )
191+ let b: better_whitespace_enabled = &buftype != ' nofile' && index (g: better_whitespace_filetypes_blacklist , &ft ) == -1
192+ endif
193+ if ! exists (' b:strip_whitespace_on_save' )
194+ let b: strip_whitespace_on_save = b: better_whitespace_enabled && g: strip_whitespace_on_save
195+ endif
190196endfunction
191197
192198" Run :StripWhitespace to remove end of line whitespace
@@ -210,12 +216,12 @@ command! -nargs=* CurrentLineWhitespaceOff call <SID>CurrentLineWhitespaceOff( <
210216command ! CurrentLineWhitespaceOn call <SID> CurrentLineWhitespaceOn ()
211217
212218" Process auto commands upon load, update local enabled on filetype change
213- autocmd FileType * let b: better_whitespace_enabled = ! <SID> ShouldSkipHighlight () | call <SID> SetupAutoCommands ()
219+ autocmd FileType * call <SID> ShouldSkipHighlight () | call <SID> SetupAutoCommands ()
214220autocmd WinEnter ,BufWinEnter * call <SID> SetupAutoCommands ()
215221autocmd ColorScheme * call <SID> WhitespaceInit ()
216222
217223function ! s: PerformMatchHighlight (pattern)
218- call s: InitVariable ( ' b:better_whitespace_enabled ' , ! <SID> ShouldSkipHighlight () )
224+ call <SID> ShouldSkipHighlight ()
219225 if b: better_whitespace_enabled == 1
220226 exe ' match ExtraWhitespace "' . a: pattern . ' "'
221227 else
@@ -225,7 +231,7 @@ endfunction
225231
226232function ! s: PerformSyntaxHighlight (pattern)
227233 syn clear ExtraWhitespace
228- call s: InitVariable ( ' b:better_whitespace_enabled ' , ! <SID> ShouldSkipHighlight () )
234+ call <SID> ShouldSkipHighlight ()
229235 if b: better_whitespace_enabled == 1
230236 exe ' syn match ExtraWhitespace excludenl "' . a: pattern . ' "'
231237 endif
@@ -285,8 +291,8 @@ function! <SID>SetupAutoCommands()
285291 endif
286292 endif
287293
288- " Strip whitespace on save if enabled
289- if g: strip_whitespace_on_save == 1
294+ " Strip whitespace on save if enabled.
295+ if ( exists ( ' b:strip_whitespace_on_save ' ) ? b: strip_whitespace_on_save : g: strip_whitespace_on_save) == 1
290296 autocmd BufWritePre * call <SID> StripWhitespace ( 0 , line (" $" ) )
291297 endif
292298
0 commit comments