cleaning up ecmascript

OK, so I'm writing Javascript at work. It's not too shabby; the nonsensical requirement of an explicit return is starting to drive me a bit batty, but other quirks can be dealt with. For example, let's do something about the ridiculous proliferation of the function keyword. Let's damp the syntactic noise required to use closures:

(defun js-lambda () (interactive) (insert "function () {
 (backward-char 6))
 (defun js-pretty-lambdas ()
 nil (("\\(function *\\)("
 (0 (progn (compose-region (match-beginning 1) (match-end 1)
 , (make-char greek-iso8859-7 107))
 (add-hook 'js-mode-hook 'js-pretty-lambdas)
 (define-key js-mode-map (kbd "C-c l") 'js-lambda)

That means instead of the unsightly function () {}; you get the more subtle λ () { }—much easier on the eyes. Plus you get the C-c l binding to make up for the shortsightedness of keyboard manufacturers in neglecting to include a λ key on their products. Drop this in your .emacs file to let them know who's boss.

« older | 2007-10-13T07:10:01Z | newer »