The Internet's tireless blogger Sacha Chua has another interesting video chat about Emacs. This time it's with Avdi Grimm, a well-known Ruby guru and Emacs user. The video is informative and definitely worth 40 minutes of your time so give it a look when you get a chance.

Towards the end, Grimm talks a little about how many developers use all sorts of suboptimal strategies for learning about the history of a piece of code. Many switch to a terminal and interrogate their version control system. Some go to github and browse the history there. Some even comment out old code so that the history is always there in the file. As Grimm points out, none of that is necessary if you're using Emacs or other decent programmer's editor. In the case of Emacs, you need merely invoke vc-annotate and a color coded history of the file is displayed along with the commit id, committer, date, and other information. From there you can drill down and get further details. Grimm has an excellent short video1 that demonstrates some of its functionality.

The nice thing is that vc-annotate is in stock Emacs so you don't need to do anything to use it. Just bring up a file that's under version control and type【Meta+xvc-annotate or 【Ctrl+x v g】 to try it out. You can read about vc-annotate in the Emacs manual or under the Old Revisions node in Info. This is a great feature; I can't believe I didn't know about it.


1 The video doesn't show up at all without Flash so if you don't see the video at the link, you'll need to view it with Chrome or some other browser with Flash installed.

This entry was posted in General and tagged . Bookmark the permalink.

    I knew about vc-annotate but didn't know you could use it to walk back in history. I've only used it to blame people.


  • bitti

    I also like git-log-file from git-emacs package and magit-file-log from magit. Both also have blame commands with a different touch to it.

    One of the unbelievable cool aspects of emacs, which I didn't find in any other software yet, is how you can dig into the source of a function just by using the help commands and even look into it's complete history if you happen to have compiled emacs from a git repo.

    E.g. use C-h f self-insert-command, and you're right into it's source code definition. You can now start digging around into it's history back to 1991 with git-log-file or git-blame or it's vc- equivalents. How cool is that? I mean *that's* self documenting. What can you expect more?

  • bitti

    Also tapped into the "strip away tags" trap of this blog. Of course you need <tab> <return> before you're in the source code.

    • Phil

      I find it invaluable having C-h C-f bound to find-function. That does the same thing as selecting the link you mention after calling describe-function, but it gets you there directly.

      Tangentially a documentation binding many people seem to not know about is C-h F which takes you to the indexed page in the info manual for the command in question. C-h K does the same thing, but you type the key sequence rather than the command name.

  • I have been using emacs for long. A big fan of Sacha Chua. I never knew that there was this vc-annotate. This is going to save me a lot of time, as the only time I switch to a terminal is for introspection.