Browse Source

ob-core: Get :noweb-ref from definition instead of point of call

* lisp/ob-core.el (org-babel-expand-noweb-references): Get :noweb-ref
  from definition instead of point of call.

* testing/lisp/test-ob.el (test-ob/noweb-expansion-1):
(test-ob/noweb-expansion-2): Merge tests.  Add test.
Nicolas Goaziou 7 năm trước cách đây
mục cha
commit
3acc212c8f
2 tập tin đã thay đổi với 39 bổ sung8 xóa
  1. 2 1
      lisp/ob-core.el
  2. 37 7
      testing/lisp/test-ob.el

+ 2 - 1
lisp/ob-core.el

@@ -2771,7 +2771,8 @@ block but are passed literally to the \"example-block\"."
                                            body)))
                               (setq expansion (cons sep (cons full expansion)))))
                         (org-babel-map-src-blocks nil
-			  (let ((i (org-babel-get-src-block-info 'light)))
+			  (let ((i (let ((org-babel-current-src-block-location (point)))
+				     (org-babel-get-src-block-info 'light))))
                             (when (equal (or (cdr (assq :noweb-ref (nth 2 i)))
                                              (nth 4 i))
                                          source-name)

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

@@ -668,8 +668,12 @@ x
       (check-eval "never-export" nil)
       (check-eval "no-export" nil))))
 
-(ert-deftest test-ob/noweb-expansion-1 ()
-  (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
+(ert-deftest test-ob/noweb-expansion ()
+  ;; Standard test.
+  (should
+   (string=
+    "bar"
+    (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
   <<foo>>
 #+end_src
 
@@ -677,10 +681,12 @@ x
 #+begin_src sh
   bar
 #+end_src"
-    (should (string= (org-babel-expand-noweb-references) "bar"))))
-
-(ert-deftest test-ob/noweb-expansion-2 ()
-  (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
+      (org-babel-expand-noweb-references))))
+  ;; Handle :noweb-sep.
+  (should
+   (string=
+    "barbaz"
+    (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
   <<foo>>
 #+end_src
 
@@ -692,7 +698,31 @@ x
 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
   baz
 #+end_src"
-    (should (string= (org-babel-expand-noweb-references) "barbaz"))))
+      (org-babel-expand-noweb-references))))
+  ;; :noweb-ref is extracted from definition, not point of call.
+  (should
+   (string=
+    "(+ 1 1)"
+    (org-test-with-temp-text
+	"
+* Call
+:PROPERTIES:
+:header-args: :noweb-ref bar
+:END:
+
+<point>#+begin_src emacs-lisp :results output :tangle yes
+  <<foo>>
+#+end_src
+
+* Evaluation
+:PROPERTIES:
+:header-args: :noweb-ref foo
+:END:
+
+#+begin_src sh :noweb-sep \"\"
+  (+ 1 1)
+#+end_src"
+      (org-babel-expand-noweb-references)))))
 
 (ert-deftest test-ob/splitting-variable-lists-in-references ()
   (org-test-with-temp-text ""