Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 8 down vote accepted

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))

Then you add this hook to your mode:

   (add-hook 'emacs-lisp-mode-hook 'sm-greek-lambda)
share|improve this answer
It would be better to rename sm-lambda-mode-hook by sm-replace-lambda or sm-greek-lambda. XXX-mode-hook is usually used to identify hooks ran by run-hook by the specified mode and thus to which you can use add-hook. – Daimrod Jan 26 '12 at 12:11
Is make-char just there to support 22? – Jon Purdy Jan 26 '12 at 13:08
@Daimrod: Can you please explain the difference between a XXX-mode-hook and this custom one defined in the answer? Or at least point me to a useful documentation? – rahmu Jan 26 '12 at 13:29
@rahmu: xxx-mode-hook is usually the name of the hook ran - with run-hooks - by the mode xxx. i.e. emacs-lisp-mode-hook is ran when the function emacs-mode is called. In this case, no hook is ran but a function is added to a hook. Look at the Elisp Manual (Hooks) for more information. – Daimrod Jan 26 '12 at 14:10
@rahmu: Just to add a small example, you can do (add-hook 'emacs-lisp-mode-hook 'some-function) but (add-hook 'sm-lambda-mode-hook 'some-function) will never work unless you've some piece of code that does (run-hooks 'sm-lambda-mode-hook). – Daimrod Jan 26 '12 at 15:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.