lang/org: fix ob-async support

ob-async uses org-babel-load-languages to load babel packages in a child
process, but packages entered into the org-babel-load-languages variable
by Doom's lazy loader were misnamed. This caused load errors in the
child process.

The language-to-package resolution is now performed before it is entered
into org-babel-load-languages. Additionally, ob-async will now be lazy
loaded if it is available (and fail silently otherwise).
This commit is contained in:
Henrik Lissner 2018-12-10 13:45:31 -05:00
parent 9144bcb19c
commit 2d13dbe10a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -31,14 +31,12 @@ the first function to return non-nil.")
"Load babel libraries as needed when babel blocks are executed." "Load babel libraries as needed when babel blocks are executed."
(when (funcall orig-fn info) (when (funcall orig-fn info)
(let* ((lang (nth 0 info)) (let* ((lang (nth 0 info))
(lang (if (symbolp lang) lang (intern lang)))) (lang (if (symbolp lang) lang (intern lang)))
(lang (or (cdr (assq lang +org-babel-mode-alist))
lang)))
(when (and (not (cdr (assq lang org-babel-load-languages))) (when (and (not (cdr (assq lang org-babel-load-languages)))
(or (run-hook-with-args-until-success '+org-babel-load-functions lang) (or (run-hook-with-args-until-success '+org-babel-load-functions lang)
(require (require (intern (format "ob-%s" lang)) nil t)))
(intern (format "ob-%s"
(or (cdr (assq lang +org-babel-mode-alist))
lang)))
nil t)))
(add-to-list 'org-babel-load-languages (cons lang t))) (add-to-list 'org-babel-load-languages (cons lang t)))
t))) t)))
(advice-add #'org-babel-confirm-evaluate :around #'+org*babel-lazy-load-library) (advice-add #'org-babel-confirm-evaluate :around #'+org*babel-lazy-load-library)
@ -52,7 +50,14 @@ the first function to return non-nil.")
(cl-loop with fn = (if others #'not #'identity) (cl-loop with fn = (if others #'not #'identity)
for p in params for p in params
if (funcall fn (eq (car p) key)) if (funcall fn (eq (car p) key))
collect p))) collect p))
;; org-async has its own agenda for lazy loading packages (in the child
;; process), so we only need to make sure it's loaded.
(defun +org|load-async (&rest _)
"Load `ob-async', if it is available."
(require 'ob-async nil t))
(add-hook '+org-babel-load-functions #'+org|load-async))
;; ;;