[gnu.emacs] Prefixes for function keys

allan@svax.cs.cornell.edu (James Allan) (04/01/89)

This is my first posting to this group and I've only read the group
for the first time this morning.  Consequently, I can only hope that
this is an appropriate request and that it isn't one of those "oh boy,
we've heard THIS one 783 times before" requests.  If so, please set me
straight and I'll do penance by using vi or something....

I'm a gnu-emacs novice who wants to set things up so that I can use
the function keys on my Sun3/60 under X11.  The keys generate a
sequence of the form "<esc>[123z" where "123" can be pretty much any
number.  I've looked around at keymaps and Lisp vectors and other such
stuff and it seems like MAYBE I could figure out how to do it (if it
can be done), but since Lisp and I aren't great buddies, I figure it'd
be a tremendous chore.

So, the question of the day is: Can it be done?  If so, has anyone
done it and is that person willing to share some code?  If it can be
done, but no one has done it, can someone point me toward useful
documentation or somesuch?

Thanks in advance for the help!

			-- james allan
			   allan@cs.cornell.edu

bob@tinman.cis.ohio-state.edu (Bob Sutterfield) (04/03/89)

In article <26575@cornell.UUCP> allan@svax.cs.cornell.edu (James Allan) writes:
   I'm a gnu-emacs novice who wants to set things up so that I can use
   the function keys on my Sun3/60 under X11.  The keys generate a
   sequence of the form "<esc>[123z" where "123" can be pretty much
   any number.

Here's what Chris Lott worked up for our students, when their
instructor wanted them to be able to use the arrow keys.  You should
be able to figure out from this, how to program all the others as
well.

It seems that sometimes you'll see VT100-mapping keycodes from the
arrow keys, and other times you'll see the numbers.  That may depend
upon what version of what window system you're using, and what version
of the keyboard ROMs it knows how to talk to at initialization time.

Anyway, stick this in your .emacs and enjoy!

;;
; arrow key remappings
; unmap the escape sequence esc-left_bracket
(global-unset-key       "\e[")
;;
; esc-[-A is up arrow, vt100 mapping
(global-set-key         "\e[A"          'previous-line)
; esc-[-215z is up arrow, sun kbd mapping
(global-set-key         "\e[215z"       'previous-line)
;;
; esc-[-B is down arrow, vt100 mapping
(global-set-key         "\e[B"          'next-line)
; esc-[-221z is up arrow, sun kbd mapping
(global-set-key         "\e[221z"       'next-line)
;;
; esc-[-C is right arrow, vt100 mapping
(global-set-key         "\e[C"          'forward-char)
; esc-[-219z is right arrow, sun kbd mapping
(global-set-key         "\e[219z"       'forward-char)
;;
; esc-[-D is left arrow, vt100 mapping
(global-set-key         "\e[D"          'backward-char)
; esc-[-217z is left arrow, sun kbd mapping
(global-set-key         "\e[217z"       'backward-char)
;;
; map r11 key to set mark - a safe null command for key between arrow keys
(global-set-key         "\e[218z"       'set-mark-command)
;;
; R15  key - move down in file
(global-set-key         "\e[222z"       'scroll-up)
; R9  key  - move up in file
(global-set-key         "\e[216z"       'scroll-down)
; R7 key   - go to top
(global-set-key         "\e[214z"       'beginning-of-buffer)
; R13 key  - go to end
(global-set-key         "\e[220z"       'end-of-buffer)
;;