From fe859ed252bfb9cd7d34ad0f3cb8bdf7f279e7e9 Mon Sep 17 00:00:00 2001 From: Daneel Date: Wed, 25 Feb 2026 13:14:42 +0100 Subject: [PATCH] bibliography: fix commands, add manual entry, universal search - biblio-crossref-lookup doesn't exist; use biblio-lookup (universal) - biblio-doi: require biblio before biblio-doi (load order fix) - my/bib-insert-manual: template for 8 entry types with cursor at KEY - All commands lazy-load biblio via (require 'biblio) - SPC B s = universal search (prompts for backend: CrossRef/arXiv/DBLP) - SPC B m = manual entry template - SPC B D = import by DOI --- config.el | 63 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/config.el b/config.el index 1e999a6..e5fa420 100644 --- a/config.el +++ b/config.el @@ -1842,8 +1842,7 @@ Skip for beamer exports — beamer uses adjustbox on plain tabular." (t csl)))) ;; biblio.el: polite CrossRef access (required by their API policy) -(after! biblio - (setq biblio-crossref-user-email-address "martin@sukany.cz")) +(setq biblio-crossref-user-email-address "martin@sukany.cz") ;; BibTeX editing defaults (setq bibtex-dialect 'biblatex @@ -1855,40 +1854,66 @@ Skip for beamer exports — beamer uses adjustbox on plain tabular." ;; Helper: create new .bib file for a project (defun my/bib-new () - "Create a new .bib file at prompted path." + "Create a new .bib file at prompted path and open it." (interactive) (let ((path (read-file-name "New .bib file: " default-directory nil nil "refs.bib"))) + (make-directory (file-name-directory path) t) (unless (file-exists-p path) - (make-directory (file-name-directory path) t) (with-temp-file path - (insert (format "%% Bibliography: %s\n\n" (file-name-nondirectory path))))) + (insert (format "%% Bibliography: %s\n%% Add entries via SPC B s (search) or SPC B m (manual)\n\n" + (file-name-nondirectory path))))) (find-file path) - (message "Created %s — add #+BIBLIOGRAPHY: %s to your org file" path path))) + (message "Opened %s — search online (SPC B s) or add manual entry (SPC B m)" path))) -;; Helper: import from DOI (prompts for DOI, appends to current/global .bib) +;; Helper: import from DOI → appends to currently open .bib or global (defun my/bib-import-doi () - "Fetch BibTeX for a DOI and append to the current .bib or global references.bib." + "Fetch BibTeX for a DOI and insert at point (open a .bib file first)." (interactive) + (require 'biblio) (require 'biblio-doi) - (let* ((doi (read-string "DOI (e.g. 10.1145/2898442.2898444): ")) - (target (if (and buffer-file-name - (string-suffix-p ".bib" buffer-file-name)) - buffer-file-name - (car (ensure-list citar-bibliography))))) - (biblio-doi-insert-bibtex doi) - (message "Imported DOI %s" doi))) + (let ((doi (read-string "DOI: "))) + (biblio-doi-insert-bibtex doi))) +;; Helper: insert a manual BibTeX entry template +(defun my/bib-insert-manual () + "Insert a BibTeX entry template at point for manual editing." + (interactive) + (let ((type (completing-read "Entry type: " + '("article" "book" "inproceedings" "misc" "online" + "techreport" "thesis" "manual") nil t))) + (insert (pcase type + ("article" + "@article{KEY,\n author = {},\n title = {},\n journal = {},\n year = {},\n volume = {},\n pages = {},\n doi = {},\n}\n") + ("book" + "@book{KEY,\n author = {},\n title = {},\n publisher = {},\n year = {},\n isbn = {},\n}\n") + ("inproceedings" + "@inproceedings{KEY,\n author = {},\n title = {},\n booktitle = {},\n year = {},\n pages = {},\n doi = {},\n}\n") + ("misc" + "@misc{KEY,\n author = {},\n title = {},\n year = {},\n url = {},\n note = {},\n}\n") + ("online" + "@online{KEY,\n author = {},\n title = {},\n url = {},\n urldate = {},\n year = {},\n}\n") + ("techreport" + "@techreport{KEY,\n author = {},\n title = {},\n institution = {},\n year = {},\n number = {},\n}\n") + ("thesis" + "@thesis{KEY,\n author = {},\n title = {},\n school = {},\n year = {},\n type = {phdthesis},\n}\n") + ("manual" + "@manual{KEY,\n title = {},\n organization = {},\n year = {},\n url = {},\n}\n"))) + ;; Position cursor at KEY for immediate editing + (search-backward "KEY" nil t) + (message "Fill in KEY and fields. KEY = unique citation identifier (e.g. burns2016)."))) + +;; biblio-lookup is the universal search command (prompts for backend) +;; crossref-lookup, arxiv-lookup, dblp-lookup are backend-specific (map! :leader (:prefix ("B" . "bibliography") :desc "Browse references" "b" #'citar-open - :desc "Insert citation" "i" #'citar-insert-citation + :desc "Insert citation [cite:]" "i" #'citar-insert-citation :desc "Open notes for reference" "n" #'citar-open-notes :desc "Refresh bibliography" "r" #'citar-refresh :desc "New .bib file" "N" #'my/bib-new - :desc "Search CrossRef" "s" #'biblio-crossref-lookup - :desc "Search arXiv" "a" #'biblio-arxiv-lookup - :desc "Search DBLP" "d" #'biblio-dblp-lookup + :desc "Search online" "s" (cmd! (require 'biblio) (call-interactively #'biblio-lookup)) :desc "Import from DOI" "D" #'my/bib-import-doi + :desc "Insert manual entry" "m" #'my/bib-insert-manual :desc "Open global .bib" "f" (cmd! (find-file (expand-file-name "~/org/references.bib")))))