Alpha |
Version: | 9.2.3 - "Suhail" |
Last update: | 2021-05-21 14:43:30 |
This page is about the syntax coloring mechanism by which a mode
may define the coloring rules to apply to the text. It is intended for
developers who want to define a new mode for Alpha.
Users looking for information about using colors in Alpha should
read the Alpha Colors help page. It explains how you
can customize the colors used by the different modes.
Introduction
Mode coloring is defined as a set of coloring rules (aka color schemes) which describe which items should be colored and in which color.
Coloring schemes are declared using the [modeColoring register] command. This command returns a coloring
token which uniquely identifies the scheme. Each scheme corresponds to a
particular mode. There may be any number of schemes for a given mode.
Types of schemes
There are five types of schemes which expect different kinds of
information:
- keyword schemes: they declare lists of mode-specific keywords
to colorize.
- regexp schemes: they declare regular expression patterns of words
to colorize.
- symbol schemes: they declare a specific color for some symbols.
- comment schemes: they declare a color to apply to comment
lines or comment blocks. They are useful for programming languages.
- string schemes: they declare a color for strings, that is to
say portions of text enclosed in single quotes, or double quotes or more
generally in any pair of enclosing symbols.
The syntax to declare a scheme is explained in great detail in the
reference of the [modeColoring] command.
The colorizing engine
For efficiency, Alpha has a mechanism of "coloring on demand". This means
that it applies the coloring schemes only when necessary, that is to say
only when some portion of a document is displayed. As the user scrolls
inside a document and displays new portions of the text, coloring is
extended.
All these portions of text are colorized only once as long as the
user does not modify the contents of the window. A sophisticated mechanism
updates the colors as the user inserts or deletes some text.
The coloring engine processes line by line and switches between
three states: plain, comment and string. When it
is in plain state, it first applies the regexp schemes, then the
keyword schemes, then the symbol schemes (if any). When the engine is in
comment or in string state, it ignores the keyword, regexp
and symbols schemes. Schemes of the same type are applied in the order they
were initially declared.