Showing posts with label sbt. Show all posts
Showing posts with label sbt. Show all posts

Monday, May 3, 2010

Run sbt inside emacs

Today I found a nice emacs addon that allows you to run sbt inside emacs. It even has clickable compiler errors (although I don't need those because ensime does this nicer).
Actually it's mentioned in the scala wiki, but I managed to over read it until now :)

Add (setq comint-scroll-to-bottom-on-output t) to autoscroll to the bottom when new output is written (M-x eval-expression).

Sunday, May 2, 2010

Emacs and sbt

After selecting sbt as my new build-environment I still needed an editor to code in. First I went with TextMate with a Scala Bundle (don't remember which one, I installed that some time ago). While it offers just code highlighting and some code templates it works just fine. I didn't miss code completion all that much (probably because it didn't work very well in Eclipse either). But what I really missed was  compilation-error highlighting. I spent some time coding with the sbt-iTerm window beside the TextMate-editor and using Command+L (enter line number) to jump to the errors that showed up in iTerm. Works, but nothing to write home about..

I remembered a nice video about Aemon Cannon showing his ensime-Emacs mode (video on youtube). He shows syntax highlighting (actually that's provided by the scala-mode), code completion, compilation errors, type inspection and package overviews. Quite impressing, isn't it? And what I liked best about it, is that it directly uses scala itself (running in a "server-process") to provide those features. So they're accurate and not "guessed" by a second parser implementation. Also all the stuff happens in the background, so it doesn't slow down your typing. Great stuff!

So here's how I installed it

  • Install/Update to Emacs 23 for Mac OS X according to this blog. Ensime needs the Emacs 23.
  • Spent some time with various Emacs tutorials to refresh my Emacs-skills :)
  • Install the scala-mode for emacs as described on scala-lang.org
  • Download Ensime and unpack it to some path (i.e. to ~/scala/emacs/ensime)
  • Make sure you got a 'java' and a 'scala' on the path (i.e. ln -s /Applications/scala/bin/scala /usr/local/bin/scala)
  • add some lines to .emacs as described in the Ensime readme
  • create a .ensime file in your project root. Mine looks as follows (current version):
(
  :server-root "/Users/ms/scala/emacs/ensime/"
  :server-cmd  "bin/server.sh"
  :server-host "localhost"
  :server-env ()

  :project-package "ch.inventsoft.scalabase"
  :source ("src/main/scala")
  :exclude-source ()
  :classpath ("lib/jsr166y.jar"
        "lib_managed/scala_2.8.0-SNAPSHOT/compile/logback-classic-0.9.20.jar"
        "lib_managed/scala_2.8.0-SNAPSHOT/compile/logback-core-0.9.20.jar"
        "lib_managed/scala_2.8.0-SNAPSHOT/compile/slf4j-api-1.5.11.jar"
        "lib_managed/scala_2.8.0-SNAPSHOT/plugin/continuations-2.8.0-SNAPSHOT.jar"
        "project/boot/scala-2.8.0-SNAPSHOT/lib/scala-compiler.jar"
        "project/boot/scala-2.8.0-SNAPSHOT/lib/scala-library.jar"
        "lib_managed/scala_2.8.0-SNAPSHOT/test/scalatest-1.0.1-for-scala-2.8.0.RC1-SNAPSHOT.jar")        
)
  • fire up emacs, open a scala file of your project. If it doesn't have syntax highlighting enter 'M-x scala-mode'
  • Enter 'M-x ensime' and answer the questions.
  • See the Ensime readme for all the available shortcuts (Tab, C-c t, C-c p)
  • Feel happy :)

I still got some problems with the inspector (didn't figure out how to have it open in a separate window, probably due to my incomplete emacs know-how), but overall it works just great. With sbt ~test-quick executing all tests as I change the code it provides very fast feedback.

And it'll get even better. I just read on the scala-Maillist, that Cannon's proposal for Google's summer of code has been accepted. Looking forward to that! Great job, Aemon

Saturday, May 1, 2010

Searching a new IDE for Scala

Ever since I started trying and using Scala I used the nightly build of the Eclipse-Plugin. I was never really happy with it, it works fine for smaller projects but slows down to a crawl if used with larger projects. Also it has some annoying glitches with unit-tests (no support for scalatest and junit works sometimes and sometimes not), auto-completion, presentation compiler showing false errors and compilation.
Recently I started to lock up completely on certain code-fragments, forcing me to kill the process and restart Eclipse. Unfortunately it was "reproducible", so I actually had to (cosmetically) change some code I was trying to write in order to avoid to lockup. (Miles Sabin et al are doing a great work, it just needs some time, I really admire what they're doing)


That's why I started looking to alternative ways to code Scala. First I tried IntelliJ withthe  Scala-Plugin: Tried it, but didn't fall in love with it... I probably should've given it more time, but I was afraid, that it was going to have to same behavior as Eclipse (fine for small, bad for larger projects).


During surfing on the net I also found several posters, that really liked the sbt along with some text editor (some guys even pair it with an IDE), so I gave it a try. It does a great job at setting up your project and managing its dependencies (similar to maven, but easier).

Here's the scala/build/ScalaBase.scala (my project is named ScalaBase and uses the new cps-plugin of Scala 2.8):
import sbt._
 
class ScalaBaseProject(info: ProjectInfo) extends DefaultProject(info) with AutoCompilerPlugins {      
  val continuations = compilerPlugin("org.scala-lang.plugins" % "continuations" % "2.8.0-SNAPSHOT")
  override def compileOptions = CompileOption("-P:continuations:enable") :: super.compileOptions.toList
 
 
  val slf4j = "org.slf4j" % "slf4j-api" % "1.5.11"
  val logbackcore = "ch.qos.logback" % "logback-core" % "0.9.20"
  val logbackclassic = "ch.qos.logback" % "logback-classic" % "0.9.20"
 
  val scalatest = "org.scalatest" % "scalatest" % "1.0.1-for-scala-2.8.0.RC1-SNAPSHOT" % "test"
  val toolsSnapshot = ScalaToolsSnapshots
}

But what's really great: Start it up with
[~/scala/myproject] sbt
then type
~test-quick
and then edit your source files. As soon as you save a file it compiles all the affected classes and tests and then executes only the tests that were recompiled! This is great and gives you immediate feedback without stopping you from coding on. And it's really quick too (seems to take half the time of Eclipse-plugin to compile my code).

For more infos see the sbt documentation.