From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#60162: [PATCH] * lisp/cus-edit.el (setopt--set): Warn instead of rasing an error Date: Sat, 17 Dec 2022 18:00:43 +0000 Message-ID: <87y1r56hbo.fsf@posteo.net> References: <87a63mvvib.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32819"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "60162@debbugs.gnu.org" <60162@debbugs.gnu.org> To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 17 19:01:20 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6bUt-0008Ni-Cd for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Dec 2022 19:01:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p6bUf-0004Sy-Oj; Sat, 17 Dec 2022 13:01:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6bUd-0004RF-NP for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2022 13:01:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p6bUc-00087T-Cd for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2022 13:01:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p6bUc-0008MX-4n for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2022 13:01:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Dec 2022 18:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60162 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 60162-submit@debbugs.gnu.org id=B60162.167130005032130 (code B ref 60162); Sat, 17 Dec 2022 18:01:02 +0000 Original-Received: (at 60162) by debbugs.gnu.org; 17 Dec 2022 18:00:50 +0000 Original-Received: from localhost ([127.0.0.1]:57206 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6bUP-0008MA-Q7 for submit@debbugs.gnu.org; Sat, 17 Dec 2022 13:00:50 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:41363) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6bUN-0008Ly-Cn for 60162@debbugs.gnu.org; Sat, 17 Dec 2022 13:00:48 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 3D999240103 for <60162@debbugs.gnu.org>; Sat, 17 Dec 2022 19:00:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1671300041; bh=5kceszv/5sDLQC1lpAvKURJ7uYc3IPyR0Gueuih7mJI=; h=From:To:Cc:Subject:Date:From; b=gNtJbtP83D9B9IXNuZdllbS2lalmHJhgGO07B/Enhj4Zd3qIpPFBdSDj0nHzMEh5G 8IxSFg0Lvdrw6aIBKtjmJvJCkfcFUE+6434J8DTYOzutG6Yh8C2W6myLbxvBCqE/vz 832FrJidQNb4HjoHKyiw2yqhvk5TqOrrOnsVzQeRXjFIScI8RjgH5NEYI6sOabTBxg w7w3jxjsqCZwkgmO2cfOMU9g52OPkTOpXLyRIIGw//bzvJtSKNTUXuFCRHe3urh30+ Hs0ALwBtT0gbHGoPu2GJJWZ2VQnN1rDY7xWxtQPphJJYwVSBX2zzzet+HIQGwlBRR/ Aiee7rHitUt7A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NZDKM5J98z6tn5; Sat, 17 Dec 2022 19:00:39 +0100 (CET) In-Reply-To: (Drew Adams's message of "Sat, 17 Dec 2022 17:40:37 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251303 Archived-At: Drew Adams writes: >> Setopt checks the :type of a user option, and raises an user-error if >> the value doesn't match the type. This can be annoying during >> initialisation, because minor mistakes interrupt everything and you are >> let with a partially loaded configuration. >> >> I'd propose replacing the `user-error' with a `warn', that would still >> indicate mistakes, but continue loading the init.el. > > I don't have Emacs 29, so I don't know what > `setopt' is/does. But if it does more or less > what `customize-set-variable` does then: It is a macro that allows customising user options like setq +++ ** New macro 'setopt'. This is like 'setq', but is meant to be used for user options instead of plain variables, and uses 'custom-set'/'set-default' to set them. > Can `setopt' be used interactively? No, for it is a macro. > `customize-set-variable' raises an error when > used interactively, if the type doesn't match. > It does that in the `interactive' form, with > `custom-prompt-variable'. > > But `customize-set-variable' _doesn't_ raise > an error when called from Lisp with a type > mismatch (the type check is done only in > `interactive'). Yes, take a look at the changed definitions: --8<---------------cut here---------------start------------->8--- ;;;###autoload (defmacro setopt (&rest pairs) "Set VARIABLE/VALUE pairs, and return the final VALUE. This is like `setq', but is meant for user options instead of plain variables. This means that `setopt' will execute any `custom-set' form associated with VARIABLE. \(fn [VARIABLE VALUE]...)" (declare (debug setq)) (unless (zerop (mod (length pairs) 2)) (error "PAIRS must have an even number of variable/value members")) (let ((expr nil)) (while pairs (unless (symbolp (car pairs)) (error "Attempting to set a non-symbol: %s" (car pairs))) (push `(setopt--set ',(car pairs) ,(cadr pairs)) expr) (setq pairs (cddr pairs))) (macroexp-progn (nreverse expr)))) ;;;###autoload (defun setopt--set (variable value) (custom-load-symbol variable) ;; Check that the type is correct. (when-let ((type (get variable 'custom-type))) (unless (widget-apply (widget-convert type) :match value) (warn "Value `%S' does not match type %s" value type))) (put variable 'custom-check-value (list value)) (funcall (or (get variable 'custom-set) #'set-default) variable value)) --8<---------------cut here---------------end--------------->8--- You see that `customize-set-variable' isn't used at all, to prevent modifying the user theme. The error/warning is raised by `setopt--set'. > Since you mention "initialisation" I guess > this is about calls from Lisp. > ___ > > [If `setopt' does what `customize-set-variable' > does, why was it added? If not, what's its > particular use case? Just curious; I can always > wait to find out what Emacs 29 presents...] As mentioned above, it allows user options to be set like variables using setq. That means no quoting of user option names and multiple options can be set in a single call.