emacs-devel
[Top][All Lists]
Advanced

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

Re: add-hook and defvar


From: Robin Templeton
Subject: Re: add-hook and defvar
Date: Sat, 21 Feb 2015 17:35:10 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Artur Malabarba <address@hidden> writes:

> While it's nice that `add-hook' tries to do the right thing even when
> the variable isn't defined yet, that's a bit of a false assurance.
> Although it's documented in the docstring, it seems undesirable that
> it sets the variable. This means that if the hook's defvar were to
> specify an initial value, this value won't take effect because of that
> preceding `add-hook' invocation.

This seems like a bug in the program defining the hook variable, not a
problem with `add-hook' per se; programs should always allow for the
possibility that the user has set their own value for a variable and
that the default value in the defvar form is ignored. I would expect the
program to call `add-hook' itself if the default hook functions were
important.

> In this situation, add-hook doesn't so much "add" as it actually sets
> the value of the hook.
>
> The following patch is one way of having `add-hook' always add,
> without overriding the "future" initial value of the hook. It is not
> complete, it's intended as a possible outline (hopefully a
> conversation starter).
>
> The big disadvantage is that it's not backwards compatible. Any code
> out there that relies on the variable being set by `add-hook' will
> break.
> There's also the disadvantage that it adds a symbol-property check to
> every `defvar' call.
>
> Any thoughts?

Another potential problem is that `add-hook' followed by `run-hooks'
will do nothing if the hook variable has not been defined. If the
behavior of `add-hook' were changed, I would prefer it if it simply
required the variable to be defined; that would avoid the above
disadvantages, would make it consistent with functions like
`add-to-list', and would normally ensure that the hook is initialized as
expected.

my 2ยข,
robin
-- 
Inteligenta persono lernas la lingvon Esperanton rapide kaj facile.
Esperanto estas moderna, kultura lingvo por la mondo. Simpla, fleksebla,
belsona, Esperanto estas la praktika solvo de la problemo de universala
interkompreno. Lernu la interlingvon Esperanton!




reply via email to

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