How to modify previous line in REPL - scala to modify the typing errors to save time compare to entering each line using up/down arrows

StackOverflow https://stackoverflow.com/questions/10912565

Question

There are chances that some typing (in Ubuntu terminal - scala -version Scala code runner version 2.9.1) errors occur, example shown below where instead of (l: Int) (l: int) has been typed in parameters.

 scala> class Rectangle (l:int, w: Int){
 | val length = l
 | val length = w
    .
    .
    .
    few more lines but still ... module Rectangle is not defined. Or sometimes enter command given and error shows up.

Is there anyway where directly that typing error can be edited / modified and rerun the code? It will save great deal of time otherwise I am entering line by line using up/down arrow.

Please guide.

Was it helpful?

Solution

Right now, you can't. There are Scala GUI REPL's (see them here, plus kojo and the big IDEs), though, which allow this kind of thing. Pick one of them.

OTHER TIPS

I don't know if there is a better solution, but in my case I tend to use my usual text editor to write code snippet and paste them using the paste mode of the REPL (you can enter the paste mode thanks to the :paste command).

Since Scala 2.13.2 multi-line editing is supported in the REPL based on JLine 3

JLine 3 supports multi-line editing, a better tab-completion UI, and more.

Configure keybindings with -Xjline:emacs (the default) or -Xjline:vi; disable with -Xjline:off

History file is now ~/.scala_history_jline3

For example, to try multiline editing using vim keybindings start the REPL like so

scala -Xjline:vi

then enter a multiline definition and press up arrow key. Note how it gives

scala> class Foo {
     |   val x = 42
     | }
class Foo

scala> class Foo {
     |   val x = 42
     | }

instead of the old behaviour

scala> class Foo {
     |   val x = 42
     | }
defined class Foo

scala> }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top