@@ -217,7 +217,7 @@ function! s:detect_style_file() abort
217217endfunction
218218
219219function ! clang_format#format (line1, line2) abort
220- let args = printf ( ' -lines=%d:%d ' , a: line1 , a: line2 )
220+ let args = " "
221221 if ! (g: clang_format #detect_style_file && s: detect_style_file ())
222222 if g: clang_format #enable_fallback_style
223223 let args .= ' ' . s: shellescape (printf (' -style=%s' , s: make_style_options ())) . ' '
@@ -233,8 +233,7 @@ function! clang_format#format(line1, line2) abort
233233 endif
234234 let args .= g: clang_format #extra_args
235235 let clang_format = printf (' %s %s --' , s: shellescape (g: clang_format #command ), args )
236- let source = join (getline (1 , ' $' ), " \n " )
237- return s: system (clang_format, source )
236+ return s: system (clang_format, join (getline (a: line1 , a: line2 ), " \n " ))
238237endfunction
239238" }}}
240239
@@ -254,8 +253,12 @@ function! clang_format#replace(line1, line2, ...) abort
254253 try
255254 let formatted = clang_format#format (a: line1 , a: line2 )
256255 if s: success (formatted)
256+ let indent = indent (a: line1 ) / shiftwidth ()
257+ silent exe a: line1 .' ,' a: line2 .' delete _'
258+
257259 call setreg (' g' , formatted, ' V' )
258- silent keepjumps normal ! gg0VG" gp
260+ silent put ! g
261+ silent exe " '[,']" .repeat (' >' , indent )
259262 else
260263 call s: error_message (formatted)
261264 endif
0 commit comments