help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: add-hook


From: Robert D. Crawford
Subject: Re: add-hook
Date: Wed, 06 Jun 2007 15:41:20 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Sebastian Tennant <address@hidden> writes:

> Am I right in thinking this is OK:
>
> (add-hook 'foo-hook 'bar-function 'baz-function ...)

As I understand it, no.  Only one function can be added to a hook at a
time.  This is what the lambda is for.  In effect it creates a single
function from multiple functions when only one function can be used.
For example:

(add-hook 'emacs-lisp-mode-hook
          '(lambda ()
             (make-local-hook 'after-save-hook)
             (add-hook 'after-save-hook
                       '(lambda ()
                          (byte-compile-file buffer-file-name)) 
                       nil t)))


Everything contained within the lambda on line 2 is considered one
item.  

> That is to say, single functions passed via add-hook are added to a
> list the contents of which are evaluated in turn, but a lambda
> function passed via add-hook is evaluated as it stands, (no list of
> functions is created) so there can be only one lambda function passed
> via add-hook at any one time?

I am not sure what exactly you mean here.  I _think_ you can run
add-hook multiple times for the same hook in the same file using lambda
each time, as inefficient as it may be.

I hope this answers your questions,
rdc
-- 
Robert D. Crawford                                      address@hidden

BOFH excuse #351:

PEBKAC (Problem Exists Between Keyboard And Chair)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]