# PceEmacs SGML mode

This page describes the PceEmacs modes SGML, HTML and XML. These modes are based on the SWI-Prolog package sgml2pl, an SGML/XML parser for Prolog. It exploits this parser to achieve both colouring syntax elements and errors as well as to provided menu-driven editing of SGML, HTML and XML documents.

## Syntax highlighting

These PceEmacs modes are designed to be simple. Colouring uses the following colours

`bold blue` | begin tag
`bold blue onlight-grey` | SGML SHORTREF expansion
`blue` | end tag
sea-green | CDATA declared content element
`orange` | warning
`red` | error

Colouring the whole buffer is the only really safe colouring method, but unfortunately doesn't scale with large files. Therefore, this mode is only initiated after loading a file in this mode, after typing Control-L (recenter) or after an explicit colourise_buffer command.

The more error-prone colourise_element is activated after many commands as well as after an idle-period of 2 seconds. This command searches backward to the first element that encloses the caret and then colourises this element. It is errorprone for two reasons. First of all, it does not validate whether the checked element itself is at a valid location. Second, it does not see elements allowed throught the DTD's +(Model) construct.

## Errors and warnings

Errors and warning encountered during parsing cause the suspect region to be coloured orange (warning) or red (error). Moving the caret in the suspect area causes the error to be printed in the status line at the bottom of the editor.

## Syntax-guided editing

Most syntax-guided editing is supported using a context-sensitive popup-menu associated with the right mouse button. To create an new element, press the right mouse-button at the desired location and select the desired element. The modifier buttons define how the element is inserted:

control | Insert adjacent begin- and end-tag.
shift | Place begin- and end-tag each on their own line
alt | (SGML only) create a SHORTTAG element

To tag the current selection with a tag, first make a selection and then press the right mouse-button inside the selection. The same modifiers as above apply. If no modifier is given, the default is to place the tag at their own line of the selection contains complete lines and `in-line' otherwise.

To add attributes to an element, press the right-button inside the elements begin-tag and select the desired elements.

## Bugs and TODO

- Cache the parsed DTD
- Deal with included +(Group) elements properly
- Display total number of encountered errors and provide navigation on large files
- Personalise layout: style to use for certain tags, syntax highlighting, etc.
- Take are of already present attributes and elements.