From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Geoff Gole Newsgroups: gmane.emacs.devel Subject: Idempotency of add-hook wrt lambda expressions Date: Wed, 4 Mar 2009 21:10:45 +0900 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1236168671 29421 80.91.229.12 (4 Mar 2009 12:11:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Mar 2009 12:11:11 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 04 13:12:27 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 1LepxS-0006vr-IC for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 13:12:18 +0100 Original-Received: from localhost ([127.0.0.1]:60563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lepw7-0008Aj-8s for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 07:10:55 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lepw2-0008Ad-Id for emacs-devel@gnu.org; Wed, 04 Mar 2009 07:10:50 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lepvz-0008AN-Pj for emacs-devel@gnu.org; Wed, 04 Mar 2009 07:10:50 -0500 Original-Received: from [199.232.76.173] (port=52584 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lepvz-0008AK-Je for emacs-devel@gnu.org; Wed, 04 Mar 2009 07:10:47 -0500 Original-Received: from wf-out-1314.google.com ([209.85.200.175]:23112) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lepvz-0008Hy-72 for emacs-devel@gnu.org; Wed, 04 Mar 2009 07:10:47 -0500 Original-Received: by wf-out-1314.google.com with SMTP id 28so3478505wfc.24 for ; Wed, 04 Mar 2009 04:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=A4o9jgOhqLikn5C5cHETLfxK0hTvr4zhR3Uuft9aVoc=; b=b0/4zIVdwQ47SYQQHFsKVkBtKp/4Vb2VHp7NPjmPRYqqSIRtq0aJNor47JzRk+LhYJ QCoaJDqbhJ0itzkrE9Xp+Csoqboc/sVEUfw/1xzTy2bqgq4EUZ+/BZ+9EuD8CT2EFuXr 8mMNhH0712A7Qyb86ODTw1xFZ751H7jy9fn4Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=MefNcTP9HG24nV6wunKxaCwmkE4NseqO0VGW9Dn6/CKRzOTR5rHS6vB2trsAnSFIjK q9bZNSSN99kZQvOEh/9qQSsTKTVoqVQSvA3EcSHpbcv+e7SFJ7ibUa6noN2yQrLdQHmm BUePFbB5sXHbAoUUCwFryFs89//aQdYxGZTvI= Original-Received: by 10.142.89.13 with SMTP id m13mr4178848wfb.50.1236168645850; Wed, 04 Mar 2009 04:10:45 -0800 (PST) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:109438 Archived-At: 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?