From 5ec364a1ae327312da6f69766a2bec79bc7691e8 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 29 Mar 2023 16:13:29 +0200 Subject: [PATCH] org-cite-list-bibliography-files: Preserve relative bibliography paths * lisp/oc.el (org-cite-list-bibliography-files): When the bibliography path is relative to the exported file location, keep the path relative. Resolve relative paths for bibliographies from SETUPFILE as well. * testing/lisp/test-oc.el (test-org-cite/list-bibliography-files): * testing/examples/sub-bib/include-relative-bib.org: * testing/examples/sub-bib/include-global-bib.org: New test. Link: https://orgmode.org/list/CAO48Bk_upR4h-xd0YL+FxeKtWvDoqH+Eju6F_Vzds_m6oxBKcg@mail.gmail.com --- lisp/oc.el | 13 ++++++++++++- testing/examples/sub-bib/include-global-bib.org | 1 + testing/examples/sub-bib/include-relative-bib.org | 1 + testing/lisp/test-oc.el | 14 +++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 testing/examples/sub-bib/include-global-bib.org create mode 100644 testing/examples/sub-bib/include-relative-bib.org diff --git a/lisp/oc.el b/lisp/oc.el index 4b1420271..69b5cff7a 100644 --- a/lisp/oc.el +++ b/lisp/oc.el @@ -602,7 +602,18 @@ to (adaptive outside after)." (append (mapcar (lambda (value) (pcase value (`(,f . ,d) - (expand-file-name (org-strip-quotes f) d)))) + (setq f (org-strip-quotes f)) + (if (or (file-name-absolute-p f) + (file-remote-p f) + (equal d default-directory)) + ;; Keep absolute paths, remote paths, and + ;; local relative paths. + f + ;; Adjust relative bibliography path for + ;; #+SETUP files located in other directory. + ;; Also, see `org-export--update-included-link'. + (file-relative-name + (expand-file-name f d) default-directory))))) (pcase (org-collect-keywords '("BIBLIOGRAPHY") nil '("BIBLIOGRAPHY")) (`(("BIBLIOGRAPHY" . ,pairs)) pairs))) diff --git a/testing/examples/sub-bib/include-global-bib.org b/testing/examples/sub-bib/include-global-bib.org new file mode 100644 index 000000000..e7a4ffb79 --- /dev/null +++ b/testing/examples/sub-bib/include-global-bib.org @@ -0,0 +1 @@ +#+bibliography: /foo.bib diff --git a/testing/examples/sub-bib/include-relative-bib.org b/testing/examples/sub-bib/include-relative-bib.org new file mode 100644 index 000000000..9fae85005 --- /dev/null +++ b/testing/examples/sub-bib/include-relative-bib.org @@ -0,0 +1 @@ +#+bibliography: ./foo.bib diff --git a/testing/lisp/test-oc.el b/testing/lisp/test-oc.el index 4a39874a8..b1db742d7 100644 --- a/testing/lisp/test-oc.el +++ b/testing/lisp/test-oc.el @@ -482,8 +482,20 @@ (let ((org-cite-global-bibliography '("/other-bibliography"))) (org-cite-list-bibliography-files))))) (should - (equal '(t) + (equal '("./bibliography") (org-test-with-temp-text "#+bibliography: ./bibliography" + (let ((org-cite-global-bibliography nil)) + (org-cite-list-bibliography-files))))) + (should + (equal '("/foo.bib") + (org-test-with-temp-text + (format "#+SETUPFILE: \"%s/examples/sub-bib/include-global-bib.org\"" org-test-dir) + (let ((org-cite-global-bibliography nil)) + (org-cite-list-bibliography-files))))) + (should + (equal '(nil) + (org-test-with-temp-text + (format "#+SETUPFILE: \"%s/examples/sub-bib/include-relative-bib.org\"" org-test-dir) (let ((org-cite-global-bibliography nil)) (mapcar #'file-name-absolute-p (org-cite-list-bibliography-files)))))) (should