ob-core: Call org-confirm-babel-evaluate with expanded noweb refs

* lisp/ob-core.el (org-babel-check-confirm-evaluate): Expand noweb
references in the body passed to org-confirm-babel-evaluate.
* testing/lisp/test-ob.el (test-ob/check-eval-noweb-expanded): New
test.

When noweb references are set to be expanded for evaluation,
org-confirm-babel-evaluate should receive the expanded body so that it
can make its decision based on what actually will be evaluated
(without resorting to calling org-babel-get-src-block-info itself).

Note that this results in up to three calls to
org-babel-expand-noweb-references.  Possible ways to avoid this are
discussed at the thread referenced below.

Reported-by: Tom Gillespie <tgbugs@gmail.com>
https://orgmode.org/list/CA+G3_PNi3uMvBiWgBdKuC3C6VJt1T1j-RKH43LRqYbr+4NS8ZA@mail.gmail.com/
This commit is contained in:
Kyle Meyer 2020-08-02 22:34:36 -04:00
parent 521d7f5fe4
commit df5a836375
2 changed files with 23 additions and 1 deletions

View File

@ -239,7 +239,10 @@ should be asked whether to allow evaluation."
(if (functionp org-confirm-babel-evaluate)
(funcall org-confirm-babel-evaluate
;; Language, code block body.
(nth 0 info) (nth 1 info))
(nth 0 info)
(if (org-babel-noweb-p headers :eval)
(org-babel-expand-noweb-references info)
(nth 1 info)))
org-confirm-babel-evaluate))))
(cond
(noeval nil)

View File

@ -1847,6 +1847,25 @@ default-directory
(message (car pair))
(should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair)))))))
(ert-deftest test-ob/check-eval-noweb-expanded ()
"`org-confirm-babel-evaluate' function receives expanded noweb refs."
(should
(equal t
(org-test-with-temp-text "
#+name: foo
#+begin_src emacs-lisp
:bar
#+end_src
<point>#+begin_src emacs-lisp :noweb yes
<<foo>>
#+end_src"
(let ((org-confirm-babel-evaluate
(lambda (_ body)
(not (string-match-p ":bar" body)))))
(org-babel-check-confirm-evaluate
(org-babel-get-src-block-info)))))))
(defun org-test-ob/update-block-body ()
"Test `org-babel-update-block-body' specifications."
(should