From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jesper Harder Newsgroups: gmane.emacs.help Subject: Re: Canonical add-hook idiom Date: Sat, 15 Nov 2003 17:55:25 +0100 Organization: http://purl.org/harder/ Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1068915629 884 80.91.224.253 (15 Nov 2003 17:00:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 15 Nov 2003 17:00:29 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 15 18:00:26 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AL3mc-0004OE-00 for ; Sat, 15 Nov 2003 18:00:26 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AL4jY-0006yj-JP for geh-help-gnu-emacs@m.gmane.org; Sat, 15 Nov 2003 13:01:20 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!not-for-mail Original-Newsgroups: gnu.emacs.help X-Face: ^RrvqCr7c,P$zTR:QED"@h9+BTm-"fjZJJ-3=OU7.)i/K]<.J88}s>'Z_$r; List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:14269 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14269 Bob Nelson writes: > What is the preferred approach given these examples: > > 1). (add-hook 'some-mode-hook (lambda () [...] > 2). (add-hook 'some-mode-hook '(lambda () [...] > 3). (add-hook 'some-mode-hook (function (lambda () [...] > 4). None of the above -- please explain. 1) or 4). It's sometimes better to avoid lambda and add a function instead. This makes it easier to remove it from the hook again: (add-hook 'foo-hook 'bar) ;; Oops, bar didn't work as expected: (remove-hook 'foo-hook 'bar) Removing isn't quite as easy for lambda's.