diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e28a5f3dd..3ce6c9ece 100644 --- a/lisp/ob-core.el +++ b/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) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 9d9453acd..3e8f485ac 100644 --- a/testing/lisp/test-ob.el +++ b/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 <> #+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 <> #+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: + +#+begin_src emacs-lisp :results output :tangle yes + <> +#+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 ""