GNU bug report logs -
#70295
[PATCH] Allow preprocessing of previews
Previous Next
Reported by: Paul Nelson <ultrono <at> gmail.com>
Date: Tue, 9 Apr 2024 03:20:04 UTC
Severity: normal
Tags: patch
Done: Arash Esbati <arash <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 70295 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
Paul Nelson <ultrono <at> gmail.com> writes:
> The attached patch introduces an optional preprocessing step to
> preview-region.
>
> As motivation, I've been using such functionality (implemented via
> advice) in https://github.com/ultronozm/czm-preview.el to give correct
> equation numbers in previews. This patch would allow me to excise the
> advice.
Thanks, the change is non-intrusive enough so I don't see why we should
not install it.
> From 417c9e465b4d0cd507e122268c8caad8d74d76f3 Mon Sep 17 00:00:00 2001
> From: Paul Nelson <ultrono <at> gmail.com>
> Date: Tue, 9 Apr 2024 05:04:56 +0200
> Subject: [PATCH] Allow preprocessing of previews
>
> * preview.el.in (preview--preprocess-function): New variable.
> (preview-region): Use the new variable (if non-nil) to
> preprocess the region being previewed.
> ---
> preview.el.in | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/preview.el.in b/preview.el.in
> index 95410439..6afff5b9 100644
> --- a/preview.el.in
> +++ b/preview.el.in
> @@ -4030,6 +4030,9 @@ stored in `preview-dumped-alist'."
> (preview-format-kill old-format)
> (setcdr old-format nil))
>
> +(defvar preview--preprocess-function nil
> + "Function used to preprocess region before previewing.")
This variable will be set by your package, right? Then it doesn't make
sense to me to declare it as an internal one. What do you think about
something like this:
(defvar preview-preprocess-function nil
"Function used to preprocess region before previewing.
The function bound to this variable will be called inside
`preview-region' with one argument which is a string.")
> (defun preview-region (begin end)
> "Run preview on region between BEGIN and END."
> (interactive "r")
> @@ -4038,7 +4041,10 @@ stored in `preview-dumped-alist'."
> (concat (preview--counter-information begin)
> TeX-region-extra)))
> (TeX-region-create (TeX-region-file TeX-default-extension)
> - (buffer-substring-no-properties begin end)
> + (let ((str (buffer-substring-no-properties begin end)))
> + (if preview--preprocess-function
> + (funcall preview--preprocess-function str)
Need to be adjusted then.
> + str))
> (if buffer-file-name
> (file-name-nondirectory buffer-file-name)
> "<none>")
WDYT? Best, Arash
This bug report was last modified 1 year and 103 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.