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.
This commit is contained in:
TEC 2024-01-14 02:42:32 +08:00
parent 59f4ba2111
commit de4fb9de11
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 11 additions and 2 deletions

View File

@ -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))))