Alex Henning home about projects blog

Pretty Lambdas!

A neat little trick I found a while ago allows emacs to transform (lambda ...) into (\lambda ...) which makes lisp code more concise and easier to read. (You can also use it for python and any other language).

1:  (defun pretty-lambdas ()
2:    (interactive)
3:    (font-lock-add-keywords
4:     nil `(("\\(lambda\\>\\)"
5:            (0 (progn (compose-region (match-beginning 1) (match-end 1)
6:                                      ,(make-char 'greek-iso8859-7 107))
7:                      nil))))))
8:  

It is a bit of a mess, but when it's activated you type lambda normally and it auto transforms into \lambda for display, but saves as lambda. This allows you to use it in source code and run the code normally. To enable it, add it as a hook in .emacs or type M-x pretty-lambdas when the file is open.

Edit: I got this from emacswiki.org, one of the problems with a large .emacs is sometimes it's hard to remember where you got everything…

Posted on 29 October 2010 in emacs lisp lambda

<Previous: Keeping Track of Ideas for Blog PostsNext: River Rage!>

blog comments powered by Disqus