From de4fb9de1124f330d0fddcecc4cffb574486bda4 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 14 Jan 2024 02:42:32 +0800 Subject: [PATCH] org-latex-preview: Accommodate a flaky cache * lisp/org-latex-preview.el (org-latex-preview--get-cached): When using persist, occasionally we need to be more careful about assuming that cache entries exist. --- lisp/org-latex-preview.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 83cb8e062..603475dc3 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -2731,8 +2731,17 @@ Example result: (org-persist-read org-latex-preview--cache-name (list :key key) nil nil :read-related t))) - (cons (cadr label-path-info) - (caddr label-path-info)))) + ;; While /in theory/ this check isn't needed, sometimes the + ;; org-persist cache can be modified outside the current Emacs + ;; process. When this occurs the metadata of the fragment can + ;; still exist in `org-persist--index', but the image file is + ;; gone. This condition can be detected by checking if the + ;; `cadr' is nil (indicating the image has gone AWOL). + (if (cadr label-path-info) + (cons (cadr label-path-info) + (caddr label-path-info)) + (org-latex-preview--remove-cached key) + nil))) (org-latex-preview--table (gethash key org-latex-preview--table))))