Skip to content

Commit

Permalink
ob-jupyter.el: Generate language aliases in org-mode-hook
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nnicandro committed Jun 27, 2023
1 parent f412f08 commit 2f14f2e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions ob-jupyter.el
Original file line number Diff line number Diff line change
Expand Up @@ -778,16 +778,14 @@ mapped to their appropriate minted language in

;;; Hook into `org'

;; Defer generation of the aliases until the first call to
;; `org-babel-execute-src-block' to avoid generating them at top-level
;; when loading ob-jupyter. Some users, e.g. those who use conda
;; environments, may not have a jupyter command available at load
;; time.
(defun org-babel-jupyter--aliases-advice (&rest _)
;; Defer generation of the aliases until Org is enabled in a buffer to
;; avoid generating them at top-level when loading ob-jupyter. Some
;; users, e.g. those who use conda environments, may not have a
;; jupyter command available at load time.
(defun org-babel-jupyter-make-local-aliases ()
(let ((default-directory user-emacs-directory))
(org-babel-jupyter-aliases-from-kernelspecs))
(advice-remove #'org-babel-execute-src-block #'org-babel-jupyter--aliases-advice))
(advice-add #'org-babel-execute-src-block :before #'org-babel-jupyter--aliases-advice)
(org-babel-jupyter-aliases-from-kernelspecs)))
(add-hook 'org-mode-hook #'org-babel-jupyter-make-local-aliases)

(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)
Expand Down

0 comments on commit 2f14f2e

Please sign in to comment.