Karl Fogel at
Later I made a small optimization, so if you're looking at this it's probably best to use the latest code:
http://viewvc.red-bean.com/kfogel/trunk/.emacs?revision=HEAD&view=markup#l3620
http://viewvc.red-bean.com/kfogel/trunk/.emacs?revision=HEAD&view=markup#l3620