carp-lang / Carp

A statically typed lisp, without a GC, for real-time applications.
Apache License 2.0
5.52k stars 178 forks source link

Emacs repl sub prompt problems #723

Open eriksvedang opened 4 years ago

eriksvedang commented 4 years ago

When using the Carp repl via emacs mode, the "sub prompt" (which currently is five spaces, defined in Repl.hs, line 130) is echoed leading to buggy/messy output, like this:

鲤 
               鲤 

The alignment issue comes from evaluating a form with line breaks, which activates the sub prompt (printing a bunch of spaces). The idea behind the sub prompt in a normal repl (in the terminal) is to let the user enter multi line expressions in a nice looking way.

In inf-carp-mode.el (in the emacs dir of the Carp repo) there are two variables with regexps that are supposed to match and remove these spaces:

inf-carp-prompt
inf-carp-subprompt

But for some reason they don't work. If any emacs expert has the time to look into this it would be great!

eriksvedang commented 4 years ago

One hint is that the colorizing of the output string might mess it up...

eriksvedang commented 4 years ago

One more hint is this function:

(defun inf-carp-remove-subprompts (string)
  "Remove subprompts from STRING."
  (replace-regexp-in-string inf-carp-subprompt "" string))

If it is defined like this instead (replacing inf-carp-subprompt with a string literal) it works:

(defun inf-carp-remove-subprompts (string)
  "Remove subprompts from STRING."
  (replace-regexp-in-string "     " "" string))
hellerve commented 4 years ago

@adityaathalye I think you also experienced this issue, is that correct?

adityaathalye commented 4 years ago

@hellerve yes, if I eval buffer (C-c C-l), then the REPL prints appears to print one prompt per expression.