A Brief Introduction to Emacs psvn

Ideaworks edits most of its Perl using Emacs and stores that code in a Subversion repository. As the resident Emacs guru, I was recently asked by a coworker to write up some tips on using the Emacs psvn mode for doing integrated work on Subversion repositories and Trac.

You can download the latest copy here: psvn.el Once you do, put it in your ~/.emacs.d folder (and optionally, you can byte compile it). If you work with large repositories, you may want to configure the Customize group svn-status-verbose to nil so that psvn will run svn status instead of svn status -v. The verbosity of the latter can be painfully slow for repositories with tens of thousands of files.

Emacs psvn status dot
Emacs psvn status dot

The Status Dot

You’ll notice when psvn is installed that visiting a version controlled file causes a little dot to appear in the corner of the mode line. This dot indicates svn status. Green (and the one in that picture is green, believe it or not) means the file is up-to-date and unmodified on disk. “Tomato red” is an edited file, darker red indicates the file was deleted. Added files are blue, unmerged files are purple, and gray signifies files with an ‘unknown’ status.

Part of the svn status menu
Part of the svn status menu

Using svn status mode

In any buffer you can type M-x svn-status to get the status of the current folder. (You can check which folder is current with M-x pwd.) You should only see modified files in this view. You can arrow up and down through the files, mark files for action with m, unmark with u, commit the marked files with c, etc. Note that you can even compose your svn log message right in Emacs if you commit from svn status mode. Look at the source to psvn.el and browse the major mode menu to find what you’re interested in. Basically anything that you can do on the command line you can do inside Emacs, and many times you can save time in svn status mode.

Blame and Praise

I have begun to find it very helpful to know who was the last person to work on a particular area of a source file. This feature, svn blame (some people cheerfully call this by its synonym, “svn praise,” but I’m a cynic – all code is buggy), can be quickly executed on the current file with C-x M-s f b

SVN Diffs and Ediff Merge

When you’re working in a buffer and you wonder what you’ve changed, try running M-x svn-status-show-svn-diff (shortcut: C-x M-s =) to see an svn diff.

Sometimes, though, you really want the power of Emacs ediff mode (which is a lesson for another time). From svn-status mode, try typing E (capital E). That will immediately launch M-x svn-status-ediff-with-revision, which is an Ediff session comparing the selected file’s contents to HEAD of the working copy. If you threw in a bunch of debugging code, for instance, this is a quick and easy way to get it out – assuming you know your way around Ediff.

Trac integration

Trac integration is a great tool, but it’s limited. You have quick shortcuts to opening links in your web browser based on the current svn repository’s base. For instance, M-x svn-trac-browse-ticket (C-x M-s t iM-x svn-trac-browse-timeline (C-x M-s t t) will pop open the Trac timeline.

This feature is limited, though. You might expect M-x svn-trac-browse-source to pop open Trac to the correct page based on the source file you’re visiting in the current buffer, but it won’t. Hopefully in the future someone will implement this – patches welcome, I guess!

Have any more psvn tips? Please share them in the comments below.

4 thoughts on “A Brief Introduction to Emacs psvn

  1. I found Emacs’s generic VC commands (Menu: Tools => Version Control) come in very handy. The following commands do what is mentioned in the article equivalenly:

    Blame and Praise: C-x v g (Annotate: this is color-highlighted so is nicer than svn-status-blame)

    SVN Diff: C-x v = (Compare with Base Version)

    To use Ediff automatically when you invoke “C-x v =”, write the following line in your .emacs file:

    (eval-after-load “vc-hooks” ‘(define-key vc-prefix-map “=” ‘vc-ediff))

  2. It’s been a few years since I’ve been a series emacs user, and it appears that you’re quite right – in the 4.5 years since this article, the native VC commands for svn have come a long way. Thanks for your comment.

Comments are closed.