All posts by Dominik

Dominik is a PhD student at the Control Theory and Robotics Lab, TU Darmstadt, as part of the Research Training Group GKMM (GRK1362). My research focuses on state estimation in distributed systems. As hobby, I contribute to the KDE project and work on the Kate application and editor component.

KSyntaxHighlighting – A new Syntax Highlighting Framework

Today, KDE Frameworks 5.28 was released with the brand new KSyntaxHighlighting framework. The announcement says:

New framework: syntax-highlighting
Syntax highlighting engine for Kate syntax definitions

This is a stand-alone implementation of the Kate syntax highlighting engine. It’s meant as a building block for text editors as well as for simple highlighted text rendering (e.g. as HTML), supporting both integration with a custom editor as well as a ready-to-use QSyntaxHighlighter sub-class.

This year, on March 31st, KDE’s advanced text editor Kate had its 15th birthday. 15 years are a long time in the software world, and during this time Kate won the hearts of many users and developers. As text editing component, Kate uses the KTextEditor framework, which is used also by applications such as KDevelop or Kile.

The KTextEditor framework essentially is an embeddable text editing component. It ships everything from painting the line numbers, the background color, the text lines with syntax highlighting, the blinking cursor to code completion and many more features. One major feature is its very powerful syntax highlighting engine, enabling us to properly highlight around 275 languages.

Each syntax highlighting is defined in terms of an xml file (many examples), as described in Kate’s documentation. These xml files are read by KTextEditor and the context based highlighting rules in these files are then used to highlight the file contents.

For the last 15 years, this syntax highlighting engine was tightly coupled with the rest of the KTextEditor code. As such, it was not possible to simply reuse the highlighting engine in other projects without using KTextEditor. This lead to the unfortunate situation, where e.g. the Qt Creator developers partly reimplemented Kate’s syntax highlighting engine in order to support other languages next to C/C++.

This changed as of today: The KSyntaxHighlighting framework is a tier 1 functional framework that solely depends on Qt (no dependency on Qt Widgets or QML), is very well unit tested, and licensed under the LGPLv2+. As mentioned in the announcement and in the API documentation, it is a stand-alone implementation of the Kate syntax highlighting engine. It’s meant as a building block for text editors as well as for simple highlighted text rendering (e.g. as HTML), supporting both integration with a custom editor as well as a ready-to-use QSyntaxHighlighter sub-class. This also implies that you can reuse this framework to add syntax highlighting to e.g. QML applications.

We hope that other applications such as Qt Creator will start to use the KSyntaxHighlighting framework, since it allows us to cleanly share one single implementation of the syntax highlighting engine.

In the next KDE Frameworks releases, we will remove KTextEditors syntax highlighting engine in favor of just using KSyntaxHighlighting. This will happen step by step. For instance, we already have a pending patch that removes all xml files from KTextEditor.git in favor of using the ones shipped by the KSyntaxHighlighting framework. That means, with the KDE Frameworks 5.29 release, Kate’s and KTextEditors dependency (and other application’s dependencies) will look as follows:

KTextEditor and KSyntaxHighlighting

This is quite an interesting change, especially since moving the syntax highlighting engine out of KTextEditor was already planned since Akademy 2013 in Bilbao:

Another idea was raised at this year’s Akademy in Bilbao: Split Kate Part’s highlighting into a separate library. This way, other applications could use the Kate Part’s highlighting system. Think of a command line tool to create highlighted html pages, or a syntax highlighter for QTextEdits. The highlighting engine right now is mostly internal to Kate Part, so such a split could happen also later after the initial release of KTextEditor on 5.

This goal is now reached – thanks to Volker Krause who did most of the work. Pretty cool!

If you are interested in using the KSyntaxHighlighting framework, feel free to contact us on our mailing list. Further, we welcome all contributions, so please send patches to our mailing list, or post them on phabricator. (You can also find the KSyntaxHighlighting framework on github for convenience, but it’s not our primary platform).

You can also support Kate and the KDE Frameworks by donating to the KDE e.V., KDE’s non-profit organization.

KTextEditor gets Scrollbar and Code Folding Preview (Updated)

The KTextEditor Framework just got a new features for the next KDE Frameworks 5.24 release: A Text Preview on the vertical scrollbar.

If enabled in the options, the KTextEditor now shows a preview of the text when the mouse hovers over the scrollbar. The feature is available both when the minimap is used and also when the standard scrollbar is used. The text preview is only visible when vertical scrolling is possible.

This feature is enabled by default, and is also automatically available in Kile and KDevelop, so we hope this is useful to you!

For developers, to ensure this feature is off, the ConfigInterface of the View can be used through the config key “scrollbar-preview” of type bool.

Kate Text PreviewAnd in addition to the preview in the scrollbar, it is now also possible to have a preview for folded code: Hovering over folded code pops up a preview of the hidden lines. When clicked, the code folding opens.

Kate Code Folding Preview

These features got added during the KDE Randa sprint, where around 40 KDE developers focus on improving KDE software and bringing KDE software to other platforms such as Windows and Mac OS. You can support us by donating through the following banner: 🙂

Kate’s TabBar gets Movable Tabs

With the next Applications 16.08 release, Kate5’s tabs will be movable with the mouse. This was a feature request for quite some time, which is now fixed.Kate5's Moving TabsFor the record, the animated gif was created with the following two commands:

  1. ffmpeg -f alsa -f x11grab -r 30 -s 680x385 -i :0.0+0,0 -threads 0 output%04d.png
  2. convert -delay 1/30 -loop 0 -layers OptimizeFrame -size 680x385 -fuzz 2% output*.png output.gif

Much more work is going on at the Randa spring currently held in Switzerland. Would be nice if you support us 😉