From d99a4b9e01142daf9ec3c20a0c7e2421cc24be75 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 29 Oct 2006 04:18:16 +0000 Subject: [PATCH] Remove whitespace in some cases --- plugin/surround.vim | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 9fbb02e..55068f3 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -282,13 +282,19 @@ function! s:insert(...) " {{{1 endfunction " }}}1 function! s:reindent() " {{{1 - if @@ =~ '\n' && (exists("b:surround_indent") || exists("g:surround_indent")) + if (exists("b:surround_indent") || exists("g:surround_indent")) silent norm! '[='] endif endfunction " }}}1 function! s:dosurround(...) " {{{1 + let g:scount = v:count1 let char = (a:0 ? a:1 : s:inputtarget()) + let spc = "" + if char =~ '^ ' + let char = strpart(char,1) + let spc = 1 + endif let newchar = "" if a:0 > 1 let newchar = a:2 @@ -302,6 +308,7 @@ function! s:dosurround(...) " {{{1 exe "norm di".char "exe "norm vi".char."d" let keeper = @@ + let okeeper = keeper " for reindent below if @@ == "" let @@ = original return "" @@ -330,6 +337,10 @@ function! s:dosurround(...) " {{{1 "let g:rem2 = rem2 "let g:keeper = keeper let regtype = getregtype('"') + if char =~ '[\[({<]' || spc + let keeper = substitute(keeper,'^\s\+','','') + let keeper = substitute(keeper,'\s\+$','','') + endif if oldtail == rem2 && col('.') + 1 == col('$') if oldhead =~# '^\s*$' && a:0 < 2 "let keeper = substitute(keeper,'\n\s*','\n','') @@ -362,7 +373,9 @@ function! s:dosurround(...) " {{{1 let @@ = substitute(keeper,'\n\s+\n','\n\n','g') call setreg('"','','a'.regtype) silent exe "norm! ".(a:0 < 2 ? "" : "").pcmd.'`[' - call s:reindent() + if removed =~ '\n' || okeeper =~ '\n' + call s:reindent() + endif if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n' silent norm! cc endif