15

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.

3
  • How are you starting the REPL within Emacs?
    – leedm777
    Jan 20, 2012 at 16:22
  • I open a new buffer with ansi-term. Then, in that terminal buffer, I start the REPL by calling "scala" directly or using sbt console. Either way, this problem seems to occur.
    – nomad
    Jan 20, 2012 at 16:23
  • 2
    You may have better luck opening a new buffer with shell, and starting scala or sbt from the shell.
    – leedm777
    Jan 20, 2012 at 18:52

3 Answers 3

10

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.

2
  • Thanks for the tip. This seems to work pretty well for me. In fact, I like the rlwrap approach over the Ensime approach because it gives me a command history. Right now, the only remaining limitation to invoking the REPL via Emacs using the rlwrap approach is an inability to use tab-completion.
    – nomad
    Jan 20, 2012 at 18:49
  • How did you get tab-completion in the REPL through emacs? Jul 22, 2014 at 17:23
9

You may install ENSIME and follow instructions. I don't know about your way to invoke REPL, but REPL called from ENSIME works (it allows moving the cursor backward and deleting symbols, I've checked).

2
  • 2
    Thanks for the tip. It looks like invoking the REPL from Ensime does solve this problem, but it introduces a few others. In particular, the REPL invoked via Ensime doesn't have a command history, and doesn't seem capable of tab-completion.
    – nomad
    Jan 20, 2012 at 18:47
  • @nomad: they made tab-completion work. See ensime.github.io/editors/emacs/userguide/#code-completion.
    – serv-inc
    Feb 27, 2019 at 8:04
1

You could try using the ammonite repl, amm. I can confirm tab completion works in the emacs ansi-term. This is true for its default mode (based on stty) or you can use JLine3 with amm. Note that the Dotty (tentative Scala 3) repl, dotr, is also based on amm and also has working tab-completion in ansi-term.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.