ldk@raistlin.udev.cdc.com (ld kelley x-6857) (09/21/89)
I am trying (for the first time) to bind a function to a key.
I am not having a good time :-). The function I am trying to use
if find-tag with a numeric argument (ie: fing the next tag). No
matter what arguments I put there, I get the message
Wrong type argument: commandp,...
I am working on a Sun3 with version 18.54 of emacs (Sun OS 4.0.3).
I have tried the following:
(define-key sun-raw-map "212z" '(find-tag nil 1 ))
(define-key sun-raw-map "212z" '(find-tag 1))
The manual states that if you pass find-tag a numeric argument, and it
will use the last tag and continue searching.
thanks in advance,
larry
-------------------------------------------------------------------------------
Larry D. Kelley | Internet: ldk@udev.cdc.com
Control Data Corporation| uucp: {uunet}!shamash!punjab!raistlin!ldk
4201 Lexington Ave No. | AT&T: 01-612-482-2046mdb@ESD.3Com.COM (Mark D. Baushke) (09/22/89)
On 21 Sep 89 15:49:56 GMT, ldk@raistlin.udev.cdc.com (ld kelley) said:
ldk> I am trying (for the first time) to bind a function to a key.
ldk> I am not having a good time :-). The function I am trying to use
ldk> if find-tag with a numeric argument (ie: fing the next tag). ...
ldk> I am working on a Sun3 with version 18.54 of emacs (Sun OS 4.0.3).
[...deleted examples which failed...]
You might try the following:
(define-key sun-raw-map "212z" '(lambda () (find-tag nil t)))
ldk> -------------------------------------------------------------------------
ldk> Larry D. Kelley | Internet: ldk@udev.cdc.com
ldk> Control Data Corporation| uucp: {uunet}!shamash!punjab!raistlin!ldk
ldk> 4201 Lexington Ave No. | AT&T: 01-612-482-2046
Enjoy!
--
Mark D. Baushke
mdb@ESD.3Com.COMben@nsf1.mth.msu.edu (Ben Lotto) (09/22/89)
On 22 Sep 89 09:04:10 GMT,
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)))
This doesn't work (at least on my emacs on my system). I get an error
which says
Wrong type argument: commandp, (lambda nil (find-tag nil t))
The thing that does work here is
(defun my-find-tag-next ()
(interactive)
(find-tag nil t))
(define-key sun-raw-map "212z" 'my-find-tag-next)
This is because the third argument to define-key must be nil, a command,
a string, a keymap, or a list consisting of elements of the form
(keymap . char).
--
-B. A. Lotto (ben@nsf1.mth.msu.edu)
Department of Mathematics/Michigan State University/East Lansing, MI 48824guttman@mitre.org (Joshua D. Guttman) (09/23/89)
In a posting from mdb@ESD.3Com.COM (Mark D. Baushke), the all-important form (interactive) got left out. His example should have read: (define-key sun-raw-map "212z" '(lambda () (interactive)(find-tag nil t)))
mdb@ESD.3Com.COM (Mark D. Baushke) (09/23/89)
>>>>> 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