forked from mirrors/org-mode
org-latex-preview: Add hooks for customization
* lisp/org-latex-preview.el (org-latex-preview-process-finish-functions, org-latex-preview-update-overlay-hook, org-latex-preview-close-hook, org-latex-preview-open-hook, org-latex-preview--create-image-async, org-latex-preview-auto--handle-post-cursor, org-latex-preview--run-finish-functions): Add four hooks for better control of the LaTeX preview process. `org-latex-preview-process-finish-functions': Runs after the image conversion process. This is an abnormal hook: each hook function accepts the same arguments as other `org-async' callbacks for this process. `org-latex-preview-close-hook' and `org-latex-preview-open-hook': Run after a preview is closed (text hidden to reveal image) or opened (image hidden to reveal text) respectively. `org-latex-preview-update-overlay-functions': Run after a LaTeX preview overlay is updated with a new image. This is an abnormal hook: each hook function accepts one argument, the overlay that was updated. The "live" preview system introduced in the following commits uses these hooks, along with the facilities provided by `org-latex-preview-auto-mode'. In addition, these hooks will prove useful when writing code that reuse the API afforded by `org-latex-preview-place' to provide LaTeX previews for other major modes.
This commit is contained in:
parent
0f2943b10e
commit
3e648d95b6
|
@ -489,7 +489,8 @@ overlay face is set to `org-latex-preview-processing-face'."
|
|||
(overlay-put
|
||||
ov 'before-string
|
||||
(propertize "!" 'display
|
||||
`(left-fringe exclamation-mark error)))))))
|
||||
`(left-fringe exclamation-mark error))))))
|
||||
(run-hook-with-args 'org-latex-preview-update-overlay-functions ov))
|
||||
|
||||
(defun org-latex-preview--face-around (start end)
|
||||
"Return the relevant face symbol around the region START to END.
|
||||
|
@ -722,7 +723,8 @@ image and display its text."
|
|||
(overlay-put ov 'hidden-face f)
|
||||
(overlay-put ov 'face nil))
|
||||
(org-latex-preview-auto--move-into ov)
|
||||
(setq org-latex-preview-auto--from-overlay nil))))
|
||||
(setq org-latex-preview-auto--from-overlay nil)
|
||||
(run-hooks 'org-latex-preview-open-hook))))
|
||||
|
||||
(defun org-latex-preview-auto--close-previous-overlay ()
|
||||
"Close Org latex preview image overlays.
|
||||
|
@ -745,7 +747,8 @@ image. The preview image is regenerated if necessary."
|
|||
(unless (eq f 'org-latex-preview-processing-face)
|
||||
(overlay-put ov 'face f))
|
||||
(overlay-put ov 'hidden-face nil))
|
||||
(overlay-put ov 'display (overlay-get ov 'preview-image))))))
|
||||
(overlay-put ov 'display (overlay-get ov 'preview-image)))
|
||||
(run-hooks 'org-latex-preview-close-hook))))
|
||||
|
||||
(defun org-latex-preview-auto--regenerate-overlay (ov)
|
||||
"Regenerate the LaTeX fragment under overlay OV."
|
||||
|
@ -1349,6 +1352,12 @@ Returns a list of async tasks started."
|
|||
(format "Creating LaTeX preview images failed (exit code %%d). Please see %s for details"
|
||||
(propertize org-latex-preview--image-log 'face 'warning))
|
||||
#'org-latex-preview--cleanup-callback))
|
||||
(when org-latex-preview-process-finish-functions
|
||||
;; Extra callbacks to run after image generation
|
||||
(push #'org-latex-preview--run-finish-functions
|
||||
(plist-get (cddr img-extract-async) :success))
|
||||
(push #'org-latex-preview--run-finish-functions
|
||||
(plist-get (cddr img-extract-async) :failure)))
|
||||
(pcase processing-type
|
||||
('dvipng
|
||||
(plist-put (cddr img-extract-async) :filter
|
||||
|
@ -1370,6 +1379,12 @@ Returns a list of async tasks started."
|
|||
(plist-put (cddr tex-compile-async) :failure img-extract-async)
|
||||
(list (org-async-call tex-compile-async))))))
|
||||
|
||||
(defun org-latex-preview--run-finish-functions (&rest args)
|
||||
"Run hooks after preview image generation, with arguments ARGS."
|
||||
(apply #'run-hook-with-args
|
||||
'org-latex-preview-process-finish-functions
|
||||
args))
|
||||
|
||||
(defun org-latex-preview--failure-callback (_exit _buf extended-info)
|
||||
"Clear overlays corresponding to previews that failed to generate.
|
||||
|
||||
|
|
Loading…
Reference in New Issue