org-latex-preview: Make clear-cache user-friendly

* lisp/org-latex-preview.el (org-latex-preview-clear-cache): Ask for
confirmation before wiping the entire LaTeX preview cache, and confirm
cache clearing at the end when clearing the buffer cache.
This commit is contained in:
Karthik Chikmagalur 2023-01-06 01:52:50 -08:00 committed by TEC
parent b8e2f65cee
commit daaa034cd0
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 10 additions and 9 deletions

View File

@ -1416,7 +1416,7 @@ When CLEAR-ENTIRE-CACHE is non-nil (interactively set by \\[universal-argument])
the *entire* preview cache will be cleared, and `org-persist-gc' run."
(interactive
(if current-prefix-arg
'(nil nil t)
(list nil nil (y-or-n-p "This will clear the systemwide LaTeX preview cache, continue? "))
(let ((context (if (derived-mode-p 'org-mode)
(org-element-context)
(user-error "This command must be run in an org-mode buffer"))))
@ -1427,7 +1427,7 @@ the *entire* preview cache will be cleared, and `org-persist-gc' run."
'(latex-fragment latex-environment))
(list (org-element-property :begin context)
(org-element-property :end context)))
(t (list (point-min) (point-max)))))))
(t (list nil nil))))))
(org-latex-preview-clear-overlays beg end)
(if clear-entire-cache
(let ((n 0))
@ -1441,10 +1441,11 @@ the *entire* preview cache will be cleared, and `org-persist-gc' run."
(message "The Org LaTeX preview cache was already empty.")
(org-persist-gc)
(message "Cleared all %d entries fom the Org LaTeX preview cache." n)))
(let* ((imagetype (or (plist-get (alist-get org-latex-preview-default-process
org-latex-preview-process-alist)
:image-output-type)
"png")))
(let ((imagetype
(or (plist-get (alist-get org-latex-preview-default-process
org-latex-preview-process-alist)
:image-output-type)
"png")))
(dolist (element (org-latex-preview-collect-fragments beg end))
(pcase-let* ((begin (org-element-property :begin element))
(`(,fg ,bg) (org-latex-preview--colors-at begin))
@ -1452,9 +1453,9 @@ the *entire* preview cache will be cleared, and `org-persist-gc' run."
(org-latex-preview--remove-cached
(org-latex-preview--hash
org-latex-preview-default-process
value
imagetype
fg bg)))))))
value imagetype fg bg))))
(message "Cleared LaTeX preview cache for %s."
(if (or beg end) "region" "buffer")))))
;; TODO: Switching processes from imagemagick to dvi* with an existing
;; dump-file during a single Emacs session should trigger