Skip to content

Commit 3131571

Browse files
committed
Fix undo and partial format
1 parent 890ca5d commit 3131571

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

autoload/clang_format.vim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function! s:detect_style_file()
186186
endfunction
187187

188188
function! clang_format#format(line1, line2)
189-
let args = printf(' -lines=%d:%d', a:line1, a:line2)
189+
let args = ""
190190
if ! (g:clang_format#detect_style_file && s:detect_style_file())
191191
let args .= printf(' -style=%s ', s:make_style_options())
192192
else
@@ -198,7 +198,7 @@ function! clang_format#format(line1, line2)
198198
endif
199199
let args .= g:clang_format#extra_args
200200
let clang_format = printf('%s %s --', s:shellescape(g:clang_format#command), args)
201-
return s:system(clang_format, join(getline(1, '$'), "\n"))
201+
return s:system(clang_format, join(getline(a:line1, a:line2), "\n"))
202202
endfunction
203203
" }}}
204204

@@ -216,8 +216,12 @@ function! clang_format#replace(line1, line2)
216216
try
217217
let formatted = clang_format#format(a:line1, a:line2)
218218
if s:success(formatted)
219+
let indent = indent(a:line1) / shiftwidth()
220+
silent exe a:line1.','a:line2.'delete _'
221+
219222
call setreg('g', formatted, 'V')
220-
silent keepjumps normal! ggVG"gp
223+
silent put! g
224+
silent exe "'[,']".repeat('>', indent)
221225
else
222226
call s:error_message(formatted)
223227
endif

0 commit comments

Comments
 (0)