diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 9843bb53a9..8a963fa8e2 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2994,7 +2994,8 @@ block but are passed literally to the \"example-block\"." ;; run. Yet, ID is not in cache (see the above ;; condition). Process missing reference in ;; `expand-references'. - ((hash-table-p org-babel-expand-noweb-references--cache) + ((and (hash-table-p org-babel-expand-noweb-references--cache) + (gethash 'buffer-processed org-babel-expand-noweb-references--cache)) (expand-references id)) ;; Though luck. We go into the long process of ;; checking each source block and expand those @@ -3010,6 +3011,7 @@ block but are passed literally to the \"example-block\"." (let* ((info (org-babel-get-src-block-info t)) (ref (cdr (assq :noweb-ref (nth 2 info))))) (push info (gethash ref org-babel-expand-noweb-references--cache)))))) + (puthash 'buffer-processed t org-babel-expand-noweb-references--cache) (expand-references id))))) ;; Interpose PREFIX between every line. (if noweb-prefix diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 7fa330fe14..99912fe639 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -883,7 +883,52 @@ x #+begin_src emacs-lisp :noweb yes <> #+end_src" - (org-babel-expand-noweb-references))))) + (org-babel-expand-noweb-references)))) + ;; Test :noweb-ref expansion. + (should + (equal "(message \"!! %s\" \"Running confpkg-test-setup\") + +(message \"- Ran `%s'\" 'confpkg-test-strip-package-statements) + +(message \"!! %s\" \"Still running confpkg-test-setup\") + +(message \"- Ran elisp blocks in `%s'\" 'confpkg-test-dependency-analysis) + +(message \"!! %s\" \"End of confpkg-test-setup\")" + (org-test-with-temp-text " +* Setup + +#+name: confpkg-test-setup +#+begin_src emacs-lisp :results silent :noweb no-export +(message \"!! %s\" \"Running confpkg-test-setup\") + +<> + +(message \"!! %s\" \"Still running confpkg-test-setup\") + +<> + +(message \"!! %s\" \"End of confpkg-test-setup\") +#+end_src + +#+call: confpkg-test-setup[:results none]() + +* Identify cross-package dependencies + +#+begin_src emacs-lisp :noweb-ref confpkg-test-dependency-analysis +(message \"- Ran elisp blocks in `%s'\" 'confpkg-test-dependency-analysis) +#+end_src + +* Commenting out ~package!~ statements + +#+name: confpkg-test-strip-package-statements +#+begin_src emacs-lisp +(message \"- Ran `%s'\" 'confpkg-test-strip-package-statements) +#+end_src +" + (goto-char (point-min)) + (search-forward "begin_src") + (org-babel-expand-noweb-references))))) (ert-deftest test-ob/splitting-variable-lists-in-references () (org-test-with-temp-text ""