From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Idempotency of add-hook wrt lambda expressions Date: Thu, 5 Mar 2009 16:12:06 +0000 Message-ID: <20090305161206.GA1855@muc.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1236268184 29343 80.91.229.12 (5 Mar 2009 15:49:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Mar 2009 15:49:44 +0000 (UTC) Cc: emacs-devel@gnu.org To: Geoff Gole Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 05 16:51:00 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LfFqR-0002jA-2a for ged-emacs-devel@m.gmane.org; Thu, 05 Mar 2009 16:50:47 +0100 Original-Received: from localhost ([127.0.0.1]:42704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfFp5-000349-RI for ged-emacs-devel@m.gmane.org; Thu, 05 Mar 2009 10:49:23 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfFox-00031f-A1 for emacs-devel@gnu.org; Thu, 05 Mar 2009 10:49:15 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfFov-00030y-Jf for emacs-devel@gnu.org; Thu, 05 Mar 2009 10:49:14 -0500 Original-Received: from [199.232.76.173] (port=55588 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfFov-00030t-BK for emacs-devel@gnu.org; Thu, 05 Mar 2009 10:49:13 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:2113 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LfFou-0005t4-PI for emacs-devel@gnu.org; Thu, 05 Mar 2009 10:49:13 -0500 Original-Received: (qmail 3839 invoked by uid 3782); 5 Mar 2009 15:49:08 -0000 Original-Received: from acm.muc.de (pD9E5203E.dip.t-dialin.net [217.229.32.62]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Thu, 05 Mar 2009 16:49:06 +0100 Original-Received: (qmail 2411 invoked by uid 1000); 5 Mar 2009 16:12:07 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-operating-system: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:109471 Archived-At: Hi, Geoff, Hi, Emacs! On Wed, Mar 04, 2009 at 09:10:45PM +0900, Geoff Gole wrote: > 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. That begs the question as to what the Right Thing actually is. Surely this is a case of "you asked for it, you got it". Also, is there really anything special about hooks here? You're going to be having this sort of problem wherever you use a lambda when you "really ought" to be using a symbol. > 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? No, it's not "pretty horrible", it's utterly horrific. ;-) I'm not convinced anything's really needed in the add-hook docstring or manual entry, but if so, I'd suggest something along the lines "you'd best use a symbol here unless you really know what you're doing". -- Alan Mackenzie (Nuremberg, Germany).