Skip to content

feat: Customizable basename for citar-export-local-bib-file#885

Open
bigodel wants to merge 6 commits into
emacs-citar:mainfrom
bigodel:feat/configurable-local-bib-name
Open

feat: Customizable basename for citar-export-local-bib-file#885
bigodel wants to merge 6 commits into
emacs-citar:mainfrom
bigodel:feat/configurable-local-bib-name

Conversation

@bigodel
Copy link
Copy Markdown

@bigodel bigodel commented Apr 28, 2026

Summary

Makes citar-export-local-bibtex-file (renamed from citar-export-local-bib-file) flexible:

  • Takes a FILENAME argument; with prefix arg, prompts the user.
  • Without prefix arg, derives the basename from a new user option citar-export-local-bibtex-base-name — string, function, or nil for a mode-aware default.
  • The nil choice falls back to a new helper citar-local-bibtex-base-name, which derives a basename from the buffer's bibliography declaration (Org #+bibliography:, TeX \bibliography{}) via the new private citar--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

  • Default value of the user option ("local-bib") preserves prior behavior.
  • Old function name retained via 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)

João Pedro added 6 commits April 28, 2026 03:37
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.
@aikrahguzar
Copy link
Copy Markdown
Contributor

This is part of #879 (title doesn't make sense anymore), please see the discussion there and review the changes.

@bigodel
Copy link
Copy Markdown
Author

bigodel commented Apr 28, 2026

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:

  • Extending the defcustom type to accept a function (called with no args, returns a basename). On nil, prompt the user, but the prompt should live in the interactive declaration, with filename as a required argument so programmatic callers always pass it explicitly. A prefix argument could also force a prompt as an ad-hoc override.

  • Rename citar-exported-bib-file-name -> citar-exported-bibtex-base-name (emphasizing that the extension does not matter and will be dervied), and citar-export-local-bib-file -> citar-export-local-bibtex-file. Without the explicit "bibtex" the names read like they could also produce CSL bibliographies.

  • The citar-local-bibtex-base-name helper that derives a basename from the buffer's bibliography declaration (Org #+bibliography:, TeX \bibliography{}). Plug-and-play as a function value of the defcustom.

  • The extracted citar--local-bibliography-files helper for per-buffer local bib lookup, especially if we agree on keeping citar-local-bibtex-base-name.

  • Tests covering the option dispatch and the helpers.

Comment thread citar.el
Comment on lines +1751 to +1752
(current-prefix-arg
(read-file-name "File name: "))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion for prompting on citar-exported-bibtex-file-name being nil.

Suggested change
(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"))

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