[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: executing a lisp command as a hook
From: |
Steinar Bang |
Subject: |
Re: executing a lisp command as a hook |
Date: |
Fri, 28 Apr 2006 09:58:43 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) |
>>>>> mmuurr@gmail.com:
> So I tried a simple elisp function:
> (message jde-project-name)
> This works when I execute the command from a scratch buffer using C-c
> C-e, but if I include that command as is in the hook line (set using a
> configure-variable interface) I get this is a response in the echo
> area:
> Invalid function: (message jde-project-name)
I'm guessing that's because (message jde-project-name) by itself isn't
a function. It's a function call.
Did you try doing something like this?
(add-hook 'my-hook '(message jde-project-name))
?
> Can anyone tell me how to provide a way to call an elisp function from
> a hook variable?
You can use an anonymous lambda function, or define a function with a
name and use the name. I prefer using named functions, because they
are easier to recognize when looking at the hook's value, and easier
to remove.
Using a lambda it would be something like this:
(add-hook 'my-hook '(lambda () (message jde-project-name)))
Using a named function it would be something like this
(defun display-jde-project-name () (message jde-project-name))
(add-hook 'my-hook 'display-jde-project-name)
(though as was hinted at later in this thread, message may not be the
best function to use here)