@@ -217,7 +217,7 @@ function! s:detect_style_file() abort
217
217
endfunction
218
218
219
219
function ! clang_format#format (line1, line2) abort
220
- let args = printf ( ' -lines=%d:%d ' , a: line1 , a: line2 )
220
+ let args = " "
221
221
if ! (g: clang_format #detect_style_file && s: detect_style_file ())
222
222
if g: clang_format #enable_fallback_style
223
223
let args .= ' ' . s: shellescape (printf (' -style=%s' , s: make_style_options ())) . ' '
@@ -233,8 +233,7 @@ function! clang_format#format(line1, line2) abort
233
233
endif
234
234
let args .= g: clang_format #extra_args
235
235
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 " ))
238
237
endfunction
239
238
" }}}
240
239
@@ -254,8 +253,12 @@ function! clang_format#replace(line1, line2, ...) abort
254
253
try
255
254
let formatted = clang_format#format (a: line1 , a: line2 )
256
255
if s: success (formatted)
256
+ let indent = indent (a: line1 ) / shiftwidth ()
257
+ silent exe a: line1 .' ,' a: line2 .' delete _'
258
+
257
259
call setreg (' g' , formatted, ' V' )
258
- silent keepjumps normal ! gg0VG" gp
260
+ silent put ! g
261
+ silent exe " '[,']" .repeat (' >' , indent )
259
262
else
260
263
call s: error_message (formatted)
261
264
endif
0 commit comments