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

From: Gregory Heytings <[email-masked]>
Date: Thu, 09 Sep 2021 11:44:58 +0000

>
> Instead of building such a list, is this not something that could be 
> done inside Fsetq, by checking whether Fget (sym, Qcustom_set) is 
> non-nil, and if so, issue an error/warning?
>

Patch attached.

From 50d1e07ab098c3c98259f435167cb1cb4bfeb3b5 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Thu, 9 Sep 2021 11:40:50 +0000
Subject: [PATCH] Warn when defcustom is wrongly set.

* src/eval.c (Fsetq): Display warning when a custom variable with a :set
property is set with setq.
---
 src/eval.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/eval.c b/src/eval.c
index 48104bd0f4..b72577e791 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -525,8 +525,16 @@ 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 ("initialization"),
+		 CALLN (Fformat,
+			build_string
+			("`%s' should be set with `customize-set-variable', not `setq'"),
+			sym));
 	Fset (sym, val);	/* SYM is dynamically bound.  */
+      }
     }
 
   return val;
-- 
2.33.0