lang/org: fix errors lazy-loading mismatched babel libraries

The ob-C.el library takes care of C, C++ and D. This modifies the babel
lazy-loader to take this into account. Name => library mappings are
defined in +org-babel-mode-alist.
This commit is contained in:
Henrik Lissner 2018-01-28 17:20:23 -05:00
parent cd6fb816fd
commit 0cc3b34fa2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -2,6 +2,14 @@
(add-hook 'org-load-hook #'+org|init-babel)
(defvar +org-babel-mode-alist
'(("cpp" . C)
("C++" . C)
("D" . C)
("matlab" . octave))
"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.")
(defun +org|init-babel ()
(setq org-src-fontify-natively t ; make code pretty
org-src-preserve-indentation t ; use native major-mode indentation
@ -13,8 +21,11 @@
"Load babel libraries as needed when babel blocks are executed."
(let* ((language (org-element-property :language (org-element-at-point)))
(lang-sym (intern language)))
(unless (cdr (assoc lang-sym org-babel-load-languages))
(require (intern (format "ob-%s" language)))
(when (and (not (cdr (assq lang-sym org-babel-load-languages)))
(require
(intern (format "ob-%s"
(or (cdr (assoc (downcase language) +org-babel-mode-alist))
language)))))
(add-to-list 'org-babel-load-languages (cons lang-sym t)))
(apply orig-fn args)))
(advice-add #'org-babel-execute-src-block :around #'+org*babel-execute-src-block)