Remote pair programming in Emacs
July 19, 2013  

The biggest disadvantage of working remotely is that it isolates you from your coworkers. Remote pair programming is a great way to restore the day-to-day interactions you normally get by working at the same location.

I like to do all my programming in Emacs, whether it’s as part of a pair or solo. For remote pair programming the usual way to do this is using a terminal sharing program such as tmux, screen, or dtach: the programmers run a pair of synchronized terminals, and run Emacs (and/or other programs) in that shared terminal.

This can work well, and tmux, in particular, has become really popular. You can easily find tutorials and support tools for remote pairing built on tmux (e.g., wemux).

The thing is, if you’re going to use Emacs, there’s no reason to use a separate terminal multiplexer. Of course Emacs has multiplexing built in with Emacs Client and Emacs Server.

The only thing missing is synchronization: the “driver” needs the “passenger” to follow along as the driver edits files, changes buffers, etc.

I’ve written a small Emacs package, LOCKSTEP, that provides this type of synchronization. Each participant in the pairing session starts out by connecting to the same Emacs server and then invokes

M-x lockstep

Whenever one participant inserts a character, moves point, or reconfigures windows, the other participants will see the same changes on their screens. At any point a participant can become the driver just by typing as usual at Emacs.

This is a particular kind of collaborative editing, not suitable for all purposes, but I’ve found it to be very effective for pair programming. The most common alternative is to use an editor where each participant gets their own cursor (e.g., as in the Mother of All Demos).

The problem with this is that the participants can lose track of what the others are doing. This defeats the purpose of pairing, in my opinion—I can get this effect just by not pairing. However, if you do want that kind of collaborative editing, of course that is already supported in Emacs.