Syntax highlighting problem with .html.erb files in Kate text editor

March 15, 2009 by alex

Recently, I’ve been trying out the Kate ( text editor when programming. It’s free, lightweight, and seems quite nice. It has most of the features of TextMate (my current favorite), runs on Linux, and is free.

Last weekend I noticed the syntax highlighting for Ruby on Rails view templates (files ending in .html.erb) was all messed up. Matching tags were not marked, functions weren’t highlighted, and everything was basically really difficult to read. After trolling around Kate’s configuration files, I think I found the issue. I submitted a bug to the KDE development team, but in the meantime I thought I’d post this for anyone else trying to do RoR work in this editor.

Kate keeps its syntax highlighting definition files in XML files in bash/usr/share/kde/apps/katepart/syntax . Each file has an element like this one : xml rhtml.xml The ‘extensions’ part should mean that my template files get highlighted according to the rules in this XML file. But that wasn’t happening. It turns out there’s another file… xml apache.xml So apparently apache.xml is applied before rhtml.xml.

Kate saves the syntax style for each file you open, which means this broken association will stick around until you fix it manually. I’ve removed apache.xml from /usr/share/kde/apps/katepart/syntax entirely, since I’ll never use Kate to edit Apache config. This may or may not work for you. To fix files which are currently highlighted incorrectly, try this: bash cd ~/.kde/share/apps/kate/sessions ls You will see a .katesession file for each session you have created. You can edit these by hand. I recommend that Kate not be running while you do this. (It crashed on me a few times when I was manually editing the files, which isn’t really a surprise, I suppose.) Find the section for the file which is highlighted incorrrectly, and change all occurrences of ‘Apache Configuration’ to ‘Ruby/Rails/RHTML’. Then save and quit.

☙ ☙ ☙