alhassy / repl-driven-development

Press "C-x C-e" to send any piece of code (in any language) to a REPL in the background, within Emacs!
GNU General Public License v3.0
63 stars 2 forks source link

problems with output being overwritten while using scala #7

Closed fedreg-bn closed 11 months ago

fedreg-bn commented 1 year ago

Hi, awesome package!!! Thank you for sharing it!

I was excited to try this out in scala, but ran into a couple issues. Maybe someone can point me in the right direction

The package seems to work and evaluate the code correctly, but immediately after evaluating the output, it is being overwritten by the command name, scala.

For example, say I have a .scala file with the following code in it:

def add2(a: Int, b: Int): Int = {
  a + b
}

add2(1,2)

I can evaluate the definition of add2 and see it printed in the *messages* buffer, but in the buffer the output is => scala

Similarly, if I evaluate the call, add2(1,2) I see the correct value printed in *messages* and the output also shows up in the buffer UI for a fraction of a second before being replaced by => scala

Example output of in *messages*:

Mark set
﴾scala-eval﴿⇒ def add2(a: Int, b: Int): Int
﴾scala-eval﴿⇒ scala 
scala
﴾scala-eval﴿⇒ val res7: Int = 3
﴾scala-eval﴿⇒ scala

oh, and when I first evaluate I get an error:

error in process filter: repl-driven-development--ignore-ansi-color-codes: Symbol’s function definition is void: ansi-color-apply-on-region

but it seems to go away after several evaluations... :shrug:

Hope that makes sense!! any ideas?

Seems like the scala interpreter itself always spits out a newline with scala> after every evaluation, which is likely the issue but not sure if there is a way to work around that with this package. (couldn't find a way in the repl itself)

image

Debian linux Emacs 29.1 config:

(use-package repl-driven-development
  :defer t
  :config
  (repl-driven-development [C-c r] "scala"))
fedreg-bn commented 1 year ago

UPDATE: I actually read through the code a bit (which I should have done before creating an issue :blush: ) and found echo-rewrite-fn.

Adding this config seems to make it usable although not perfect.

(use-package repl-driven-development
  :defer t
  :config
  (repl-driven-development [C-c r] "scala"
   :echo-rewrite-fn
   (lambda (echo)
     (car (split-string echo "\n")))))

But perfectly workable for the time being and I can dig into the code a bit more to figure out the ansi-color-codes error