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

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

Re: hooks, again


From: Stefan Monnier
Subject: Re: hooks, again
Date: Wed, 06 May 2015 00:08:50 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> With
>     (setq foo-hook '(grok greed gold))
> I can by inspection learn what the hook is. I don't
> need the help or evaluation of the variable name or
> anything. I need just bring up the definition itself
> and read.

But as seen earlier, you have to look at the value of `foo-hook' before
this setq takes place to be sure it's safe.  So you still need
"the help or evaluation of the variable name or anything".

And next time you upgrade Emacs, you'll have to look again at the value
of `foo-hook' before this setq, to make sure your `setq' is still OK.

And nothing explains why you want to remove previously present elements
from that hook.

And of course the above setq doesn't prevent later modification of the
hook (luckily), so you may still need to look at the var's value if you
want to know what's on the hook.

>     (add-hook 'foo 'grok)
>     (add-hook 'foo 'greed)
>     (add-hook 'foo 'gold)
> I see only what functions are at that point added -

Normally, you shouldn't need to care what other functions are there.

> With `setq' I can add and remove functions by editing
> the one form (and evaluating it), without using
> `add-hook' or `remove-hook' or anything at all.

"Without using add-hook or remove-hook" is not a virtue.

As mentioned before, if you like to use `setq' for your hooks, go
right ahead.  After all, that's how add-hook works under the hood.
I just strongly discourage it and consider it a bug to do that in an
Elisp package, except for very particular circumstances.


        Stefan


reply via email to

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