Hello Arash & Ikumi,
On 25/09/2025, Arash Esbati wrote: >> Hmm. If I understand correctly, it is no longer possible to keep the >> compatibility of the structure of (each element of) >> `preview-dumped-alist' anyway, right? Yes exactly. Any user code that accessed these elements using CD*R functions would break no matter where the output-file is placed. > Thanks for looking at this. So, we have to bite the bullet. Should I > install the patch provided upthread? We can then add something about it > to NEWS.org. I am not sure if you still want the change so that at least the function `preview-watch-preamble` is backward compatible. I am attaching that version here in any case. Otherwise, this patch still saves the output-file as the cadr of elements of `preview-dumped-alist`. Best regards, -- Al
>From 66aeac66585adff29e5060e0eb8f8a60a20f2962 Mon Sep 17 00:00:00 2001 From: Al Haji-Ali <a.haji...@hw.ac.uk> Date: Wed, 3 Sep 2025 21:56:08 +0100 Subject: [PATCH] preview: Save ini files inside TeX-output-dir * preview.el (preview-dumped-alist): Change format to include output file. (preview-watch-preamble): Accept output file as argument to save in format-cons. (preview-unwatch-preamble, preview-mode-setup): Accommodate changes of format-cons above. (preview-format-kill): Delete output file. (preview-cache-preamble): Use TeX-master-output-file instead of TeX-master-output for ini file. --- preview.el | 77 +++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/preview.el b/preview.el index bb0f8ee9..cbad6b97 100644 --- a/preview.el +++ b/preview.el @@ -1898,7 +1898,7 @@ definition of OV, AFTER-CHANGE, BEG, END and LENGTH." (preview-format-kill format-cons) (setcdr format-cons t))) -(defun preview-watch-preamble (file command format-cons) +(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. @@ -1906,32 +1906,35 @@ FORMAT-CONS contains the format info for the main format dump handler." (let ((buffer (if (bufferp file) file - (find-buffer-visiting file))) ov) + (find-buffer-visiting file))) + ov) (setcdr format-cons - (cons command - (when buffer - (with-current-buffer buffer - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (unless (re-search-forward preview-dump-threshold nil t) - (error "Can't find preamble of `%s'" file)) - (setq ov (make-overlay (point-min) (point))) - (overlay-put ov 'format-cons format-cons) - (overlay-put ov 'insert-in-front-hooks - '(preview-preamble-changed-function)) - (overlay-put ov 'modification-hooks - '(preview-preamble-changed-function)) - ov)))))))) + (cl-list* + (or out-file file) + command + (when buffer + (with-current-buffer buffer + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (unless (re-search-forward preview-dump-threshold nil t) + (error "Can't find preamble of `%s'" file)) + (setq ov (make-overlay (point-min) (point))) + (overlay-put ov 'format-cons format-cons) + (overlay-put ov 'insert-in-front-hooks + '(preview-preamble-changed-function)) + (overlay-put ov 'modification-hooks + '(preview-preamble-changed-function)) + ov)))))))) (defun preview-unwatch-preamble (format-cons) "Stop watching a format on FORMAT-CONS. The watch has been set up by `preview-watch-preamble'." (when (consp (cdr format-cons)) - (when (cddr format-cons) - (delete-overlay (cddr format-cons))) + (when (cdddr format-cons) + (delete-overlay (cdddr format-cons))) (setcdr (cdr format-cons) nil))) (defun preview-register-change (ov) @@ -2498,10 +2501,10 @@ The elements are (NAME . ASSOC). NAME is the master file name format. Possible values: nil means no format is available and none should be generated. t means no format is available, it should be generated on demand. If the value is a cons cell, -the CAR of the cons cell is the command with which the format -has been generated, and the CDR is some Emacs-flavor specific -value used for maintaining a watch on possible changes of the -preamble.") +the CAR of the cons cell is the name of output master file, the CADR of +the cons cell is the command with which the format has been generated, +and the CDDR is some Emacs-flavor specific value used for maintaining a +watch on possible changes of the preamble.") (defun preview-cleanout-tempfiles () "Clean out all directories and files with non-persistent data. @@ -3156,8 +3159,9 @@ pp") (when (consp (cdr format-cons)) (preview-unwatch-preamble format-cons) (preview-watch-preamble (current-buffer) - (cadr format-cons) - format-cons))))) + (caddr format-cons) + format-cons + (cadr format-cons)))))) ;;;###autoload (defun LaTeX-preview-setup () @@ -3996,10 +4000,11 @@ Those are just needed for cleanup." "Kill a cached format. FORMAT-CONS is intended to be an element of `preview-dumped-alist'. Tries through `preview-format-extensions'." - (dolist (ext preview-format-extensions) - (condition-case nil - (delete-file (preview-dump-file-name (concat (car format-cons) ext))) - (file-error nil)))) + (when (consp (cdr format-cons)) + (dolist (ext preview-format-extensions) + (condition-case nil + (delete-file (preview-dump-file-name (concat (cadr format-cons) ext))) + (file-error nil))))) (defun preview-dump-file-name (file) "Make a file name suitable for dumping from FILE." @@ -4101,20 +4106,21 @@ If FORMAT-CONS is non-nil, a previous format may get reused." (interactive) (setq TeX-current-process-region-p nil) (let* ((dump-file - (expand-file-name (preview-dump-file-name (TeX-master-file "ini")))) + (expand-file-name (preview-dump-file-name (TeX-master-output-file "ini")))) (master (TeX-master-file)) (format-name (expand-file-name master)) (preview-format-name (shell-quote-argument - (preview-dump-file-name (file-name-nondirectory - master)))) + (preview-dump-file-name + (TeX-master-output-file nil)))) (master-file (expand-file-name (TeX-master-file t))) + (master-output-file (expand-file-name (TeX-master-output-file nil))) (command (preview-do-replacements (TeX-command-expand (preview-string-expand preview-LaTeX-command)) preview-dump-replacements)) (preview-auto-cache-preamble nil)) (unless (and (consp (cdr format-cons)) - (string= command (cadr format-cons))) + (string= command (caddr format-cons))) (unless format-cons (setq format-cons (assoc format-name preview-dumped-alist))) (if format-cons @@ -4162,7 +4168,8 @@ If FORMAT-CONS is non-nil, a previous format may get reused." (preview-watch-preamble master-file command - format-cons) + format-cons + master-output-file) (preview-format-kill format-cons)) (delete-file dump-file)) (error (preview-log-error err "Dumping" process))) -- 2.39.5 (Apple Git-154)
_______________________________________________ bug-auctex mailing list bug-auctex@gnu.org https://lists.gnu.org/mailman/listinfo/bug-auctex