Hi Kyle,
    Following up in this thread having investigated the impact of coderefs.
My conclusion is that coderefs need to be stripped out before they are
passed to org-confirm-babel-evaluate. They are not present in the
executed code and removing them is not something that a definition
of org-confirm-babel-evaluate should have to know anything about.
Right now I work around them by suggesting that users comment
out their coderefs. This works because my use case is restricted to
elisp code and I strip the comments using read, but other languages
would not have such an easy solution.

I have included a patch against maint that reuses the let block
from org-babel-execute-src-block to accomplish this.

Best!
Tom
From dfb8eee9901a0fe4bd933911386f69863785a15b Mon Sep 17 00:00:00 2001
From: Tom Gillespie <tgbugs@gmail.com>
Date: Fri, 4 Sep 2020 20:35:03 -0700
Subject: [PATCH] lisp/ob-core.el: org-babel-check-confirm-evaluate strip
 coderefs

* lisp/ob-core.el (org-babel-check-confirm-evaluate): strip coderefs
before passing the body of the block to org-confirm-babel-evaluate
using the same let block as is used in org-babel-execute-src-block.
---
 lisp/ob-core.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index cd876da0f..44b02feb9 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -240,9 +240,14 @@ should be asked whether to allow evaluation."
 			(funcall org-confirm-babel-evaluate
 				 ;; Language, code block body.
 				 (nth 0 info)
-				 (if (org-babel-noweb-p headers :eval)
-				     (org-babel-expand-noweb-references info)
-				   (nth 1 info)))
+				 (let ((coderef (nth 6 info))
+				       (expand
+					(if (org-babel-noweb-p params :eval)
+					    (org-babel-expand-noweb-references info)
+					  (nth 1 info))))
+				   (if (not coderef) expand
+				     (replace-regexp-in-string
+				      (org-src-coderef-regexp coderef) "" expand nil nil 1))))
 		      org-confirm-babel-evaluate))))
     (cond
      (noeval nil)
-- 
2.26.2

Reply via email to