all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'William Case'" <billlinux@rogers.com>,
	"'Emacs Help List'" <help-gnu-emacs@gnu.org>
Subject: RE: What do 'hooks' do  and how do they do it?
Date: Sat, 1 Aug 2009 10:39:41 -0700	[thread overview]
Message-ID: <6F23A0A343F849F4B4932EFD5C4008F2@us.oracle.com> (raw)
In-Reply-To: <1249147043.2246.18.camel@CASE>

> 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.





  reply	other threads:[~2009-08-01 17:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-01 17:17 What do 'hooks' do and how do they do it? William Case
2009-08-01 17:39 ` Drew Adams [this message]
2009-08-01 18:00 ` Dirk-Jan C. Binnema
2009-08-01 20:43   ` William Case
2009-08-01 22:05     ` Drew Adams
2009-08-01 22:44       ` William Case
2009-08-07 15:17 ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6F23A0A343F849F4B4932EFD5C4008F2@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=billlinux@rogers.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.