Skip to content

feat: Add option to preserve TeX markup in cache #865

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 11 additions & 8 deletions citar-cache.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(declare-function citar--prepend-candidate-citekey "citar" (citekey candidate))

(defvar citar-ellipsis)
(defvar citar-cache-preserve-markup)

;;; Variables:

Expand Down Expand Up @@ -189,11 +190,11 @@ needed by any other buffer."

(defun citar-cache--get-bibliography-props (filename &optional oldprops)
"Return attributes to decide if bibliography FILENAME needs to be updated.
Return a plist with keys :size, :mtime, :hash, and :fields.
OLDPROPS, if given, should be a plist with the same keys. If
FILENAME has the same size and modification time as in OLDPROPS,
then assume that the hash value is also the same without
re-hashing the file contents."
Return a plist with keys :size, :mtime, :hash, :fields, and
:preserve-markup. OLDPROPS, if given, should be a plist with the
same keys. If FILENAME has the same size and modification time
as in OLDPROPS, then assume that the hash value is also the same
without re-hashing the file contents."
(let* ((remote-file-name-inhibit-cache t)
(attr (file-attributes filename 'integer))
(size (file-attribute-size attr))
Expand All @@ -207,7 +208,8 @@ re-hashing the file contents."
(with-temp-buffer
(insert-file-contents filename)
(buffer-hash)))))
`(:size ,size :mtime ,mtime :hash ,hash :fields ,fields)))
`(:size ,size :mtime ,mtime :hash ,hash :fields ,fields
:preserve-markup ,citar-cache-preserve-markup)))

(defun citar-cache--update-bibliography-p (oldprops newprops)
"Return whether bibliography needs to be updated.
Expand All @@ -216,7 +218,8 @@ contents have changed or the list of bibliography fields to be
parsed is different."
(not (and (equal (plist-get oldprops :size) (plist-get newprops :size))
(equal (plist-get oldprops :hash) (plist-get newprops :hash))
(equal (plist-get oldprops :fields) (plist-get newprops :fields)))))
(equal (plist-get oldprops :fields) (plist-get newprops :fields))
(equal (plist-get oldprops :preserve-markup) (plist-get newprops :preserve-markup)))))

(defun citar-cache--update-bibliography (bib &optional props)
"Update the bibliography BIB from the original file.
Expand All @@ -236,7 +239,7 @@ After updating, the `props' slot of BIB is set to PROPS."
(message "%s..." messagestr)
(redisplay) ; Make sure message is displayed before Emacs gets busy parsing
(clrhash entries)
(parsebib-parse filename :entries entries)
(parsebib-parse filename :entries entries :display (not citar-cache-preserve-markup))
(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
9 changes: 9 additions & 0 deletions citar.el
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ specifies additional fields to include."
:group 'citar
:type '(repeat string))

(defcustom citar-cache-preserve-markup nil
"When non-nil, preserve TeX markup in bibliography fields.

This can be useful for preserving capitalization in titles, for
example, but it may have a performance impact when caching large
bibliographies."
:group 'citar
:type 'boolean)

;;;; Displaying completions and formatting

(defcustom citar-templates
Expand Down
Loading