emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/preview-auto f07b210e05 10/36: Allow automatic refresh


From: ELPA Syncer
Subject: [elpa] externals/preview-auto f07b210e05 10/36: Allow automatic refresh of previews after compilation
Date: Thu, 6 Jun 2024 03:59:52 -0400 (EDT)

branch: externals/preview-auto
commit f07b210e05c7378d39e38947f91e2e70d14c9f8f
Author: Paul Nelson <ultrono@gmail.com>
Commit: Paul Nelson <ultrono@gmail.com>

    Allow automatic refresh of previews after compilation
    
    * preview-auto.el (preview-auto-refresh-after-compilation): New
    variable.
    (preview-auto--already-previewed-at): Use it.
    
    This combines well with the tex-numbers and tex-continuous package to
    give live updates of equation numbers in previews.
---
 preview-auto.el | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/preview-auto.el b/preview-auto.el
index d9b2150cad..dc5d1f8096 100644
--- a/preview-auto.el
+++ b/preview-auto.el
@@ -136,12 +136,33 @@ Ignore comments and verbatim environments."
       (when (not (preview-auto--cheap-comment))
         (throw 'found (point))))))
 
-(defun preview-auto--already-previewed-at (pos)
-  "Return non-nil when there a non-disabled preview overlay at POS."
-  (cl-intersection (mapcar (lambda (ov)
-                             (overlay-get ov 'preview-state))
-                           (overlays-at (or pos (point))))
-                   '(active inactive)))
+(defcustom preview-auto-refresh-after-compilation t
+  "If non-nil, refresh previews after each compilation.
+This plays well with the packages `tex-numbers' and `tex-continuous':
+the result is that preview equation numbers are updated automatically to
+the correct form."
+  :type 'boolean)
+
+(defun preview-auto--already-previewed-at (&optional pos)
+  "Return non-nil when there is a non-disabled preview overlay at POS.
+A preview is considered non-disabled if it is active or inactive
+according to `preview.el'.  If `preview-auto-refresh-after-compilation'
+is non-nil, then we further require that the preview has been generated
+more recently than the aux file."
+  (cl-some
+   (lambda (ov)
+     (and
+      (memq (overlay-get ov 'preview-state) '(active inactive))
+      (or (null preview-auto-refresh-after-compilation)
+          (let* ((image (overlay-get ov 'preview-image))
+                 (image-file (nth 1 image))
+                 (image-time (nth 5 (file-attributes image-file)))
+                 (aux-file (TeX-master-file "aux"))
+                 (aux-time (nth 5 (file-attributes aux-file))))
+            (or (null image-time)
+                (null aux-time)
+                (time-less-p aux-time image-time))))))
+   (overlays-at (or pos (point)))))
 
 (defcustom preview-auto-predicate nil
   "Additional predicate for determining preview validity.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]