@@ -156,16 +156,27 @@ function! s:StripWhitespace( line1, line2 )
156156 call cursor (l , c )
157157endfunction
158158
159+ " Strip whitespace on file save
160+ function ! s: EnableStripWhitespaceOnSave ()
161+ let g: strip_whitespace_on_save = 1
162+ call <SID> Echo (" Strip Whitespace On Save: Enabled" )
163+ call <SID> SetupAutoCommands ()
164+ endfunction
165+
166+ " Don't strip whitespace on file save
167+ function ! s: DisableStripWhitespaceOnSave ()
168+ let g: strip_whitespace_on_save = 0
169+ call <SID> Echo (" Strip Whitespace On Save: Disabled" )
170+ call <SID> SetupAutoCommands ()
171+ endfunction
172+
159173" Strips whitespace on file save
160174function ! s: ToggleStripWhitespaceOnSave ()
161- if g: strip_whitespace_on_save == 0
162- let g: strip_whitespace_on_save = 1
163- call <SID> Echo (" Strip Whitespace On Save: Enabled" )
175+ if g: strip_whitespace_on_save == 1
176+ call <SID> DisableStripWhitespaceOnSave ()
164177 else
165- let g: strip_whitespace_on_save = 0
166- call <SID> Echo (" Strip Whitespace On Save: Disabled" )
178+ call <SID> EnableStripWhitespaceOnSave ()
167179 endif
168- call <SID> SetupAutoCommands ()
169180endfunction
170181
171182" Determines if whitespace highlighting should currently be skipped
@@ -175,6 +186,10 @@ endfunction
175186
176187" Run :StripWhitespace to remove end of line whitespace
177188command ! -range =% StripWhitespace call <SID> StripWhitespace ( <line1> , <line2> )
189+ " Run :EnableStripWhitespaceOnSave to enable whitespace stripping on save
190+ command ! EnableStripWhitespaceOnSave call <SID> EnableStripWhitespaceOnSave ()
191+ " Run :DisableStripWhitespaceOnSave to disable whitespace stripping on save
192+ command ! DisableStripWhitespaceOnSave call <SID> DisableStripWhitespaceOnSave ()
178193" Run :ToggleStripWhitespaceOnSave to enable/disable whitespace stripping on save
179194command ! ToggleStripWhitespaceOnSave call <SID> ToggleStripWhitespaceOnSave ()
180195" Run :EnableWhitespace to enable whitespace highlighting
0 commit comments