Skip to content

Commit f7453a0

Browse files
johntyreespf13
authored andcommitted
Move test for whitespace stripping out of function.
Rather than have the function call be a noop, which is misleading and a waste of resources, this commit simply moves the conditional test up to the call site. If g:spf13_keep_trailing_whitespace exists then we simply don't call the Strip() function. This way Strip() can just do its job when called. I, for example, have <leader>ws bound to this function and call it manually when needed. Hiding the conditional inside the function broke that.
1 parent 5af9095 commit f7453a0

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

.vimrc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@
233233
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
234234
"set comments=sl:/*,mb:*,elx:*/ " auto format comment blocks
235235
" Remove trailing whitespaces and ^M chars
236-
autocmd FileType c,cpp,java,go,php,javascript,python,twig,xml,yml autocmd BufWritePre <buffer> call StripTrailingWhitespace()
236+
" To disable the stripping of whitespace, add the following to your
237+
" .vimrc.before.local file:
238+
" let g:spf13_keep_trailing_whitespace = 1
239+
autocmd FileType c,cpp,java,go,php,javascript,python,twig,xml,yml autocmd BufWritePre <buffer> if !exists('g:spf13_keep_trailing_whitespace') | call StripTrailingWhitespace() | endif
237240
autocmd FileType go autocmd BufWritePre <buffer> Fmt
238241
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
239242
autocmd FileType haskell setlocal expandtab shiftwidth=2 softtabstop=2
@@ -890,20 +893,15 @@
890893

891894
" Strip whitespace {
892895
function! StripTrailingWhitespace()
893-
" To disable the stripping of whitespace, add the following to your
894-
" .vimrc.before.local file:
895-
" let g:spf13_keep_trailing_whitespace = 1
896-
if !exists('g:spf13_keep_trailing_whitespace')
897-
" Preparation: save last search, and cursor position.
898-
let _s=@/
899-
let l = line(".")
900-
let c = col(".")
901-
" do the business:
902-
%s/\s\+$//e
903-
" clean up: restore previous search history, and cursor position
904-
let @/=_s
905-
call cursor(l, c)
906-
endif
896+
" Preparation: save last search, and cursor position.
897+
let _s=@/
898+
let l = line(".")
899+
let c = col(".")
900+
" do the business:
901+
%s/\s\+$//e
902+
" clean up: restore previous search history, and cursor position
903+
let @/=_s
904+
call cursor(l, c)
907905
endfunction
908906
" }
909907

0 commit comments

Comments
 (0)