My thoughts on kateschema to theme converter
Or how I spent a weekend.
With the latest changes in ksyntaxhighlighting library the old themes (they are called “kateschema”) will become obsolete and one will have to either use some new theme and hope it will fit or try to adapt the old one and spent hours doing so.
The old format is a bit complicated, the settings for one language can vary depending on the current file type. In other words you could have different settings if you opened CSS file directly or when styles were used in HTML. This looks like a nice feature to have which allowed users to tweak everything but also added a huge overhead when doing changes to the theme. So one has to decide how to export these changes, I decided to take 2 approaches:
- First come first serve - whatever setting is read first for given data type, that is used
- main type rules - In other words it would prefer settings stored for that standalone data type and will overwrite any previously read ones
Another huge drawback while writing this script was lack of documentation which forced me to go through the source code to find answers to my questions, which took a lot of time and energy. A huge part of the script is comprised of dictionaries which are used to convert old settings to new one.
In the end I managed to convert my theme with some drawback compared to old solution. In new version you cant define default style for something by using the theme. These defaults are set by syntax highlighting definitions. So the “default” values are almost always not met and will restore setting to some theme keyword defined in syntax file (well, nothing to do here from my side).
The script was than pushed to the frameworks/syntax-highlighting repository.
I was too tired to do some proper user interface and such it is very crude. In general you need to supply 2 arguments:
- Theme name
- kateschema file
And the results will be printed to the stdout, it is up to user to save it into the file or whatever.
In the end, the script did the job for me and I can have same colors
(for time being until I fix or change the theme) as I have on old one.
I use it to convert exported theme with all the mess around (16k lines) and I got a nice theme as a result together with messy custom styles. But there is nothing to do with that, I did not wish to lay with theme for hours to make it looks nice again.
So these are my messy thoughts about this script, it works but it is not perfect. It can be used as an example for your own (hope better) creation.