Hello both,

On 27/09/2025, Arash Esbati wrote:
> I think we have 3 points to address and then we can close this report:
>
> - Add a new test
> - Announce the changes in NEWS.org
> - Touch the docstring of `preview-watch-preamble' and describe the
>   optional out-file.

Please find the attached patch which should do all three. I based my
test off `tests/japanese/preview-latex.el`, but I haven't written a
auctex test before, so let me know if I am missing anything.

The test should fail an old version of auctex (without the commit
d151b5c9), but should succeed in the new one.

Best regards,
-- Al

>From 90242bad8a0f0ccdcfc1e408bd286d13f2f12f77 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.
* 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                        |  8 ++--
 tests/latex/preview-latex-test.el | 69 +++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 4 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..6ab43ed7 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)))
diff --git a/tests/latex/preview-latex-test.el b/tests/latex/preview-latex-test.el
index 8c7d8314..0fd00cd3 100644
--- a/tests/latex/preview-latex-test.el
+++ b/tests/latex/preview-latex-test.el
@@ -24,6 +24,10 @@
 (require 'ert)
 (require 'preview)
 
+(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.
 If a utf-8 byte sequence is partially ^^-quoted in latex output, we have
@@ -42,6 +46,71 @@ 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'."
+  (skip-unless (not noninteractive))
+  (let ((TeX-clean-confirm nil)
+        (preview-auto-cache-preamble nil)
+        (process-environment (copy-sequence process-environment))
+        (TeX-output-dir "auctex-output")
+        buffer1 buffer2)
+    (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...")
+          (with-current-buffer buffer1
+            (while (get-buffer-process (TeX-process-buffer-name
+                                        (TeX-master-file)))
+              (sleep-for 1)))
+          ;; Actually, this type of trouble seems to be captured early by
+          ;; ert mechanism as error and not to reach here.
+          (should-not (string-match "error in process sentinel:"
+                                    (current-message)))
+          (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