From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Stephen J. Turnbull" Newsgroups: gmane.emacs.devel Subject: Re: Idempotency of add-hook wrt lambda expressions Date: Thu, 05 Mar 2009 10:27:28 +0900 Message-ID: <87vdqo92tb.fsf@xemacs.org> References: <74F2CF19-2E71-473F-A352-A628B3B29A8E@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1236217079 14004 80.91.229.12 (5 Mar 2009 01:37:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Mar 2009 01:37:59 +0000 (UTC) Cc: Geoff Gole , Stefan Monnier , emacs-devel@gnu.org To: David Reitter Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 05 02:39:16 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 1Lf2YN-0000LG-7L for ged-emacs-devel@m.gmane.org; Thu, 05 Mar 2009 02:39:15 +0100 Original-Received: from localhost ([127.0.0.1]:52206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lf2X1-0007FX-Sg for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 20:37:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lf2SI-0004tp-RL for emacs-devel@gnu.org; Wed, 04 Mar 2009 20:32:58 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lf2SI-0004tS-64 for emacs-devel@gnu.org; Wed, 04 Mar 2009 20:32:58 -0500 Original-Received: from [199.232.76.173] (port=33252 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lf2SH-0004tM-Nm for emacs-devel@gnu.org; Wed, 04 Mar 2009 20:32:57 -0500 Original-Received: from mx20.gnu.org ([199.232.41.8]:35441) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lf2SH-0006zl-CL for emacs-devel@gnu.org; Wed, 04 Mar 2009 20:32:57 -0500 Original-Received: from mtps01.sk.tsukuba.ac.jp ([130.158.97.223]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lf2SF-0007FZ-W0 for emacs-devel@gnu.org; Wed, 04 Mar 2009 20:32:56 -0500 Original-Received: from uwakimon.sk.tsukuba.ac.jp (uwakimon.sk.tsukuba.ac.jp [130.158.99.156]) by mtps01.sk.tsukuba.ac.jp (Postfix) with ESMTP id 326CE1535AE; Thu, 5 Mar 2009 10:32:47 +0900 (JST) Original-Received: by uwakimon.sk.tsukuba.ac.jp (Postfix, from userid 1000) id 47DEC1A2C40; Thu, 5 Mar 2009 10:27:29 +0900 (JST) In-Reply-To: <74F2CF19-2E71-473F-A352-A628B3B29A8E@gmail.com> X-Mailer: VM 8.0.12-devo-585 under 21.5 (beta28) "fuki" 83e35df20028+ XEmacs Lucid (x86_64-unknown-linux) X-detected-kernel: by mx20.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:109459 Archived-At: David Reitter writes: > On 4 Mar 2009, at 09:18, Stefan Monnier wrote: > > > As a general rule, you should not put a lambda but a function name > > (i.e. a symbol) instead, to avoid all those problems (and be able to > > replace the function with a newer version of it). But occasionally > > a lambda is really exactly what you want, of course. > People haven't adopted this, and this is pretty annoying. > > A similar case are commands bound to menu items (or any other keys): C- > h k does not bring up something useful for keys that are just bound to > a lambda term. > > As for hooks, is a lambda expression ever suitable to be added to a > hook? > Would it make sense to change add-hook such that only true function > names are allowed? In all these cases the problem that you consistently run into is that Emacs Lisp doesn't have namespaces/packages. It's very common to want to make a small tweak to a command's default arguments when it's used as a hook or menu item, and adding more symbols for that just feels wrong. Not to mention getting in the way of completion. lambdas may have docstrings, and probably things like C-h k would find them if provided. Hm, easy enough to check: (define-key global-map [(control c) z] (lambda () "Found doc!" (interactive) (message "yowza"))) C-h k C-c z ==> C-c z runs (lambda nil Found doc! (interactive) (message yowza)) Found doc! So the obvious workaround is to report a bug if a lambda in a menu item doesn't have a docstring. Maybe there should be a describe-hook help function that returns a buffer like ---------------------------------------------------------------- foo-hook runs, in this order: 1. default-foo-hook-function Drink foo in bar. 2. (lambda ...) Call auxiliary-foo-hook-function with argument "hair of dog". ----------------------------------------------------------------