From faccbc04e9adaf8deb862426214eb35b3efadb59 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Mon, 2 Jan 2023 02:03:11 -0800 Subject: [PATCH] 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. --- lisp/org-latex-preview.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 3aae697db..570fff4b6 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -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)