Go to the first, previous, next, last section, table of contents.

16. Editing source code (C mode; Lisp mode; etc.)

16.1. How can I do source code highlighting using font-lock?

For most modes, font-lock is already set up and just needs to be turned on. This can be done by

M-x font-lock-mode 

or by having XEmacs automatically start it by adding lines like

(add-hook 'emacs-lisp-mode-hook	'turn-on-font-lock)
(add-hook 'dired-mode-hook	'turn-on-font-lock)

to your `.emacs'. See the file etc/sample.emacs for more examples.

16.2. How do you arrange it so that XEmacs indents all the clauses of a Common Lisp if the same amount instead of indenting the 3rd clause differently from the first two?

One way is to add, to `.emacs':

(put 'if 'lisp-indent-function nil)

However, note that the package `cl-indent.el' that comes with XEmacs sets up this kind of indentation by default. `cl-indent' also knows about many other CL-specific forms. To use `cl-indent', one can do this:

(load "cl-indent")
(setq lisp-indent-function (function common-lisp-indent-function))

One can also customize `cl-indent.el' so it mimics the default `if' indentation (`then' indented more than the `else'). Here's how:

(put 'if 'common-lisp-indent-function '(nil nil &body))

Also, a new version (1.2) of `cl-indent.el' was posted to `comp.emacs.xemacs' on 12/9/94. This version includes more documentation than previous versions. This may prove useful if you need to customize any indent-functions. The post can be retrieved by searching the XEmacs mail archives.

16.3. I do not like cc-mode. How do I use the old c-mode?

Well, first off, consider if you really want to do this. cc-mode is much more powerful than the old c-mode. But if you still insist, add the following lines to your `.emacs':

(fmakunbound 'c-mode)
(makunbound 'c-mode-map)
(fmakunbound 'c++-mode)
(makunbound 'c++-mode-map)
(makunbound 'c-style-alist)
(load-library "old-c-mode")
(load-library "old-c++-mode")	

This must be done before any other reference is made to either c-mode or c++-mode.

16.4. When I try to edit a postscript file it gets stuck saying: fontifying 'filename' (regexps....) and it just sits there. If I press ctrl-c in the window where XEmacs was started, it suddenly becomes alive again.

This was caused by a bug in the Postscript font-lock regular expressions. It should be fixed in 19.13. For earlier versions of XEmacs, have a look at your `.emacs' file. You will probably have a line like:

(add-hook 'postscript-mode-hook	'turn-on-font-lock)

Take it out, restart XEmacs, and it won't try to fontify your postscript files anymore.

16.5. Does anyone know how to get the "More" Syntax Highlighting on by default?

For C, C++, and Lisp, you can try adding the following to your `.emacs' file:

(setq c-font-lock-keywords c-font-lock-keywords-2)
(setq c++-font-lock-keywords c++-font-lock-keywords-2)
(setq lisp-font-lock-keywords lisp-font-lock-keywords-2)

Go to the first, previous, next, last section, table of contents.