Sometimes you come across these gems of packages that seem to fulfill a wish that you didn't even realise you had.
Today I came across git-gutter for Emacs and its companion git-gutter-fringe, which are apparently based on an extension for Sumblime Text 2. These show the status of changes in a special "gutter" next to the fringe or in the fringe itself. This is very cool stuff.
To enable it I added the following code to my Emacs init file:
(eval-after-load "git-gutter" '(load "git-gutter-fringe")) (defun maybe-use-git-gutter () "Run `git-gutter' if the current file is being tracked by git." (when (eq (vc-backend (buffer-file-name)) 'Git) (git-gutter))) (add-hook 'after-save-hook 'maybe-use-git-gutter) (add-hook 'after-change-major-mode-hook 'maybe-use-git-gutter) (add-hook 'window-configuration-change-hook 'maybe-use-git-gutter)
git-gutter was easily installed through MELPA, but I had to download
git-gutter-fringe separately and use
package-install-file to install
I had to load
git-gutter-fringe manually because it didn't seem to
have any autoloads defined, and I had to run it using these three
hooks because the information seemed to disappear if I switched
windows and came back, didn't automatically update after saving and
didn't automatically show anything when first loading the file. This
was all fine, since just calling the function updates the buffer it's
easy to use this way.
Later, though, I stumbled upon diff-hl by accident. I was looking for anything involving the fringe, which I think, for the most part, is underused.
It does pretty much the same thing, except that it does so at least for git, bazaar and mercurial (according to the readme). It also defines some commands for working with the blocks of changes, like navigating between them and reverting them. It uses the fringe by default, and doesn't require a separate package to be installed. And it's much easier to set up.
It can also be installed through MELPA, and afterwards it's just a line in our init file away:
Of course if you don't want it enabled globally you can call
diff-hl-mode from some hooks, but this way works fine for me.
It's funny how I had no idea these existed, didn't even think about needing/wanting this feature and then finding two of them in the same day.