-
Notifications
You must be signed in to change notification settings - Fork 123
create new undo block for formatting (fix #30) #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This creates a new undo block to only contain the changes introduced by clang format but still preserves the original cursor position.
test failed in visual mode: https://travis-ci.org/rhysd/vim-clang-format/jobs/188839298 Could you confirm this works in visual mode? |
There was indeed a problem in visual mode when the cursor was at the first line of the buffer. Should be fixed now. Edit: Should I squash the commits? |
Current implementation looks very hacky and not easy to maintain. Instead of considering normal mode and visual mode at once, can we use let mode = mode()
if mode ==? 'v'
" normal! for visual (or visual block) mode
else
" otherwise
endif
You need not squash manually. I can do it on GitHub when mergin PR 👍 |
I would gladly like a more maintainable solution, but unfortunately I don't know how to realize it. The current implementation just performs a 'dummy edit' in order to create a new undo block. Due to the special handling of the first line in a buffer this dummy edit must be reverted. So AFAICT a special handling for visual mode won't help. Or is there an easier solution I am missing? Sadly I could not find a way to directly add an empty undo block to vim's history without actually modifying the buffer. Edit: After a couple of tests it seems that mode() is never equal to Reminder to myself: the text yanked by |
np. I think this is good start point to improve undo. I'll merge this after your tiny fix and then try improving it later.
yeah, and entering insert mode fires silent execute "noautocmd normal! ii\<esc>\"_x"
|
Thanks. |
I think this solves issue #8. The expectation at the time of that issue I guess was not to have an extra undo point for formatting, but since that can't be easily circumvented or the choice is to keep this undo point regardless, then the only thing left from that issue regards positioning, which seems fixed here. |
On undo, cursor moves to the top of buffer. So I think #8 is not solved yet. vim-go resolves it by creating a new file formatted with |
This PR creates a new undo block to separate formatting related changes from the last undo block. The proposed solution in #30 (to simply remove the undojoin) does not respect the old cursor position. Thus a new undo block is created to store the current cursor position.