Skip to content

Commit

Permalink
org-babel-expand-references: Fix :noweb-ref expansion
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
yantar92 committed Sep 17, 2022
1 parent 8cc821b commit cb8bf4a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lisp/ob-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
47 changes: 46 additions & 1 deletion testing/lisp/test-ob.el
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,52 @@ x
#+begin_src emacs-lisp :noweb yes<point>
<<AA>>
#+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\")
<<confpkg-test-strip-package-statements>>
(message \"!! %s\" \"Still running confpkg-test-setup\")
<<confpkg-test-dependency-analysis>>
(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 ""
Expand Down

0 comments on commit cb8bf4a

Please sign in to comment.