Gedit with Scala
This shell script downloads and installs Scala syntax highlighting for the gedit editor and a plugin which will highlight errors in your code.
Installation
- Copy the script below and save it in a file called
plugin-install.sh
- Open a command line.
cd
to wherever you storedplugin-install.sh
- 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 plugin-install.sh
- Run the script like this (you will be asked to enter your password):
$ ./plugin-install.sh
- 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/scala-2.9.1.final/
- 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 toScala->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 /opt/scala-2.9.1.final/
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
#!/bin/sh # # 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. wget http://lampsvn.epfl.ch/trac/scala/export/26099/scala-tool-support/trunk/src/gedit/scala.lang # 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='http://www.freedesktop.org/standards/shared-mime-info'> <mime-type type="text/x-scala"> <comment>Scala Source</comment> <!-- more translated comment elements --> <glob pattern="*.scala"/> </mime-type> </mime-info> EOF # 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 wget https://raw.github.com/snim2/gedit-scala-plugin/master/flyscala.plugin wget https://raw.github.com/snim2/gedit-scala-plugin/master/flyscala.gedit-plugin wget https://raw.github.com/snim2/gedit-scala-plugin/master/flyscala.py # Installing gsettings scheme for the flyscala plugin wget https://raw.github.com/snim2/gedit-scala-plugin/master/org.gnome.gedit.plugins.flyscala.gschema.xml 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"