From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: the hand that feeds you Date: Thu, 27 Jul 2006 17:43:27 -0600 Organization: IHS Message-ID: References: <1154035859.849298@elch.in-berlin.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1154043831 8153 80.91.229.2 (27 Jul 2006 23:43:51 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 Jul 2006 23:43:51 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 28 01:43:51 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 1G6FWA-0001wm-KL for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Jul 2006 01:43:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G6FW9-0000gK-Nq for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Jul 2006 19:43:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G6FVy-0000fs-Hc for help-gnu-emacs@gnu.org; Thu, 27 Jul 2006 19:43:38 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G6FVw-0000eC-GO for help-gnu-emacs@gnu.org; Thu, 27 Jul 2006 19:43:38 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G6FVw-0000e9-DX for help-gnu-emacs@gnu.org; Thu, 27 Jul 2006 19:43:36 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G6FXn-0004i2-RK for help-gnu-emacs@gnu.org; Thu, 27 Jul 2006 19:45:32 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1G6FVk-0001tK-Tr for help-gnu-emacs@gnu.org; Fri, 28 Jul 2006 01:43:24 +0200 Original-Received: from 207.167.42.206 ([207.167.42.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Jul 2006 01:43:24 +0200 Original-Received: from ihs_4664 by 207.167.42.206 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Jul 2006 01:43:24 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 53 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.206 User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) In-Reply-To: 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:36309 Archived-At: Harald Hanche-Olsen wrote: > + 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 ())) That is just as dependent on the implementation of defun as the original is on the implementation of run-hooks and remove-hooks, isn't it? Although I guess you could argue that it's only fragile with respect to 1 special form instead of 2 functions. BTW, this is truly suicidal: (defun kill-myself () (insert "only once") (unintern 'kill-myself)) But maybe (fmakunbound 'kill-myself) or (fset 'kill-myself (symbol-function 'ignore)) is good enough. :-) All I wanted was a Pepsi, -- Kevin