lang/org: disable ob-async on export or :session

Refactors advice to disable ob-async when exporting org documents or
when the :session parameter is present (ob-async does not support it).
Execution is degraded to synchronous execution and a warning logged.
This commit is contained in:
Henrik Lissner 2021-03-01 10:54:27 -05:00
parent 2ebc4be111
commit 49c3c84d7f
2 changed files with 28 additions and 13 deletions

View file

@ -134,6 +134,11 @@ https://www.mfoot.com/blog/2015/11/22/literate-emacs-configuration-with-org-mode
** Hacks ** Hacks
+ Adds support for a ~:sync~ parameter for org src blocks. This overrides
~:async~.
+ Gracefully degrades ~:async~ babel blocks to ~:sync~ when =ob-async= would
cause errors or issues (such as with a ~:session~ parameter, which =ob-async=
does not support, or when exporting org documents).
+ The window is recentered when following links. + The window is recentered when following links.
+ The breadcrumbs displayed in eldoc when hovering over an org headline has been + The breadcrumbs displayed in eldoc when hovering over an org headline has been
reworked to strip out link syntax and normalize font-size disparities. reworked to strip out link syntax and normalize font-size disparities.

View file

@ -214,20 +214,28 @@ Is relative to `org-directory', unless it is absolute. Is used in Doom's default
;; won't likely complete in time, and will instead output an ob-async hash ;; won't likely complete in time, and will instead output an ob-async hash
;; instead of the wanted evaluation results. ;; instead of the wanted evaluation results.
(after! ob (after! ob
(add-to-list 'org-babel-default-lob-header-args '(:async . nil))) (add-to-list 'org-babel-default-lob-header-args '(:sync)))
(defadvice! +org-inhibit-async-babel-blocks-on-export-a (orig-fn &optional fn arg info params) (defadvice! +org-babel-disable-async-if-needed-a (orig-fn &optional fn arg info params)
"Exporting org documents with async blocks will sometimes substitute "Disable ob-async when leaving it on would cause errors or issues.
evaluation output with hashes in the exported document. This is because the
block is executed asynchronously, but the exporter doesn't wait for it to Such as when exporting org documents or executing babel blocks with :session
finish. This advice forces babel blocks to not execute asychronously when being parameters (which ob-async does not support), in which case this advice forces
exported." these blocks to run synchronously.
Also adds support for a `:sync' parameter to override `:async'."
:around #'ob-async-org-babel-execute-src-block :around #'ob-async-org-babel-execute-src-block
(let ((async (or (assoc :async params) (if (null fn)
(assoc :async (nth 2 (or info (org-babel-get-src-block-info))))))) (funcall orig-fn fn arg info params)
(if (and async (null (cdr async))) (let* ((info (or info (org-babel-get-src-block-info)))
(funcall fn arg info params) (params (org-babel-merge-params (nth 2 info) params)))
(funcall orig-fn fn arg info params)))) (cond ((or (assq :sync params)
(not (assq :async params)))
(funcall fn arg info params))
((not (member (cdr (assq :session params)) '("none" nil)))
(message "Org babel :: :session is incompatible with :async. Executing synchronously!")
nil)
((funcall orig-fn fn arg info params))))))
(defadvice! +org-fix-newline-and-indent-in-src-blocks-a (&optional indent _arg _interactive) (defadvice! +org-fix-newline-and-indent-in-src-blocks-a (&optional indent _arg _interactive)
"Mimic `newline-and-indent' in src blocks w/ lang-appropriate indentation." "Mimic `newline-and-indent' in src blocks w/ lang-appropriate indentation."
@ -306,7 +314,9 @@ exported."
((stringp lang) (intern lang)))) ((stringp lang) (intern lang))))
(lang (or (cdr (assq lang +org-babel-mode-alist)) (lang (or (cdr (assq lang +org-babel-mode-alist))
lang))) lang)))
(+org--babel-lazy-load lang (assq :async (nth 2 info))) (+org--babel-lazy-load
lang (and (not (assq :sync (nth 2 info)))
(assq :async (nth 2 info))))
t)) t))
(advice-add #'org-babel-do-load-languages :override #'ignore)) (advice-add #'org-babel-do-load-languages :override #'ignore))