From 239f8c5d534a4791a1e43b73a48f04acec2b9b00 Mon Sep 17 00:00:00 2001 From: Bruce D'Arcus Date: Tue, 14 Mar 2023 07:55:18 -0400 Subject: [PATCH 1/2] cache: Don't restrict fields parsed Ideally, we want citeproc to be able to use our cache. So we don't want to throw out data it may need. Close #741 --- citar-cache.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/citar-cache.el b/citar-cache.el index 15e5cb57..676d8b13 100644 --- a/citar-cache.el +++ b/citar-cache.el @@ -227,9 +227,7 @@ use the value returned by that function. This argument is provided in case that function has already been called so that its return value can be reused. -Only the bibliography fields listed in the :fields value of PROPS -are parsed. After updating, the `props' slot of BIB is set to -PROPS." +After updating, the `props' slot of BIB is set to PROPS." (let* ((filename (citar-cache--bibliography-filename bib)) (props (or props (citar-cache--get-bibliography-props filename))) (entries (citar-cache--bibliography-entries bib)) @@ -238,7 +236,7 @@ PROPS." (message "%s..." messagestr) (redisplay) ; Make sure message is displayed before Emacs gets busy parsing (clrhash entries) - (parsebib-parse filename :entries entries :fields (plist-get props :fields)) + (parsebib-parse filename :entries entries) (setf (citar-cache--bibliography-props bib) props) (citar-cache--preformat-bibliography bib) (message "%s...done (%.3f seconds)" messagestr (float-time (time-since starttime))))) From 4dae0c66c0cf722e1d0ef7510bd340f4343d8a9f Mon Sep 17 00:00:00 2001 From: Bruce D'Arcus Date: Tue, 14 Mar 2023 07:56:46 -0400 Subject: [PATCH 2/2] citeproc: Use Citar cache Close #702 --- citar-citeproc.el | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/citar-citeproc.el b/citar-citeproc.el index 84dfe4bf..00742025 100644 --- a/citar-citeproc.el +++ b/citar-citeproc.el @@ -100,9 +100,8 @@ STYLE is a CSL style as a path or a string." citar-citeproc-csl-style (expand-file-name citar-citeproc-csl-style citar-citeproc-csl-styles-dir)))) - (bibs (citar--bibliography-files)) (proc (citeproc-create style - (citeproc-hash-itemgetter-from-any bibs) + #'citar-citeproc--itemgetter (citeproc-locale-getter-from-dir citar-citeproc-csl-locales-dir) "en-US")) (references (car (progn @@ -110,5 +109,35 @@ STYLE is a CSL style as a path or a string." (citeproc-render-bib proc 'plain))))) references)) +;; from org-cite-csl-activate; AndrĂ¡s Simonyi +(defun citar-citeproc--cslize-special-vars (entry) + "Convert bibtex format name and date field values in ENTRY to CSL." + (mapcar + (pcase-lambda (`(,var . ,value)) + (cons var + (cond ((memq var citeproc--date-vars) (citeproc-bt--to-csl-date value nil)) + ((memq var citeproc--name-vars) (citeproc-bt--to-csl-names value)) + (t value)))) + entry)) + +(defun citar-citeproc--csl-from-entry (entry) + "Return a CSL version of ENTRY." + (pcase (caar entry) + ('nil nil) + ;; If keys are strings then it is a bib(la)tex entry, which has to be converted + ;; to CSL. + ((pred stringp) (citeproc-blt-entry-to-csl entry)) + ;; Symbol keys indicate CSL entries, only special vars are converted. + ((pred symbolp) (citar-citeproc--cslize-special-vars entry)) + (_ (error "Bib entry with unknown format: %s" entry)))) + +(defun citar-citeproc--itemgetter (keys) + "Return itemdata for KEYS from the citar cache." + (mapcar + (lambda (key) + (let ((citar-entry (citar-get-entry key))) + (cons key (citar-citeproc--csl-from-entry citar-entry)))) + keys)) + (provide 'citar-citeproc) ;;; citar-citeproc.el ends here