mirror of
https://github.com/spf13/spf13-vim.git
synced 2024-09-21 07:27:11 +00:00
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.
This commit is contained in:
parent
5af90958f8
commit
f7453a0991
28
.vimrc
28
.vimrc
@ -233,7 +233,10 @@
|
||||
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
|
||||
"set comments=sl:/*,mb:*,elx:*/ " auto format comment blocks
|
||||
" Remove trailing whitespaces and ^M chars
|
||||
autocmd FileType c,cpp,java,go,php,javascript,python,twig,xml,yml autocmd BufWritePre <buffer> call StripTrailingWhitespace()
|
||||
" To disable the stripping of whitespace, add the following to your
|
||||
" .vimrc.before.local file:
|
||||
" let g:spf13_keep_trailing_whitespace = 1
|
||||
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
|
||||
autocmd FileType go autocmd BufWritePre <buffer> Fmt
|
||||
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
|
||||
autocmd FileType haskell setlocal expandtab shiftwidth=2 softtabstop=2
|
||||
@ -890,20 +893,15 @@
|
||||
|
||||
" Strip whitespace {
|
||||
function! StripTrailingWhitespace()
|
||||
" To disable the stripping of whitespace, add the following to your
|
||||
" .vimrc.before.local file:
|
||||
" let g:spf13_keep_trailing_whitespace = 1
|
||||
if !exists('g:spf13_keep_trailing_whitespace')
|
||||
" Preparation: save last search, and cursor position.
|
||||
let _s=@/
|
||||
let l = line(".")
|
||||
let c = col(".")
|
||||
" do the business:
|
||||
%s/\s\+$//e
|
||||
" clean up: restore previous search history, and cursor position
|
||||
let @/=_s
|
||||
call cursor(l, c)
|
||||
endif
|
||||
" Preparation: save last search, and cursor position.
|
||||
let _s=@/
|
||||
let l = line(".")
|
||||
let c = col(".")
|
||||
" do the business:
|
||||
%s/\s\+$//e
|
||||
" clean up: restore previous search history, and cursor position
|
||||
let @/=_s
|
||||
call cursor(l, c)
|
||||
endfunction
|
||||
" }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user