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.

Kate gains Support for Inline Notes

Thanks to Michal Srb and Sven Brauch for pioneering the work an a new KTextEditor interface that allows applications like Kate, KDevelop, etc. to display inline notes in a text document. As demo, we quickly prototyped one application to display colors in CSS documents:

Clicking on the color rectangle will launch the color chooser:

Choosing a color and clicking OK finally adapts the color in the CSS document:

The code for this is just a demo and looks as follows:

class NoteProvider : public KTextEditor::InlineNoteProvider {
    QVector<int> inlineNotes(int line) const override
        if (line == 1) return { 29 };
        if (line == 11) return { 29 };
        if (line == 12) return { 29 };
        if (line == 13) return { 29 };

        return {};

    QSize inlineNoteSize(const KTextEditor::InlineNote& note) const override
        return QSize(note.lineHeight(), note.lineHeight());

    void paintInlineNote(const KTextEditor::InlineNote& note, QPainter& painter) const override
        const auto line = note.position().line();
        const auto color = QColor(note.view()->document()->text({line, 22, line, 29}));
        painter.drawRoundedRect(1, 1, note.width() - 2, note.lineHeight() - 2, 2, 2);

    void inlineNoteActivated(const KTextEditor::InlineNote& note, Qt::MouseButtons buttons, const QPoint& globalPos) override
        const int line = note.position().line();
        const auto oldColor = QColor(note.view()->document()->text({line, 22, line, 29}));
        const auto newColor = QColorDialog::getColor(oldColor);
        note.view()->document()->replaceText({line, 22, line, 29},;

    void inlineNoteFocusInEvent(const KTextEditor::InlineNote& note, const QPoint& globalPos) override
    {} // unused in this example

    void inlineNoteFocusOutEvent(const KTextEditor::InlineNote& note) override
    {} // unused in this example

    void inlineNoteMouseMoveEvent(const KTextEditor::InlineNote& note, const QPoint& globalPos) override
    {} // unused in this example

// later in code:
auto provider = new NoteProvider();
// final cleanup

As you can see, it’s actually not much code at all: We have to derive a class from KTextEditor::InlineNoteProvider, and then register an instance of our Note Provider in the KTextEditor::View. In a next step, we implement the inlineNotes(), inlineNoteSize(), and the paintInlineNote() functions to get basic visual drawing at the desired location. The above code is just a tech-demo, since it uses hard-coded lines and color positions. Additionally, one can also track mouse events (unused in the example above). On mouse click, we open the QColorDialog to let the user choose a new color.

To give more examples of what’s possible, the initial Phabricator review requests contained many other interesting examples (the examples were really implemented). From review request D12662:

Kate showing additional information for loops and structs.

Or a KDevelop addition that adds a lot of meta information on the current code if desired:

KDevelop showing detailed code meta information

We believe this addition to the KTextEditor component has a lot of potential for nice features and plugins. Feel free to use this interfaces starting with KDE Frameworks 5.50. Happy coding! 🙂

A big thanks also goes to this year’s Akademy organizers. Thanks to this event, we could meet up in person and also finalize the InlineNoteInterface, InlineNoteProvider, and InlineNote class to make it ready for public release. This again shows the importance of the yearly KDE conferences since it enables us to significantly push things forward.

Downloading Kate Highlighting Files

Starting with the KDE Frameworks 5.50 release we decided to remove the capability in Kate/KTextEditor to download / update syntax highlighting files from the Kate homepage.

The reasons for this are as follows:

  1. The KTextEditor framework is released once a month, meaning that users who use latest KDE software usually anyways have the most recent versions. Other users who do not follow the latest development releases (like your mom) are likely not the target audience for downloading highlighting files.
  2. There are technical problems with only updating certain highlighting files, since it can lead to an inconsistent state when one highlighting file needs another one that was not updated or does not exist, or also if a highlighting file needs a certain indenter that does not yet exist or contains bugs.
  3. We have a nice small cleanup in the UI, since we have now one button less.

Git changes:

Contributing new Highlighting Files

By the way, we are always very happy to accept new highlighting files under MIT license. Documentation about how to write a syntax highlighting file can be found in the Kate Handbook. When you are done, please contribute your highlighting file in phabricator for the ‘syntax-highlighting’ framework (click Code Review, then on the very top right “Create Diff”). You can find nice instructions also on the Community wiki.

Improving Syntax Highlighting Files

When building the KSyntaxHighlighting framework, the syntax highlighting xml files are compiled into the KSyntaxHighlighting library. In order to do so, we have a small little helper program that generates an index of all xml files. This indexer also validates the xml files against the XML Schema, and performs some more sanity checks.

Review request D10621 tries to extend the indexer even further and suggest optimizations for our highlighting files. For instance, the rule

 <AnyChar context="#stay" String="&space;" attribute="Normal Text" />

should be replaced by the faster rule

 <DetectChar context="#stay" char="&space;" attribute="Normal Text" />

Similarly, the rule

 <RegExpr attribute="Normal" context="conditionNot" String="\bnot\b" lookAhead="true" insensitive="true"/>

should be replaced by the much faster rule

 <WordDetect attribute="Normal" context="conditionNot" String="not" lookAhead="true" insensitive="true"/>

The proposed patch above generates more than 1500 suggestions to improve our highlighting files, so a lot of work. Help would be very much appreciated. So if you would like to contribute to KDE and are looking for simple work to do, then feel free to get started by sending improved highlighting files to us via (click “Code Review” on the left, and then “Create Diff” on the top right – or even better use arc to automatically manage your patches). Oh, and please increase the version number in the xml files whenever you provide a patch 🙂