Setting up emacs for LilyPond

Use the following at your own risk. It worked for me. It might not for you.

First, your LilyPond distribution came with some files that emacs needs (or at least it should have come with them). Find files with the suffix .el in one of the LilyPond subdirectories. Copy them into emacs-nn.n/elisp, where "emacs-nn.n" is the directory into which you installed emacs.

Second, edit your .emacs file. (If you don't have one or don't know where it is, <Ctrl>-x <Ctrl>-f ~/.emacs will load it.) Add the following lines to it:

(autoload 'LilyPond-mode "lilypond-mode")
(setq auto-mode-alist
      (cons '("\\.ly$" . LilyPond-mode) auto-mode-alist))

(add-hook 'LilyPond-mode-hook (lambda () (turn-on-font-lock)))

While you're at it, prepare emacs to deal with UTF-8 characters (this will allow it to handle accented characters, the copyright symbol, and other unusual characters.) Add this to your .emacs file also:

(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

Finally, you need to be able to enter those unusual characters. I recommend installing leim, which you can probably get from the same place you got emacs (and which may even have been installed with it). Download the leim file and unpack it into the directory where you installed emacs.

To turn leim on, type this: <Ctrl>-x <Ret>  <Ctrl>-\ TeX (note that case is significant). Once it's turned on, you can enter accented characters like this:

\"a produces ä

\'e produces é

\copyright produces ©

And so forth. Browsing leim/quail/latin-ltx.el will show you the whole list.

One drawback is that any use of a \ in LilyPond is likely to be (mis)interpreted by leim and mangled. Fortunately, it's easy to turn leim on and off once it's been activated. <Ctrl>-\ toggles it. Turn it on only when needed, and off again as soon as possible.