[comp.emacs] Mapping wierd function keys with GNU

markb@sdcrdcf.UUCP (02/19/87)

I want to map the function keys on a couple of terminals that have wierd
sequences of characters for their function keys (tvi920 and VT220).
I will use the TVI920 as an example.  Function keys on the 920 send the
sequence "\C-A<letter>\r".  Now I know I can map these keys by defining
a sparce keymap for \C-A, then a sparce keymap for each function key
with \r bound to the function wanted.  Or I can bind the letters in the \C-A
map to functions that gobble up the \r and then invoke the wanted function
with call-interactively.  Either way it takes a lot of set-up and
greatly increases how long emacs takes to come up (which is long enough
already).  What I really want is a way to tell emacs to ignore the
following n characters when even it executes a function for the \C-A keymap.

This whole problem is much worse with the VT220 as it uses the sequence
"\e[<digit><digit>~" so complete binding of the 12 function keys takes
dozens of sparse keymaps or an intrepreter function that duplicates a lot
of the functionallity of keymaps and the command input system.

Mark Biggar
{allegra,burdvax,cbosgd,hplabs,ihnp4,akgua,sdcsvax}!sdcrdcf!markb

jr@ALEXANDER.BBN.COM.UUCP (02/24/87)

I came across the same thing when writing the code to handle BBN
bitgraph mice.  The bitgraph sends ANSI-standard (definitely NOT
wierd, in fact) sequences, which are a generalization of the VT220's
sequences:

   `ESC' `[' {<num> `;'}* {<num>} <letter>

and similar ones with `:' substituted for `['.  The <num>'s are
decimal numbers (maybe signed?) using the digits 0-9.  I had to write
a parser (it's in bg-mouse.el if you're interested).

I think the best approach to this is to put in a mode for
(interactive) which says "parse typed arguments according to ANSI
conventions, then dispatch on the first non-numeric and non-`;'
character".  The arguments would be assigned to the formal parameters
of the called function.  The dispatch would be through an auxilliary
keymap (similar to ESC-keymap) included for this purpose.  Maybe the
way to do it is to have two kinds of keymaps, one which invokes the
ANSI parsing; this type would be bound to ESC-[ and ESC-:.  Maybe it
is sufficient to have a global ANSI-parsing mode which can be turned
on based on terminal type.  Or maybe the way to do it is to assign a
special meaning to numbers and `;' in the ESC-[ keymap which says
"keep parsing numbers but stick to this keymap;" the numbers could be
cons'ed together into a list for later use in (interactive).

I didn't have the heart to attack the source changes, so there it
stands, but I think this could be a useful addition to GNU emacs.
Feel free to pick up the code in bg-mouse.el and re-use it (in the FSF
spirit of course!); maybe a general package to handle VT220 function
keys and friends would be considered useful.  Notice that this ANSI
mechanism is in fact a pretty general remote procedure call mechanism,
and could be used to do pretty fancy things in a programmable terminal
(and was in the Bitgraph).

/jr
jr@bbn.com or jr@bbnccv.uucp

Without life, there wouldn't be chemical companies.