Based on jhamrick/emacs