hylang / hy-mode

Hy mode for Emacs
GNU General Public License v3.0
189 stars 48 forks source link

colored output in inferior-lisp #46

Closed gilch closed 6 years ago

gilch commented 6 years ago

Hy uses clint/colorama to color some of its error messages. But the inferior-lisp buffer output appears to be getting the same syntax highlighting as a Hy file, at least in my Spacemacs configuration.

This is appropriate for the Hy language input, but undesirable for output, since reprs are written in Python, not Hy, and the print function can display things that aren't even reprs. Is there a way to print output colors in inferior-lisp output the same way a terminal does? I think colorama uses different color codes on Windows and Linux (and Mac?).

gilch commented 6 years ago

When running hy --spy as the inferior lisp command, it would be nice to highlight the Python translation as Python instead of as Hy.

The normal repr output could likewise be highlighted as Python. But stdout and stderr shouldn't otherwise get this highlighting. I don't know if Emacs has any way to distinguish these. But perhaps hy's repl could be modified to make this easier, like writing to a different pipe for automatic reprs of Python objects than for stdout used by the print functions.

I'd like stdout and stderr to support colorama highlighting like the terminal. But I'd also like to be able to distinguish stdout from stderr somehow. I'm not sure if we can do both at once though. IDLE does this by making stdout blue and stderr red. Maybe we could use something other than color, like italics for stderr or something.

ekaschalk commented 6 years ago

I'm rewriting the shell.

But the inferior-lisp buffer output appears to be getting the same syntax highlighting as a Hy file

This is now fixed. I also have current line being highlighted according to hy-mode implemented.

Is there a way to print output colors in inferior-lisp output the same way a terminal does?

It should've been simple but emacs is not receiving text laden with ansi color codes from a hy process. For example

=> (})
;; Yields the raw string from the hy process
"  File \"<stdin>\", line 1, column 2\n\n  (})\n   ^\nLexException: Ran into a RCURLY where it wasn't expected.\n\n\n=> "

I can't figure out why ansi color codes are not included, the colors display fine in other shells. If the codes are retrieved in the raw string then we would have colored output.

highlight the Python translation as Python instead of as Hy.

This actually might be possible. I would have to capture the --spy output, put in a temporary buffer, font-lock it, and retrieve it back. Because this text is static, it makes the problem tractable.

distinguish stdout from stderr

Up until recently there was no support within Emacs for this. You can see this in eshell, being discouraged for streaming usecases in the manual.

Now it appears stderr can be piped to a buffer with the low level process functions. However comint-mode which streamlines processes in context of a repl does not implement any stderr based options. So it might be possible.

gilch commented 6 years ago

I can't figure out why ansi color codes are not included

I think that colorama is supposed to filter out the codes on Windows and use system calls instead. Are you on Windows? If you call colorama.deinit() do you get the ANSI color codes back in stdout?

ekaschalk commented 6 years ago

On my laptop I develop in Windows and on my desktop Linux.

I was working on the shell on Windows and haven't tried it on my main work pc yet.

I'll see if that helps.

ekaschalk commented 6 years ago

Did the trick! Now we have colored error messages. Do you know if this is possible on Windows?

ekaschalk commented 6 years ago

I noticed that ipython has the same issue - no error highlighting in Windows but has error highlighting in Linux.

ekaschalk commented 6 years ago

The new shell is added, startup with C-c C-e or rebind spacemacs's binding to run-hy rather than inferior-lisp.

ekaschalk commented 6 years ago

Closed pending hy PR merged.