help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(1) defcustom :set, (2) similar for defvar


From: Drew Adams
Subject: (1) defcustom :set, (2) similar for defvar
Date: Fri, 11 Aug 2017 15:12:52 -0700 (PDT)

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))
   
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=27348



reply via email to

[Prev in Thread] Current Thread [Next in Thread]