Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling prints ANSI color sequences in plaintext #366

Closed
timlod opened this issue Dec 3, 2021 · 5 comments
Closed

Error handling prints ANSI color sequences in plaintext #366

timlod opened this issue Dec 3, 2021 · 5 comments

Comments

@timlod
Copy link

timlod commented Dec 3, 2021

Since bb53fdd, errors in org are not printed correctly:

#+begin_src python
1/0
#+end_src

#+RESULTS:
:RESULTS:
# [goto error]
: �[0;31m---------------------------------------------------------------------------�[0m
: �[0;31mZeroDivisionError�[0m                         Traceback (most recent call last)
: �[0;32m/tmp/ipykernel_25664/2354412189.py�[0m in �[0;36m<module>�[0;34m�[0m
: �[0;32m----> 1�[0;31m �[0;36m1�[0m�[0;34m/�[0m�[0;36m0�[0m�[0;34m�[0m�[0;34m�[0m�[0m
: �[0m
: �[0;31mZeroDivisionError�[0m: division by zero
:END:

Reverting the aforementioned commit fixes this:

#+begin_src python
1/0
#+end_src

#+RESULTS:
:RESULTS:
# [goto error]
: ---------------------------------------------------------------------------
: ZeroDivisionError                         Traceback (most recent call last)
: /tmp/ipykernel_25664/2354412189.py in <module>
: ----> 1 1/0
: 
: ZeroDivisionError: division by zero
:END:

I think the commit was added under the assumption that org-mode will fontify, but it appears that it doesn't (at least for me on 27.1 with org 9.5.1, minimal config).

@nnicandro
Copy link
Collaborator

When I first open an Org buffer and type the error code I do get the ANSI codes printed as plaintext in the buffer, but upon reverting the buffer they display the colors. If you revert the buffer do the sequences disappear and do you get the highlighting?

Another thing, do you get highlighting when you run the following code? You should see the CD characters with a yellow background.

#+begin_src jupyter-python :session test
print('AB\x1b[43mCD\x1b[0mEF')
#+end_src

I'm on Emacs 27.1 with Org 9.4.4.

The commit message of bb53fdd should have been more specific and said that the fontification is handled by font-lock in the Org buffer since we add to the value of org-font-lock-keywords a function that handles the ANSI escapes for fixed-width and example blocks when jupyter-org-interaction-mode is enabled.

https://github.com/nnicandro/emacs-jupyter/blob/c702f1e90f9acded57297fbba88322f16f127b27/jupyter-org-client.el#L640-L644

@timlod
Copy link
Author

timlod commented Dec 3, 2021

OK, since you said it worked I went a little deeper to isolate the issue - turns out my minimal config wasn't minimal enough (I had still loaded a couple things inside my org config, which was all I activated within emacs -q)!
https://github.com/integral-dw/org-superstar-mode is the culprit - without it, colours render correctly, with it, there are no colours in any results. I had assumed that this was normal (have not gone without org-superstar for a while) - turns out, there should be fontification inside the results :)

I will file a bug report there and disable the package until this is fixed.

@gerritvreeman
Copy link

Adding this hook to my config appears to fix the output upon src block execution without disabling org-superstar.

(defun display-ansi-colors ()
  (ansi-color-apply-on-region (point-min) (point-max)))

(add-hook 'org-babel-after-execute-hook #'display-ansi-colors)

@akirakyle
Copy link
Contributor

@nnicandro I am also observing this issue and tried debugging it on my setup. I think the culprit to this issue may lie in the combination of the above mentioned emacs-jupyter commit bb53fdd in combination with emacs commit 21dcb9830a which renamed ansi-color--find-face to ansi-color--face-vec-face. Thus if you're running a build of emacs and emacs-jupyter after both those commits, you'll fail to see the error which is thrown in jupyter-org-font-lock-ansi-escapes as it seems org-font-lock-keywords suppresses the error as part font-lock in the org buffer. However manually calling (jupyter-org--ansi-color-apply-on-region (point-min) (point-max)) in an org buffer with your provided jupyter-python test block will yield the backtrace

Debugger entered--Lisp error: (void-function ansi-color--find-face)
  ansi-color--find-face(nil)
  jupyter-ansi-color-apply-on-region(4925 4928)
  jupyter-org--ansi-color-apply-on-region(1 4928)
  #<subr eval-expression>((jupyter-org--ansi-color-apply-on-region (point-min) (point-max)) nil nil 127)
  apply(#<subr eval-expression> ((jupyter-org--ansi-color-apply-on-region (point-min) (point-max)) nil nil 127))
  eval-expression((jupyter-org--ansi-color-apply-on-region (point-min) (point-max)) nil nil 127)
  funcall-interactively(eval-expression (jupyter-org--ansi-color-apply-on-region (point-min) (point-max)) nil nil 127)
  command-execute(eval-expression)

I hope this helps towards figuring out a fix to this issue in emacs-jupyter.

@stardiviner
Copy link

This function ansi-color--find-face is removed in new Emacs release.
Hope maintainer can also support new Emacs version related API like ansi-color-apply-on-region etc. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants