hilight - Manage the buffer hilighting schemes
0 hilight "hil-no" "flags" ["nol" "open" "close"] "colorScheme"
hilight "hil-no" "type" "token" [ ["rtoken"]
-1 hilight "hil-no" "type" "token"
The hilight command creates and manages the buffer hilighting, the process of creating a new hilighting scheme is best described in File Language Templates. The command takes various forms as defined by the arguments. Each of the argument configurations is defined as follows:-
0 hilight "hil-no" "flags" ["nol" "open" "close"] "colorScheme"
With an argument of 0, hilight initializes or re-initializes the hilight scheme hil-no (1-255). Every buffer has a hilight scheme, the default is 0 which means no hi-lighting and only the $global-scheme(5) etc. are used. The hilighting scheme must be defined before use and is used to specify how the buffer is to be hilighted. MicroEmacs '99 supports the following hilighting concepts:-
Terminals that cannot display color directly may still be able to take advantage of the hi-lighting. A terminal that has fonts (i.e. Termcap) can use them in the same way using the add-color-scheme(2) command. The hi-light scheme is also used in printing (see print-buffer(2)). If your terminal cannot display color in any way, it is recommended that hi-lighting is disabled (except when printing) as it does take CPU time.
The "hil-no" argument specifies which hi-lighting scheme is being initialized. Once a hilighting scheme has been initialized, hi-light tokens can be added to it and it can be used by setting the current buffer's $buffer-hilight(5) variable to "hil-no". The "flags" argument is a bit based flag setting global hi-light characteristics, where:-
0x01
house == HOUSE == hOuSe
When the hilight scheme is attributed as case insensitive then the tokens must all be specified in lower case.
0x02
0 hilight 1 2 10 $global-scheme
of the following, only the first would begin hi-lighted which is correct (assuming the "/*" is 10 or less lines away).
/* ........ /*......... ......... ........ .........*/ ......... ---------------- --------------- --------------- top of ........*/ ......... ......... window
The argument "colorScheme" specifies the default colors to use if there is no specific hi-light. The colorScheme is a reference to a set of foreground and background color pairs previously defined with add-color-scheme(2).
The hi-lighting scheme required is based on the type of file being edited and so is usually directly related to the file extension, thus it can be automatically set using file hooks (see add-file-hook(2)).
hilight "hil-no" "type" "token" [ ["rtoken"]
With the default argument of 1, hilight creates a hilight token to be used in hilight color scheme identified by "hil-no" (1-255) (see the section on Hilight Scheme Creation for a overview of hi-lighting). The second argument "type" specifies the token type and must always be specified, it determines which other arguments required.
Typically the last argument, schemeNum, is also required. This identifies the color scheme to use when hilighting the token, defining the foreground, background and selection color schemes. This is an index generated from add-color-scheme(2). If the schemeNum argument is omitted the default hilght color scheme is used.
The token "type" is a bit based flag of which 0, 1 or more of the bits may be set, the effect of the bits are defined as follows:
0x001
hilight 1 1 "if" .scheme.keyword
this hilights the 'if' in " if " but not in "aifa".
0x002
; this is a comment line hilight 1 2 ";" .scheme.comment
0x004
hilight 1 4 "\"" "\"" "\\" .scheme.string
An empty value, "", effectively disables the ignore feature. If replacing bit 0x040 is set the replacement close bracket "rclose" must be supplied.
0x008
#define a_single_line_macro() printf("hello world\n") #define a_four_lined_macro() \ do { \ printf("hello world\n") ; \ } while(0)
This can be correctly hilighted with the pre-processor scheme using:
; use to-end-of-line (2) and continuation (8), i.e. 2+8=10 hilight 1 10 "#" "\\" .scheme.prepro
0x010
If this is an end of line token (0x002) then
Else if this is a bracket token (0x004) then
Else
This feature enables the searching and hilighting of specific brackets contained within a to-end-of-line scheme. For example, consider the following C code:
#define My_Token 0x01 /* This is a multi-lined comment * describing My_Token */
With the '#' pre-processor hilight (see bit 0x08 above) the #define line would all be hilighted with the pre-process scheme, the comment would be missed causing incorrect hilighting of the next line. Instead this feature may be used by both the pre-processor and comment hilight tokens to correctly hilight the above example:
hilight 1 26 "#" "\\" .scheme.prepro hilight 1 20 "/\\*" "*/" "" .scheme.comment
0x020
0x040
"the word \C[cDbold\C[cA is in \C[cDbold\C[cA"
Obviously the hilight delimiters should not appear so the character sequence may be correctly drawn using a bracket token, starting with "\C[cD" and ending with "\C[cA", replacing both with an empty string:
hilight 1 0x44 "\C[cD" "" "\C[cA" "" "" .scheme.bold
0x080
0x100
0x200
This has the second highest precedence (see 0x400) and all other bits are ignored. Only the first 3 arguments are required. For example, if there are 11 tokens starting with "delete-" as with the hi-lighting of this buffer, then adding the token "delete-", while invalid in its own right, means that "delete-" is only checked for once. This also reduces the size of the internal hilighting tables so if the message "Table full" appears, the hilighting scheme should be reduced by removal of the common components.
0x400
0x800
0x1000
hilight .hilight.pascal 0x1004 "'" "'" "" .scheme.string
This is especially important with bracket characters such as the single quote (') which legitimately appear in annotation text on their own.
Note that 0x004, 0x008 and 0x080 are mutually exclusive and more than 1 should not be set in any one hilight token, if 2 or more are set the effect is undefined. Other than this there is no restrictions placed on the types of token used, although strange combinations like 0x006 may lead to unexpected results -- hopefully not a core dump, but not guaranteed !
The token and close token of brackets may contain a limited subset of regular expression tokens as follows:-
^
$
\{
\}
\a
\f
\n
\r
\sc
'w' - Word characters i.e. a-z, A-Z, 0-9 etc.
' ' (space) - White space characters i.e. space, tab etc.
'-' - White space characters i.e. space, tab etc.
\Sc
'w' - Word characters i.e. a-z, A-Z, 0-9 etc.
' ' (space) - White space characters i.e. space, tab etc.
'-' - White space characters i.e. space, tab etc.
\t
\v
\w
\W
\xXX
\(.\)
.
[...]
hilight 1 1 "#[gpl][0-9]"
This matches a token which starts with a '#', followed by a 'g', 'p' or 'l' character and ends with a numerical digit. If the user required the replacement (bit 0x40) of the "#" to "#register" to aid readability, the replacement string some now needs to know whether the second character was a 'g', 'p' or 'l' and which digit. Up to 9 groups ("\(.\)") can be use to store a store a single search character, which can be used later in the search string and in the replacement string by using the form "\#", where # is the range test number counting from the left, e.g. for the given example use:
hilight 1 65 "#\\([gpl]\\)\\([0-9]\\)" "#register\\1\\2"
The content of the brackets ([...]) include a set of special short cuts and regular expression syntax definitions as follows:-
[abc]
[a-z]
[-.0-9]
[[:space:]]
[[:digit:]]
[[:xdigit:]]
[[:lower:]]
[[:upper:]]
[[:alpha:]]
[[:alnum:]]
[[:sword:]]
[^...]
\#
hilight 1 64 "\\(.\\)\CH\\1" "\\1" .scheme.bold
The use of "\1" in the search string ensures that the second character is the same as the first. This is replace by a single character drawn in the bold scheme.
? + *
Following is a list of hilighting regular expression restrictions:
The number of characters to the left of a \{ and to the right of a \} token must be fixed, i.e. the '?', '+' and '*' tokens cannot be used before this token. Consider the hilighting of a C function name defined to be a token at the start of a line followed by 0 or more spaces followed by a '('. The following hilight token looks valid but the variable space match is incorrect as it is to the right of the \}:
hilight 1 0 "^\\w+\\}\\s-*(" .scheme.function
Instead either the space match must be include in the function token hilighting (which may cause problems, particularly if printing with underlining) or by fixing the number of spaces as follows:
; include the spaces in the function hilighting hilight 1 0 "^\\w+\\s-*\\}(" .scheme.function ; or fix the number of spaces to 0, 1 ... hilight .hilight.c 0 "^\\w+\\}(" .scheme.function hilight .hilight.c 0 "^\\w+\}\\s-(" .scheme.function
The + and * tokens match the longest string and do not narrow, e.g. consider the hilighting of a C goto label which takes the form of an alpha-numerical name at the start of a line followed by a ':' character. The token "^.*:" cannot be used as . will also match and move past the ending ':', ending only at the end of the line. As no narrowing is performed the final ':' in the token will not match and the label will not be hilighted. Instead a character range which excludes a ':' character must be used, e.g. "^[^:]*:".
A group should not be followed by a ? or * closure, it should either be a fixed single character or followed by a + closure (in which case the last matching character is stored).
Following is a list of hilight type bit / token regex equivalents:
0x01
0x02
0x20
0x100
-1 hilight "hil-no" "type" "token" With a -ve argument hilight deletes the given "token" from a hi-light color scheme identified by "hil-no". The token "type" must also be specified to distinguish between normal and column token types.
Hilighting a MicroEmacs character given in hex form, checking its validity (i.e. "\x??" where ? is a hex digit):
hilight 1 0 "\\x[[:xdigit:]][[:xdigit:]]" .hilight.variable
Hilighting a C style variable length hex number (i.e. "0x???"):
hilight 1 1 "0[xX][[:xdigit:]]+" .hilight.variable
Replacing a quoted character with just the character (i.e. 'x' -> x)
hilight 1 64 "'\\(.\\)'" "\\1" %magenta
The following example uses the branch hilighting feature to hilight each window line a different color to its neighbors by cycle through 3 different color schemes:
0 hilight .hilight.line1 0 $global-scheme hilight .hilight.line1 0x80 "\\n" .hilight.line2 .scheme.no1 0 hilight .hilight.line2 0 .scheme.no1 hilight .hilight.line2 0x80 "\\n" .hilight.line3 .scheme.no2 0 hilight .hilight.line3 0 .scheme.no2 hilight .hilight.line3 0x80 "\\n" .hilight.line1 $global-scheme
Simulate the hilighting from the output of a UNIX man page (taken from hkman.emf):
0 hilight .hilight.man 0 $global-scheme ; ignore hilight .hilight.man 64 ".\CH" "" $global-scheme ; normal underline/italic hilight .hilight.man 64 "_\CH\\(.\\)\\}[^\CH]" "\\1" .scheme.italic hilight .hilight.man 64 "\\(.\\)\CH_\\}[^\CH]" "\\1" .scheme.italic ; bold - first is for nroff -man hilight .hilight.man 64 "\\(.\\)\CH\\1\\}[^\CH]" "\\1" .scheme.bold hilight .hilight.man 64 "_\CH_\CH_\CH_\\}[^\CH]" "_" .scheme.header hilight .hilight.man 64 "\\(.\\)\CH\\1\CH\\1\CH\\1\\}[^\CH]" "\\1" .scheme.header ; bold underline hilight .hilight.man 64 "_\CH_\CH_\CH_\CH_\\}[^\CH]" "_" .scheme.italic hilight .hilight.man 64 "_\CH\\(.\\)\CH\\1\CH\\1\CH\\1\\}[^\CH]" "\\1" .scheme.italic
This replaces the complex nroff character string with a single hi-lighted character (don't believe me, try it!).
MicroEmacs hilight was written with speed and flexibility in mind, as a result the user is assumed to know what they are doing, if not the effects can be fatal.
File Language Templates, $buffer-hilight(5), add-file-hook(2), add-color-scheme(2), hilight-print(2), indent(2), $system(5), print-buffer(2).
(c) Copyright JASSPA 1999
Last Modified: 1999/11/29
Generated On: 1999/12/01