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 Schöpf. The current version applies to both REDUCE mode and REDUCE Run mode (Running REDUCE in an Emacs window) and provides 4 strictly inclusive level: “Symbolic” includes “Algebraic”, which includes “Basic”, which includes “Minimal”. The level can be selected using the standard font-lock facilities, or interactively most easily via the REDUCE major mode Syntax Highlighting sub-menu. The levels and corresponding highlighting are as follows:
font-lock-string-face
and
“syntactic” comments (namely comments from %
to the end of
the line, and C-style comments between /*
and */
delimiters) are displayed using font-lock-comment-face
.
In REDUCE Run mode (Running REDUCE in an Emacs window) REDUCE warning and error messages, and
REDUCE (rtrace
) and Lisp trace output, are displayed using
font-lock-warning-face
.
font-lock-comment-face
; the main keywords
including block delimiters and group delimiters are displayed using
font-lock-keyword-face
.
font-lock-function-name-face
and procedure
parameters are displayed using font-lock-variable-face
; general
types such as “algebraic” are displayed using
font-lock-type-face
; local variable types such as “scalar”
are displayed using font-lock-type-face
and variable names
declared local are displayed using
font-lock-variable-name-face
; goto and label names and named
constants such as “pi” and “Catalan” are displayed using
font-lock-constant-face
; declared operator, operator type such
as “linear”, vector, array and matrix declarations are displayed
using font-lock-type-face
; operator, vector, and array and
matrix identifiers (with or without bounds) are displayed using
font-lock-function-face
.
font-lock-preprocessor-face
;
the key symbolic-mode “types” fluid
and global
are
displayed using font-lock-type-face
and the variable names
declared fluid or global are displayed using
font-lock-variable-name-face
; all other quoted objects are
displayed using font-lock-constant-face
; asserted types are
displayed using font-lock-type-face
; “declare” and “struct”
statements, as used in “redlog”, are displayed using
font-lock-keyword-face
, font-lock-function-name-face
and
font-lock-type-face
; module, endmodule and other symbolic-mode
keywords are displayed using font-lock-keyword-face
; module
names are displayed using font-lock-constant-face
; key
symbolic-mode functions such as “flag” and “get” are displayed
using font-lock-builtin-face
; other symbolic-mode “types”
such as “switch” and “share” are displayed using
font-lock-type-face
; declared lambda parameters are displayed
using font-lock-variable-face
.
Using Emacs’ default settings gives symbolic-level highlighting, but
if you find this too gaudy or too slow then you might prefer to select
a lower level. 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 Syntax Highlighting
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, customize the appropriate
options in the Font Lock
group. The default level of
fontification used by any mode can be specified by customizing the
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.
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. The solution I adopt in
REDUCE mode is to reset the syntax of !
from escape to
punctuation when it occurs immediately followed by a double quote,
i.e. as !"
, but only within a string.