Selaa lähdekoodia

fixed regexp when resolving noweb references

* lisp/ob.el (org-babel-expand-noweb-references): Fixed regexp.
* testing/lisp/test-ob.el (test-ob/noweb-expansion): Test both named
  code block and noweb-ref header argument references.
Eric Schulte 13 vuotta sitten
vanhempi
commit
3bf8d8fd86
2 muutettua tiedostoa jossa 27 lisäystä ja 2 poistoa
  1. 3 2
      lisp/ob.el
  2. 24 0
      testing/lisp/test-ob.el

+ 3 - 2
lisp/ob.el

@@ -1989,7 +1989,8 @@ block but are passed literally to the \"example-block\"."
          (lang (nth 0 info))
          (body (nth 1 info))
 	 (comment (string= "noweb" (cdr (assoc :comments (nth 2 info)))))
-	 (rx-prefix (regexp-opt (list org-babel-src-name-regexp ":noweb-ref")))
+	 (rx-prefix (concat "\\(" org-babel-src-name-regexp "\\|"
+			    ":noweb-ref[ \t]+" "\\)"))
          (new-body "") index source-name evaluate prefix blocks-in-buffer)
     (flet ((nb-add (text) (setq new-body (concat new-body text)))
 	   (c-wrap (text)
@@ -2030,7 +2031,7 @@ block but are passed literally to the \"example-block\"."
 		    (when (org-babel-ref-goto-headline-id source-name)
 		      (org-babel-ref-headline-body)))
 		  ;; find the expansion of reference in this buffer
-		  (let ((rx (concat rx-prefix "[ \t]+" source-name))
+		  (let ((rx (concat rx-prefix source-name))
 			expansion)
 		    (save-excursion
 		      (goto-char (point-min))

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

@@ -552,6 +552,30 @@ on two lines
       (check-eval "never-export" nil)
       (check-eval "no-export" nil))))
 
+(ert-deftest test-ob/noweb-expansion ()
+  (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
+  <<foo>>
+#+end_src
+
+#+name: foo
+#+begin_src sh
+  bar
+#+end_src"
+    (should (string= (org-babel-expand-noweb-references) "bar")))
+  (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
+  <<foo>>
+#+end_src
+
+#+name: foo
+#+begin_src sh
+  bar
+#+end_src
+
+#+begin_src sh :noweb-ref foo
+  baz
+#+end_src"
+    (should (string= (org-babel-expand-noweb-references) "barbaz"))))
+
 (provide 'test-ob)
 
 ;;; test-ob ends here