forked from mirrors/org-mode
org-latex-preview: Clear failed preview overlays
* lisp/org-latex-preview.el: (org-latex-preview-create-image-async): If preview images fail to generate for some or all LaTeX fragments, the overlays placed on the fragments during processing need to be cleared. This is done by adding a (failure) callback function to the image generation process. (org-latex-preview--failure-callback): Add callback that clears overlays for previews that fail to generate. Other behaviours are possible here but not implemented yet. This includes signalling failure by changing how the overlays are displayed, such as by adding a face or fringe marker.
This commit is contained in:
parent
daaa034cd0
commit
1194febb98
|
@ -948,6 +948,8 @@ during processing to hold more information on the fragments."
|
|||
(list ; The order is important here.
|
||||
#'org-latex-preview--check-all-fragments-produced
|
||||
#'org-latex-preview--cleanup-callback))
|
||||
(plist-put (cddr img-extract-async) :failure
|
||||
#'org-latex-preview--failure-callback)
|
||||
(pcase processing-type
|
||||
('dvipng
|
||||
(plist-put (cddr img-extract-async) :filter
|
||||
|
@ -965,6 +967,29 @@ during processing to hold more information on the fragments."
|
|||
(plist-put (cddr tex-compile-async) :failure img-extract-async))
|
||||
(org-async-call tex-compile-async))))
|
||||
|
||||
(defun org-latex-preview--failure-callback (_exit _buf extended-info)
|
||||
"Clear overlays corresponding to previews that failed to generate.
|
||||
|
||||
EXTENDED-INFO contains the information needed to identify such
|
||||
previews."
|
||||
(cl-loop for fragment in (plist-get extended-info :fragments)
|
||||
for path = (plist-get fragment :path)
|
||||
when (not path)
|
||||
for ov = (plist-get fragment :overlay)
|
||||
do
|
||||
;; ;TODO: Other options here include:
|
||||
;; ;Fringe marker
|
||||
;; (overlay-put ov 'before-string
|
||||
;; (propertize "!" 'display
|
||||
;; `(left-fringe exclamation-mark
|
||||
;; warning)))
|
||||
;; ;Special face
|
||||
;; (unless (overlay-get ov 'face)
|
||||
;; (overlay-put ov 'face 'org-latex-preview-processing-face))
|
||||
;;
|
||||
;; ;Note: ov has buffer extended-info, no need to set current-buffer
|
||||
(delete-overlay ov)))
|
||||
|
||||
(defun org-latex-preview--create-tex-file (processing-info fragments)
|
||||
"Create a LaTeX file based on PROCESSING-INFO and FRAGMENTS.
|
||||
|
||||
|
|
Loading…
Reference in New Issue