The highlighter module#

This module provides a SyntaxHighlighter.

class SyntaxHighlighter(worker)[source]#

Bases: SingleInstance

Provides syntax highlighting using parce parsers.

Instantiate with:

SyntaxHighlighter.instance(worker)

You need to set a Formatter which supplies the highlighting text formats.

By default, no formatter is set; use set_formatter() to set a Formatter, which is needed to enable highlighting.

worker()[source]#

Return the worker we were instantiated with.

delete()[source]#

Reimplemented to clear the highlighting before delete.

document()[source]#

Return the QTextDocument.

set_formatter(formatter)[source]#

Set the Formatter to use, or None for no formatter.

The Formatter provides the text formats to highlight. If you set the Formatter to None, highlighting is effectively disabled, although the TreeBuilder still does the tokenizing.

formatter()[source]#

Return the currently set Formatter.

clear()[source]#

Clear the highlighting.

This method is called when the formatter is set to None, and when SyntaxHighlighter is explicitedly delete()-d.

rehighlight()[source]#

Draw or clear the highlighting, depending on the Formatter.

This method is automatically called when the Formatter is changed. Clears the highlighting if the current formatter is None.

slot_preview(start, tree)[source]#

Called when there is a peek preview.

slot_updated(start, end)[source]#

Called on update; performs the highlighting.

draw_highlighting(root, start, end, interruptible=False)[source]#

Draw the highlighting using tree root from start to end.

If interruptible is True, QApplication::process_events() is called every 1000 lines, to enable the user typing in the document, which also causes the highlighting to quit and resume later.

split_formats(block, position)[source]#

Return two lists of FormatRange instances from the block’s layout.

The first are the formats from the start of the block until position (which must be inside the block). The second are the formats from the position to the end of the block, shifted as if the block started at position.

A format range is neatly cut in two when position lies in the middle of a range.