Search for usage in LXR

KSyntaxHighlighting::Definition Class Reference

#include <definition.h>

Public Member Functions

 Definition ()
 Definition (const Definition &other)
 ~Definition ()
bool operator!= (const Definition &other) const
Definitionoperator= (const Definition &rhs)
bool operator== (const Definition &other) const
General Header Data
bool isValid () const
QString filePath () const
QString name () const
QString translatedName () const
QString section () const
QString translatedSection () const
QVector< QStringmimeTypes () const
QVector< QStringextensions () const
int version () const
int priority () const
bool isHidden () const
QString style () const
QString indenter () const
QString author () const
QString license () const
Advanced Definition Data
bool isWordDelimiter (QChar c) const
bool isWordWrapDelimiter (QChar c) const
bool foldingEnabled () const
bool indentationBasedFoldingEnabled () const
QStringList foldingIgnoreList () const
QStringList keywordLists () const
QStringList keywordList (const QString &name) const
bool setKeywordList (const QString &name, const QStringList &content)
QVector< Formatformats () const
QVector< DefinitionincludedDefinitions () const
QString singleLineCommentMarker () const
CommentPosition singleLineCommentPosition () const
QPair< QString, QStringmultiLineCommentMarker () const
QVector< QPair< QChar, QString > > characterEncodings () const

Detailed Description

Represents a syntax definition.

Introduction to Definitions

A Definition is the short term for a syntax highlighting definition. It typically is defined in terms of an XML syntax highlighting file, containing all information about a particular syntax highlighting. This includes the highlighting of keywords, information about code folding regions, and indentation preferences.

General Header Data

Each Definition contains a non-translated unique name() and a section(). In addition, for putting this information e.g. into menus, the functions translatedName() and translatedSection() are provided. However, if isHidden() returns true, the Definition should not be visible in the UI. The location of the Definition can be obtained through filePath(), which either is the location on disk or a path to a compiled-in Qt resource.

The supported files of a Definition are defined by the list of extensions(), and additionally by the list of mimeTypes(). Note, that extensions() returns wildcards that need to be matched against the filename of the file that requires highlighting. If multiple Definitions match the file, then the one with higher priority() wins.

Advanced Definition Data

Advanced text editors such as Kate require additional information from a Definition. For instance, foldingEnabled() defines whether a Definition has code folding regions that can be shown in a code folding pane. Or singleLineCommentMarker() and multiLineCommentMarker() provide comment markers that can be used for commenting/uncommenting code. Similarly, formats() returns a list of Format items defined by this Definition (which equal the itemDatas of a highlighing definition file). includedDefinitions() returns a list of all included Definitions referenced by this Definition via the rule IncludeRules, which is useful for displaying all Format items for color configuration in the user interface.

See also

Definition at line 85 of file definition.h.

Constructor & Destructor Documentation

Definition::Definition ( )

Default constructor, creating an empty (invalid) Definition instance.

isValid() for this instance returns false.

Use the Repository instead to obtain valid instances.

Definition at line 52 of file definition.cpp.

Definition::Definition ( const Definition other)

Copy constructor.

Both this definition as well as other share the Definition data.

Definition at line 57 of file definition.cpp.

Definition::~Definition ( )


Definition at line 68 of file definition.cpp.

Member Function Documentation

QString Definition::author ( ) const

Name and email of the author of this syntax definition.

Definition at line 153 of file definition.cpp.

QVector< QPair< QChar, QString > > Definition::characterEncodings ( ) const

Returns a list of character/string mapping that can be used for spell checking.

This is useful for instance when spell checking LaTeX, where the string "{A} represents the character Ä.


Definition at line 309 of file definition.cpp.

QVector< QString > Definition::extensions ( ) const

File extensions associated with this syntax definition.

The returned list contains wildcards.

Definition at line 123 of file definition.cpp.

QString Definition::filePath ( ) const

Returns the full path to the definition XML file containing the syntax definition.

Note that this can be a path to QRC content.

Definition at line 93 of file definition.cpp.

bool Definition::foldingEnabled ( ) const

Returns whether the highlighting supports code folding.

Code folding is supported either if the highlighting defines code folding regions or if indentationBasedFoldingEnabled() returns true.

See also

Definition at line 175 of file definition.cpp.

QStringList Definition::foldingIgnoreList ( ) const

If indentationBasedFoldingEnabled() returns true, this function returns a list of regular expressions that represent empty lines.

That is, all lines matching entirely one of the regular expressions should be treated as empty lines when calculating the indentation-based folding ranges.

This list is only of relevance, if indentationBasedFoldingEnabled() returns true.
See also

Definition at line 200 of file definition.cpp.

QVector< Format > Definition::formats ( ) const

Returns a list of all Format items used by this definition.

The order of the Format items equals the order of the itemDatas in the xml file.


Definition at line 230 of file definition.cpp.

QVector< Definition > Definition::includedDefinitions ( ) const

Returns a list of Definitions that are referenced with the IncludeRules rule.

The returned list does not include this Definition. In case no other Definitions are referenced via IncludeRules, the returned list is empty.


Definition at line 243 of file definition.cpp.

bool Definition::indentationBasedFoldingEnabled ( ) const

Returns whether indentation-based folding is enabled.

