Index  Menus  Panels  Troubleshooting  Key glossary  Glossary
Text rulers  Text shortcuts  Fonts  Size and gadgets  Colours  Commands

The language options panel

The language options panel

Select Language options... (Options menu, Shift Ctrl L) to open the language options panel. in which the behaviour of the basic text editing functions and for syntax highlighting can be set individually for a selected number of text window modes.

WORDS AND INDENTATION

The panel lets you specify two character sets; one defines which letters, numbers etc. make up a word. The other, count as indentation, which nonblank characters are to be considered equivalent to white space (the space character, tab, carriage return and line feed are always in this set, so they don't need to be specified).

The characters of the ASCII/ISO set are now divided into three sets: the in-word characters, the white space characters and interpunction (everything that is not in the other sets).

You can now select how word left, word right, delete word and backspace word should behave in terms of these three character classes (See also Moving around).

TEXT HIGHLIGHTING

In the lower half of the language panel, you can select the language definition that defines how text is highlighted and how bracket matching works. Normally, this selection of a language will be all you are interested in, and there will be no need to edit the language definition itself; the most frequent exception is to just change the type effects (fonts, colours) for certain types of information; this can be done without editing the language definition itself: you should then close the language panel and try Highlighting styles... (Options menu, Shift Ctrl G) instead.

The definition of a language, called a bounded stack language, is used to determine special effects for displaying a text, as well as how the operation Find bracket (Browse menu, Ctrl B) is performed. Because such a language definition is inherently complicated, it can not be constructed immediately from this panel, but must be made in a text window. In the panel, you can change the name of the language file, remove the definition altogether (does not remove the file but merely switches off highlighting), or click Edit to open an editor on the language definition.

The option switch on highlighting at `open' and `switch mode' decides whether text highlighting is switched on automatically. Because for large files or files with very long lines, some highlighting modes dramatically increase memory consumption and degrade the editing speed, it may sometimes be wise to have highlighting switched on only on your explicit request, using Highlight syntax (Mark menu, Alt Shift G).

WRITING YOUR OWN LANGUAGE DEFINITIONS

As with text shortcuts, modifying existing highlighting definitions (BSL files for short) is the most effective way to get acquainted with creating new definitions.

A BSL file consists of a number of sections, some of which are optional. These sections must always appear in the same fixed order listed below. An empty line indicates the end of a section. A line starting with a number symbol ('#') introduces a single line comment.

BSL type
This obligatory header specifies two properties of the language that influence how much storage an editor window reserves per line to keep its analysis of the text up to date.

Most often, your highlighting style will be finite-state. Two of the preset styles however, LaTeX and HTML, are recursive; a recursive language is one that has embedding; in the LaTeX case this means that when you go into italic mode, then into boldface mode, then return, the editor should remember that is was in italic mode. The stacks used for such recursive languages take up 10 bytes, and a complete stack is stored for each line in the text file. Finite-state languages only take up 2 bytes extra for each line. Both are in addition to a standard 4 bytes per line used to efficiently access the text buffer.

In some highlighting styles (these are mainly the ones for Edith's panels), each line can be highlighted independently, eliminating the need for storage of line information altogether. These are called intra-line. Normally, highlighting styles for editing modes are trans-line.

typefaces
This obligatory section specifies a number of typeface names, and their default text effects. These effects can later be modified in the highlighting styles panel. It is not a bad idea to create more typeface names than you might personally want to assign different text effects, because other users may think differently (see the default style for C/C++ for an example of a sparsely highlighted, but potentially wild-looking mode). Typeface names (for panels) are sometimes shared between different BSL files.

Each line in this section consists of a five character typeface specification, followed by one (true) tab, and a typeface name. The typeface name must begin with a capital letter, and can otherwise contain letters, dashes and underscores.

The five characters in the typeface specifications can be the following:

type:
r (roman), i (italic), t (typewriter) or l (large).
weight:
b (bold) or - (normal).
emphasis:
u (underline) or - (normal).
colour:
r (light red), g (light green), b (light blue), R (dark red), G (dark green), B (dark blue), y (yellow), l (light) or - (default foreground colour).
functional:
i (insensitive to bracket checking) or - (normal).
state set
This obligatory section defines one up to sixteen states. Typically, there are more typefaces than there are states. The first state is the initial state. A state identifier is a single letter; case is distinguishing.
demo string
This optional section consists of the keyword demo string immediately followed by a one line example of various constructs in the language. This string is displayed in the text display/fonts panel.
word range
This optional section consists of the keyword word range immediately followed by a character range. This range determines how the matching operators \< and \> are interpreted in the rules section. It is independent from the range you specify behind a word may contain in the language panel. The latter is aimed at influencing the behaviour of cursor movement; the word range in the BSL file is typically used to define what characters can make up a keyword or identifier in the defined language.
rules
This last section is obligatory. Each line in this section consists of one up to eight upper case letters identifying trigger states, followed by a single tab, then an expression, then one or more tabs, and finally one or two actions, separated by a comma.

Highlighting is performed as follows. The (1,0) position in the text gets assigned an empty stack with the initial state on top. Then, on a line-by-line basis, the text is scanned from left to right using the rules defined in this section.

At each position, the rules are tried top-down. The first rule that matches the current top state, and whose expression matches the text immediately following that position (up to at most the end of the line), is selected. Longest match and prefer keywords mechanisms can be simulated using the end-of-word marker \>.

If there is a matching rule, the matched text is scanned, and any typeface overrides in the expression of the form \{typeface-identifier} are substituted by face changes. Then the actions are performed. These actions have one of the following forms:

goto A
Go to state A
push A
Push state A
push
Push the current top state
pop
Pop
nop
No operation.
If the new top state has different type effects, the corresponding face changes are applied at the end of the scanned text.

If no rule matches, a single character is scanned, no action performed.

The same procedure is then performed at the new position.

Some notes regarding the expression syntax used: apart from the typeface tags, it is identical to the used in the search panel. The typeface tags are treated as tags between \( and \) (they increment the corresponding ampersand digit). The back reference &0 is `global', that is, its value is kept across expressions, and in trans-line BSL, also across lines.

FEEDBACK AND FUTURE FEATURES

Please be of assistance to other users, and submit your BSL definitions to zfc@zfc.nl for inclusion in future distributions! We can also help you with hints for making efficient highlighting modes.
Index  Menus  Panels  Troubleshooting  Key glossary  Glossary
Text rulers  Text shortcuts  Fonts  Size and gadgets  Colours  Commands