@@ -203,7 +203,7 @@ function! s:detect_style_file() abort
203
203
endfunction
204
204
205
205
function ! clang_format#format (line1, line2) abort
206
- let args = printf ( ' -lines=%d:%d ' , a: line1 , a: line2 )
206
+ let args = " "
207
207
if ! (g: clang_format #detect_style_file && s: detect_style_file ())
208
208
if g: clang_format #enable_fallback_style
209
209
let args .= ' ' . s: shellescape (printf (' -style=%s' , s: make_style_options ())) . ' '
@@ -219,8 +219,7 @@ function! clang_format#format(line1, line2) abort
219
219
endif
220
220
let args .= g: clang_format #extra_args
221
221
let clang_format = printf (' %s %s --' , s: shellescape (g: clang_format #command ), args )
222
- let source = join (getline (1 , ' $' ), " \n " )
223
- return s: system (clang_format, source )
222
+ return s: system (clang_format, join (getline (a: line1 , a: line2 ), " \n " ))
224
223
endfunction
225
224
" }}}
226
225
@@ -238,13 +237,20 @@ function! clang_format#replace(line1, line2, ...) abort
238
237
let winview = winsaveview ()
239
238
let splitted = split (formatted, ' \n' , 1 )
240
239
241
- silent ! undojoin
242
- if line (' $' ) > len (splitted)
243
- execute len (splitted) .' ,$delete' ' _'
244
- endif
245
- call setline (1 , splitted)
240
+ let fold_closed_save = foldclosed (line (' .' ))
241
+
242
+ let indent = indent (a: line1 ) / shiftwidth ()
243
+ silent exe a: line1 .' ,' a: line2 .' delete _'
244
+
245
+ call append (a: line1 - 1 , splitted)
246
+ silent exe a: line1 ." ;+" .(len (splitted)-1 ).repeat (' >' , indent )
247
+
246
248
call winrestview (winview)
247
249
call setpos (' .' , pos_save)
250
+
251
+ if fold_closed_save == -1
252
+ foldopen !
253
+ endif
248
254
endfunction
249
255
" }}}
250
256
0 commit comments