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)
(interactive)
(shell-command (concat "git walk " direction))
(revert-buffer nil t))
(defun git-walk-next ()
(interactive)
(git-walk "next"))
(defun git-walk-prev ()
(interactive)
(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.
Comments
Mark Nijhof
(http://cre8ivethought.com/blog/index)
4. September, 23:50
Btw your validation logic doesn't like it when I use capitals in my e-mail address?
Christian
7. September, 09:35
Sorry about the rigid validation logic.
Thomas Ferris Nicolaisen
(http://www.tfnico.com)
22. September, 10:37
(In the first line, I re-assign my leader key to "," - this is just a personal preference.)
This enables me to do this:
I don't get any output from the command (like commit message) into vim, but it works.
(not sure if my angle brackets will make it through here in this comment)
Christian
23. September, 13:14
In Emacs I actually get the commit message in the mini-buffer, which is pretty cool. Next thing to add would be ability to walk only commits related to the file the current buffer is visiting. Would be a cool way to explore a file's history throughout the project. Would require (fairly trivial) extensions to the underlying git-walk script.
Chris Lloyd
(http://thelincolnshirepoacher.com)
12. October, 23:44
http://thelincolnshirepoacher.com/play/liberace.html
Type any key to start the magic. CTRL-C to break in/out of the routine (that really freaked out the crowd).
At the end I started typing all those Unicode characters with only one hand holding a beer in the other.
Using Git, however is far more practical and totally awesome. Good idea!
Christian
13. October, 00:00
Comments are closed