@@ -203,7 +203,7 @@ function! s:detect_style_file() abort
203203endfunction 
204204
205205function !  clang_format#format (line1, line2) abort 
206-     let  args  =  printf ( '  -lines=%d:%d ' ,  a: line1 ,  a: line2 ) 
206+     let  args  =  " " 
207207    if  ! (g: clang_format&&  s: detect_style_file
208208        if  g: clang_format
209209            let  args  .=  '  ' s: shellescapeprintf (' -style=%s' s: make_style_options'  ' 
@@ -219,8 +219,7 @@ function! clang_format#format(line1, line2) abort
219219    endif 
220220    let  args  .=  g: clang_format
221221    let  clang_format =  printf (' %s %s --' s: shellescapeg: clang_formatcommand ), args )
222-     let  source  =  join (getline (1 , ' $' " \n " 
223-     return  s: systemsource )
222+     return  s: systemjoin (getline (a: line1a: line2" \n " 
224223endfunction 
225224"  }}}
226225
@@ -236,15 +235,22 @@ function! clang_format#replace(line1, line2, ...) abort
236235    endif 
237236
238237    let  winview =  winsaveview ()
238+     let  fold_closed_save =  foldclosed (line (' .' 
239+ 
239240    let  splitted =  split (formatted, ' \n' 1 )
240241
241-     silent !  undojoin 
242-     if  line (' $'  >  len (splitted)
243-         execute  len (splitted) .' ,$delete' ' _' 
244-     endif 
245-     call  setline (1 , splitted)
242+     let  indent  =  indent (a: line1shiftwidth ()
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+ 
246248    call  winrestview (winview)
247249    call  setpos (' .' 
250+ 
251+     if  fold_closed_save ==  -1 
252+         foldopen ! 
253+     endif 
248254endfunction 
249255"  }}}
250256
0 commit comments