Search for usage in LXR

KSyntaxHighlighting::Definition Class Reference

#include <definition.h>


QString author
QString license
QString name
QString section
QString translatedName
QString translatedSection

Public Member Functions

 Definition ()
 Definition (const Definition &other)
 Definition (Definition &&other) noexcept
 ~Definition ()
bool operator!= (const Definition &other) const
Definitionoperator= (const Definition &rhs)
Definitionoperator= (Definition &&other) noexcept
bool operator== (const Definition &other) const
General Header Data
bool isValid () const
QString filePath () const
QString name () const
QStringList alternativeNames () const
QString translatedName () const
QString section () const
QString translatedSection () const
QList< QStringmimeTypes () const
QList< 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)
QList< Formatformats () const
QList< DefinitionincludedDefinitions () const
QString singleLineCommentMarker () const
CommentPosition singleLineCommentPosition () const
QPair< QString, QStringmultiLineCommentMarker () const
QList< 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 highlighting 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 82 of file definition.h.

Property Documentation

◆ author

QString KSyntaxHighlighting::Definition::author

Definition at line 89 of file definition.h.

◆ license

QString KSyntaxHighlighting::Definition::license

Definition at line 90 of file definition.h.

◆ name

QString KSyntaxHighlighting::Definition::name

Definition at line 85 of file definition.h.

◆ section

QString KSyntaxHighlighting::Definition::section

Definition at line 87 of file definition.h.

◆ translatedName

QString KSyntaxHighlighting::Definition::translatedName

Definition at line 86 of file definition.h.

◆ translatedSection

QString KSyntaxHighlighting::Definition::translatedSection

Definition at line 88 of file definition.h.

Constructor & Destructor Documentation

◆ Definition() [1/3]

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 44 of file definition.cpp.

◆ Definition() [2/3]

Definition::Definition ( Definition && other)

Move constructor.

This definition takes the Definition data from other.

other may only be assigned to or destroyed afterwards.

◆ Definition() [3/3]

Definition::Definition ( const Definition & other)

Copy constructor.

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

◆ ~Definition()

Definition::~Definition ( )


Member Function Documentation

◆ alternativeNames()

QStringList Definition::alternativeNames ( ) const

Alternate names the syntax can be referred to by.


Definition at line 89 of file definition.cpp.

◆ author()

QString Definition::author ( ) const

Name and email of the author of this syntax definition.

Definition at line 151 of file definition.cpp.

◆ characterEncodings()

QList< 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 286 of file definition.cpp.

◆ extensions()

QList< QString > Definition::extensions ( ) const

File extensions associated with this syntax definition.

The returned list contains wildcards.

Definition at line 121 of file definition.cpp.

◆ filePath()

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 79 of file definition.cpp.

◆ foldingEnabled()

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 173 of file definition.cpp.

◆ foldingIgnoreList()

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 198 of file definition.cpp.

◆ formats()

QList< 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 229 of file definition.cpp.

◆ includedDefinitions()

QList< 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 242 of file definition.cpp.

◆ indentationBasedFoldingEnabled()

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 192 of file definition.cpp.

◆ indenter()

QString Definition::indenter ( ) const

Indentation style to be used for this syntax.

Definition at line 146 of file definition.cpp.

◆ isHidden()

bool Definition::isHidden ( ) const

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

Definition at line 136 of file definition.cpp.

◆ isValid()

bool Definition::isValid ( ) const

Checks whether this object refers to a valid syntax definition.

Definition at line 74 of file definition.cpp.

◆ isWordDelimiter()

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 161 of file definition.cpp.

◆ isWordWrapDelimiter()

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 167 of file definition.cpp.

◆ keywordList()

QStringList Definition::keywordList ( const QString & name) const

Returns the list of keywords for the keyword list name.

See also
keywordLists(), setKeywordList()

Definition at line 210 of file definition.cpp.

◆ keywordLists()

QStringList Definition::keywordLists ( ) const

Returns the section names of keywords.

See also

Definition at line 204 of file definition.cpp.

◆ license()

QString Definition::license ( ) const

License of this syntax definition.

Definition at line 156 of file definition.cpp.

◆ mimeTypes()

QList< QString > Definition::mimeTypes ( ) const

Mime types associated with this syntax definition.

Definition at line 116 of file definition.cpp.

◆ multiLineCommentMarker()

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 280 of file definition.cpp.

◆ name()

QString Definition::name ( ) const

Name of the syntax.

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

Definition at line 84 of file definition.cpp.

◆ operator!=()

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

Checks two definitions for inequality.

Definition at line 69 of file definition.cpp.

◆ operator=() [1/2]

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

Copy assignment operator.

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

◆ operator=() [2/2]

Definition & Definition::operator= ( Definition && other)

Move assignment operator.

This definition takes the Definition data from other.

other may only be assigned to or destroyed afterwards.

◆ operator==()

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

Checks two definitions for equality.

Definition at line 64 of file definition.cpp.

◆ priority()

int Definition::priority ( ) const

Returns the definition priority.

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

Definition at line 131 of file definition.cpp.

◆ section()

QString Definition::section ( ) const

The group this syntax definition belongs to.

For display, consider translatedSection().

Definition at line 102 of file definition.cpp.

◆ setKeywordList()

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 217 of file definition.cpp.

◆ singleLineCommentMarker()

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 268 of file definition.cpp.

◆ singleLineCommentPosition()

CommentPosition Definition::singleLineCommentPosition ( ) const

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

See also

Definition at line 274 of file definition.cpp.

◆ style()

QString Definition::style ( ) const

Generalized language style, used for indentation.

Definition at line 141 of file definition.cpp.

◆ translatedName()

QString Definition::translatedName ( ) const

Translated name for display.

Definition at line 94 of file definition.cpp.

◆ translatedSection()

QString Definition::translatedSection ( ) const

Translated group name for display.

Definition at line 107 of file definition.cpp.

◆ version()

int Definition::version ( ) const

Returns the definition version.

Definition at line 126 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-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:49:44 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.