emacs-devel
[Top][All Lists]
Advanced

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

Idempotency of add-hook wrt lambda expressions


From: Geoff Gole
Subject: Idempotency of add-hook wrt lambda expressions
Date: Wed, 4 Mar 2009 21:10:45 +0900

Say a file contains an add-hook form with a lambda argument:

  (add-hook 'foo-mode (lambda () (bar)))

Annoyingly, the function will be added to the hook twice if the file
is byte compiled, loaded, then reevaluated (such as with eval-buffer).
This can be worked around in any number of ways (don't byte compile,
don't use lambdas in hooks, restart emacs on every change), but I
wonder if add-hook can be made to do the right thing. One way is to
change the hook membership test from:

  (member function hook-value)

to something like

  (ignore-errors
    (let ((bc-function (byte-compile function)))
      (or (member function hook-value)
          (member bc-function hook-value))))

But that's pretty horrible. In any case, if there is no fix shouldn't
this wrinkle be mentioned in the add-hook docstring?




reply via email to

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