bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54399: 27.2; Problems with (let ((custom-variable ...)) (autoload-fu


From: Ignacio Casso
Subject: bug#54399: 27.2; Problems with (let ((custom-variable ...)) (autoload-function ...))
Date: Wed, 13 Apr 2022 14:08:50 +0200
User-agent: mu4e 1.6.10; emacs 29.0.50

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> > +for this variable. This function may no behave as expected inside let
>>                      ^                  ^^
>> Typo: should be "not".  Also, only one space between sentences.
>

Fixed

>
>> +values for this variable. Let bindings may shadow this default value.
>                            ^^^^^^^^^^^^
>
> "Let-bindings" (with a hyphen; appear several times).
>

Fixed

> But the more interesting question is whether the changes per se are all
> correct.
>

Most things are corrections to the docstrings. I explain each change
below, as I should probably have done earlier:


>  (defun custom-initialize-set (symbol exp)
>    "Initialize SYMBOL based on EXP.
>  If the symbol doesn't have a default binding already,
> -then set it using its `:set' function (or `set-default' if it has none).
> +then set it using its `:set' function (or `set-default-toplevel-value' if it 
> has none).
>  The value is either the value in the symbol's `saved-value' property,
>  if any, or the value of EXP."
>    (condition-case nil

docstring correction, the function used is actually `set-default-toplevel-value'


>  (defun custom-initialize-reset (symbol exp)
>    "Initialize SYMBOL based on EXP.
> -Set the symbol, using its `:set' function (or `set-default' if it has none).
> +Set the symbol, using its `:set' function (or `set-default-toplevel-value' 
> if it has none).
>  The value is either the symbol's current value
>   (as obtained using the `:get' function), if any,
>  or the value in the symbol's `saved-value' property if any,

Same

> (defun custom-initialize-changed (symbol exp)
>    "Initialize SYMBOL with EXP.
>  Like `custom-initialize-reset', but only use the `:set' function if
>  not using the standard setting.
> -For the standard setting, use `set-default'."
> +For the standard setting, use `set-default-toplevel-value'."
>    (condition-case nil
>        (let ((def (default-toplevel-value symbol)))
>          (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value)

and

>                  symbol
>                  (eval (car (get symbol 'saved-value)))))
>        (t
> -       (set-default symbol (eval exp)))))))
> +       (set-default-toplevel-value symbol (eval exp)))))))
>  

Everywhere else `set-default-toplevel-value' is used instead, so I have
changed it here too.

> @@ -262,11 +262,11 @@ defcustom
> :set  VALUE should be a function to set the value of the symbol
>       when using the Customize user interface.  It takes two arguments,
>       the symbol to set and the value to give it.  The function should
>       not modify its value argument destructively.  The default choice
> -     of function is `set-default'.
> +     of function is `set-default-toplevel-value'.

Same correction

>  :get VALUE should be a function to extract the value of symbol.
>       The function takes one argument, a symbol, and should return
>       the current value for that symbol.  The default choice of function
> -     is `default-value'.
> +     is `default-toplevel-value'.

Similar correction

> @@ -717,7 +717,7 @@ custom-set-default
>    (if custom-local-buffer
>        (with-current-buffer custom-local-buffer
>       (set variable value))
> -    (set-default variable value)))
> +    (set-default-toplevel-value variable value)))

Here and in the rest of the changes in custom.el I have made or
suggested one of the following changes:

`default-value' -> `default-toplevel-value'

`set-default' -> `set-default-toplevel-value'

