From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Harald Hanche-Olsen Newsgroups: gmane.emacs.help Subject: Re: the hand that feeds you Date: Fri, 28 Jul 2006 00:05:30 +0200 Organization: Norwegian university of science and technology Message-ID: References: <1154035859.849298@elch.in-berlin.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1154040066 31658 80.91.229.2 (27 Jul 2006 22:41:06 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 Jul 2006 22:41:06 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 28 00:41:01 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G6EXF-0000pH-Az for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Jul 2006 00:40:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G6EXE-0007AH-UT for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Jul 2006 18:40:52 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!uninett.no!ntnu.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-NNTP-Posting-Host: fiinbeck.math.ntnu.no Original-X-Trace: orkan.itea.ntnu.no 1154037737 31119 129.241.15.140 (27 Jul 2006 22:02:17 GMT) Original-X-Complaints-To: usenet@itea.ntnu.no Original-NNTP-Posting-Date: Thu, 27 Jul 2006 22:02:17 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.0 (berkeley-unix) Cancel-Lock: sha1:Ebm1qYnB3nGJ2zhqWTiR35UhJMU= Original-Xref: shelby.stanford.edu gnu.emacs.help:140681 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:36306 Archived-At: + Andreas Seik : | Hello Newsgroup, | | i need code in a hook that is executed only once, | so i tested the following: | | | (defvar my-hook '()) | (defun kill-myself () | (insert "only once")(remove-hook 'my-hook 'kill-myself)) | (add-hook 'my-hook 'kill-myself) | (run-hooks 'my-hook);; i think it might crash here, but it does not | (run-hooks 'my-hook) | | it, seems to work, but i do not trust it. | is it not "biting the hand that feeds you" It works, even in the presence of more hooks on the hook variable. But I agree it looks scary, and it seems to rely on the implementation of run-hooks and remove-hook: In all likelihood, run-hooks will just cdr down the list, running the car of the rest each time. And remove-hook will not modify the cons cell containing kill-myself as its car and the remaining list as its cdr, so all is well. But it's bad coding style, because you must reason out all that to see why it works. And it is conceivable, if unlikely, that the implementation one of these functions will change so that it no longer works. Better then, to let kill-myself really to commit suicide, rather than just to remove itself from a hook: (defun kill-myself () (insert "only once") (defun kill-myself ())) -- * Harald Hanche-Olsen - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell