Skip to content

Commit 77bea8c

Browse files
Ram-ZSamir Benmendil
authored andcommitted
Fix undo and partial format
1 parent 661e7b3 commit 77bea8c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

autoload/clang_format.vim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function! s:detect_style_file() abort
205205
endfunction
206206

207207
function! clang_format#format(line1, line2) abort
208-
let args = printf(' -lines=%d:%d', a:line1, a:line2)
208+
let args = ""
209209
if ! (g:clang_format#detect_style_file && s:detect_style_file())
210210
let args .= printf(' -style=%s ', s:make_style_options())
211211
else
@@ -217,8 +217,7 @@ function! clang_format#format(line1, line2) abort
217217
endif
218218
let args .= g:clang_format#extra_args
219219
let clang_format = printf('%s %s --', s:shellescape(g:clang_format#command), args)
220-
let source = join(getline(1, '$'), "\n")
221-
return s:system(clang_format, source)
220+
return s:system(clang_format, join(getline(a:line1, a:line2), "\n"))
222221
endfunction
223222
" }}}
224223

@@ -238,8 +237,12 @@ function! clang_format#replace(line1, line2, ...) abort
238237
try
239238
let formatted = clang_format#format(a:line1, a:line2)
240239
if s:success(formatted)
240+
let indent = indent(a:line1) / shiftwidth()
241+
silent exe a:line1.','a:line2.'delete _'
242+
241243
call setreg('g', formatted, 'V')
242-
silent keepjumps normal! gg0VG"gp
244+
silent put! g
245+
silent exe "'[,']".repeat('>', indent)
243246
else
244247
call s:error_message(formatted)
245248
endif

0 commit comments

Comments
 (0)