From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: (1) defcustom :set, (2) similar for defvar Date: Fri, 11 Aug 2017 15:12:52 -0700 (PDT) Message-ID: References: <1502373086.1171866.1069247696.71F9FED4@webmail.messagingengine.com> <8660dvuzsr.fsf@zoho.com> <1502436066.2568371.1070085968.1D25E0E7@webmail.messagingengine.com> <87tw1ekxgo.fsf@127.0.0.1> <867ey9sva2.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1502489626 15469 195.159.176.226 (11 Aug 2017 22:13:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 Aug 2017 22:13:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 12 00:13:42 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgIBV-0003Sf-5m for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Aug 2017 00:13:37 +0200 Original-Received: from localhost ([::1]:53246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgIBb-00058c-4u for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Aug 2017 18:13:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgIAu-00056g-IJ for help-gnu-emacs@gnu.org; Fri, 11 Aug 2017 18:13:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dgIAq-0003Ac-IT for help-gnu-emacs@gnu.org; Fri, 11 Aug 2017 18:13:00 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:51066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dgIAq-0003A0-5n for help-gnu-emacs@gnu.org; Fri, 11 Aug 2017 18:12:56 -0400 Original-Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v7BMCsKi024805 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 11 Aug 2017 22:12:54 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v7BMCrx2031719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 11 Aug 2017 22:12:54 GMT Original-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v7BMCrUe012860 for ; Fri, 11 Aug 2017 22:12:53 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6774.5000 (x86)] X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:113997 Archived-At: 1. Q: What's a use case for a `defcustom' `:set' function? A1: Add/remove a hook function, depending on the new option value. A2: Perform some updating or synchronizing, after a value change. ;; hooking/unhooking (lambda (sym val) (custom-set-default sym val) (if val (add-hook 'isearch-update-post-hook 'isearchp-repeat-search-if-fail) (remove-hook 'isearch-update-post-hook 'isearchp-repeat-search-if-fail))) ;; updating (lambda (sym val) (custom-set-default sym val) (echo-bell-update)) ;; synchronizing (lambda (sym val) ; Synchronize an associated variable. (custom-set-default sym val) (setq isearchp-current-filter-preds-alist isearchp-filter-predicates-alist)) =20 2. Q: Wouldn't some `defcustom' features (`:set', :type', `:group', etc.) be useful also for other, non-option Lisp variables? A: Yes, I think so. (But it seems I'm a minority of one, here.) See bug #27348, which provides a patch to let you do the same things with `defvar' that you can do with `defcustom'. (Actually, it provides a new macro, `defvarc', which is `defcustom' with, by default, no interactive Customizing). Here's the blurb motivating this feature (from bug #27348): The ability to type-check, provide :set and :initialize trigger functions, automatically :require libraries, add links to doc, associate with one or more :groups, etc. - these are useful things to be able to do with at least some defvars, not just with defcustoms. Similarly, the ability to persist non-option variables in a user's custom file can be useful. In sum, this enhancement makes it possible to uncouple interactive customization from the other features that `custom.el' offers, in particular, type-checking and persistence, and to provide the latter for non-option variables. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D27348