Next: , Previous: , Up: Top   [Contents][Index]

10 Font-lock support for automatic font selection

Font-lock mode causes Emacs to select automatically the font in which text is displayed (“fontify” it) so as to indicate its logical status. See Font Lock mode in The Emacs Editor. The first version of font-lock support for REDUCE mode was contributed by Rainer Schoepf. The current version provides 4 levels of decoration, which can be selected using the standard font-lock facilities, or interactively most easily via the REDUCE mode font-lock sub-menu. The levels and corresponding highlighting are as follows.

  1. Minimum: main keywords and group delimiters, procedure and other main type declarations, strings, %-comments
  2. Algebraic: minimum plus labels, algebraic-mode declarations and variables
  3. Symbolic: minimum plus labels, symbolic-mode declarations and variables
  4. Maximum: all the above plus function calls and all uses of variables

Minimum highlighting is probably a good general-purpose level for normal use, but if you program almost exclusively in either the algebraic or symbolic mode of REDUCE then you might prefer the highlighting tailored to that mode. Maximum highlighting is probably too gaudy and too slow for general use; also the code is complicated and not well tested, so maximum highlighting is likely to be the least reliable.

REDUCE mode does not make any (user configurable) face definitions of its own and only standard font-lock faces are used. The faces used to highlight particular syntactic elements are as follows:


not currently used


%-comments (only)




procedure, operator and module names in their definition statements only (which may change in a later version)


main REDUCE keywords




type declaration keywords




currently used only by REDUCE run mode


obsolete and replaced by font-lock-constant-face

Font-lock mode can be turned on interactively in the normal way that any minor mode is turned on, e.g. it can be toggled on and off by the command font-lock-mode. It can also be turned on and off via the REDUCE mode font-lock sub-menu. To turn on font-lock mode automatically with REDUCE mode, put this in your .emacs file:

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

To control the operation of font-lock mode use the customization buffer for the Font Lock group. The default level of fontification used by any mode can be specified by customizing the user option font-lock-maximum-decoration, which REDUCE mode respects.

Emacs provides standard facilities to control the use of different display faces. See Using Multiple Typefaces in The Emacs Editor. See Faces in The GNU Emacs Lisp Reference Manual, for further technical detail. To alter the appearance of a Font Lock face, use the customization buffer for the Font Lock Highlighting Faces group. See Customizing Faces in The Emacs Editor.

REDUCE mode passes information to font-lock mode via the value of the buffer-local variable font-lock-defaults, which could be re-set or modified via the REDUCE mode hook, although this is not recommended.

For more information see the description of the command font-lock-mode and related commands and variables, and/or the ELisp source code file font-lock.el.

Standard font-lock fontification can be slow. An elegant solution is provided by the lazy-lock package, which immediately fontifies only the visible part of the buffer and fontifies the remainder “stealthily” in the background when Emacs is not otherwise busy. This makes font-lock mode eminently usable even on a relatively low-powered computer (provided it has a suitable display) and I recommend it!

Font-locking of major syntactic elements, such as comments and strings, is normally controlled by the syntax table for the text being edited. This leads to a problem with a language such as REDUCE, because the character ! represents an escape character within an identifier but not within a string. This is different from the convention in the languages (C and Emacs Lisp) that Emacs was primarily designed to support, in which the significance of the escape character does not depend on the context. I have not found a completely satisfactory way to deal with this problem. The solution currently adopted in REDUCE mode is to use a recently added font-lock facility that allows the syntax of ! to be reset from escape to punctuation when it occurs immediately followed by a double quote, i.e. as !". This avoids most of the difficulties, but it fails in the (fairly rare) case that !" appears in an identifier (which it does in one or two of the core REDUCE system files).

Next: , Previous: , Up: Top   [Contents][Index]