Gedit with Scala

From mi-linux
Revision as of 19:16, 16 April 2012 by In0316 (talk | contribs) (Fixed typo)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This shell script downloads and installs Scala syntax highlighting for the gedit editor and a plugin which will highlight errors in your code.


  • Copy the script below and save it in a file called
  • Open a command line. cd to wherever you stored
  • Make the script executable by executing the following command on the shell (remember you don't type in the $, that's the shell prompt!):
$ chmod +x
  • Run the script like this (you will be asked to enter your password):
$ ./
  • Start gedit as you normally would.

In gedit

  • Go to Edit->Preferences on the gedit menu.
  • Open the Plugins tab.
  • Find Sala on the fly in the list of plugins and select it.
  • Click on the Preferences button.
  • Edit your SCALA_HOME variable in the text box. Set this to be the directory /opt/
  • Close the Preferences dialog.
  • You should now see a Scala menu on the menu bar with options to compile a file, compile all the files in a directory or restart the fast Scala compiler if anything goes wrong.

Try out the script

  • Open a new file and copy in the following code (which contains an error):
object badhello {
    def main(args : Array[String]) : Unit {
        println("hello world!")
  • Save the code in a file called badhello.scala. You should see some wavy red and white underlining. The red lines show compiler errors, the white lines show warnings.
  • Go to View->Bottom Pane in the menus to open the bottom panel in gedit.
  • Click on the Scala output tab in the bottom panel.
  • You should see a list of the compiler errors. If you click on each compiler error in the bottom panel the line of code which caused the problem will be highlighted.
  • Fix the error (hint: this is the first "hello world!" program that Kevan gave you!), save it and run it by either pressing F5 or going to Scala->Compile and run this file in the menus. You should see the output in the bottom panel.

What if it doesn't work?

There are two possible problems that can occur. Either your SCALA_HOME variable has been incorrectly set, in which case you should check what the value of that variable should be by opening a command line and typing the following:

$ echo $SCALA_HOME

The other possible problem is that you may have a very old version of gedit. Open gedit and go to Help->About. If the version of gedit you are running starts with a 2 then this plugin won't work. You can fix that by upgrading gedit.

If you are installing the plugin on a University machine then you cannot run sudo (or privileged) operations. However, the plugin should still work. Come and speak to a member of staff in the workshops if it doesn't.

Shell script


# Shell script to download and install a Scala language specification
# for the Gedit text editor.
# (c) Sarah Mount 26 Jan 2012.

# Create a directory for the language spec.
mkdir -p ~/.gnome2/gtksourceview-1.0/
mkdir -p ~/.gnome2/gtksourceview-1.0/language-specs/

cd ~/.gnome2/gtksourceview-1.0/language-specs/

# Download the spec.

# Add a MIME type for Scala files.
mkdir -p ~/.local/share/mime/
mkdir -p ~/.local/share/mime/packages

cat > Scala.xml << EOF 
<mime-info xmlns=''>
  <mime-type type="text/x-scala">
    <comment>Scala Source</comment>
    <!-- more translated comment elements -->
    <glob pattern="*.scala"/>

# Update MIME database.
cd ~/.local/share/
update-mime-database mime

# Done.
echo "Scala language specification for GEdit has been installed."

# Install the Scala plugin for on-the-fly compilation.
echo "Installing a gedit3 plugin for Scala."

# Create gedit directory structure, if it does not exist.
cd ~/.local/share
mkdir -p gedit
mkdir -p gedit/plugins
cd gedit/plugins


# Installing gsettings scheme for the flyscala plugin

gksudo cp org.gnome.gedit.plugins.flyscala.gschema.xml /usr/share/glib-2.0/schemas/

gksudo glib-compile-schemas /usr/share/glib-2.0/schemas/

echo "Plugin installed."
echo "*** IMPORTANT ***"
echo "Please start gedit and activate the Scala On The Fly plugin from the Edit->Preferences dialog"