org-latex-preview: Avoid duplicating cached images

* lisp/org-latex-preview.el (org-latex-preview--cache-image): When
caching an image, check if there is already an entry in the
`org-persist--index' with the same hash as this one.  This avoids
missing preview images for fragments with duplicates in a buffer, or
across org-persist's cache.  Without this measure, when we try to
register two fragments identified by the same hash,
`org-persist-register' returns a structure with the correct metadata
for both, but with the cached image path field missing for the second
fragment.
This commit is contained in:
Karthik Chikmagalur 2023-01-02 02:03:11 -08:00 committed by TEC
parent 18095e6578
commit faccbc04e9
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 7 additions and 4 deletions

View File

@ -1199,11 +1199,14 @@ listed in EXTENDED-INFO will be used."
"Save the image at PATH with associated INFO in the cache indexed by KEY.
Return (path . info)."
(let ((label-path-info
(org-persist-register `("LaTeX preview cached image data"
(file ,path)
(elisp-data ,info))
(or (org-persist-read "LaTeX preview cached image data"
(list :key key)
:write-immediately t)))
nil nil :read-related t)
(org-persist-register `("LaTeX preview cached image data"
(file ,path)
(elisp-data ,info))
(list :key key)
:write-immediately t))))
(cons (cadr label-path-info) info)))
(defun org-latex-preview--get-cached (key)