From: Drew Adams <drew.adams@oracle.com>
To: tomas@tuxteam.de, help-gnu-emacs@gnu.org
Subject: RE: Using "Emacs Configure" **and** modifying .emacs
Date: Sat, 12 Aug 2017 09:04:41 -0700 (PDT) [thread overview]
Message-ID: <2d0d85f2-8ed5-4c09-bc1f-cf7f6bd897b1@default> (raw)
In-Reply-To: <20170812073057.GB20873@tuxteam.de>
> > > And that's not hard to do: just use
> > > `customize-variable' instead of `setq', for
> > > user options. How hard is that? If you want
> > > something shorter, define an alias...
> >
> > I don't think it is about being difficult, or
> > long, rather what is the benefit?
>
> I think Drew has explained that pretty well. Besides,
> the "defcustom" ("15.3 Defining Customization Variables"
> node in the elisp doc does a good job, too.
>
> > What kind of function(s) get triggered? Is it
> > to ensure the new value of the variable makes
> > sense? That is, some variant of validating
> > the input?
>
> Yes. (The :type arg of defcustom)
>
> > Or is it to control behavior in a wider sense,
> > so that some function, that does something, is
> > set to something depending on the value of
> > the variable?
>
> Yes. (Among others, :set, but also perhaps :initialize,
> :set-after, etc.)
>
> > If it is about validation, i.e. making sure the
> > variable value makes sense (is within some
> > range or have a certain type; is a member of
> > the input domain set) then I never bothered
> > with that.
>
> Some dont want a validation to explode deep whithin
> the guts of some module loaded by another module,
> where the user has no clue about what the heck is
> going on, but next to the place where a variable
> is being set to a value it's not supposed to have.
>
> Sometimes I can sympathize with that :-)
Indeed.
TL;DR: Few start out embracing `defcustom'. Some end up
realizing how to live with it and take advantage of it.
At the risk of belaboring this (if that hasn't been
done already - if it has, apologies):
If you do everything you do with Emacs Lisp code only
for your own use then, yes, you can take care of all
places where a variable is used/set. You can find them
and make them do the right thing, even in situations
where dependent behavior is involved.
But if you provide code that others (people or libraries)
use then the situation can be a bit different. You have
no real control over all of the places and ways that a
variable might be set.
Declaring some things about the variable, its intended
behavior/uses (or non-behavior/non-uses) can serve to
_let others know what to expect_. It gives them a
heads-up, similar to how a code comment can do that.
If nothing else, you can think of `defcustom' as
providing such a declaration of intent - about the
types of values expected by your code, dependencies
wrt value changes, etc. `defcustom' is a way of
letting users (people, libraries) know stuff about
_your_ uses of the variable - what your code does
with it.
In the context of others who use your variable,
features provided by `defcustom' can be helpful.
Provided, that is, that they understand that it is
a variable that is helped by `defcustom', so that
they use `custom-*' and `customize-*' functions to
set and save it.
That's really the point, I think.
A library author uses `defcustom' to:
1. Let human users, especially but not only
non-Lispers, use Customize to _interactively_
browse, test, set, and persistently save the
variable.
2. Let other code take advantage of type-checking
(`:type'); setup, updating, synchronizing, etc.
trigger functions (`:set' etc.); linking to doc,
download, Commentary, etc. URLS (`:link');
persistence, etc.
That's all. No one is trying to make you use `custom*'
functions or Customize.
One point is that you will likely be interacting with
variables that someone has defined using `defcustom',
so it behooves you to understand what that means: what
`defcustom' offers and how you might take advantage of
that.
A second point is that if you write code that might be
used by others then you can take advantage of what
`defcustom' offers you and your users (people & code).
Not that you must; only that you can. Again, it can
help you to be aware of what `defcustom' offers;
that's all.
The same things apply to faces and `defface'.
`defface', `defcustom', and `defgroup' are your friends -
or they can be, if you are interested.
FWIW, many of us wrote Elisp code mainly for ourselves,
to start with. And many of us didn't care about or use
`defcustom'. And many of us didn't bother with Customize
interactively.
Later, some of us started sharing some of our code, and
we eventually started using `defcustom' to easily give
users a way to persist their choices. But we still
didn't really care about the various features `defcustom'
offers.
At some point, some of us fell upon the gotcha of trying
to set a user option created by someone else and not
realizing there was more going on than just changing the
value - e.g. a `:set' function.
We've all been pretty much where you are, I think
(Emmanuel), in case that helps. No one, I think, starts
out as a fan of Customize. Few, I think, realize or care
about the benefits of `defcustom' features, at the outset.
My bet is that as you share your code more with others
(people & libraries), those _users_ will help you learn
the benefits of `defcustom', and little by little you
will change your view: something like
i-dont-need-it--i-can-do-all-i-want-in-my-own-corner
will become something more like
i-can-do-this-to-make-things-easier-for-myself-and-users.
next prev parent reply other threads:[~2017-08-12 16:04 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-10 13:51 Using "Emacs Configure" **and** modifying .emacs Ronald Fischer
2017-08-10 15:59 ` Drew Adams
2017-08-10 16:58 ` Emanuel Berg
2017-08-12 17:24 ` John Ankarström
2017-08-13 20:16 ` Emanuel Berg
2017-08-12 17:32 ` John Ankarström
2017-08-10 16:00 ` Óscar Fuentes
2017-08-10 16:56 ` Emanuel Berg
2017-08-11 7:21 ` Ronald Fischer
2017-08-11 13:51 ` Emanuel Berg
2017-08-11 14:11 ` Tomas Nordin
[not found] ` <mailman.12937.1502460691.21957.help-gnu-emacs@gnu.org>
2017-08-11 15:20 ` notbob
2017-08-11 15:31 ` Emanuel Berg
2017-08-11 16:54 ` Drew Adams
2017-08-11 19:07 ` Emanuel Berg
2017-08-11 19:15 ` Drew Adams
2017-08-12 15:53 ` ken
2017-08-12 16:11 ` Emanuel Berg
2017-08-12 16:24 ` ken
2017-08-13 20:19 ` Emanuel Berg
[not found] ` <mailman.12941.1502465490.21957.help-gnu-emacs@gnu.org>
2017-08-11 15:57 ` notbob
2017-08-11 16:37 ` Emanuel Berg
[not found] ` <mailman.12935.1502459723.21957.help-gnu-emacs@gnu.org>
2017-08-11 14:09 ` HASM
2017-08-11 15:20 ` Emanuel Berg
[not found] ` <mailman.12940.1502464872.21957.help-gnu-emacs@gnu.org>
2017-08-11 18:55 ` Alan Mackenzie
2017-08-11 20:08 ` HASM
2017-08-11 20:29 ` Emanuel Berg
2017-08-11 20:46 ` Drew Adams
2017-08-11 22:12 ` (1) defcustom :set, (2) similar for defvar Drew Adams
2017-08-12 0:15 ` Using "Emacs Configure" **and** modifying .emacs Emanuel Berg
2017-08-12 7:30 ` tomas
2017-08-12 7:43 ` Emanuel Berg
2017-08-12 8:02 ` tomas
2017-08-12 10:03 ` Emanuel Berg
2017-08-12 10:38 ` Tomas Nordin
2017-08-12 11:38 ` Emanuel Berg
2017-08-15 22:10 ` Emanuel Berg
2017-08-15 22:18 ` Drew Adams
2017-08-15 22:27 ` Emanuel Berg
2017-08-15 23:38 ` Drew Adams
2017-08-16 0:09 ` John Mastro
2017-08-16 0:37 ` Robert Thorpe
2017-08-16 1:20 ` Emanuel Berg
2017-08-16 0:09 ` Emanuel Berg
2017-08-15 22:25 ` John Mastro
2017-08-15 22:41 ` Emanuel Berg
2017-08-15 23:09 ` Drew Adams
2017-08-16 0:07 ` John Mastro
2017-08-16 0:13 ` Emanuel Berg
2017-08-12 12:50 ` Emanuel Berg
2017-08-12 16:04 ` Drew Adams
2017-08-12 16:20 ` Emanuel Berg
2017-08-12 16:04 ` Drew Adams [this message]
2017-08-12 0:32 ` Emanuel Berg
2017-08-14 16:33 ` Emanuel Berg
2017-08-14 18:15 ` Emanuel Berg
2017-08-14 21:41 ` Emanuel Berg
2017-08-14 23:17 ` John Mastro
2017-08-15 0:24 ` Emanuel Berg
2017-08-15 2:20 ` Emanuel Berg
[not found] ` <mailman.12888.1502380810.21957.help-gnu-emacs@gnu.org>
2017-08-10 17:47 ` Dan Espen
2017-08-10 18:06 ` Drew Adams
2017-08-10 18:10 ` Drew Adams
[not found] ` <mailman.12897.1502388423.21957.help-gnu-emacs@gnu.org>
2017-08-10 19:08 ` Dan Espen
2017-08-10 19:14 ` Emanuel Berg
[not found] ` <mailman.12899.1502392471.21957.help-gnu-emacs@gnu.org>
2017-08-11 12:03 ` Dan Espen
2017-08-11 13:46 ` Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d0d85f2-8ed5-4c09-bc1f-cf7f6bd897b1@default \
--to=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=tomas@tuxteam.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).