Skip to content

Live coding help from Git and Emacs

A small git script and two lisp functions can go a long way in helping you "live code" in a prepared and controlled matter at conferences.

So, next week I'm speaking at JavaZone, and I'm planning on a couple of minor coding sessions. Just in case the demo monster visits and I fuck up entirely, I've got some insurance.

With a little help from my good friends Git and Emacs (oh and also my human friend August) I've set it up so I can run through recorded steps of the coding exercise if all else fails.

Extending Git with Ruby

August wrote a small Git script a while back, git-walk. git-walk next and git-walk prev moves your repository one commit forward or backward, respectively. This means you can prepare a coding session - however detailed you want it - and record each step in a git commit.

Shelling out with Lisp

And then for the cool part: I wrote three very simple Lisp functions that I can issue with a key binding in Emacs. I recon I'll use these when visiting relevant buffers, so for good measure I added in a call to revert-buffer, which causes the buffer to reload from the file. revert-buffer normally asks for confirmation, but you can suppress that by passing a non-nil argument as the second argument. The final functions:

(defun git-walk (direction)
  (shell-command (concat "git walk " direction))
  (revert-buffer nil t))

(defun git-walk-next ()
  (git-walk "next"))

(defun git-walk-prev ()
  (git-walk "prev"))

;; Key-bindings
(global-set-key (kbd "C-c <right>") 'git-walk-next)
(global-set-key (kbd "C-c <left>") 'git-walk-prev)

As you can see I bound these to C-c [arrow left/right]. Very handy backup.

Possibly related