From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Steinar Bang Newsgroups: gmane.emacs.help Subject: Re: executing a lisp command as a hook Date: Fri, 28 Apr 2006 09:58:43 +0200 Organization: Probably a good idea Message-ID: <87d5f2ku6k.fsf@dod.no> References: <1146179269.179185.88680@j33g2000cwa.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: sea.gmane.org 1146211187 15132 80.91.229.2 (28 Apr 2006 07:59:47 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 28 Apr 2006 07:59:47 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 28 09:59:45 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FZNt6-0007N2-0m for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Apr 2006 09:59:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FZNt5-0005S9-HA for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Apr 2006 03:59:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FZNsV-0005Jk-3U for help-gnu-emacs@gnu.org; Fri, 28 Apr 2006 03:59:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FZNsR-0005Hc-SM for help-gnu-emacs@gnu.org; Fri, 28 Apr 2006 03:59:01 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FZNsR-0005HO-9x for help-gnu-emacs@gnu.org; Fri, 28 Apr 2006 03:58:59 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FZNvW-0005ZA-KA for help-gnu-emacs@gnu.org; Fri, 28 Apr 2006 04:02:10 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1FZNsJ-0007FM-Pc for help-gnu-emacs@gnu.org; Fri, 28 Apr 2006 09:58:51 +0200 Original-Received: from pat-gw.osl.fast.no ([217.144.235.5]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Apr 2006 09:58:51 +0200 Original-Received: from sb by pat-gw.osl.fast.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Apr 2006 09:58:51 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-To: help-gnu-emacs@gnu.org Original-Lines: 37 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: pat-gw.osl.fast.no Mail-Copies-To: never User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:Xt8tjh9sQxD1mti+JWqPOK/UL9E= 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:34697 Archived-At: >>>>> 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)