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.
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.
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.


[...] This post was mentioned on Twitter by bread. bread said: @meteor1113 可以吧。。。我也记不得了,很久没用了。http://bit.ly/aMyg4L 看这里 [...]
[...] It’s fairly late at night, and I’m doing some desperately needed work coding. I’ve been using SVN to track my progress, as I do at work, and I’ve found myself using PSVN more and more. I’ve long had it installed, but never taken full advantage of it. It provides a central point within emacs to do just about anything you could want to do with an SVN-controlled directory, file or repo (or make new ones). It also hooks into ediff and various other bits of emacs magic. Rather than rehash things, here’s a link to an intro to it I found. [...]
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))
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.
Feiming Chen, thanks for the ediff tip. This is basically what I was looking for. An other useful mode to track the changes is the diff-hl. I find it very useful to track the changes in the current buffer. It highlights the chagnes using colors so you can see the code areas you changed/add/deleted and you can navigated between your changes in the current buffer easilly.