I use git-gutter
for visualizing changes I make to version-controlled files, and magit
for staging/committing/diffing etc.
When working on a project I usually keep a magit-status
window open at all times. The problem I have is that when I stage or unstage changes in the magit-status
buffer and then switch back to the window showing the file whose status I just updated, the fringe annotations produced by git-gutter
are not adjusted automatically. (My current workaround to trigger an update is to hit SPC Backspace followed by C-x C-s to save the file, but that's not very efficient.)
I looked at git-gutter.el
, and sure enough it provides a customizable variable called git-gutter:update-hooks
which is set to
(after-save-hook after-revert-hook window-configuration-change-hook)
by default. So all I really need to do is add the correct hook to this list and I should be good to go. What's the name of the hook that is run when switching windows? I've looked at various sections of the Elisp manual and haven't been able to find what I am looking for. Alternatively, does magit
provide a hook that is run when staging or unstaging changes?
EDIT:
If you are reading this because you're facing a similar problem: Both of the answers I got below are working solutions! For newer versions of magit
, @lunaryorn's solution is short and sweet. @Jordon Biondo's solution requires adding a bit more custom code, but comes with generalizable (!) advice for creating custom hooks and injecting them into existing functionality. So, since I can only accept one answer: Boost your SO karma by rewarding both posters with an upvote :)
magit-revert-buffer-hook
in any buffer of a repo after every operation. – Bordure