From 3bf8d8fd86b28c11c0021745f14640f3b44a3e16 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 11 Dec 2011 12:02:02 -0700 Subject: [PATCH] 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. --- lisp/ob.el | 5 +++-- testing/lisp/test-ob.el | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 64c82b880..493f8c65d 100644 --- a/lisp/ob.el +++ b/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)) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 5d673c404..70b7dc720 100644 --- a/testing/lisp/test-ob.el +++ b/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 + <> +#+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 + <> +#+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 -- 2.11.4.GIT