Override built-in src blocks with emacs-jupyter

I’m trying to use emacs-jupyter’s built-in src-block override feature in my config.el. The instructions in the README say I should first call org-babel-do-load-languages, then call e.g. (org-babel-jupyter-override-src-block "python"). However, this doesn’t work, since Doom uses a custom lazy loading mechanism for Babel.

Is there any other way I can get this override feature to work with Doom? Trying to hook into the lazy loading mechanism is a chicken and egg problem: I want to avoid having to use #+begin_src jupyter-python, but doing so is the only way to trigger the lazy loading, IIUIC.

System information


Loading data dump...

Turns out it’s pretty simple :) There’s an +org-babel-load-functions variable, which in my case contains +org-babel-load-jupyter-h, so that prompted me to try whether I can just run that eagerly, instead of org-babel-do-load-languages. It works, so it’s just a matter of:

(after! org
  (+org-babel-load-jupyter-h 'jupyter-python)
  (org-babel-jupyter-override-src-block "python"))

EDIT: I ended up also figuring out a way to keep the lazy loading:

(defadvice! override-src-block-when-loading-jupyter (oldfun lang)
  "If lang is in langs-to-override, map it to jupyter-lang instead."
  :around '+org-babel-load-jupyter-h
  (let* ((langs-to-override '(python))
         (jupyter-lang (if (member lang langs-to-override)
                         (intern (concat "jupyter-" (symbol-name lang)))
                         lang))
         (ans (funcall oldfun jupyter-lang)))
    (when (member lang langs-to-override)
      (org-babel-jupyter-override-src-block (symbol-name lang)))
    ans))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.