emacs-devel
[Top][All Lists]
Advanced

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

Re: doc on define-minor-mode hook variable(s)


From: Kevin Rodgers
Subject: Re: doc on define-minor-mode hook variable(s)
Date: Wed, 08 Mar 2006 14:06:06 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Stefan Monnier wrote:
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.


Either way it's a mistake: when people think of a hook as a variable, they
think that (boundp 'foo-hook) can tell them whether the hook exists or not.

So I prefer to think that a hook is its own kind of object, which happens to
be implemented using a variable.

(defmacro defhook (symbol &rest optional-args)
  "Define SYMBOL as a hook.
You are not required to define a hook in order to use it,
but the definition can supply documentation and an initial value
in a way that `\\[describe-variable]' can recognize.

INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
If SYMBOL is buffer-local, its default value is what is set;
 buffer-local values are not affected.
INITVALUE and DOCSTRING are optional.
If INITVALUE is missing, SYMBOL's value is not set."
  `(let ((initvalue (car optional-args))
         (docstring (cadr optional-args)))
     (defvar ,symbol ,initvalue
       ,(if (and docstring
                 (string-match "\\`\\*" docstring))
            (substring docstring 1)
          docstring))
     (when (null optional-args)
       (makunbound ,symbol))))

Just kidding,
--
Kevin Rodgers





reply via email to

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