8000 Don't throw out field data; use cache for citeproc by bdarcus · Pull Request #742 · emacs-citar/citar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't throw out field data; use cache for citeproc #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions citar-cache.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)))))
Expand Down
33 changes: 31 additions & 2 deletions citar-citeproc.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,44 @@ 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
(citeproc-add-uncited keys proc)
(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
0