Update: A small typo, an unnecessary “<” tag before xmlns in scala-mime.xml has been corrected. Thanks @win for finding the error. See the comments below for additional references.
The default text editor on Ubuntu, or for that matter any Gnome powered desktop, is gedit. If you are a developer like me, who isn’t a huge fan of IDE(s), there is a good chance you use gedit for some of your development. Gedit supports syntax highlighting for a number of languages but if you were hacking some Scala code using the editor, you wouldn’t find any syntax highlighting support out-of-the-box. However, the Scala folks offer gedit syntax highlighting support via the scala-tool-support subproject. To get it working with your gedit installation, do the following:
- Download the scala.lang file from http://lampsvn.epfl.ch/trac/scala/browser/scala-tool-support/trunk/src/gedit/scala.lang. You can checkout the source using svn or scrape the screen by simply copying the contents and pasting it into a file named scala.lang. On Ubuntu, using Ctrl-Shift and the mouse, helps accurately select and copy the content from the screen.
- Copy or move scala.lang file to ~/.gnome2/gtksourceview-1.0/language-specs/
Create a file named scala-mime.xml at /usr/share/mime/packages/ using <pre class="wp-code-highlight prettyprint">sudo touch /usr/share/mime/packages/scala-mime.xml</pre>
- Add the following contents to scala-mime.xml: <pre class="wp-code-highlight prettyprint"><?xml version=”1.0” encoding=”UTF-8”?>
<comment>Scala programming language</comment>
Run <pre class="wp-code-highlight prettyprint">sudo update-mime-database /usr/share/mime</pre>
Start (or restart, if its running) gedit and you now have scala syntax highlighting in place.