Bläddra i källkod

Fix recursive Noweb expansion

* lisp/ob-core.el (org-babel-expand-noweb-references): Recursive Noweb
  expansion obey to :noweb parameter.
* testing/lisp/test-ob.el (test-ob/noweb-expansion): Add tests.

Fixes: 17523
Nicolas Goaziou 7 år sedan
förälder
incheckning
d9125e435f
2 ändrade filer med 46 tillägg och 6 borttagningar
  1. 9 5
      lisp/ob-core.el
  2. 37 1
      testing/lisp/test-ob.el

+ 9 - 5
lisp/ob-core.el

@@ -2760,14 +2760,16 @@ block but are passed literally to the \"example-block\"."
                       (if org-babel-use-quick-and-dirty-noweb-expansion
                           (while (re-search-forward rx nil t)
                             (let* ((i (org-babel-get-src-block-info 'light))
-                                   (body (org-babel-expand-noweb-references i))
+                                   (body (if (org-babel-noweb-p (nth 2 i) :eval)
+					     (org-babel-expand-noweb-references i)
+					   (nth 1 i)))
                                    (sep (or (cdr (assq :noweb-sep (nth 2 i)))
                                             "\n"))
                                    (full (if comment
                                              (let ((cs (org-babel-tangle-comment-links i)))
-                                                (concat (funcall c-wrap (car cs)) "\n"
-                                                        body "\n"
-                                                        (funcall c-wrap (cadr cs))))
+					       (concat (funcall c-wrap (car cs)) "\n"
+						       body "\n"
+						       (funcall c-wrap (cadr cs))))
                                            body)))
                               (setq expansion (cons sep (cons full expansion)))))
                         (org-babel-map-src-blocks nil
@@ -2776,7 +2778,9 @@ block but are passed literally to the \"example-block\"."
                             (when (equal (or (cdr (assq :noweb-ref (nth 2 i)))
                                              (nth 4 i))
                                          source-name)
-                              (let* ((body (org-babel-expand-noweb-references i))
+                              (let* ((body (if (org-babel-noweb-p (nth 2 i) :eval)
+					       (org-babel-expand-noweb-references i)
+					     (nth 1 i)))
                                      (sep (or (cdr (assq :noweb-sep (nth 2 i)))
                                               "\n"))
                                      (full (if comment

+ 37 - 1
testing/lisp/test-ob.el

@@ -722,7 +722,43 @@ x
 #+begin_src sh :noweb-sep \"\"
   (+ 1 1)
 #+end_src"
-      (org-babel-expand-noweb-references)))))
+      (org-babel-expand-noweb-references))))
+  ;; Handle recursive expansion.
+  (should
+   (equal "baz"
+	  (org-test-with-temp-text "
+#+begin_src emacs-lisp :noweb yes<point>
+  <<foo>>
+#+end_src
+
+#+name: foo
+#+begin_src emacs-lisp :noweb yes
+  <<bar>>
+#+end_src
+
+#+name: bar
+#+begin_src emacs-lisp
+  baz
+#+end_src"
+	    (org-babel-expand-noweb-references))))
+  ;; During recursive expansion, obey to `:noweb' property.
+  (should
+   (equal "<<bar>>"
+	  (org-test-with-temp-text "
+#+begin_src emacs-lisp :noweb yes<point>
+  <<foo>>
+#+end_src
+
+#+name: foo
+#+begin_src emacs-lisp :noweb no
+  <<bar>>
+#+end_src
+
+#+name: bar
+#+begin_src emacs-lisp
+  baz
+#+end_src"
+	    (org-babel-expand-noweb-references)))))
 
 (ert-deftest test-ob/splitting-variable-lists-in-references ()
   (org-test-with-temp-text ""