unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ignacio Casso <ignaciocasso@hotmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Michael Heerdegen <michael_heerdegen@web.de>,
	larsi@gnus.org, 54399@debbugs.gnu.org
Subject: bug#54399: 27.2; Problems with (let ((custom-variable ...)) (autoload-function ...))
Date: Tue, 12 Apr 2022 15:51:17 +0200	[thread overview]
Message-ID: <PAXPR06MB77600E8276B9E70D2ED02293C6ED9@PAXPR06MB7760.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <jwv7d7ufniz.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 899 bytes --]


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Should I go ahead and just update the docstrings so that they reflect
>> this behavior, and then close this bug report?  Or do you think that the
>> code should be changed too?  For the latter I don't think I could help,
>> since that code is too low level for me.
>
> If you can send a patch for the docs which addresses your concerns that
> would be very helpful.
>
>
>         Stefan

Here is a first attempt of a patch. It updates the docstrings for those
functions and makes some other changes regarding the original
`defcustom' issue. For some places were I was not sure if a change was
necessary, I just wrote a comment to mark them and maybe discuss later.

I also would replace in other files `set-default' with
`set-default-toplevel-value', when it is used inside a lambda expression
that is passed as :set argument for `defcustom'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch for bug#54399 --]
[-- Type: text/x-diff, Size: 7190 bytes --]

From 348f43797e3a126471681e1f5be00bc3fd34914d Mon Sep 17 00:00:00 2001
From: Ignacio <ignaciocasso@hotmail.com>
Date: Tue, 12 Apr 2022 10:48:32 +0200
Subject: [PATCH] updated documentation regarding default toplevel values of
 variables

---
 lisp/custom.el | 26 +++++++++++++-------------
 src/data.c     | 16 +++++++++++-----
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/lisp/custom.el b/lisp/custom.el
index 76c14831ca..e23ca7915a 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -68,7 +68,7 @@ custom-initialize-default
 (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
@@ -81,7 +81,7 @@ custom-initialize-set
 
 (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,
@@ -100,7 +100,7 @@ custom-initialize-changed
   "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)
@@ -114,7 +114,7 @@ custom-initialize-changed
                 symbol
                 (eval (car (get symbol 'saved-value)))))
       (t
-       (set-default symbol (eval exp)))))))
+       (set-default-toplevel-value symbol (eval exp)))))))
 
 (defvar custom-delayed-init-variables nil
   "List of variables whose initialization is pending until startup.
@@ -262,11 +262,11 @@ defcustom
 	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'.
 :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'.
 :require
 	VALUE should be a feature symbol.  If you save a value
 	for this option, then when your init file loads the value,
@@ -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)))
 
 (defun custom-set-minor-mode (variable value)
   ":set function for minor mode variables.
@@ -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))
@@ -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))))
@@ -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)))))))
 
 (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))))))
 
 (defun custom-theme-recalc-face (face)
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;
@@ -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);
@@ -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 no behave as expected inside let
+bindings of SYMBOL.  To take them into account, use
+`set-default-toplevel-value' instead. */)
+
   (Lisp_Object symbol, Lisp_Object value)
 {
   set_default_internal (symbol, value, SET_INTERNAL_SET);
-- 
2.25.1


  reply	other threads:[~2022-04-12 13:51 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 11:50 bug#54399: 27.2; Problems with (let ((custom-variable ...)) (autoload-function ...)) Ignacio Casso
2022-03-17 11:23 ` Lars Ingebrigtsen
2022-03-18  0:22   ` Michael Heerdegen
2022-03-18  1:02     ` Michael Heerdegen
2022-03-18  9:32     ` Lars Ingebrigtsen
2022-03-18  9:38       ` Ignacio Casso
2022-04-12 13:18         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-12 13:23           ` Ignacio Casso
2022-04-12 13:55             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-12  9:13 ` Ignacio Casso
2022-04-12 11:38   ` Eli Zaretskii
2022-04-12 12:16     ` Ignacio Casso
2022-04-12 13:35       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-12 14:27         ` Ignacio Casso
2022-04-12 15:04           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-12 15:27             ` Ignacio Casso
2022-04-12 22:15               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-13 15:26                 ` Ignacio Casso
2022-04-13  0:24         ` Michael Heerdegen
2022-04-13  3:26           ` Glenn Morris
2022-04-13  3:43             ` Michael Heerdegen
2022-04-12 15:24       ` Eli Zaretskii
2022-04-13 17:22         ` Ignacio Casso
2022-04-12 13:19   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-12 13:51     ` Ignacio Casso [this message]
2022-04-12 15:22       ` Eli Zaretskii
2022-04-13  0:06         ` Michael Heerdegen
2022-04-13 12:08           ` Ignacio Casso
2022-05-12  2:32             ` Lars Ingebrigtsen
2022-05-12  6:58               ` Ignacio Casso
2022-05-12  7:34                 ` Eli Zaretskii
2022-05-12  8:14                   ` Ignacio Casso
2022-05-12  8:36                     ` Eli Zaretskii
2022-05-12  8:41                       ` Ignacio Casso
2022-05-12  9:40                         ` Eli Zaretskii
2022-05-12 11:49                           ` Lars Ingebrigtsen
2022-06-09 15:02                         ` Lars Ingebrigtsen
2022-06-09 21:19                           ` Ignacio Casso
2022-06-10  9:13                             ` Lars Ingebrigtsen
2022-06-10 14:01                               ` dick
2022-06-11 10:51                                 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PAXPR06MB77600E8276B9E70D2ED02293C6ED9@PAXPR06MB7760.eurprd06.prod.outlook.com \
    --to=ignaciocasso@hotmail.com \
    --cc=54399@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=michael_heerdegen@web.de \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).