From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: What do 'hooks' do and how do they do it? Date: Sat, 1 Aug 2009 10:39:41 -0700 Message-ID: <6F23A0A343F849F4B4932EFD5C4008F2@us.oracle.com> References: <1249147043.2246.18.camel@CASE> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1249148421 25485 80.91.229.12 (1 Aug 2009 17:40:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 1 Aug 2009 17:40:21 +0000 (UTC) To: "'William Case'" , "'Emacs Help List'" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 01 19:40:14 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MXIZ3-00042p-Qq for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Aug 2009 19:40:14 +0200 Original-Received: from localhost ([127.0.0.1]:37037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXIZ3-0000Zv-74 for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Aug 2009 13:40:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MXIYc-0000YX-29 for help-gnu-emacs@gnu.org; Sat, 01 Aug 2009 13:39:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MXIYW-0000Xt-NY for help-gnu-emacs@gnu.org; Sat, 01 Aug 2009 13:39:44 -0400 Original-Received: from [199.232.76.173] (port=40964 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXIYW-0000Xp-IY for help-gnu-emacs@gnu.org; Sat, 01 Aug 2009 13:39:40 -0400 Original-Received: from rcsinet12.oracle.com ([148.87.113.124]:55808 helo=rgminet12.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MXIYW-0003Dj-6c for help-gnu-emacs@gnu.org; Sat, 01 Aug 2009 13:39:40 -0400 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rgminet12.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n71HdZHD005800 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Aug 2009 17:39:37 GMT Original-Received: from abhmt005.oracle.com (abhmt005.oracle.com [141.146.116.14]) by acsinet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n71Hds7I009357; Sat, 1 Aug 2009 17:39:54 GMT Original-Received: from dradamslap1 (/141.144.64.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 01 Aug 2009 10:39:34 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcoSzBir0No8//3NSxOXMyxOyDaYNwAAH5mg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 In-Reply-To: <1249147043.2246.18.camel@CASE> X-Source-IP: abhmt005.oracle.com [141.146.116.14] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090203.4A747DD7.00E2:SCFSTAT5015188,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) 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:66627 Archived-At: > I know at a high level what a 'hook' is and how to use it an elisp > statement. And, I have seen hooks used in other programs > like SELinux. > > But I am curious about what is going on at the kernel level with a > 'hook'. If someone can give me a brief overview in relatively plain > language, I would appreciate it. > > e.g. some of the kind of questions that spring to mind. > Is it a process that is added to the task structure waiting to be > called? > How is it woken up? And what kind of events might wake it? etc. > > As I said, an overview would be helpful. If there is some > detail that I > want clarified, I can dig deeper once I have a general idea of what is > going on. See the Emacs manual, node `Hooks'. See the Elisp manual, node `Hooks'. A hook is a variable whose value is a list of functions. Typically, code invokes the functions in such a list, one by one. Such invocation is done using a function such as `run-mode-hooks' or `run-hooks'. A typical example is the code for a major mode, such as `emacs-lisp-mode'. The last thing such code does, when you turn on the mode, is to call `run-mode-hooks' to run the hook provided specifically for that mode, e.g. `emacs-lisp-mode-hook'. That is, it tries to invoke each of the functions on the list `emacs-lisp-mode-hook', in turn. If there are no functions on the hook, then nothing is done. Because you can change the value of a hook variable, to include different functions, you can in effect modify the behavior of the code that runs the hook. If, for example, you add your own function `foo' to `emacs-lisp-mode-hook', then whenever Emacs-Lisp mode is entered, `foo' will be invoked. In effect, you have extended the definition of function `emacs-lisp-mode' so that it also does `foo', after doing what it normally does. Hooks are thus a way to allow easy code extension at predefined places.