Emacs: How to insert ‘λ’ instead of ‘lambda’ in Scheme mode

emacsunicode

Long ago, I came across a text editor function that replaced the word 'lambda' with the character 'λ'. I would like to do this in emacs. My preferences:

  • I would like to activate this function in certain modes only (activate it for Scheme-mode but turn it off for C-mode for example).

  • At work I still use an older version of emacs, so the solution should work for emacs22 and emacs23.

How should I proceed?

Best Answer

You create a mode hook, which replaces lambda with the Greek character.

   (defun sm-greek-lambda ()
       (font-lock-add-keywords nil `(("\\<lambda\\>"
           (0 (progn (compose-region (match-beginning 0) (match-end 0)
           ,(make-char 'greek-iso8859-7 107))
           nil))))))

Then you add this hook to your mode:

   (add-hook 'emacs-lisp-mode-hook 'sm-greek-lambda)
Related Question