`default-boundp' -> (condition-case nil
                        (or (default-toplevel-value) t)
                      (void-variable nil))

But I'm not really sure of when those functions are used, so I don't
know whether they are necessary. I actually made the changes just to get
the feedback, we can discard them if you don't think that they are an
improvement or that it is worth to invest the time in finding out
whether they are an improvement.

> @@ -752,7 +752,7 @@ customize-mark-to-save
>  
>  Return non-nil if the `saved-value' property actually changed."
>    (custom-load-symbol symbol)
> -  (let* ((get (or (get symbol 'custom-get) #'default-value))
> +  (let* ((get (or (get symbol 'custom-get) #'default-toplevel-value))
>        (value (funcall get symbol))
>        (saved (get symbol 'saved-value))
>        (standard (get symbol 'standard-value))

See last comment


> @@ -779,7 +779,7 @@ customize-mark-as-set
>  
>  Return non-nil if the `customized-value' property actually changed."
>    (custom-load-symbol symbol)
> -  (let* ((get (or (get symbol 'custom-get) #'default-value))
> +  (let* ((get (or (get symbol 'custom-get) #'default-toplevel-value))
>        (value (funcall get symbol))
>        (customized (get symbol 'customized-value))
>        (old (or (get symbol 'saved-value) (get symbol 'standard-value))))

See last comment

> @@ -1054,12 +1054,12 @@ custom-theme-set-variables
>                    ;; Rogue variable, set it now.
>                    (put symbol 'force-value t)
>                    (funcall set symbol (eval value)))
> -                 ((default-boundp symbol)
> +                 ((default-boundp symbol) ; condition-case + 
> default-toplevel-value?
>                    ;; Something already set this, overwrite it.
>                    (funcall set symbol (eval value))))
>           (error
>            (message "Error setting %s: %s" symbol data)))
> -       (and (or now (default-boundp symbol))
> +       (and (or now (default-boundp symbol)) ; condition-case + 
> default-toplevel-value?
>              (put symbol 'variable-comment comment)))))))

See last comment

>  
>  (defvar custom--sort-vars-table)
> @@ -1608,8 +1608,8 @@ custom-theme-recalc-variable
>        (setq valspec (get variable 'standard-value)))
>      (if (and valspec
>            (or (get variable 'force-value)
> -              (default-boundp variable)))
> -        (funcall (or (get variable 'custom-set) #'set-default) variable
> +              (default-boundp variable))) ; (condition-case ... 
> default-toplevel-value ...) ?
> +        (funcall (or (get variable 'custom-set) #'set-default) variable ; 
> set-default-toplevel-value?
>                (eval (car valspec))))))

See last comment

> diff --git a/src/data.c b/src/data.c
> index f06b561dcc..b73a997341 100644
> --- a/src/data.c
> +++ b/src/data.c
> @@ -1927,9 +1927,10 @@ default_value (Lisp_Object symbol)
>  
>  DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
>         doc: /* Return t if SYMBOL has a non-void default value.
> -A variable may have a buffer-local or a `let'-bound local value.  This
> -function says whether the variable has a non-void value outside of the
> -current context.  Also see `default-value'.  */)
> +This is the value that is seen in buffers that do not have their own
> +values for this variable. Let-bindings may shadow this default value.
> +To take them into account, use `default-toplevel-value' together with
> +`condition-case' instead. */)
>    (Lisp_Object symbol)
>  {
>    register Lisp_Object value;

Corrected `default-boundp' docstring, which said that it can be used
to check if a variable is non-void outside a let-binding context, which
is false. I just reverted to Emacs 27's version, which was correct.

Also, in this docstring and the ones for `default-value' and
`set-default', I update them to suggest using their "toplevel"
counterparts when let-bindings need to be taken into account. But I
probably use the wrong vocabulary to do so, and that information is
already on the pertinent section of the manual, so we can discard these
changes too if you don't think they belong in the docstrings.


> @@ -1942,7 +1943,9 @@ DEFUN ("default-value", Fdefault_value, Sdefault_value, 
> 1, 1, 0,
>         doc: /* Return SYMBOL's default value.
>  This is the value that is seen in buffers that do not have their own values
>  for this variable.  The default value is meaningful for variables with
> -local bindings in certain buffers.  */)
> +local bindings in certain buffers.  Let-bindings may shadow this
> +default value.  To take them into account, use
> +`default-toplevel-value' instead. */)
>    (Lisp_Object symbol)
>  {
>    Lisp_Object value = default_value (symbol);

See last comment

> @@ -2045,7 +2048,10 @@ set_default_internal (Lisp_Object symbol, Lisp_Object 
> value,
>  DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
>         doc: /* Set SYMBOL's default value to VALUE.  SYMBOL and VALUE are 
> evaluated.
>  The default value is seen in buffers that do not have their own values
> -for this variable.  */)
> +for this variable. This function may not behave as expected inside 
> let-bindings
> +of SYMBOL.  To take them into account, use
> +`set-default-toplevel-value' instead. */)
> +

See last comment


I've also made some new changes in customize.texi after I sent this
patch. They are equivalent to those in the docstring of
`defcustom'.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]