Subject: bug#77834: [PATCH] Improve help-fns-edit-variable for Lisp editing

From: Philip Kaludercic <[email-masked]>
Date: Thu, 17 Apr 2025 08:05:54 +0000

Spencer Baugh <[email-masked]> writes:

[...]

> diff --git a/lisp/help-fns.el b/lisp/help-fns.el
> index 0eb0a7a40be..7a0bc2908e9 100644
> --- a/lisp/help-fns.el
> +++ b/lisp/help-fns.el
> @@ -1561,11 +1561,20 @@ help-fns-edit-variable
>    (let ((var (get-text-property (point) 'help-fns--edit-variable)))
>      (unless var
>        (error "No variable under point"))
> -    (let ((str (read-string-from-buffer
> -                (format ";; Edit the `%s' variable." (nth 0 var))
> -                (prin1-to-string (nth 1 var)))))
> -      (set (nth 0 var) (read str))
> -      (revert-buffer))))
> +    (string-edit
> +     (format ";; Edit the `%s' variable." (nth 0 var))
> +     (prin1-to-string (nth 1 var))
> +     (lambda (edited)
> +       (set (nth 0 var) edited)
> +       (exit-recursive-edit))
> +     :abort-callback
> +     (lambda ()
> +       (exit-recursive-edit)
> +       (error "Aborted edit, variable unchanged"))
> +     :major-mode #'emacs-lisp-mode
> +     :read #'read)
> +    (recursive-edit)
> +    (revert-buffer)))

I don't remember the details here anymore, but why do you need the
`recursive-edit' and `exit-recursive-edit'?  Shouldn't `string-edit'
take care of this instead of the caller?

[...]