SetUp jEdit
From Lift
!!!! DRAFT !!!!!
How to setup jEdit to develop Scala stuff, including:
- syntax highlighting
- compilation of .scala on save (standalone .scala and into a Maven project) with errors in the editor
- running scalaTest (with the right classpath) from jEdit
- compiling/packaging Maven projects from jEdit and grabbing errors in the editor
- setting keyboard shortcuts for each action* a configured environment after 1 or 2 hours
I (David Bernard) use this page as a mini site for the ScalaMiniIDE plugin for jEdit until I create an official one. Contributions and feedback to the project page are welcome.
jEdit :
- is an editor (lighter than Eclipse or Netbeans)
- is written in java
- supports macros (written in BeanShell)
- supports plugins (written in Java, Scala, ...)
Contents |
Installation
Step 0
- install jdk 1.5 or higher
- install jEdit 4.3pre12 or higher (download)
- install a scala distibution to compile and run .scala file (eg: scala-2.6.1, scala-2.7.0,...)
Required Plugins
All required (minimal) plugins are packaged into a single zip.
- Download ScalaMiniIDEPlugin-0.3.1-full.zip
- Unzip the file into $HOME/.jedit/jars
- Run jEdit
The zip file contains :
- Console 4.3.7 : The Console plugin allows jEdit to execute arbitrary commands from an internal shell. In addition, it provides buttons in a "commando toolbar" for your favorite command-line tools (Make, Ant, QMake, Latex, etc.), and an easy way to add others.
- a patched version of ErrorList to display multi-line errors (the patch is part of the future version : ErrorList > 1.7) : The ErrorList plugin provides one-click access and on-the-spot highlighting of errors generated by EditBus-aware packages, such as the Console.
- Additional plugins not yet available on the jEdit - Plugin Central
- ScalaPlugin : Scala-library packaged as a jEdit plugin (it is used only to run the plugin, not your project).
- MvnPlugin : to manage Maven projects from jEdit
- ScalaMiniIDEPlugin : to compile and test Scala files from jEdit
The plugins are not available from Plugin Central, but can be download one by one (if you prefer) from sourceforge. Patched versions of Console and ErrorList aren't available alone. The source code is include in the zip without "-bin" and also available from the scm (http://alchim.sourceforge.net/hg/)
Optional Plugins
I suggest that you browse/use the Plugin manager (in jEdit: Plugins > Plugin Manager... > Install) or the jEdit - Plugin Central web site to find the plugin that matches your need:
- EditorScheme : The EditorScheme plugin allows you to switch easily between editor color/style schemes for jEdit.
- LookAndFeel : The LookAndFeel plugin provides several additional look-and-feel implementations which allow skinning of the GUI by means of "themepacks" to change the default look and feel (I use NimROD).
- OpenIt : The OpenIt plug-in provides a quick and easy way to open files in jEdit. Users simply open a dialog box, start typing the name of the file they wish to open, and as they type the list of files will be updated to match what they are typing.
- Optional : A replacement for the three Options actions/dialogs.
- Project Viewer : The Project Viewer provides a filtered view of the project. It has some bugs (action not done on FS, automatic refresh doesn't work, etc.), but it is sometimes useful and is required by other plugins to work.
- SVNPlugin : Subversion support for jEdit
- XML : The XML plugin (version 2) provides features for editing XML, HTML, JavaScript and CSS files. For XML files, it does validation against a DTD or XSD. For all languages, it displays element trees in the sidekick dockable. For XML, HTML and CSS, you get completion pop-ups for elements, attributes, and entities to help when you write XML files (indentation, completion, etc.), which is useful for Maven's pom.xml and HTML files.
Configuration
Shortcuts
Plugins in jEdit shouldn't define keyboard shortcuts, so if you want shortcuts, then click on "Global Options" button and select "Shortcuts" in the tree (under jEdit). Then associate the keyboard shortcuts as you prefer. E.g.:
- "mvn compile" -> F10
- "mvn test" -> S+F10
- "comments toggle" -> CS+Colon (on my laptop to do ctrl+/, I click on ctrl+shift+: )
- "Go to Next Error" -> C+DOWN
- "Go to Previous Error" -> C+UP
Docking
By default every window in jedit floats, but you can dock them if you prefer. For example, go to Utilities > Gobal Options... > jEdit > Docking , and set :
- Console : bottom
- ErrorList : bottom
- File Browser : left
- Project Viewer : left (if you have one)
Console/ErrorList
You should define the Regular expression use by the console to detect scalac errors:
- Go to
Plugins > Plugin Options... > Console > Errors Pattern - Add a new Error pattern (click on + )
- Name: scalac
- Error Regexp: \s*((/|\w:).+?):(\d+),?\d*:(.+)
- Warning Regexp: \s*((/|\w:).+?):(\d+):\s*(?:Warning|warning|Caution|caution):\s(.+)
- Extra lines Regexp: \s*((?:symbol|location|found|required|missing).*)
- Filename: $1
- Line number: $3
- Error message: $4
- Move the scalac pattern to top of the list
- Click Test/Commit (you'll see a popup with No Matches since there isn't any text in the Test Area)
- Click OK
ScalaMiniIDE
You should define the path of Scala home to use for "quick" compile-and-run.
- Go to
Plugins > Plugin Options... > ScalaMiniIDE - Select the right directory for Scala Home
- Click OK
Use it
My first "class"
- Under jEdit create a new File (Ctrl+N)
- Write a helloworld program (with the "syntax error")
object Hello extends Application { pntln("hello") } - Save it (Ctrl+S) with the name of the mainClass : Hello.scala (ex: /tmp/Hello.scala)
- Notice after save:
- Syntax color is activated
- The typo is shown. If you look into the errorList panel (at bottom) you can see the error message or you can move the mouse over the icon to display the message
- Fix the error
object Hello extends Application { println("hello") } - Save it (Ctrl+S)
- The error is gone
- Run it (Plugins > ScalaMiniIDE > run)
- If you look at the console (System), you should see "hello" (and the command line used to run it)
If you have dependencies, then you should use a Maven project. ScalaMiniIDE uses information from the pom.xml (dependencies, source directory, classes directory, etc.)
My first project
A quick version of this future section is :
- Follow instructions at Maven for scala
- Use jedit for editing scala files, pom.xml,...
- After creating the project (with an archetype as in the article or by hand, e.g. mkdir, etc.), use the actions from
Plugins > Maven2 Plugin > "(F10 or Shift+F10 if you bound the same shortcut as in the doc).
Notes :
- I expect to provide a GUI for creating the project from an archetype directly from jEdit.
- The Maven2 Plugin for eclipse doesn't display on the console the result of jUnit tests :( I expect to fix it in the next version.
My first test with ScalaTest
If you want to play with scalatest, you need to be in a Maven project (see above)
- Add ScalaTest to the project dependencies in pom.xml
<dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest</artifactId> <version>0.9.1</version> </dependency> - create your test class (Ctrl+N)
import org.scalatest.Suite class MySuite extends Suite { def testAddition() { val sum = 1 + 1 assert(sum === 2) assert(sum + 2 === 4) } def testSubtraction() { val diff = 4 - 1 assert(diff === 3) assert(diff - 2 === 1) } } - Save it (src/test/scala/MySuite.scala)
- Run it
Plugins > ScalaMiniIDE > run with ScalaTest
Notes:
- Maven doesn't support ScalaTest as part of the standard build lifecycle (may be a future version of scalaTest or maven-scala-plugin will allow it).
Tips
- To reindent a Scala file : select all (Ctrl+A), and
Edit > Indent > Indent lines(or Ctrl+I)
DONE
- Add support for macros written in Scala - User:Dwayneb
TODO
Below is the todo list. You are free to add your request, or to select a task and provide a solution or patch.
- Create an official documentation - User:Dwayneb
- Embedded Scala console - User:Dwayneb* Fix the runpath problem with ScalaTest - User:Dwayneb
- Support interactive shell for Maven - User:Dwayneb
- Create a RunnerJPanel for ScalaTest (to replace the Window, allow reuse, and allow docking into jEdit) - User:Dwayneb
- Use the same Scala-compiler in quick compile as in pom.xml - User:Dwayneb
- Use maven-scala-plugin to run fsc - User:Dwayneb
- Add a GUI to create the project from an archetype - User:Dwayneb
- Automatic registration in the Console of ErrorList pattern matchers for Scala errors - User:Dwayneb
- Registration of Scala mode without erasing the user's catalog - User:Dwayneb
- Add support to retrieve the classpath from ProjectViewer - User:Dwayneb
- Provide templates to create empty classes, Specifications (for Specs), and Suites for ScalaTest - User:Dwayneb
-
Share the errorSource between MvnPlugin and ScalaMiniIDEPlugin - Host the plugins on "jedit central plugin" - User:Dwayneb


