[comp.emacs] vt-100 keys, microemacs

kjartan@askja.UUCP (Kjartan R. Gudmundsson) (07/21/87)

I have been working on EDT emulation in microemacs, 
EDT uses arrow keys and function keys so I had to add support for those 
keys. I did that in a similar manner to the way this is done for 
MS-DOS, each function key (arrow keys included) respond by FNx where x
is a letter a-z or A-Z, case is significant. You have to 
put  definitions in the .emacsrc file for those function keys that you 
want to use. For example

bind-to-key forward-character FNC
bind-to-key backward-character FND
bind-to-key next-line FNB
bind-to-key previous-line FNA

There is a bug in microemacs that hinders the use of M-FNC etc.
I will wait until microemacs 3.9 has been posted, to post my
EDT emulation (which will be in the form of diffs between uemacs and my
modified files). (And also how to fix this Meta-Function bug 
if it will not be gone). I also had to turn flow control off,
and there fore I can not bind any functions to ^S nor ^Q.

I would like to point out that this is NOT the best way to support 
function keys, for example we have HP terminals, Altos terminals, VT-220
and VT-100 terminals, each with different (and sometimes stupid) ESC-sequences.
What is needed is a function in emacs of the form 

bind-to-many 

and then you could support any terminal by statements like
 
bind-to-many something-special ^AP --- F1 on an Altos terminal
bind-to-many previous-line ^[[A   --- arrow key on VT-100
or
(?)bind-to-many previous-line \0x1B[A

I hope to see this function in uemacs some day.

Insert the rest of this file into a file say: "diff.input"
and then give the command 

patch input.c diff.input

this will make a new input.c file and rename the old one to input.c.orig


--------------cut----here------------------------------------------
*************
*** 279,284
  	return(c);
  }
  
  /*	GET1KEY:	Get one keystroke. The only prefixs legal here
  			are the SPEC and CTRL prefixes.
  								*/

--- 281,301 -----
  		return(c);
  }
  
+ #define BUFSIZE  10
+ int	bufp = 0;
+ 
+ char buf[BUFSIZE]; /*buffer  for ungetch  */
+ 
+ 
+ ungetch(c)	/* push character back on input */
+ int c;
+ {  	
+ 	if (bufp > BUFSIZE )
+ 	  printf("ungetch: too many characters");
+ 	else 
+ 	  buf[bufp++] = c;
+ }
+ 	  
  /*	GET1KEY:	Get one keystroke. The only prefixs legal here
  			are the SPEC and CTRL prefixes.
  								*/
***************
*** 287,292
  
  {
  	int    c;
  #if	AMIGA
  	int	d;
  #endif

--- 304,311 -----
  
  {
  	int    c;
+         char   *ttype;
+         char   *getenv();
  #if	AMIGA
  	int	d;
  #endif
**************
*** 292,298
  #endif
  
  	/* get a keystroke */
!         c = tgetc();
  
  #if	MSDOS | ST520
  	if (c == 0) {				/* Apply SPEC prefix	*/

--- 310,316 -----
  #endif
  
  	/* get a keystroke */
!         c = ( ( bufp > 0) ? buf[--bufp] : tgetc() );
  
  #if	MSDOS | ST520
  	if (c == 0) {				/* Apply SPEC prefix	*/
***************
*** 294,300
  	/* get a keystroke */
          c = tgetc();
  
! #if	MSDOS | ST520
  	if (c == 0) {				/* Apply SPEC prefix	*/
  	        c = tgetc();
  	        if (c>=0x00 && c<=0x1F)		/* control key? */

--- 312,318 -----
  	/* get a keystroke */
          c = ( ( bufp > 0) ? buf[--bufp] : tgetc() );
  
! #if	MSDOS | ST520
 	if (c == 0) {				/* Apply SPEC prefix	*/
  	        c = tgetc();
  	        if (c>=0x00 && c<=0x1F)		/* control key? */
***************
*** 302,307
  		return(SPEC | c);
  	}
  #endif
  
  #if	AMIGA
  	/* apply SPEC prefix */

--- 320,329 -----
  		return(SPEC | c);
  	}
  #endif
+ #if 	USG
+ /* support or function keys, and arrow keys on vt100
+  * KRG may 1987
+  */
  
          if ((ttype = getenv("TERM")) == NULL)
          {
***************
*** 303,308
  	}
  #endif
  
  #if	AMIGA
  	/* apply SPEC prefix */
  	if ((unsigned)c == 155) {

--- 325,360 -----
   * KRG may 1987
   */
  
+         if ((ttype = getenv("TERM")) == NULL)
+         {
+                 puts("Environment variable TERM not defined!");
+                 exit(1);
+                 
+         }
+         if ( (0 == strcmp(ttype,"vt100") ) && (c == 0x1B ) )
+ 	{ 
+ 	
+ 	
+ 	     c = tgetc();
+ 	     if ( c == '[' )
+ 	     {
+ 	     	c = tgetc();
+ 	     	return (SPEC | c );
+              };
+ 	     if ( c == 'O' )
+ 	     {
+ 	     	c = tgetc();
+ 	     	return (SPEC | c );
+              };
+              ungetch(c);
+              c = 0x1B; /* we didn't get a leagal character, so we
+              		       return the ESC that started this */
+              
+         };
+ 
+ 	     	
+ 	     
+ #endif
  #if	AMIGA
  	/* apply SPEC prefix */
  	if ((unsigned)c == 155) {