Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!bu-cs!oliveb!3comvax!bridge2!mdb
From: mdb@ESD.3Com.COM (Mark D. Baushke)
Newsgroups: comp.emacs
Subject: Re: Using tags and a function key
Message-ID: 
Date: 23 Sep 89 07:20:54 GMT
References: <14063@shamash.cdc.com> 
	
Sender: news@bridge2.ESD.3Com.COM
Distribution: usa
Organization: 3Com Corp., Mountain View, CA.
Lines: 64

>>>>> On 22 Sep 89 14:02:18 GMT, ben@nsf1.mth.msu.edu (Ben Lotto) said:

Ben> On 22 Sep 89 09:04:10 GMT,
Ben> mdb@ESD.3Com.COM (Mark D. Baushke) said:

Mark> On 21 Sep 89 15:49:56 GMT, ldk@raistlin.udev.cdc.com (ld kelley)
Mark> said:

ldk> I am trying (for the first time) to bind a function to a key.

Mark> You might try the following:

Mark> (define-key sun-raw-map "212z" '(lambda () (find-tag nil t)))

Ben> This doesn't work (at least on my emacs on my system).  I get an error
Ben> which says

Ben>   Wrong type argument: commandp, (lambda nil (find-tag nil t))

Oops, sorry about that. My previous lambda-expression example fails
because it is not interactive. From the documentation:

commandp:
[...]

Interactively callable functions include strings (treated as keyboard macros),
lambda-expressions that contain a top-level call to  interactive ,
autoload definitions made by  autoload  with non-nil fourth argument,
and some of the built-in functions of Lisp.


Ben> The thing that does work here is

Ben>   (defun my-find-tag-next ()
Ben>     (interactive)
Ben>     (find-tag nil t))

Ben>   (define-key sun-raw-map "212z" 'my-find-tag-next)

Yes. This is a reasonable alternative and it allow you to get at it
via M-x my-find-tag-next as well as binding it to more than one key.

Ben> This is because the third argument to define-key must be nil, a command,
Ben> a string, a keymap, or a list consisting of elements of the form 
Ben> (keymap . char).

The lambda form is equivalent to the body of a (defun name (args) BODY).
Had you defined your defun as

	(defun my-find-tag-next ()
	  (find-tag nil t))

you would have had the same error about a wrong type argument from
commandp.

If you did not want to use the separate function my-find-tag-next, you
should be able to use the following:

(define-key sun-raw-map "212z" '(lambda () (interactive) (find-tag nil t)))

Enjoy!
--
Mark D. Baushke
mdb@ESD.3Com.COM