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

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

RE: which one to use: custom-set-variables, customize-set-variable, or c


From: Drew Adams
Subject: RE: which one to use: custom-set-variables, customize-set-variable, or customize-set-value?
Date: Mon, 30 Nov 2015 07:20:27 -0800 (PST)

Hi Alan,

> Thank you for the explanation. For the moment I'm sticking with
> `customize-set-variable'

Good choice.

> and I'll see if I get in trouble.

I don't think you can get in trouble that way.

> > I agree that the doc is not very clear.  Recently I forgot
> > that `customize-set-value' does not use the defcustom's :set
> > function, and I was bitten by the fact that it does not.
> 
> I'm curious about this: what is the scenario where this can be
> a problem?

Situations where setting the variable is more complex than just
changing its value, that is, where other changes to the state
of Emacs need to be associated with the change in the variable
value.

If you look at the doc (Elisp manual, node Variable Definitions),
have a look at not only :set but also :initialize, to get an
idea of what can be involved.  You will see, for example, that
there are multiple initialization functions that are predefined,
and they act differently with respect to :set and setting the
value during initialization.  This might give you an idea of
different :set scenarios.

Here is one example of a :set function (from character-fold+.el)
that does something more than just change the value:

(defcustom char-fold-symmetric nil
  "Non-nil means char-fold searching treats equivalent chars the same.
That is, use of any of a set of char-fold equivalent chars in a search
string finds any of them in the text being searched.

If nil then only the \"base\" or \"canonical\" char of the set matches
any of them.  The others match only themselves, even when char-folding
is turned on."
  :set (lambda (sym defs)
         (custom-set-default sym defs)
         (update-char-fold-table))
  :type 'boolean :group 'isearch)

Standard function `custom-set-default' is the usual way to change
the variable's (default) value, so this :set function firt calls
that.  Then it calls a function that changes some other state,
taking the new variable value into account.

HTH.



reply via email to

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