org-latex-preview: Guard against caching nil-files

* lisp/org-latex-preview.el (org-latex-preview--cache-image): When
caching an image with `org-latex-preview--cache-image', check that the
image path is non-nil.  Should this not be true, a warning message is
emitted suggesting this is a bug that should be reported to the Org
mailing list.
This commit is contained in:
TEC 2023-02-27 18:35:36 +08:00
parent c769032876
commit 13888aeeb3
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 21 additions and 13 deletions

View File

@ -1968,18 +1968,26 @@ Return (path . info).
The caching location depends on whether preview persistence is
enabled, see `org-latex-preview-persist'."
(if org-latex-preview-persist
(let ((label-path-info
(or (org-persist-read org-latex-preview--cache-name
(list :key key)
nil nil :read-related t)
(org-persist-register `(,org-latex-preview--cache-name
(file ,path)
(elisp-data ,info))
(list :key key)
:expiry org-latex-preview-persist-expiry
:write-immediately t))))
(cons (cadr label-path-info) info))
(cond
((not path)
(ignore
(display-warning
'(org latex-preview put-cache)
(format "Tried to cache %S without a path, skipping. This should not happen, please report it as a bug to the Org mailing list (M-x org-submit-bug-report)." key)
:warning)))
(org-latex-preview-persist
(let ((label-path-info
(or (org-persist-read org-latex-preview--cache-name
(list :key key)
nil nil :read-related t)
(org-persist-register `(,org-latex-preview--cache-name
(file ,path)
(elisp-data ,info))
(list :key key)
:expiry org-latex-preview-persist-expiry
:write-immediately t))))
(cons (cadr label-path-info) info)))
(t
(unless org-latex-preview--table
(setq org-latex-preview--table (make-hash-table :test 'equal :size 240)))
(when-let ((path)
@ -1988,7 +1996,7 @@ enabled, see `org-latex-preview-persist'."
temporary-file-directory)))
(copy-file path new-path 'replace)
(puthash key (cons new-path info)
org-latex-preview--table))))
org-latex-preview--table)))))
(defun org-latex-preview--get-cached (key)
"Retrieve the image path and info associated with KEY.