Hi,
The function `org-babel-execute-src-block' will emit an error message
if the language is not loaded.

Before the error message, the patch will give a try to load the
associated babel language.

Why does the language exist in the `lang org-babel-load-languages' but
not be loaded?
Because the `org-babel-load-languages' are defined as a customer
variable with  :set 'org-babel-do-load-languages,  the ":set" function
can only be triggered with function `custom-set-variables`.
While setq/cl-pushnew `org-babel-load-languages' won't trigger the
`:set' function, then the error message will be displayed if I run the
code in the org file.

Please help review that patch. Thanks. Regards
From 39a15a34bdb8bd0c397fbd80cdfb0723ce229066 Mon Sep 17 00:00:00 2001
From: Lin Sun <sunl...@hotmail.com>
Date: Sat, 22 Apr 2023 00:00:39 +0000
Subject: [PATCH] *lisp/ob-core.el: load lang in (org-babel-execute-src-block)

---
 lisp/ob-core.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 471887a3a..2ed4f6b5b 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -795,7 +795,9 @@ guess will be made."
 		 (cmd (intern (concat "org-babel-execute:" lang)))
 		 result exec-start-time)
 	    (unless (fboundp cmd)
-	      (error "No org-babel-execute function for %s!" lang))
+              (if (alist-get lang org-babel-load-languages)
+                  (require (intern (concat "ob-" lang)))
+                (error "No org-babel-execute function for %s!" lang)))
 	    (message "Executing %s %s %s..."
 		     (capitalize lang)
                      (pcase executor-type
-- 
2.20.5

Reply via email to