Skip to content

Commit

Permalink
Restore unnamed register after format (#57)
Browse files Browse the repository at this point in the history
* Restore unnamed register after format

Replacing a visual selection with the formatted lines (ggVG"gp),
puts in the unnamed register the selections.

This commit restores the previously held value of the unnamed register
after applying the formatting.

* Use v:register instead of '' for getreg/setreg
  • Loading branch information
kinote authored and rhysd committed Mar 31, 2017
1 parent e8d39a3 commit 3b0b1c8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions autoload/clang_format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function! clang_format#replace(line1, line2)
let sel_save = &l:selection
let &l:selection = 'inclusive'
let [save_g_reg, save_g_regtype] = [getreg('g'), getregtype('g')]
let [save_unnamed_reg, save_unnamed_regtype] = [getreg(v:register), getregtype(v:register)]

try
let formatted = clang_format#format(a:line1, a:line2)
Expand All @@ -219,6 +220,7 @@ function! clang_format#replace(line1, line2)
call s:error_message(formatted)
endif
finally
call setreg(v:register, save_unnamed_reg, save_unnamed_regtype)
call setreg('g', save_g_reg, save_g_regtype)
let &l:selection = sel_save
call setpos('.', pos_save)
Expand Down

0 comments on commit 3b0b1c8

Please sign in to comment.