From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: ~`symbol-function' to get code as list even when byte-compiled? Date: Mon, 25 May 2015 19:48:19 +0200 Organization: Informatimago Message-ID: <87h9r08s64.fsf@kuiper.lan.informatimago.com> References: <877frxid14.fsf@debian.uxu> <87twv18i91.fsf@kuiper.lan.informatimago.com> <87wpzw1t8e.fsf@debian.uxu> <87k2vw1rmh.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1432576142 5139 80.91.229.3 (25 May 2015 17:49:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 May 2015 17:49:02 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 25 19:48:49 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YwwUa-0005py-SB for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2015 19:48:49 +0200 Original-Received: from localhost ([::1]:44593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwwUa-0008Jk-Dk for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2015 13:48:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwwUL-0008Id-Vk for help-gnu-emacs@gnu.org; Mon, 25 May 2015 13:48:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YwwUG-0003nX-SE for help-gnu-emacs@gnu.org; Mon, 25 May 2015 13:48:33 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:43866) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwwUG-0003nK-LX for help-gnu-emacs@gnu.org; Mon, 25 May 2015 13:48:28 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YwwUF-0005iC-7Q for help-gnu-emacs@gnu.org; Mon, 25 May 2015 19:48:27 +0200 Original-Received: from amontsouris-654-1-18-241.w90-2.abo.wanadoo.fr ([90.2.153.241]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 May 2015 19:48:27 +0200 Original-Received: from pjb by amontsouris-654-1-18-241.w90-2.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 May 2015 19:48:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 43 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-654-1-18-241.w90-2.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:MjMyNzM0OGY1YTQ3OWY3MjY5YjkwMTlkY2UxNzlhMTUxMDE4MDI1Yw== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor 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 Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104560 Archived-At: Emanuel Berg writes: > "Pascal J. Bourguignon" > writes: > >> To store state. >> >> Don't store state in the code, use the code to act >> on state stored in variables! > > The problem can be restated like this: > > A, B, ..., N are arbitrary functions. > > At some time they (in any constellation) will be > included in a hook function list. > > However, each function should only be executed *once* > and then immediately dropped from that hook. > > A, B, ..., and N don't know any of this, and in > particular they don't know what hook they might be > added to. Then you can just write: ;;;; -*- mode:emacs-lisp;lexical-binding:t;coding:utf-8 -*- (defun add-one-shot-meat (hook fun) (let ((name (gensym))) (setf (symbol-function name) (lambda () (remove-hook hook name) (funcall fun))) (add-hook hook name))) and use add-one-shot-meat instead of add-hook. -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk