[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: doc on define-minor-mode hook variable(s)
From: |
Drew Adams |
Subject: |
RE: doc on define-minor-mode hook variable(s) |
Date: |
Mon, 6 Mar 2006 11:10:47 -0800 |
> In the past, hook variables were used, and the new notion
> that a hook need not be associated with a variable should
> be explained in the doc.
A hook IS a variable--that is to say, a symbol whose value is used.
It is a mistake to think that a hook is not a variable.
You quoted me, but I got the idea from Stefan - possibly I misunderstood
him.
IIUC, what Stefan meant was this (he will correct me):
- What makes a hook a hook is its use: if `run-hooks' uses it, then it's a
hook.
- A symbol used as a hook need not necessarily be bound before it is run.
That is, you can call `run-hooks' on a symbol that has never been bound -
nothing happens.
- Such an unbound symbol is not a variable. Of course, to do anything
useful as a hook, it must be bound.
- The way to set up a symbol to serve as a useful hook is to use
`add-hook'. Binding the symbol is not the way to go.
- For these reasons (I think), Stefan doesn't like to refer to "variable"
in this context: 1) The symbol can be run as an (inert) hook without being
bound. 2) Simply binding a symbol is not the way to make it useful as a
hook.
I don't know or care what terminology is used to describe the behavior of
hooks - I'm just learning.
To me, reading the `define-minor-mode' doc about `MODE-hook', I expected to
find existing (bound) variables named `MODE-hook' after calling
`define-minor-mode'. When I searched for them, I found none and I wondered
what the doc really meant.
It turns out (IIUC) that the doc simply meant that the created minor mode
command does (run-hooks 'MODE-hook). And, given an understanding of hooks
(which, in my case was incomplete), this means:
1. IF someone does (add-hook `MODE-hook' <something>) THEN <something> will
be run when the mode is entered and exited.
2. OTHERWISE, nothing will happen, because (run-hooks 'MODE-hook) does
nothing if `MODE-hook' is not bound or is bound to nil. I should say,
instead of speaking of binding, "if either `add-hook' was never called on it
or `remove-hook' was called to remove everything that `add-hook' had added".
I called this an "empty" hook, but Stefan didn't like that term.
IOW, in Stefan's terminology (IIUC): because `run-hooks' runs it, the hook
exists, even though the hook symbol might not be bound (so, no variable).
All this was not clear to me when I read the `define-minor-mode' doc. I
think it would be good if it were explained (using whatever terminology you
like) in the Hooks nodes of the manuals.
Again, I don't claim that my understanding is correct on this. My message
really is that I was confused by the current doc. Do with that feedback what
you will.
- doc on define-minor-mode hook variable(s), Drew Adams, 2006/03/05
- Re: doc on define-minor-mode hook variable(s), Stefan Monnier, 2006/03/05
- RE: doc on define-minor-mode hook variable(s), Drew Adams, 2006/03/05
- Re: doc on define-minor-mode hook variable(s), Stefan Monnier, 2006/03/05
- RE: doc on define-minor-mode hook variable(s), Drew Adams, 2006/03/05
- Re: doc on define-minor-mode hook variable(s), Stefan Monnier, 2006/03/06
- Re: doc on define-minor-mode hook variable(s), Richard Stallman, 2006/03/06
- Re: doc on define-minor-mode hook variable(s), Stefan Monnier, 2006/03/06
- Re: doc on define-minor-mode hook variable(s), Kevin Rodgers, 2006/03/08
- RE: doc on define-minor-mode hook variable(s),
Drew Adams <=