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:38:53 +0000 Message-ID: <20090305163853.GB1855@muc.de> References: <74F2CF19-2E71-473F-A352-A628B3B29A8E@gmail.com> <861vtcxpt1.fsf@lola.quinscape.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1236269787 3841 80.91.229.12 (5 Mar 2009 16:16:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Mar 2009 16:16:27 +0000 (UTC) Cc: emacs-devel@gnu.org To: David Kastrup Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 05 17:17:44 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 1LfGGH-0007ec-VN for ged-emacs-devel@m.gmane.org; Thu, 05 Mar 2009 17:17:30 +0100 Original-Received: from localhost ([127.0.0.1]:48854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfGEw-0006f8-GP for ged-emacs-devel@m.gmane.org; Thu, 05 Mar 2009 11:16:06 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfGEr-0006bt-9V for emacs-devel@gnu.org; Thu, 05 Mar 2009 11:16:01 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfGEq-0006ZW-Ek for emacs-devel@gnu.org; Thu, 05 Mar 2009 11:16:00 -0500 Original-Received: from [199.232.76.173] (port=49400 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfGEq-0006ZF-1c for emacs-devel@gnu.org; Thu, 05 Mar 2009 11:16:00 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:3793 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 1LfGEp-000171-HF for emacs-devel@gnu.org; Thu, 05 Mar 2009 11:15:59 -0500 Original-Received: (qmail 8113 invoked by uid 3782); 5 Mar 2009 16:15:55 -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 17:15:52 +0100 Original-Received: (qmail 2755 invoked by uid 1000); 5 Mar 2009 16:38:53 -0000 Content-Disposition: inline In-Reply-To: <861vtcxpt1.fsf@lola.quinscape.zz> 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:109472 Archived-At: On Thu, Mar 05, 2009 at 10:49:14AM +0100, David Kastrup wrote: > Geoff Gole writes: > >> I'd much rather add a patch that complains when you pass a lambda to > > add-hook. > > Sounds good to me. > Does not jibe with existing practise. "Me too!". > For example, (info "(emacs) Init Examples") carefully explains > * Turn on Auto Fill mode automatically in Text mode and related > modes. > (add-hook 'text-mode-hook > '(lambda () (auto-fill-mode 1))) > This shows how to add a hook function to a normal hook variable > (*note Hooks::). The function we supply is a list starting with > `lambda', with a single-quote in front of it to make it a list > constant rather than an expression. > It's beyond the scope of this manual to explain Lisp functions, > but for this example it is enough to know that the effect is to > execute `(auto-fill-mode 1)' when Text mode is entered. You can > replace that with any other expression that you like, or with > several expressions in a row. > Sure, you can "fix" the manual here. But you can't expect that the > real world has never used an idiom explicitly documented and used as an > example. I have stuff like the following in my setup: (global-set-key [f1] (lambda () "Switch to frame F1" (interactive) (select-frame-acm-no 0))) That `global-set-key' might easily have been an `add-hook'. I think it would get tedious very quickly if warnings were given with add-hook + lambda. To outlaw it would be the Wrong Thing completely. With all due respect to Geoff, I don't think this is really a problem. > Also, in some cases you can't avoid lambda, namely when using computed > functions. Yes. > David Kastrup -- Alan Mackenzie (Nuremberg, Germany).