ob-jupyter.el: Generate language aliases in org-mode-hook

As opposed to generating them on the first call to
`org-babel-execute-src-block` which is too late, e.g. for
fontification of source blocks and editing source blocks via
`org-edit-src-code`.

closes #470
closes #473
closes #475
This commit is contained in:
Nathaniel Nicandro 2023-06-27 15:19:46 -05:00
parent f412f08f0a
commit 2f14f2e253

View file

@ -778,16 +778,14 @@ mapped to their appropriate minted language in
;;; Hook into `org' ;;; Hook into `org'
;; Defer generation of the aliases until the first call to ;; Defer generation of the aliases until Org is enabled in a buffer to
;; `org-babel-execute-src-block' to avoid generating them at top-level ;; avoid generating them at top-level when loading ob-jupyter. Some
;; when loading ob-jupyter. Some users, e.g. those who use conda ;; users, e.g. those who use conda environments, may not have a
;; environments, may not have a jupyter command available at load ;; jupyter command available at load time.
;; time. (defun org-babel-jupyter-make-local-aliases ()
(defun org-babel-jupyter--aliases-advice (&rest _)
(let ((default-directory user-emacs-directory)) (let ((default-directory user-emacs-directory))
(org-babel-jupyter-aliases-from-kernelspecs)) (org-babel-jupyter-aliases-from-kernelspecs)))
(advice-remove #'org-babel-execute-src-block #'org-babel-jupyter--aliases-advice)) (add-hook 'org-mode-hook #'org-babel-jupyter-make-local-aliases)
(advice-add #'org-babel-execute-src-block :before #'org-babel-jupyter--aliases-advice)
(add-hook 'org-export-before-processing-hook #'org-babel-jupyter-setup-export) (add-hook 'org-export-before-processing-hook #'org-babel-jupyter-setup-export)
(add-hook 'org-export-before-parsing-hook #'org-babel-jupyter-strip-ansi-escapes) (add-hook 'org-export-before-parsing-hook #'org-babel-jupyter-strip-ansi-escapes)