summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <eric.schulte@gmx.com>2011-12-11 12:02:02 -0700
committerEric Schulte <eric.schulte@gmx.com>2011-12-11 12:02:02 -0700
commit3bf8d8fd86b28c11c0021745f14640f3b44a3e16 (patch)
treec48113e026623000d37b2fa448a60bd0291ef6ce
parent68cc108759bbe07382adf6707e0a10aa81a4e0e5 (diff)
downloadorg-mode-3bf8d8fd86b28c11c0021745f14640f3b44a3e16.tar.gz
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.
-rw-r--r--lisp/ob.el5
-rw-r--r--testing/lisp/test-ob.el24
2 files changed, 27 insertions, 2 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 64c82b8..493f8c6 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 5d673c4..70b7dc7 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
+ <<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