[comp.emacs] key mapping and commandp error

kayvan@APPLE.COM (Kayvan Sylvan) (03/04/91)

Erik Hennum writes:
> I am a writer (not a Lisp programmer) trying to take greater 
> advantage of the glory that is emacs.  I'm trying to bind 
> keys to commands.  For example:
> 
>     (global-set-key "\M-p" '(move-to-window-line 0))
> 
> Emacs reads the previous line in my .emacs without complaint.
> When I press Meta-p, however, I get:
> 
>     Wrong type argument: commandp, (move-to-window-line 0)

You can only bind keys to commands (that's what the error message is
telling you). You can use the lambda form, however, like this:

(global-set-key "\M-p" '(lambda () (interactive) (move-to-window-line 0)))

The "(interactive)" tells Emacs this is a command (interactively
callable function).

			---Kayvan

| Kayvan Sylvan       Unix/C, GNU tools   879 Lewiston Drive   408-978-1407  |
| Sylvan Associates   GUIs, Databases     San Jose, CA 95136  Think Globally |
|                     Networking, X       apple!satyr!kayvan   Act Locally   |
| === Currently looking for contracts === Hire me now! Avoid the rush! ===   |