Subject: bug#21311: 25.0.50; non-defvared hooks are not declared special with lexical-binding

From: Stefan Monnier <[email-masked]>
Date: Fri, 21 Aug 2015 09:48:53 -0400

> It seems that hooks that are not declared using defvar but come into
> being just because of a (add-hook 'my-hook ...) are not declared as
> special meaning you cannot let-bind them to change their value in the
> dynamic scope of the let.

Yes.

> The bug disappears as soon as I
>   - don't use lexical-binding, or
>   - defvar the hook (Fix #1 or #2)

I think either of fix #1 or #2 are proper fixes and I think there's not
much more we can do about it.

If the hook hasn't been created yet at all (neither defvar, nor
add-hook) then fix #1 or #2 are really the only options.

Arguably, nowadays packages should defvar all their hooks.

        Stefan