build_highlight_table
Void build_highlight_table (String n);
This function builds a DFA table for the enhanced syntax
highlighting scheme specified for the syntax table specified
by the name n
. This must be called before any syntax
highlighting will be done for that syntax table.
create_syntax_table, use_syntax_table, define_highlight_rule, enable_highlight_cache
WANT_SYNTAX_HIGHLIGHT,USE_ANSI_COLORS
create_syntax_table
Void create_syntax_table (String name);
This the purpose of this function is to create a new syntax table
with the name specified by name
. If the table already exists, this
function does nothing.
define_syntax, use_syntax_table, define_keywords
define_highlight_rule
Void define_highlight_rule (String rule, String color, String n);
This function adds an enhanced highlighting rule to the
syntax table specified by the name n
. The rule is described
as a regular expression by the string rule
, and the
associated color is given by the string color
, in the same
format as is passed to set_color
. For example:
create_syntax_table ("demo");
define_highlight_rule ("[A-Za-z][A-Za-z0-9]*", "keyword", "demo");
define_highlight_rule ("//.*$", "comment", "demo");
build_highlight_table ("demo");
causes a syntax table to be defined in which any string of
alphanumeric characters beginning with an alphabetic is
highlighted in keyword color, and anything after "//" on a
line is highlighted in comment color.
The regular expression syntax understands character classes
like [a-z]
and [^a-z0-9]
, parentheses, +
, *
, ?
, |
and .
. Any metacharacter can be escaped using a backslash
so that it can be used as a normal character, but beware that
due to the syntax of S-Lang strings the backslash has to be
doubled when specified as a string constant. For example:
define_highlight_rule ("^[ \t]*\\*+[ \t].*$", "comment", "C");
defines any line beginning with optional whitespace, then one
or more asterisks, then more whitespace to be a comment. Note
the doubled backslash before the *
.
Note also that build_highlight_table
must be called before
the syntax highlighting can take effect.
create_syntax_table, use_syntax_table, build_highlight_table
WANT_SYNTAX_HIGHLIGHT,USE_ANSI_COLORS
define_keywords_n
String define_keywords_n (String table, String kws, Integer len, Integer n);
This function is used to define a set of keywords that will be color
syntax highlighted in the keyword color associated with the table
specified by n
. The first parameter, table
, specifies which
syntax table is to be used for the definition. The second parameter,
kws
, is a string that is the concatenation of keywords of length
specified by the last parameter len
. The list of keywords specified
by kws
must be in alphabetic order. The function returns the
previous list of keywords of length len
. For example, C mode uses
the statement
() = define_keywords_n ("C", "asmforintnewtry", 3, 0);
to define the four three-letter keywords asm
, for
, int
, new
,
and try
. Note that in the above example, the return value is not used.
define_syntax, set_color
WANT_SYNTAX_HIGHLIGHT,USE_ANSI_COLORS
define_syntax
Void define_syntax (..., Integer type, String name);
This function adds a syntax entry to the table specified by the last
parameter name
. The actual number of parameters vary according to
the next to the last parameter type
.
If type
is '"'
or '\''
, a string or character delimiter syntax is
defined. In this case, define_syntax
only takes three parameters
where the first parameter is an integer that represents the character
for which the syntax is to be applied.
Similarly, if type
is '\\'
, then a quote syntax is defined and
again define_syntax
only takes three parameters where the first
parameter is an integer that represents the character for which the
syntax is to be applied. A quote character is one in which the
syntax of the following character is not treated as special.
If type
is '('
, then define_syntax
takes four parameters where
the first two parameters are strings that represent a matching set of
delimiters. The first string contains the set of opening delimiters
and the second string specifies the set of closing delimiters that
match the first set. If a character from the closing set is entered
into the buffer, the corresponding delimiter from the opening set
will be blinked. For example, if the C language syntax table is
called "C"
, then one would use
define_syntax ("([{", ")]}", '(', "C");
to declare the matching delimiter set. Note that the order of the
characters in the two strings must correspond. That is, the above
example says that '('
matches ')'
and so on.
If type
is '%'
, a comment syntax is defined. As in the
previous case, define_syntax
takes four parameters where there
first two parameters are strings that represent the begin and end
comment delimiters. If the comment syntax is such that the comment
ends at the end of a line, the second string must either be the empty
string, ""
, or a newline "\n"
. In the current implementation, at
most the begin and end comment strings can consist of at most two
characters.
If type
is '+'
, the first parameter is a string whose characters
are given the operator syntax. If type is ','
, the first parameter
is a string composed of characters that are condered to be
delimiters. If type is '0', the first parameter is a string composed
of characters that make up a number.
If type
is <
, the first parameter is a string whose successive
characters form begin and end keyword highlight directives.
Finally, if type
is '#'
, the first parameter is an integer whose
value corresponds to the character used to begin preprocessor lines.
As an example, imagine a language in which the dollar sign character
$
is used as a string delimiter, the backward quote character `
is used as a quote character, comments begin with a semi-colon and
end at the end of a line, and the characters '<'
and '>'
form
matching delimiters. The one might use
create_syntax_table ("strange");
define_syntax ('$', '"', "strange");
define_syntax ('`', '\\', "strange");
define_syntax (";", "", '%', "strange");
define_syntax ("<", ">", '(', "strange");
to create a syntax table called "strange"
and define the
syntax entries for appropriate this example.
create_syntax_table, use_syntax_table, find_matching_delimiter
BLINK
enable_highlight_cache
Void enable_highlight_cache (String file, String n);
This function enables caching of the DFA table for the
enhanced syntax highlighting scheme belonging to the syntax
table specified by the name n
. This should be called before
any calls to define_highlight_rule
or to
build_highlight_table
. The parameter file
specifies the name of the file (stored in the directory set by the
set_highlight_cache_dir
function) which should be used as a cache.
For example, in cmode.sl
one might write
enable_highlight_cache ("cmode.dfa", "C");
to enable caching of the DFA. If caching were not enabled for
C mode, the DFA would take possibly a couple of seconds to
compute every time Jed was started.
Transferring cache files between different computers is theoretically possible but not recommended. Transferring them between different versions of Jed is not guaranteed to work.
create_syntax_table, use_syntax_table, define_highlight_rule, build_highlight_table
WANT_SYNTAX_HIGHLIGHT,USE_ANSI_COLORS
parse_to_point
Integer parse_to_point ();
This function attempts to determine the syntactic context of the current editing point. That is, it tries to determine whether or not the current point is in a comment, a string, or elsewhere. It returns:
-2 In a comment
-1 In a string or a character
0 Neither of the above
Note: This routine is rather simplistic since it makes the assumption
that the character at the beginning of the current line is not in a
comment nor is in a string.
define_syntax, find_matching_delimiter
Specify characters for fortran-like comments
Void set_fortran_comment_chars (String_Type table, String_Type list
This function may be used to specify the set of characters that
denote fortran style comments. The first parameter table
is
the name of a previously defined syntax table, and list
denotes the set of characters that specify the fortran-style
comment.
The string list
is simply a set of characters and may include
character ranges. If the first character of list
is
'^'
, then the meaning is that only those characters that do
not specify fortran sytle comments are included in the list.
Fortran mode uses the following:
set_fortran_comment_chars ("FORTRAN", "^0-9 \t\n");
This means that if any line that begins with any character
except the characters 0
to 9
, the space, tab, and
newline characters will denote a comment.
The usefulness of this function is not limited to fortran modes. In fact, many languages have fortran-style comments.
This function is meaningful only if the syntax table has
fortran-style comments as specified via the set_syntax_flags
function.
define_syntax, set_syntax_flags
set_highlight_cache_dir
Void set_highlight_cache_dir (String dir);
This function sets the directory where the dfa syntax highlighting
cache files are located.
See also: enable_highlight_cache
set_syntax_flags
Void set_syntax_flags (String table, Integer flag);
This function may be used to set the flags in the syntax table
specified by the table
parameter. The flag
parameter may take
any of the following values or any combination bitwise or-ed together:
0x01 Keywords are case insensitive
0x02 Comments are Fortran-like
0x04 Ignore leading whitespace in C comments
0x08 Keywords are TeX-like
0x10 Comments start/end are whole words
0x20 Syntax highlight whole preprocessor line in same color
0x40 Leading whitespace allowed for preprocessor lines.
A Fortran-like comment means that any line that begins with certain
specified characters is considered to be a comment. This special
subset of characters must be specified via a call to the
set_fortran_comment_chars
function.
If the 0x04
bit is set, then whitespace at the beginning of a
line in a C comment preceeding a '*'
character will not be
highlighted.
A TeX-like keyword is any word that follows the quote character.
define_syntax, set_fortran_comment_chars
use_syntax_table
Void use_syntax_table (String n);
This function associates the current buffer with the syntax table
specified by the name n
. Until another syntax table is associated
with the buffer, the syntax table named n
will be used in all
operations that require a syntax. This includes parenthesis matching,
indentation, etc.
create_syntax_table, define_syntax