Bill Wohler | 19 May 07:02

Re: q? on manual (hooks)

Greg Minshall <minshall <at> acm.org> wrote:

> i'm working on learning how to customize.  (a little knowledge...)
> 
> in the manual, you give an example of using folder-mode-hook.  you have
> something like:
> ----
>      (defvar my-mh-init-done nil
>        "Non-`nil' when one-time MH-E settings made.")
>      (defun my-mh-folder-mode-hook ()
> ...
>              (setq my-mh-init-done t))))
>      (add-hook 'mh-folder-mode-hook 'my-mh-folder-mode-hook)
> ----
> to make sure the hook is only run once.
> 
> i'm curious why not use remove-hook inside my-mh-folder-mode-hook to
> remove itself as a hook?  i would think that would be more efficient
> (you wouldn't even call my-mh-folder-mode-hook after the first time
> folder mode runs).  but, i suspect the intricacies of
> emacs/emacs-lisp/mh-e may be responsible.

That would work in this case. However, I wouldn't do that for several
reasons.

You might want to do other things outside of the condition in the hook,
or you might later want to add something to the hook and simply
re-evaluate the function to have it work for the next folder without
having to re-add it to the hook.

It also violates the principle of least astonishment. If I later look at
the m-folder-mode-hook to see what's getting run, I might be surprised
that an expected hook function isn't there, or worse, not know to look
at the stealth hook function (which might have caused the problem I'm
debugging).

I think it would also confuse the customization stuff. The status on the
mh-folder-mode-hook customization option would be "Changed" I think.
While that wouldn't be fatal, if you later added a new function to the
hook and saved it, your stealth hook function would be lost forever (or
at least until you realized what happened and put it back).

--

-- 
Bill Wohler <wohler <at> newt.com>  http://www.newt.com/wohler/  GnuPG ID:610BD9AD

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

Gmane