On Sat, Apr 22, 2023 at 12:42 PM Ihor Radchenko <yanta...@posteo.net> wrote:
> the cleanest way will be using `add-variable-watcher'.
Hi Ihor,
The "add-variable-watcher" may not be able to deal with the
local/global variable `org-babel-load-languages' correctly.

On Sat, Apr 22, 2023 at 8:33 AM Ruijie Yu <rui...@netyu.xyz> wrote:
> Instead of that, I think you should have some sort of conditional in the
> `unless' condition.  Something like:
> --8<---------------cut here---------------start------------->8---
> (unless (or (fboundp cmd)
>             (ignore (and (alist-get lang org-babel-load-languages)
>                          (require (intern (concat "ob-" lang)))))
>             (fboundp cmd))
>   (error "... %s" lang))
> --8<---------------cut here---------------end--------------->8---
The logic in the patch will follow the function
`org-babel-do-load-languages' to load the ob-LANG without capturing
the error.
I changed the patch to follow your comments.
Please review the new patch I attached. Thanks.
From acc72f9f42120d07cc728eeebb9dd976b4568c1f 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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 471887a3a..0fc4cbe9f 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -714,6 +714,8 @@ a list with the following pattern:
 (defvar *this*) ; Dynamically bound in `org-babel-execute-src-block'
                 ; and `org-babel-read'
 
+(defvar org-babel-load-languages)
+
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params executor-type)
   "Execute the current source code block and return the result.
@@ -794,7 +796,9 @@ guess will be made."
 		       d))))
 		 (cmd (intern (concat "org-babel-execute:" lang)))
 		 result exec-start-time)
-	    (unless (fboundp cmd)
+	    (unless (or (fboundp cmd)
+			(and (alist-get (intern lang) org-babel-load-languages)
+			     (require (intern (concat "ob-" lang)) nil t)))
 	      (error "No org-babel-execute function for %s!" lang))
 	    (message "Executing %s %s %s..."
 		     (capitalize lang)
@@ -1952,8 +1956,6 @@ With optional prefix argument ARG, jump backward ARG many source blocks."
   (interactive "p")
   (org-previous-block arg org-babel-src-block-regexp))
 
-(defvar org-babel-load-languages)
-
 ;;;###autoload
 (defun org-babel-mark-block ()
   "Mark current source block."
-- 
2.20.5

Reply via email to