Subject: bug#70455: [PATCH] Add new user option `preview-leave-open-previews-visible'

From: Arash Esbati <[email-masked]>
Date: Mon, 22 Apr 2024 09:24:17 +0200

Hi Paul,

Paul Nelson <[email-masked]> writes:

> With the new user option disabled (default), behavior is exactly as before:
>
> - When you enter a preview, it is temporarily replaced by a
> placeholder icon together with the tex code.
> - If you exit the preview without editing, the preview reappears and
> the tex code disappears.
> - When you edit the tex code, the preview is gone forever.
> - When you regenerate a preview, a construction sign briefly appears.
>
> With the new user option disabled, behavior is instead:
>
> - When you enter a preview, it remains visible.  The tex code appears
> below the preview.
> - When you edit the tex code, the preview does not disappear.  The tex
> code persists if you then exit.
> - When you regenerate a preview, there is no construction sign, but
> instead a direct transition from the old image to the new one.
>
> The advantage is that while editing a formula, you (and anyone else
> watching your screen) can continue to look at its rendered form.  If
> the user option "preview-protect-point" is active, then a quick "C-c
> C-p C-p" or "C-c C-p C-e" will update the rendered form, without
> flickering.
>
> I would welcome suggestions for better names than
> `preview-leave-open-previews-visible'.
> [...]
>  (defun preview-gs-place (ov snippet box run-buffer tempdir ps-file _imagetype)
>    "Generate an image placeholder rendered over by Ghostscript.
>  This enters OV into all proper queues in order to make it render
> @@ -1231,7 +1238,17 @@ for the file extension."
>    (overlay-put ov 'queued
>                 (vector box nil snippet))
>    (overlay-put ov 'preview-image
> -               (list (preview-icon-copy preview-nonready-icon)))
> +               (let ((default (list (preview-icon-copy preview-nonready-icon))))
> +                 (if preview-leave-open-previews-visible
> +                     (if-let ((ovr (cl-find-if
> +                                    (lambda (ovr)
> +                                      (and
> +                                       (eq (overlay-start ovr) (overlay-start ov))
> +                                       (overlay-get ovr 'preview-image)))
> +                                    (overlays-at (overlay-start ov)))))
> +                         (overlay-get ovr 'preview-image)
> +                       default)
> +                   default)))

I don't have a suggestion for a better name, but another comment.  Your
patch uses `cl-find-if' which is a function.  Until now, we used only
macros from the cl-lib inside AUCTeX in order to have no other runtime
dependencies.  In general, I have no problem if we lift this limitation
and use cl-lib functions as well -- the library is part of Emacs and why
not use it.  But before we do this, I'd like to hear from Keita and
Tassilo what they think about this.

Best, Arash