Subject: bug#77173: [PATCH] Instruct users to use customize or setopt for user options that have :set-er

From: Stefan Kangas <[email-masked]>
Date: Sat, 22 Mar 2025 07:27:23 -0500

Visuwesh <[email-masked]> writes:

> Tags: patch
>
> Seeing the discussion in bug#77157, and another recent discussion about
> the same, WDYT about the attached that automatically adds the "use
> setopt" filler text?
>
> This is what doc-view-epub-font-size says with the patch applied:
>
>     doc-view-epub-font-size is a variable defined in ‘doc-view.el’.
>
>     Its value is nil
>
>     Font size in points for EPUB layout.
>
>       This variable was introduced, or its default value was changed, in
>       version 29.1 of Emacs.
>       You can customize this variable.
>       Setting this variable directly will not usually take effect;
>       use either customize or ‘setopt’, or call ‘doc-view-custom-set-epub-font-size’.

Thanks.  Are you on a current master?

It currently says this:

    doc-view-epub-font-size is a variable defined in ‘doc-view.el’.

    Its value is nil

    Font size in points for EPUB layout.

      This variable was introduced, or its default value was changed, in
      version 29.1 of Emacs.
      You can customize this variable.
    Setting this variable with ‘setq’ has no effect; use either ‘setopt’
    or M-x customize-option to change its value.

The formatting could use improving though.

> The word 'customize' in the last line is buttonised the same way as the
> one in "You can customize this variable'.

Neat.

> diff --git a/lisp/help-fns.el b/lisp/help-fns.el
> index bbc7700c49e..32a68d37b61 100644
> --- a/lisp/help-fns.el
> +++ b/lisp/help-fns.el
> @@ -1620,12 +1620,18 @@ help-fns--run-describe-functions
>  (defun help-fns--customize-variable (variable &optional text)
>    ;; Make a link to customize if this variable can be customized.
>    (when (custom-variable-p variable)
> -    (let ((customize-label "customize"))
> +    (let ((customize-label "customize")
> +          (custom-set (get variable 'custom-set)))
>        (princ (concat "  You can " customize-label (or text " this variable.")))
> +      (when custom-set
> +        (princ (concat "\n  Setting this variable directly will not usually take effect;"
> +                       "\n  use either customize or " (substitute-quotes "`setopt'")
> +                       ", or call "
> +                       (substitute-quotes (concat "`" (symbol-name custom-set) "'.")))))
>        (with-current-buffer standard-output
>  	(save-excursion
> -          (re-search-backward (concat "\\(" customize-label "\\)"))
> -	  (help-xref-button 1 'help-customize-variable variable)))
> +          (while (re-search-backward (concat "\\(" customize-label "\\)") nil t)
> +	    (help-xref-button 1 'help-customize-variable variable))))
>        (terpri))))
>
>  (add-hook 'help-fns-describe-variable-functions
>