Skip to content

Commit

Permalink
remove first line hack because it doesn't resolve #8
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jan 8, 2017
1 parent 5f8b884 commit 0f7cca8
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions autoload/clang_format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -212,36 +212,9 @@ function! clang_format#replace(line1, line2)

try
let formatted = clang_format#format(a:line1, a:line2)

if s:success(formatted)
try
" Note:
" Replace current buffer with workaround not to move
" the cursor on undo (issue #8)
"
" The points are:
" - Do not touch the first line.
" - Use :put (p, P and :put! is not available).
"
" To meet above condition:
" - Delete all lines except for the first line.
" - Put formatted text except for the first line.
"
let i = stridx(formatted, "\n")
if i == -1 || getline(1) !=# formatted[:i-1]
throw 'fallback'
endif

call setreg('g', formatted[i+1:], 'V')
silent normal! 2gg"_dG
silent put g
catch
" Fallback:
" The previous way. It lets the cursor move to the first line
" on undo.
call setreg('g', formatted, 'V')
silent keepjumps normal! ggVG"gp
endtry
call setreg('g', formatted, 'V')
silent keepjumps normal! ggVG"gp
else
call s:error_message(formatted)
endif
Expand Down

0 comments on commit 0f7cca8

Please sign in to comment.