Hello again,

On 29/09/2025, Al Haji-Ali wrote:
> That was what I tried first. Unfortunately, running in batch mode would 
> require further investigations and changes.

Here's another patch that allows running the test in batch-mode.

As you can see, I had to modify `preview-get-dpi` to handle nil
dimensions which are returned in batch-mode, but I don't know if this
could possibly have other consequences if run interactively (it would
have thrown an error before).

-- Al
>From a034a594e7f5940a5f353b9278e38b53c2bc56db Mon Sep 17 00:00:00 2001
From: Al Haji-Ali <[email protected]>
Date: Sat, 27 Sep 2025 21:56:01 +0200
Subject: [PATCH] Add missing documentation and test related to
 `preview-watch-preamble'.

* NEWS.org: Record changes related to `preview-dumped-alist' and
`preview-watch-preamble'.
* preview.el (preview-watch-preamble): Add missing documentation for
optional argument.
(preview-get-dpi): Handle nil dimensions for batch mode.
* tests/latex/preview-latex-test.el (preview-cache-preamble): Add test
for `preview-cache-preamble' with non-nil `TeX-output-dir'.
---
 NEWS.org                          |  4 ++
 preview.el                        | 12 +++---
 tests/latex/preview-latex-test.el | 68 +++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 6 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index d17064e0..2df87479 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -17,6 +17,10 @@
 
 - Add new support file =style/fontawesome7.el=.
 
+** Changed
+- Change the format of ~preview-dumped-alist~ and add new optional
+  argument to ~preview-watch-preamble~.
+
 * [14.1.0] - 2025-07-11
 
 ** Added
diff --git a/preview.el b/preview.el
index fc0b7566..0b1d1207 100644
--- a/preview.el
+++ b/preview.el
@@ -1900,10 +1900,10 @@ definition of OV, AFTER-CHANGE, BEG, END and LENGTH."
 
 (defun preview-watch-preamble (file command format-cons &optional out-file)
   "Set up a watch on master file FILE.
-FILE can be an associated buffer instead of a filename.
-COMMAND is the command that generated the format.
-FORMAT-CONS contains the format info for the main
-format dump handler."
+FILE can be an associated buffer instead of a filename.  COMMAND is the
+command that generated the format.  FORMAT-CONS contains the format info
+for the main format dump handler. If OUT-FILE is non-nil it is used
+instead of FILE to determine the dump-files."
   (let ((buffer (if (bufferp file)
                     file
                   (find-buffer-visiting file)))
@@ -3778,8 +3778,8 @@ name(\\([^)]+\\))\\)\\|\
 (defun preview-get-dpi ()
   (let* ((monitor-attrs (frame-monitor-attributes))
          (mm-dims (cdr (assoc 'mm-size monitor-attrs)))
-         (mm-width (nth 0 mm-dims))
-         (mm-height (nth 1 mm-dims))
+         (mm-width (or (nth 0 mm-dims) 1))
+         (mm-height (or (nth 1 mm-dims) 1))
          (pixel-dims (cl-cdddr (assoc 'geometry monitor-attrs)))
          (pixel-width (nth 0 pixel-dims))
          (pixel-height (nth 1 pixel-dims)))
diff --git a/tests/latex/preview-latex-test.el b/tests/latex/preview-latex-test.el
index 8c7d8314..8b69bb2e 100644
--- a/tests/latex/preview-latex-test.el
+++ b/tests/latex/preview-latex-test.el
@@ -23,6 +23,11 @@
 
 (require 'ert)
 (require 'preview)
+(require 'font-latex)
+
+(AUCTeX-set-ert-path
+ 'preview-test-file
+ "../../circ.tex")
 
 (ert-deftest preview-error-quote-utf-8 ()
   "`preview-error-quote' is robust against partial ^^-quoting or not.
@@ -42,6 +47,69 @@ emacs' coding system later."
   (dolist (str '("prim\xC3\xA1rias" "prim^^c3\xA1rias" "prim^^c3^^a1rias"))
     (should (string= (preview--decode-^^ab str 'utf-8) "primárias"))))
 
+(ert-deftest preview-cache-preamble ()
+  "Test caching of preamble with non-nil `TeX-output-dir'."
+  (let ((TeX-clean-confirm nil)
+        (preview-auto-cache-preamble nil)
+        (process-environment (copy-sequence process-environment))
+        (TeX-output-dir "auctex-output")
+        buffer1 buffer2
+        (pt-msg (with-current-buffer (messages-buffer) (point))))
+    (unwind-protect
+        (save-window-excursion
+          (setq buffer1 (find-file preview-test-file))
+          (delete-other-windows)
+          (preview-cache-preamble)
+          (setq buffer2 (TeX-active-buffer))
+          (message "Please wait for asynchronous process to finish...")
+          (while (get-buffer-process buffer2)
+            (sleep-for 1))
+          (should-error
+           (with-current-buffer (messages-buffer)
+             (goto-char pt-msg)
+             (search-forward "error in process sentinel:")))
+          (message "Please wait for asynchronous process to finish...done")
+
+          (with-current-buffer buffer1
+            ;; ini file should be deleted
+            (should-not
+             (or
+              (file-exists-p
+               (expand-file-name
+                (TeX-master-output-file "ini")))
+              (file-exists-p
+               (expand-file-name
+                (TeX-master-file "ini")))))
+            ;; fmt file should be in output-directory
+            (should
+             (file-exists-p
+              (expand-file-name
+               (preview-dump-file-name
+                (TeX-master-output-file "fmt")))))
+            ;; and not be in master directory
+            (should-not
+             (file-exists-p
+              (expand-file-name
+               (preview-dump-file-name
+                (TeX-master-file "fmt")))))))
+      ;; Cleanup.
+      (if (buffer-live-p buffer2)
+          (kill-buffer buffer2))
+      (when (buffer-live-p buffer1)
+        (set-buffer buffer1)
+        (TeX-clean t) ;; delete the log files
+        (preview-cache-preamble-off)
+
+        ;; Check clean-up
+        (should-not
+         (file-exists-p
+          (expand-file-name
+           (preview-dump-file-name
+            (TeX-master-output-file "fmt")))))
+
+        (delete-directory (expand-file-name TeX-output-dir))
+        (kill-buffer buffer1)))))
+
 ;;; preview-latex-test.el ends here
 
 ;; Local Variables:
-- 
2.50.1 (Apple Git-155)

_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex

Reply via email to