feat: Customizable basename for citar-export-local-bib-file#885
feat: Customizable basename for citar-export-local-bib-file#885bigodel wants to merge 6 commits into
Conversation
Add a user option controlling the basename used by `citar-export-local-bibtex-file' when invoked without a prefix argument. May be a string, a function, or nil to defer to a mode-aware default.
Pull the per-buffer local bibliography lookup out of `citar--bibliography-files' into a dedicated private function for reuse. Slightly simplifies the caller using `ensure-list'.
Derive a default basename for `citar-export-local-bibtex-file' from the current buffer's bibliography declaration via `citar--local-bibliography-files', falling back to "references". Intended for use as a value of `citar-export-local-bibtex-base-name'.
The function now takes a FILENAME argument. When called interactively without a prefix argument, FILENAME is derived from `citar-export-local-bibtex-base-name'; with a prefix argument the user is prompted.
Rename `citar-export-local-bib-file' to `citar-export-local-bibtex-file' to reflect that it writes BibTeX, not a generic "bib file". Old name retained as an obsolete alias.
- `citar-local-bibtex-base-name' falls back to "references" when no local bibliography is declared. - `citar-local-bibtex-base-name' returns the basename of the first declared local bibliography. - `citar-export-local-bibtex-file' writes cited entries to FILENAME. - `citar-export-local-bibtex-base-name' is honoured as the exported file's basename when set to a string.
|
This is part of #879 (title doesn't make sense anymore), please see the discussion there and review the changes. |
Thanks for the pointer to #879, I'd dismissed it because of the title. Agreed it has significant overlap and should land first. There are a few things from this PR I'd still like to retain in some form:
|
| (current-prefix-arg | ||
| (read-file-name "File name: ")) |
There was a problem hiding this comment.
My suggestion for prompting on citar-exported-bibtex-file-name being nil.
| (current-prefix-arg | |
| (read-file-name "File name: ")) | |
| ((or current-prefix-arg (not citar-exported-bibtex-file-name)) | |
| (read-file-name "File name: " nil "some-sensible-default-or-error")) |
Summary
Makes
citar-export-local-bibtex-file(renamed fromcitar-export-local-bib-file) flexible:FILENAMEargument; with prefix arg, prompts the user.citar-export-local-bibtex-base-name— string, function, ornilfor a mode-aware default.nilchoice falls back to a new helpercitar-local-bibtex-base-name, which derives a basename from the buffer's bibliography declaration (Org#+bibliography:, TeX\bibliography{}) via the new privatecitar--local-bibliography-files.Motivation
The hardcoded
local-bib.<ext>output is opaque and conflicts with workflows where a project's bibliography file has a meaningful name (e.g.,references.bib). Letting users choose the basename, or derive it from the buffer's own bibliography declaration, gives users much more flexibility when generating a local BibTeX file from citations.The rename clarifies that the function writes BibTeX, not a generic "bib" artifact.
Backwards compatibility
"local-bib") preserves prior behavior.define-obsolete-function-alias.Public API additions
citar-export-local-bibtex-base-name(defcustom)citar-local-bibtex-base-name(helper)citar-export-local-bibtex-file(renamed function)