From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lucien Cartier-Tilet Newsgroups: gmane.emacs.devel Subject: [PATCH] Add new csetq macro Date: Sat, 3 Sep 2022 16:07:25 +0200 Message-ID: <20220903140723.809684-1-lucien@phundrak.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36384"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lucien Cartier-Tilet To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 03 16:25: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 1oUU5i-0009IV-7T for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Sep 2022 16:25:46 +0200 Original-Received: from localhost ([::1]:57052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUU5g-0002ZG-Q1 for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Sep 2022 10:25:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUU4g-0001g8-QG for emacs-devel@gnu.org; Sat, 03 Sep 2022 10:24:42 -0400 Original-Received: from 105.ip-51-83-47.eu ([51.83.47.105]:54586 helo=mail.phundrak.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUU4f-0004Ul-AU for emacs-devel@gnu.org; Sat, 03 Sep 2022 10:24:42 -0400 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DABA8C002F; Sat, 3 Sep 2022 16:14:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phundrak.com; s=dkim; t=1662214457; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=5wecrklCfH1AL8Z0/W8Bo1cX3XfLmRU1bB9hy520t3o=; b=Di3k7W3WQEioEhk5vqsZDCXk/BqOTKOsMzuqoHjH42huj+h2IUird1Bb+FtIIpCOsZvtAm Aa1ngmpmqfe+asVv9LJDEsHfF1Pu8/eI/ZAXPp58e4bHz9MeMUs6e2qd7B+Bt8a/i9xeS4 wXRTF4h68VZL++zCLtyYXCt6Sw9DvGs= X-Last-TLS-Session-Version: TLSv1.3 Received-SPF: pass client-ip=51.83.47.105; envelope-from=lucien@phundrak.com; helo=mail.phundrak.com X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 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, PP_MIME_FAKE_ASCII_TEXT=0.08, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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:294650 Archived-At: 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 –if it exists– while `custom-set-variable' 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)))) +(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 (= (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) + 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