فهرست منبع

Merge branch 'maint' into master

Kyle Meyer 4 سال پیش
والد
کامیت
d4f48821c1
2فایلهای تغییر یافته به همراه33 افزوده شده و 14 حذف شده
  1. 13 14
      lisp/ob-core.el
  2. 20 0
      testing/lisp/test-ob.el

+ 13 - 14
lisp/ob-core.el

@@ -239,9 +239,7 @@ 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)))
+				 (org-babel--expand-body info))
 		      org-confirm-babel-evaluate))))
     (cond
      (noeval nil)
@@ -636,6 +634,17 @@ a list with the following pattern:
 	(setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info)))
 	info))))
 
+(defun org-babel--expand-body (info)
+  "Expand noweb references in body and remove any coderefs."
+  (let ((coderef (nth 6 info))
+	(expand
+	 (if (org-babel-noweb-p (nth 2 info) :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))))
+
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params)
   "Execute the current source code block.
@@ -681,17 +690,7 @@ block."
 	 ((org-babel-confirm-evaluate info)
 	  (let* ((lang (nth 0 info))
 		 (result-params (cdr (assq :result-params params)))
-		 ;; Expand noweb references in BODY and remove any
-		 ;; coderef.
-		 (body
-		  (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))))
+		 (body (org-babel--expand-body info))
 		 (dir (cdr (assq :dir params)))
 		 (mkdirp (cdr (assq :mkdirp params)))
 		 (default-directory

+ 20 - 0
testing/lisp/test-ob.el

@@ -1955,6 +1955,26 @@ default-directory
 	    (let ((org-confirm-babel-evaluate
 		   (lambda (_ body)
 		     (not (string-match-p ":bar" body)))))
+	      (org-babel-check-confirm-evaluate
+	       (org-babel-get-src-block-info))))))
+  ;; The code block passed to `org-confirm-babel-evaluate' does not
+  ;; include coderefs.
+  (should
+   (equal t
+	  (org-test-with-temp-text "
+#+name: foo
+#+begin_src emacs-lisp
+  :bar
+#+end_src
+
+<point>#+begin_src emacs-lisp :noweb yes
+  #(ref:foo)
+  <<foo>>
+#+end_src"
+	    (let ((org-coderef-label-format "#(ref:%s)")
+		  (org-confirm-babel-evaluate
+		   (lambda (_ body)
+		     (string-match-p "ref:foo" body))))
 	      (org-babel-check-confirm-evaluate
 	       (org-babel-get-src-block-info)))))))