Refactor lang/org +babel lazy loader for src blocks
Exposes +org-babel-load-functions, which are a list of functions that will be tried in order to load the dependencies of a src block.
This commit is contained in:
parent
bb9f00e275
commit
98b439e3bb
1 changed files with 11 additions and 5 deletions
|
@ -12,6 +12,11 @@
|
||||||
"An alist that maps languages to babel libraries. This is necessary for babel
|
"An alist that maps languages to babel libraries. This is necessary for babel
|
||||||
libraries (ob-*.el) that don't match the name of the language.")
|
libraries (ob-*.el) that don't match the name of the language.")
|
||||||
|
|
||||||
|
(defvar +org-babel-load-functions ()
|
||||||
|
"A list of functions that are used to try to load the current executing src
|
||||||
|
block. They take one argument (the language specified in the src block, as
|
||||||
|
string). Stops at the first function to return non-nil.")
|
||||||
|
|
||||||
(defun +org|init-babel ()
|
(defun +org|init-babel ()
|
||||||
(setq org-src-fontify-natively t ; make code pretty
|
(setq org-src-fontify-natively t ; make code pretty
|
||||||
org-src-preserve-indentation t ; use native major-mode indentation
|
org-src-preserve-indentation t ; use native major-mode indentation
|
||||||
|
@ -24,11 +29,12 @@ libraries (ob-*.el) that don't match the name of the language.")
|
||||||
(let* ((language (org-element-property :language (org-element-at-point)))
|
(let* ((language (org-element-property :language (org-element-at-point)))
|
||||||
(lang-sym (intern language)))
|
(lang-sym (intern language)))
|
||||||
(when (and (not (cdr (assq lang-sym org-babel-load-languages)))
|
(when (and (not (cdr (assq lang-sym org-babel-load-languages)))
|
||||||
(require
|
(or (run-hook-with-args-until-success '+org-babel-load-functions language)
|
||||||
(intern (format "ob-%s"
|
(require
|
||||||
(or (cdr (assoc (downcase language) +org-babel-mode-alist))
|
(intern (format "ob-%s"
|
||||||
language)))
|
(or (cdr (assoc (downcase language) +org-babel-mode-alist))
|
||||||
nil t))
|
language)))
|
||||||
|
nil t)))
|
||||||
(map-put org-babel-load-languages lang-sym t))
|
(map-put org-babel-load-languages lang-sym t))
|
||||||
(apply orig-fn args)))
|
(apply orig-fn args)))
|
||||||
(advice-add #'org-babel-execute-src-block :around #'+org*babel-execute-src-block)
|
(advice-add #'org-babel-execute-src-block :around #'+org*babel-execute-src-block)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue