From xemacs-m  Thu Jun  5 22:24:56 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id WAA23550
	for <xemacs-beta@xemacs.org>; Thu, 5 Jun 1997 22:24:55 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id FAA08969; Fri, 6 Jun 1997 05:24:55 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: Moving more of character->event handling to Lisp-land
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 06 Jun 1997 05:24:53 +0200
Message-ID: <kigyb8oct16.fsf@jagor.srce.hr>
Lines: 103
X-Mailer: Gnus v5.4.52/XEmacs 20.3(beta3)

I have attempted to play with destroying the code in
`character_to_event', and it initially worked much better than I
expected.  Disregarding the fact that XEmacs called \177 C-? and
escape C-[ instead of the fancy `delete' and `escape' (which would
normally get translated to DEL and ESC for printing), everything
worked fine -- primarily due to fact that `backspace-or-delete' was
bound to ?\177 rather than 'delete.  As expected, the line

(global-set-key 'delete 'foo)

had no effect on TTY-s.

X code worked more or less like before, which actually means that it
*didn't* work.  Pressing the key-above-enter generates a Delete X
event for me.  But since \177 is bound to `backspace-or-delete', and
it has no connection with the delete keysym, this is fine.

However, main problem arose when I tried to add the following code to
be executed after the TTY allocation (but before
termcap/terminal-library initialization):

  Fdefine_key (con->function_key_map, build_string ("\t"), QKtab);
  Fdefine_key (con->function_key_map, build_string ("\n"), QKlinefeed);
  Fdefine_key (con->function_key_map, build_string ("\r"), QKreturn);
  Fdefine_key (con->function_key_map, build_string ("\033"), QKescape);
  Fdefine_key (con->function_key_map, build_string ("\177"), QKdelete);
  Fdefine_key (con->function_key_map, build_string (" "), QKspace);

I added that code to `tty_init_console', right before the call to
`connect_to_gpm'.

However, `xemacs -nw' won't startup after doing this, because very
early during the startup it tries to bind something to (e.g.) "\C-[OA"
(cursor key up).  This dies with the error message:

early-error-handler(error (error "can't bind C-[ O D: C-[ C-[ has a non-keymap binding" escape)

Obviously, when given "\C-[OA", `define-key' doesn't really appreciate 
the fact that `function-key-map' binds "\C-[" to `escape'.

The question is: is this a bug or a feature?  Is it intended
behaviour?  What should the workaround be?  Was it a good idea to use
`function-key-map' for this anyway?


The experimental patches follow.  DON'T APPLY THEM UNLESS YOU KNOW
WHAT YOU ARE DOING and want to test things.

Patch to clean up `character_to_event':

--- events.c.orig	Thu Jun  5 16:32:20 1997
+++ events.c	Thu Jun  5 16:33:35 1997
@@ -675,6 +675,8 @@
   if (c < ' ') c += '@', m |= MOD_CONTROL;
   if (m & MOD_CONTROL)
     {
+      /* ...pray the Lord my soul to keep... */
+#if 0
       switch (c)
 	{
 	case 'I': k = QKtab;	  m &= ~MOD_CONTROL; break;
@@ -686,12 +688,15 @@
 	case 'H': k = QKbackspace; m &= ~MOD_CONTROL; break;
 # endif
 	}
+#endif
       if (c >= 'A' && c <= 'Z') c -= 'A'-'a';
     }
+#if 0
   else if (c == 127)
     k = QKdelete;
   else if (c == ' ')
     k = QKspace;
+#endif
   
   event->event_type	     = key_press_event;
   event->timestamp	     = 0; /* #### */


Patch to add the define-keys:

--- console-tty.c.orig	Tue Jun  3 17:16:59 1997
+++ console-tty.c	Fri Jun  6 05:19:05 1997
@@ -128,6 +128,13 @@
   CONSOLE_TTY_DATA (con)->terminal_type = terminal_type;
   CONSOLE_TTY_DATA (con)->controlling_process = controlling_process;
 
+  Fdefine_key (con->function_key_map, build_string ("\t"), QKtab);
+  Fdefine_key (con->function_key_map, build_string ("\n"), QKlinefeed);
+  Fdefine_key (con->function_key_map, build_string ("\r"), QKreturn);
+  Fdefine_key (con->function_key_map, build_string ("\033"), QKescape);
+  Fdefine_key (con->function_key_map, build_string ("\177"), QKdelete);
+  Fdefine_key (con->function_key_map, build_string (" "), QKspace);
+
 #ifdef HAVE_GPM
   connect_to_gpm(con);
 #endif


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
I'm sure they'll listen to reason! -- Neal Stevenson, _Snow Crash_

