emacs-jupyter / jupyter

An interface to communicate with Jupyter kernels.
GNU General Public License v3.0
929 stars 90 forks source link

`:display` is not working in `doom-emacs` #477

Closed aseltmann closed 2 weeks ago

aseltmann commented 1 year ago

I switched from legacy emacs to emacs-doom and in the process couldn't get my old jupyter setup running due to some zmq related errors (see https://github.com/emacs-jupyter/jupyter/issues/375#issuecomment-1611439318). I tested the next branch to circumvent that and it worked out nicely! I only noticed one bug which is a little annoying, but not super bad: the :display setting does not do anything, results are always as in :display plain

Example:

jupyter version (same for both) ```bash (conda) [user@computer ~]$ jupyter --version Selected Jupyter core packages... IPython : 7.29.0 ipykernel : 6.4.1 ipywidgets : not installed jupyter_client : 7.1.0 jupyter_core : 4.9.1 jupyter_server : 1.4.1 jupyterlab : 3.2.1 nbclient : 0.5.3 nbconvert : 6.1.0 nbformat : 5.1.3 notebook : 6.4.6 qtconsole : not installed traitlets : 5.1.1 ```
Old setup ```python #+begin_src jupyter-python :session test :display html import pandas as pd df = pd.DataFrame([[0, 1, 2, 3], [4, 5, 6, 7]]) display(df) #+end_src ``` ```html #+RESULTS: #+begin_export html
0 1 2 3
0 0 1 2 3
1 4 5 6 7
#+end_export ``` Usually, I convert the output to an org-table with pandoc: ```python #+begin_src jupyter-python :session test :display html :pandoc t import pandas as pd df = pd.DataFrame([[0, 1, 2, 3], [4, 5, 6, 7]]) display(df) #+end_src ``` ```md #+RESULTS: :RESULTS: | | 0 | 1 | 2 | 3 | |---+---+---+---+---| | 0 | 0 | 1 | 2 | 3 | | 1 | 4 | 5 | 6 | 7 | :END: ``` ``` #+begin_src emacs-lisp (emacs-version) #+end_src #+RESULTS: : GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo version 1.17.6) : of 2023-01-03 ```
New setup ```python #+begin_src jupyter-python :session test :display html import pandas as pd df = pd.DataFrame([[0, 1, 2, 3], [4, 5, 6, 7]]) display(df) #+end_src ``` ```md #+RESULTS: : 0 1 2 3 : 0 0 1 2 3 : 1 4 5 6 7 ``` Of course, pandoc has nothing to work with here, so the desired org-mode table output does not show up. ``` #+begin_src emacs-lisp (emacs-version) #+end_src #+RESULTS: : GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo version 1.17.6) : of 2023-01-03 ``` `doom/info` yields: ``` generated Jun 07, 2023 14:14:39 system "Manjaro Linux" Linux 5.15.114-1-MANJARO x86_64 x emacs 28.2 ~/Programme/doom-emacs/ doom 3.0.0-pre PROFILE=_@0 HEAD -> master 07fca7861 2023-05-30 19:39:04 -0400 ~/.doom.d/ shell /bin/bash features ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB traits gui server-running chemacs-2.0 modules :config use-package :completion company vertico :ui deft doom doom-dashboard (emoji +unicode) hl-todo minimap modeline ophints (popup +defaults) (treemacs +lsp) (vc-gutter +pretty) vi-tilde-fringe workspaces zen :editor (evil +everywhere) fold snippets :emacs dired electric (undo +tree) vc :checkers syntax :tools (eval +overlay) lookup lsp magit pdf rgb tree-sitter :lang data emacs-lisp (ess +tree-sitter) latex (markdown +grip) (org +dragndrop +jupyter +hugo +present) (python +conda +cython +tree-sitter +lsp +pyright) (sh +tree-sitter) (web +tree-sitter) (yaml +tree-sitter) :config literate (default +bindings +smartparens) packages (zetteldeft) (rainbow-identifiers) (zotxt) (ob-tmux) (jupyter :recipe (:branch next)) unpin jupyter ```

As per @nnicandro 's request I opened a new issue after first posting this here: https://github.com/emacs-jupyter/jupyter/issues/375#issuecomment-1580689834

As asked here the value of the variable jupyter-org-mime-types indeed looks normal:

(:text/org :image/svg+xml :image/jpeg :image/png :text/markdown :text/latex :text/plain)
nnicandro commented 1 year ago

The problem seems to be that your value of jupyter-org-mime-types somehow doesn't contain :text/html so the :display header argument does nothing. The :display header argument just filters the list of mime types in jupyter-org-mime-types to be the ones specified by :display. The filtering can't find an html mime-type in jupyter-org-mime-types since it doesn't exist and just falls back to looking for one of the other mime-types.

Re-adding :text/html to jupyter-org-mime-types should fix your issue. The question now is why was it removed from jupyter-org-mime-types as that variable is not supposed to be altered under normal usage.

aseltmann commented 1 year ago

Thanks for pointing that out, I didn't see that haha. I found the culprit, it was in doom-emacs/modules/lang/org/contrib/jupyter.el where my git-timemachine revealed:

Henrik Lissner 2020-08-06 06:32 lang/org: improve jupyter support

(use-package! ob-jupyter
  :defer t
  :init
  ...
  :config
  ...
  ;; Remove text/html since it's not human readable
  (delq! :text/html jupyter-org-mime-types)

And I found this thread where it was discussed: https://github.com/doomemacs/doomemacs/pull/2477 and https://github.com/doomemacs/doomemacs/pull/2477#issuecomment-636311284 even pointed out that this seems a bit too opinionated, but seems like they left it in anyway... I am thinking about opening a pull request where this line is removed.

To mitigate this issue:, I tried to add the following to my literal config:

#+BEGIN_SRC emacs-lisp
  (setq jupyter-org-mime-types '(:text/org :image/svg+xml :image/jpeg
                                 :image/png :text/html :text/markdown
                                 :text/latex :text/plain))
#+END_SRC

I am not that fluent in lisp and don't do own elisp scripting. If I execute it by hand, this does set the jupyter-org-mime-types variable correctly, but it does not work when I put it in my literal config and startup emacs after doom sync. Do you have an idea on how to do this correctly?

nnicandro commented 11 months ago

I'm not sure what could be the problem with your setup, couldn't you just re-add :text/html after the configuration that removes it loads, e.g. after the config. in that use-package expression loads?

aseltmann commented 2 weeks ago

I'm closing this, as hlissner fixed this issue in doom upstream after I suggested the change on the doom discord.