Skip to content

refactor: Skip missing per-buffer local bibliography files#886

Open
bigodel wants to merge 3 commits into
emacs-citar:mainfrom
bigodel:fix/skip-missing-local-bibliographies
Open

refactor: Skip missing per-buffer local bibliography files#886
bigodel wants to merge 3 commits into
emacs-citar:mainfrom
bigodel:fix/skip-missing-local-bibliographies

Conversation

@bigodel
Copy link
Copy Markdown

@bigodel bigodel commented Apr 28, 2026

Summary

citar--bibliography-files now treats missing per-buffer local bibliography files as a soft case (silently filtered) instead of an error. Globals (citar-bibliography) retain the previous strict existence check.

Motivation

The pre-flight existence check (introduced in #765) conflates two cases:

  • Global config: paths in citar-bibliography are user-configured up front. A missing global typically indicates a typo and should fail fast.
  • Per-buffer locals: paths declared via mechanisms like Org #+bibliography: or TeX \bibliography{}. These may legitimately point to files that haven't been written yet — e.g. a project-local bib materialized after writing citations via citar-export-local-bibtex-file.

Treating both equally meant inserting a citation into an Org buffer with #+bibliography: project.bib errored out before project.bib existed, blocking the natural pre-export workflow.

Changes

  • New helpers citar--global-bibliography-files (validates) and citar--local-bibliography-files (does not validate).
  • Rewrite citar--bibliography-files to use them.
  • Remove citar-file--normalize-paths and citar-file--files-exist-p (no longer used).
  • Tests for the four cases (global only, missing global errors, missing local filtered, both included).

Backwards compatibility

  • Globals still validated — config typos still caught.
  • Locals previously errored on missing; now silently filtered.

João Pedro added 3 commits April 28, 2026 04:31
…phy-files

Two helpers extracted in preparation for refactoring
`citar--bibliography-files':

- `citar--global-bibliography-files' returns `citar-bibliography'
  after validating it is a list of existing files (signals an error
  otherwise).
- `citar--local-bibliography-files' returns the per-buffer local
  bibliography files declared via `local-bib-files' in
  `citar-major-mode-functions', without validating existence.
Rewrite `citar--bibliography-files' to delegate global and per-buffer
bibliography file collection to the recently added
`citar--global-bibliography-files' and `citar--local-bibliography-files'
helpers.  Local bibliography files that do not exist are now silently
filtered out instead of signalling a `user-error'; globals retain the
previous strict existence check.

This unblocks workflows that declare a project-local bibliography file
(e.g. via Org `#+bibliography:') before the file has been materialized
— for instance via `citar-export-local-bibtex-file'.

`citar-file--normalize-paths' and `citar-file--files-exist-p' had only
one caller each (the rewritten `citar--bibliography-files') and have
been removed.
Add four tests for `citar--bibliography-files':

- existing global is returned;
- missing global signals a `user-error';
- missing per-buffer local is silently filtered;
- existing per-buffer local is included.
@aikrahguzar
Copy link
Copy Markdown
Contributor

I am not sure this is a good idea. The missing files might be due to a typo etc. Silently ignoring the unavailability seems problematic. I think the problem this is trying to solve can be worked around by just commenting out the line for the bibliography.

@bigodel
Copy link
Copy Markdown
Author

bigodel commented May 4, 2026

I am not sure this is a good idea. The missing files might be due to a typo etc. Silently ignoring the unavailability seems problematic.

Fair point on typo masking. I based the idea of ignoring on LaTeX's compilation process, which will produce an output even if the bibliography file does not exist. But to be fair to my initial idea, even LaTeX's compilation produces warnings and errors in stderr and log files.

Would you consider this change if I added a display-warning for missing files?

I think the problem this is trying to solve can be worked around by just commenting out the line for the bibliography.

The comment-out workaround misses the use case driving this PR (a follow-up to #885). I want citar-exported-bib-file-name set to a function that reads the buffer's declared local bibliography (e.g. #+bibliography: ./project.bib) and uses that path as the export target, the buffer becomes the single source of truth for both lookup and write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants