[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
- Re: Using "Emacs Configure" **and** modifying .emacs, (continued)
- Message not available
- Re: Using "Emacs Configure" **and** modifying .emacs, notbob, 2017/08/11
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/11
- Message not available
- Re: Using "Emacs Configure" **and** modifying .emacs, HASM, 2017/08/11
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/11
- Message not available
- Re: Using "Emacs Configure" **and** modifying .emacs, Alan Mackenzie, 2017/08/11
- Re: Using "Emacs Configure" **and** modifying .emacs, HASM, 2017/08/11
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/11
- RE: Using "Emacs Configure" **and** modifying .emacs, Drew Adams, 2017/08/11
- (1) defcustom :set, (2) similar for defvar,
Drew Adams <=
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/11
- Re: Using "Emacs Configure" **and** modifying .emacs, tomas, 2017/08/12
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/12
- Re: Using "Emacs Configure" **and** modifying .emacs, tomas, 2017/08/12
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/12
- Re: Using "Emacs Configure" **and** modifying .emacs, Tomas Nordin, 2017/08/12
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/12
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/15
- RE: Using "Emacs Configure" **and** modifying .emacs, Drew Adams, 2017/08/15
- Re: Using "Emacs Configure" **and** modifying .emacs, Emanuel Berg, 2017/08/15