[net.emacs] GNU Emacs prefix keys -- solution

mjp@spice.cs.cmu.edu (Michael Portuesi) (10/07/86)

Keywords:


My problem with binding the function keys on a VT-100 to GNU Emacs
commands has been solved.  Once again, thanks to all of you who sent
help.  Many of you pointed out to me that I am trying to re-invent the
wheel, as support code for the VT-100 (and many other terminals as
well) can be found in the directory /lisp/terms as part of the
standard Emacs distribution.

There is an ambiguity in the standard Emacs documentation.  Since the
ESC key serves as a Meta key on many terminals, it made sense to me to
assume that the ESC key was a synonym for the Meta key and try to bind
it to functions.  They are two separate and distinct entities.

The Meta key, on terminals that support it, activates the high bit of
the byte being sent so it is in the range 128-255.  Since most
terminals do not have a dedicated Meta key, Emacs binds the ESC key to
the function ESC-prefix, which contains a keymap for Meta functions to
be accessed via the ESC key.

My original attempt at key binding looked like the following:

(global-set-key "\M-OP" 'other-window)			;PF1 -- other window

which attempted to bind (other-window) to Meta-O (an O with the high
bit set) followed by P.  This is not the same as ESC followed by O
followed by P (which is what the VT-100 sends).  The former is a
two-character sequence, the latter three.  The following key binding
is correct:

(global-set-key "\eOP" 'other-window)

My .emacs file currently has global-set-keys for the function keys, to
bind them to functions I use frequently or appreciate (like undo).  I
chose not to use the vt100.el package in lisp/terms, because it
defines every key on the keypad for a particular function, and I have
to avoid becoming dependent on one particular keyboard arrangement
since I use up to five or more different keyboards every day.

Another way to bind the function keys is to set up a keymap.  I
received code from a number of individuals showing me how to do this.
Basically it involves creating a keymap and assigning it to a prefix
key sequence.  Then you bind functions using (define-key) to the
keymap, not the prefix key sequence.  Thanks goes to Robert Krawitz
(rlk@athena.mit.edu) for this example:

(setq my-prefix-map (make-keymap)) ;or make-sparse-keymap
(global-set-key "\e\\" 'my-prefix) ;that's M-\ (backslash)
(define-key my-prefix-map "f" 'forward-mumble)
(define-key my-prefix-map "b" 'backward-mumble)

This method is more complex than simply using global-set-key, but is
more flexible, since it is easier to turn the bindings on and off when
they are in a keymap and not global.
-- 

+----------------------------------------------------------------------------+
| Mike Portuesi								     |
| Carnegie-Mellon University Computer Science Department		     |
|									     |
| ARPA: mjp@spice.cs.cmu.edu (preferred), mp1u@td.cc.cmu.edu		     |
| UUCP: {harvard | seismo | ucbvax | decwrl}!spice.cs.cmu.edu!mjp	     |
|									     |
| "Little things remind me of you...Cheap cologne and that damn song too!"   |
|			--The Flirts, "Jukebox"				     |
+----------------------------------------------------------------------------+