Scala REPL in Emacs

emacsread-eval-print-loopscala

I like to do my Scala development in Emacs, and from time to time, I use the REPL to test out snippets of code or to load and test some code I've just written. I'm using Scala 2.9.1, and I've noticed that when I open the REPL in a terminal buffer, things are substantially broken. In particular, I am unable to remove any characters from the current line, and cannot move the cursor backward on the current line. This is highly frustrating as any time I mistype something, I have to begin the command anew. I was wondering if anyone else is having this problem using the Scala REPL under Emacs, and if anyone has a potential solution.

Best Answer

I find that rlwrap (readline wrapper) plays well with emacs' ansi-term and scala. Just call "rlwrap scala", and you'll have the usual bash line editing, as well as history, working properly. As a bonus, your history will span multiple invocations of scala, so you won't lose everything you've typed after exiting the Scala REPL.

If rlwrap doesn't work for you, just switching to line-mode in ansi-term (C-x C-j by default) will allow you to use emacs-style editing on the line, but without the shell niceties like history and completion.

Ensime has already been mentioned, so I'll just second that as a great option if you don't mind the setup involved.

Related Topic