An example for indentation-based folding is Python. When indentation-based folding is enabled, make sure to also check foldingIgnoreList() for lines that should be treated as empty.

See also
foldingIgnoreList(), State::indentationBasedFoldingEnabled()

Definition at line 194 of file definition.cpp.

QString Definition::indenter ( ) const

Indentation style to be used for this syntax.

Definition at line 148 of file definition.cpp.

bool Definition::isHidden ( ) const

Returns true if this is an internal definition that should not be displayed to the user.

Definition at line 138 of file definition.cpp.

bool Definition::isValid ( ) const

Checks whether this object refers to a valid syntax definition.

Definition at line 88 of file definition.cpp.

bool Definition::isWordDelimiter ( QChar  c) const

Returns whether the character c is a word delimiter.

A delimiter defines whether a characters is a word boundary. Internally, delimiters are used for matching keyword lists. As example, typically the dot '.' is a word delimiter. However, if you have a keyword in a keyword list that contains a dot, you have to add the dot to the weakDeliminator attribute of the general section in your highlighting definition. Similarly, sometimes additional delimiters are required, which can be specified in additionalDeliminator.

Checking whether a character is a delimiter is useful for instance if text is selected with double click. Typically, the whole word should be selected in this case. Similarly to the example above, the dot '.' usually acts as word delimiter. However, using this function you can implement text selection in such a way that keyword lists are correctly selected.

By default, the list of delimiters contains the following characters: \t !%&()*+,-./:;<=>?[\]^{|}~
See also

Definition at line 163 of file definition.cpp.

bool Definition::isWordWrapDelimiter ( QChar  c) const

Returns whether it is safe to break a line at before the character .

This is useful when wrapping a line e.g. by applying static word wrap.

As example, consider the LaTeX code


Applying static word wrap could lead to the following code:


command2 without a leading backslash is invalid in LaTeX. If '\' is set as word wrap delimiter, isWordWrapDelimiter('\') then returns true, meaning that it is safe to break the line before . The resulting code then would be

By default, the word wrap delimiters are equal to the word delimiters in isWordDelimiter().
See also

Definition at line 169 of file definition.cpp.

QStringList Definition::keywordList ( const QString name) const

Returns the list of keywords for the keyword list name.

See also
keywordLists(), setKeywordList()

Definition at line 212 of file definition.cpp.

QStringList Definition::keywordLists ( ) const

Returns the section names of keywords.

See also

Definition at line 206 of file definition.cpp.

QString Definition::license ( ) const

License of this syntax definition.

Definition at line 158 of file definition.cpp.

QVector< QString > Definition::mimeTypes ( ) const

Mime types associated with this syntax definition.

Definition at line 118 of file definition.cpp.

QPair< QString, QString > Definition::multiLineCommentMarker ( ) const

Returns the markers that start and end multiline comments.

For instance, in XML this is defined as "<!--" and "-->".


Definition at line 303 of file definition.cpp.

QString Definition::name ( ) const

Name of the syntax.

Used for internal references, prefer translatedName() for display.

Definition at line 98 of file definition.cpp.

bool Definition::operator!= ( const Definition other) const

Checks two definitions for inequality.

Definition at line 83 of file definition.cpp.

Definition & Definition::operator= ( const Definition rhs)

Assignment operator.

Both this definition as well as rhs share the Definition data.

Definition at line 72 of file definition.cpp.

bool Definition::operator== ( const Definition other) const

Checks two definitions for equality.

Definition at line 78 of file definition.cpp.

int Definition::priority ( ) const

Returns the definition priority.

A Definition with higher priority wins over Definitions with lower priorities.

Definition at line 133 of file definition.cpp.

QString Definition::section ( ) const

The group this syntax definition belongs to.

For display, consider translatedSection().

Definition at line 108 of file definition.cpp.

bool Definition::setKeywordList ( const QString name,
const QStringList content 

Set the contents of the keyword list name to content.

Only existing keywordLists() can be changed. For non-existent keyword lists, false is returned.

Whenever you change a keyword list, make sure to trigger a rehighlight of your documents. In case you are using QSyntaxHighlighter via SyntaxHighlighter, this can be done by calling SyntaxHighlighter::rehighlight().

In general, changing keyword lists via setKeywordList() is discouraged, since if a keyword list name in the syntax highlighting definition file changes, the call setKeywordList() may suddenly fail.
See also
keywordList(), keywordLists()

Definition at line 219 of file definition.cpp.

QString Definition::singleLineCommentMarker ( ) const

Returns the marker that starts a single line comment.

For instance, in C++ the single line comment marker is "//".

See also

Definition at line 291 of file definition.cpp.

CommentPosition Definition::singleLineCommentPosition ( ) const

Returns the insert position of the comment marker for sinle line comments.

See also

Definition at line 297 of file definition.cpp.

QString Definition::style ( ) const

Generalized language style, used for indentation.

Definition at line 143 of file definition.cpp.

QString Definition::translatedName ( ) const

Translated name for display.

Definition at line 103 of file definition.cpp.

QString Definition::translatedSection ( ) const

Translated group name for display.

Definition at line 113 of file definition.cpp.

int Definition::version ( ) const

Returns the definition version.

Definition at line 128 of file definition.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Jun 20 2021 22:58:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.