Verify modes of the session config file

Authored by nibags on Nov 22 2019, 8:48 AM.


Verify modes of the session config file

The session config file $HOME/.config/katemetainfos stores the mode of the last open files. However, it may contain invalid or non-existent modes, for example, when applying an highlighting mode of a custom XML file that will be renamed or deleted. Therefore, a verification is added, only existing modes will be applied.


  • The KTextEditor::DocumentPrivate::updateFileType() function now returns a boolean, which is false if the mode name entered in the parameter doesn't exist or is invalid.
  • Modes with empty names are considered invalid, since KateModeManager::fileType(const QString &name) returns an empty KateFileType object if the name of the parameter doesn't exist. It's understood that the name of a mode shouldn't be empty, since it acts as a unique identifier.
  • When reading the session config file (KTextEditor::DocumentPrivate::readSessionConfig()), it's checked if the stored mode is valid. If the mode is invalid, it will not be applied and the default mode will be used, depending on the file extension or MIME-type.

Test Plan:

  1. Create a custom XML highlighting file, which we will call "TestMode".
  2. Open any file, for example $HOME/test.c.
  3. Apply the mode "TestMode". Now, when the file is opened, the "TestMode" mode will be used by default.
  4. Close Kate and delete the custom XML file of "TestMode" or rename the definition name.
  5. Reopen test.c. Now the "TestMode" mode is invalid:

    Before: The "Normal" mode was used and an empty string was displayed as the mode name in the status bar.

    Now: The default mode, defined by the file extension or MIME-type, is used.


  1. Open any file, for example $HOME/test.c.
  2. Open $HOME/.config/katemetainfos, search for the previous file and modify the value of Mode=, by entering an invalid or empty one.
  3. Reopen test.c

Reviewers: KTextEditor, cullmann, dhaumann

Reviewed By: KTextEditor, cullmann

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: Kate, Frameworks

Differential Revision: