Scala syntax highlighting in gedit

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:

  1. 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.
  2. Copy or move scala.lang file to ~/.gnome2/gtksourceview-1.0/language-specs/
  3. Create a file named scala-mime.xml at /usr/share/mime/packages/ using
    sudo touch /usr/share/mime/packages/scala-mime.xml
  4. Add the following contents to scala-mime.xml:
    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;mime-info
     xmlns='http://www.freedesktop.org/standards/shared-mime-info'&gt;
    &lt;mime-type type="text/x-scala"&gt;
    &lt;comment&gt;Scala programming language&lt;/comment&gt;
    &lt;glob pattern="*.scala"/&gt;
    &lt;/mime-type&gt;
    &lt;/mime-info&gt;
  5. Run
    sudo update-mime-database /usr/share/mime
  6. Start (or restart, if its running) gedit and you now have scala syntax highlighting in place.

5 thoughts on “Scala syntax highlighting in gedit

  1. Joe Mansigian

    Hello,

    Thanks for addressing the need for syntax highlighting of Scala in gedit.

    I followed your procedures but ran into some problems.

    Everything went Ok through the end of Step 4.

    On Step 5 I would get parsing errors – first on the open tag at line 2
    and then after I fixed this I would get a parse error on line 3. I ran an XML validator on the xml and it turned up an error on ‘xmlns’.

    If you would please fix and reply to me. This would be very useful and appreciated.

    Thanks

  2. tshanky Post author

    @Joe: Which OS (version) are you on? Would you please send across your scala.lang and scala-mime.xml files. It seems something isn’t right in one of those files.

  3. win

    the scal-mime.xml has typo. it has extra “<" before xmlns
    Here is the correct one

    Scala programming language

  4. Nick

    Regarding the steps to download it – rather than copy and paste, it’s easiest to click the “Original Format” link at the very bottom of the page.

Leave a Reply