unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Idempotency of add-hook wrt lambda expressions
@ 2009-03-04 12:10 Geoff Gole
  2009-03-04 14:18 ` Stefan Monnier
  2009-03-05 16:12 ` Alan Mackenzie
  0 siblings, 2 replies; 24+ messages in thread
From: Geoff Gole @ 2009-03-04 12:10 UTC (permalink / raw)
  To: emacs-devel

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?




^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2009-03-06  9:36 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-04 12:10 Idempotency of add-hook wrt lambda expressions Geoff Gole
2009-03-04 14:18 ` Stefan Monnier
2009-03-04 20:13   ` xah lee
2009-03-04 21:23     ` Stefan Monnier
2009-03-04 21:27       ` Lennart Borgman
2009-03-05 17:22         ` M Jared Finder
2009-03-04 21:00   ` David Reitter
2009-03-05  1:27     ` Stephen J. Turnbull
2009-03-05  1:54     ` Stefan Monnier
2009-03-05  8:23       ` Geoff Gole
2009-03-05  9:49         ` David Kastrup
2009-03-05 11:41           ` tomas
2009-03-05 11:53           ` Geoff Gole
2009-03-05 16:45             ` Alan Mackenzie
2009-03-05 16:33               ` Helmut Eller
2009-03-05 16:38               ` Stefan Monnier
2009-03-05 16:50               ` Geoff Gole
2009-03-05 16:38           ` Alan Mackenzie
2009-03-05 20:44           ` Reiner Steib
2009-03-05 20:59             ` Edward O'Connor
2009-03-05 21:08               ` Reiner Steib
2009-03-06  9:36                 ` David Kastrup
2009-03-05 16:12 ` Alan Mackenzie
2009-03-05 16:37   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).