Subject: Re: bug#21695: 25.0.50; Change most occurrences of `setq' in Emacs manual to `customize-set-variable'? Really?

From: Gregory Heytings <[email-masked]>
Date: Fri, 10 Sep 2021 13:49:07 +0000

>
> Please see the solution I proposed in the past few days.
>

The solution you proposed is not optimal I think, in particular because 
variables can also be set interactively, e.g. with M-: or C-x C-e, so 
checking that they have been set correctly after loading the init file is 
not enough.

The proposed (two lines!) patch works in all cases.  Its commit message 
was perhaps not clear enough, so I made it longer to make it (hopefully) 
crystal clear that it does TRT: there are no warnings for preloaded 
variables whose files are loaded after those variables have been setq'd.

From b74e9dfcf9c67455223b2a3be99692669b3b5205 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Fri, 10 Sep 2021 13:35:50 +0000
Subject: [PATCH] Warn when custom variable is wrongly set.

* src/eval.c (Fsetq): Display warning when a custom variable with a :set
property is set with setq.  Warnings are displayed only for custom variables
whose files have been loaded and that have a :set property.  No warnings are
displayed for custom variables whose files have merely been preloaded,
for custom variables that do not have a :set property, and for non-custom
variables.  See bug#21695.
---
 src/eval.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/eval.c b/src/eval.c
index 48104bd0f4..168a7749a0 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -525,8 +525,15 @@ DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
 	   : Qnil);
       if (!NILP (lex_binding))
 	XSETCDR (lex_binding, val); /* SYM is lexically bound.  */
-      else
+      else {
+	if (!NILP (Fget (sym, intern ("custom-set"))))
+	  call2 (intern ("display-warning"), intern ("setq"),
+		 CALLN (Fformat,
+			build_string
+			("`%s' should be set with `customize-set-variable'"),
+			sym));
 	Fset (sym, val);	/* SYM is dynamically bound.  */
+      }
     }
 
   return val;
-- 
2.33.0