title: Emacs: Update git-gutter annotations when staging or unstaging changes in magit-status buffer
body: <p>I use <a href="https://github.com/syohex/emacs-git-gutter" rel="nofollow noreferrer"><code>git-gutter</code></a> for visualizing changes I make to version-controlled files, and <code>magit</code> for staging/committing/diffing etc.</p>
  
  <p>When working on a project I usually keep a <code>magit-status</code> window open at all times. The problem I have is that when I stage or unstage changes in the <code>magit-status</code> buffer and then switch back to the window showing the file whose status I just updated, <em>the fringe annotations produced by</em> <code>git-gutter</code> <em>are not adjusted automatically</em>. (My current workaround to trigger an update is to hit <kbd>SPC</kbd> <kbd>Backspace</kbd> followed by <kbd>C-x C-s</kbd> to save the file, but that's not very efficient.)</p>
  
  <p>I looked at <code>git-gutter.el</code>, and sure enough it provides a customizable variable called <code>git-gutter:update-hooks</code> which is set to</p>
  
  <pre><code>(after-save-hook after-revert-hook window-configuration-change-hook)
  </code></pre>
  
  <p>by default. So all I really need to do is add the correct hook to this list and I should be good to go. <em>What's the name of the hook that is run when switching windows?</em> I've looked at various sections of the Elisp manual and haven't been able to find what I am looking for. Alternatively, does <code>magit</code> provide a hook that is run when staging or unstaging changes?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>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 <code>magit</code>, <a href="https://stackoverflow.com/a/23364805/1199226">@lunaryorn's solution</a> is short and sweet. <a href="https://stackoverflow.com/a/23349774/1199226">@Jordon Biondo's solution</a> 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: <em>Boost your SO karma by rewarding both posters with an upvote</em> :)</p>