Skip to content

Commit cb8bf4a

Browse files
committed
org-babel-expand-references: Fix :noweb-ref expansion
* lisp/ob-core.el (org-babel-expand-noweb-references): Do not rely on reference cache being populated as a condition that all the references in buffer have been processed. Set this information explicitly. * testing/lisp/test-ob.el (test-ob/noweb-expansion): Add new test.
1 parent 8cc821b commit cb8bf4a

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

lisp/ob-core.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,8 @@ block but are passed literally to the \"example-block\"."
29942994
;; run. Yet, ID is not in cache (see the above
29952995
;; condition). Process missing reference in
29962996
;; `expand-references'.
2997-
((hash-table-p org-babel-expand-noweb-references--cache)
2997+
((and (hash-table-p org-babel-expand-noweb-references--cache)
2998+
(gethash 'buffer-processed org-babel-expand-noweb-references--cache))
29982999
(expand-references id))
29993000
;; Though luck. We go into the long process of
30003001
;; checking each source block and expand those
@@ -3010,6 +3011,7 @@ block but are passed literally to the \"example-block\"."
30103011
(let* ((info (org-babel-get-src-block-info t))
30113012
(ref (cdr (assq :noweb-ref (nth 2 info)))))
30123013
(push info (gethash ref org-babel-expand-noweb-references--cache))))))
3014+
(puthash 'buffer-processed t org-babel-expand-noweb-references--cache)
30133015
(expand-references id)))))
30143016
;; Interpose PREFIX between every line.
30153017
(if noweb-prefix

testing/lisp/test-ob.el

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,52 @@ x
883883
#+begin_src emacs-lisp :noweb yes<point>
884884
<<AA>>
885885
#+end_src"
886-
(org-babel-expand-noweb-references)))))
886+
(org-babel-expand-noweb-references))))
887+
;; Test :noweb-ref expansion.
888+
(should
889+
(equal "(message \"!! %s\" \"Running confpkg-test-setup\")
890+
891+
(message \"- Ran `%s'\" 'confpkg-test-strip-package-statements)
892+
893+
(message \"!! %s\" \"Still running confpkg-test-setup\")
894+
895+
(message \"- Ran elisp blocks in `%s'\" 'confpkg-test-dependency-analysis)
896+
897+
(message \"!! %s\" \"End of confpkg-test-setup\")"
898+
(org-test-with-temp-text "
899+
* Setup
900+
901+
#+name: confpkg-test-setup
902+
#+begin_src emacs-lisp :results silent :noweb no-export
903+
(message \"!! %s\" \"Running confpkg-test-setup\")
904+
905+
<<confpkg-test-strip-package-statements>>
906+
907+
(message \"!! %s\" \"Still running confpkg-test-setup\")
908+
909+
<<confpkg-test-dependency-analysis>>
910+
911+
(message \"!! %s\" \"End of confpkg-test-setup\")
912+
#+end_src
913+
914+
#+call: confpkg-test-setup[:results none]()
915+
916+
* Identify cross-package dependencies
917+
918+
#+begin_src emacs-lisp :noweb-ref confpkg-test-dependency-analysis
919+
(message \"- Ran elisp blocks in `%s'\" 'confpkg-test-dependency-analysis)
920+
#+end_src
921+
922+
* Commenting out ~package!~ statements
923+
924+
#+name: confpkg-test-strip-package-statements
925+
#+begin_src emacs-lisp
926+
(message \"- Ran `%s'\" 'confpkg-test-strip-package-statements)
927+
#+end_src
928+
"
929+
(goto-char (point-min))
930+
(search-forward "begin_src")
931+
(org-babel-expand-noweb-references)))))
887932

888933
(ert-deftest test-ob/splitting-variable-lists-in-references ()
889934
(org-test-with-temp-text ""

0 commit comments

Comments
 (0)