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.devel Subject: Re: [PATCH] Add new csetq macro Date: Sat, 03 Sep 2022 15:59:52 +0000 Message-ID: <875yi4ih3b.fsf@posteo.net> References: <20220903140723.809684-1-lucien@phundrak.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23820"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Lucien Cartier-Tilet Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 03 18:06:46 2022 Return-path: Envelope-to: ged-emacs-devel@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 1oUVfR-0005wW-74 for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Sep 2022 18:06:45 +0200 Original-Received: from localhost ([::1]:56150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUVfP-00034e-SK for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Sep 2022 12:06:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUVZ1-000881-A9 for emacs-devel@gnu.org; Sat, 03 Sep 2022 12:00:07 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:60439) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUVYy-0008Pa-SP for emacs-devel@gnu.org; Sat, 03 Sep 2022 12:00:06 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 350F2240026 for ; Sat, 3 Sep 2022 17:59:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1662220799; bh=1v9Yiwy6D9nxLnKPEjwR28e3AzbFgSEUBrX/ghPekw0=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=gRMTwd/Ipsk/8nDu7nt5yhY7ku+U5l6O3PkVdr34uiQG74M7aO9+3EW8bVlvm8O2r CScRXAi/rWjw3U9jp+aXvgZIoAzSRokAfNJMA0r1O6H64gSq/tPQxfpBYUr32B7aoc DOat377ucATt+vWCaACRLJknO9Vjz7zoAdnXK0DaLNSizkQx7JFzNvVRmSm0F5xnua qvBag1I98hW355Woy299OzRruhHpqeSMW62pI9WRFd2FV54enVVjHy9gJVfgrky7Bc SxxpuusBhdsacwNvG/6LW7U1SfizAACkwJ32zZwTZDlEmjznnSUVGRQFtqZ/muhbRh TDtMTyEts975A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MKfcZ4D42z9rxL; Sat, 3 Sep 2022 17:59:58 +0200 (CEST) In-Reply-To: <20220903140723.809684-1-lucien@phundrak.com> (Lucien Cartier-Tilet's message of "Sat, 3 Sep 2022 16:07:25 +0200") Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:294662 Archived-At: Lucien Cartier-Tilet writes: > The csetq macro is a quality of life macro for Emacs users and wraps > `custom-set-variable' in a `setq'-like macro, hence its name. > > It avoids repetition of `custom-set-variable' when setting the value > of custom variables, while keeping the same syntax as `setq'. I > believe this could also help and encourage people to switch more > easily to the correct way of setting the value of custom variables > instead of using raw `setq's, since `setq' doesn't call the setter of > a custom variable =E2=80=93if it exists=E2=80=93 while `custom-set-variab= le' does. > > It also has the same behaviour from the user's perspective: all the > variables are set sequentially and in order, and the last value is > returned to the user. > > --- > lisp/subr.el | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/lisp/subr.el b/lisp/subr.el > index e4d3245537..19327e49f6 100644 > --- a/lisp/subr.el > +++ b/lisp/subr.el > @@ -190,7 +190,33 @@ setq-local > (setq pairs (cdr (cdr pairs)))) > (macroexp-progn (nreverse expr)))) >=20=20 > +(defmacro csetq (&rest forms) > + "Bind each custom variable FORM to the value of its VAL. > + > +FORMS is a list of pairs of values [FORM VAL]. > +`customize-set-variable' is called sequentially on each pairs > +contained in FORMS. `csetq' thus has a similar behaviour as > +`setq': each VAL expression are evaluated sequentially, i.e. the > +first VAL is evaluated before the second, and so on. This means > +the value of the first FORM can be used to set the second FORM. > + > +The return value of `csetq' is the value of the last VAL. > + > +\(fn [FORM VAL]...)" > + (declare (debug (&rest sexp form)) > + (indent 1)) > + ;; Check if we have an even number of arguments > + (when (=3D (mod (length forms) 2) 1) > + (signal 'wrong-number-of-arguments (list 'csetq (1+ (length forms)))= )) > + ;; Transform FORMS into a list of pairs (FORM . VALUE) > + (let (sexps) > + (while forms > + (let ((form (pop forms)) > + (value (pop forms))) > + (push `(customize-set-variable ',form ,value) Note that this would have the issue that changes would automatically be added to the "user" theme, and hence be reproduced in the `custom-set-variables' section. If the user sets an option using this macro, and the `custom-set-variables' is evaluated after this point, the intended change would be silently overridden. > + sexps))) > + `(progn ,@(nreverse sexps)))) > + > (defmacro defvar-local (var val &optional docstring) > "Define VAR as a buffer-local variable with default value VAL. > Like `defvar' but additionally marks the variable as being automatically > -- > 2.37.3