[gnu.emacs] AT386 keyboard bindings

drich@dialogic.uucp (Dan Rich) (01/16/90)

  Since I have seen requests for a terminal initialization file for
the at386, I thought I would post mine again.  This was originally
written for Interactive 386/ix, but I see no reason why it shouldn't
work under any at386 terminal (ie, AT&T, SCO, etc).

  The bindings for the numeric keypad in this file are as follows:
    arrows 	as expected
    PgUp, PgDn 	scroll down and up
    -		move the current line to the top of screen
    +		move the current line to the bottom of screen
    Home/End	once - beginning/end of line
		twice - beginning/end of screen
		thrice - beginning/end of file
  It also moves the help key to F1 and C-?, and remaps the backspace
key to delete.  This way, you aren't dropped into help every time you
try to delete a character.  There is also an attempt to use ALT as a
pseudo meta key, but it doesn't work properly for keys with no ALT-key
code (such as M-< and M->).

  If anyone has any suggestions for improvements, please let me know.
I am still looking for a good set of bindings for the function keys...

8<------------------------------ Cut Here ------------------------------>8
;;; $Id: at386.el,v 1.4 89/12/13 15:27:44 drich Exp $
;;;
;;; Interactive 386/ix at386 keyboard definitions
;;; Dan Rich (drich@dialogic.UUCP)
;;; 21 August 1989
;;;
;;; $Log:	at386.el,v $
; Revision 1.4  89/12/13  15:27:44  drich
; Modified keyboard-translate-table to include all 256 characters.
; 
; Revision 1.3  89/12/04  10:22:07  drich
; Added code to use ALT as the meta key.
; 
;;; Revision 1.2  89/09/14  11:44:32  drich
;;; Modified to tread DEL/BS correctly, also modified to use C-? for help.
;;; 
;;; Revision 1.1  89/09/14  11:06:16  drich
;;; Initial revision
;;; 
;;;
;;; Tested on: GNU Emacs 18.55.7 of Sat Oct 21 1989 on dialogic (usg-unix-v)
;;;
;;; Note: The shift key will affect the value of a function key, but
;;; the control and alt keys do not.
;;;
;;; Most of the information needed to create this file was taken from
;;; documentation found in lisp/keypad.el
;;;

(require 'keypad)

(defvar AT386-map-1 nil
  "The map for the function keys on the at386")
(defvar AT386-map-2 nil
  "The keypad map for the at386")
(defvar AT386-meta-map nil
  "Map to use ALT as the meta key")
(defvar last2 nil
  "Last key home/end, used in at386-home and at386-end")

(defun enable-at386-keys ()
  "Enable the use of the at386 function keys."
  (interactive)
  (global-set-key "\eO" AT386-map-1)
  (global-set-key "\e[" AT386-map-2)
  (global-set-key "\eN" AT386-meta-map))

(defun at386-home ()
  "Move cursor to top of screen."
  (interactive)
  (setq last last-command)
  (if (equal last 'at386-home)
      (if (equal last2 t)
	  (beginning-of-buffer)
	(progn
	  (move-to-window-line 0)
	  (setq last2 t)))
    (progn
      (beginning-of-line)
      (setq last2 nil))))

(defun at386-end ()
  "Move cursor to bottom of screen."
  (interactive)
  (setq last last-command)
  (if (equal last 'at386-end)
      (if (equal last2 t)
	  (end-of-buffer)
	(progn
	  (move-to-window-line -1)
	  (end-of-line)
	  (setq last2 t)))
    (progn
      (end-of-line)
      (setq last2 nil))))

(defun line-to-top ()
  (interactive)
  (recenter 0))

(defun line-to-bottom ()
  (interactive)
  (recenter (- (window-height) 2)))

;;; Create a few new keypad defaults.  Here's what I think I'm doing here:
;;; I look through "keypad.el" to find any unused entries in function-keymap
;;; and then create my own bindings for them here.  Then I use the newly
;;; created ?x string in the setup-terminal-keymap.

(define-key function-keymap "1" 'at386-end)
(define-key function-keymap "3" 'scroll-down)
(define-key function-keymap "5" 'recenter)
(define-key function-keymap "7" 'at386-home)
(define-key function-keymap "9" 'scroll-up)
(define-key function-keymap "-" 'line-to-top)
(define-key function-keymap "+" 'line-to-bottom)

(if AT386-map-1
    nil
  (setq AT386-map-1 (make-keymap))   ; <ESC>O commands
  (setup-terminal-keymap AT386-map-1
			 '(("P" . ??)   ; F1 (help-map)
			   )))

(if AT386-map-2
    nil
  (setq AT386-map-2 (make-keymap))   ; <ESC>[ commands
  (setup-terminal-keymap AT386-map-2
			 '(("A" . ?u)	; Up Arrow (previous-line)
			   ("B" . ?d)	; Down Arrow (next-line)
			   ("C" . ?r)	; Right Arrow (forward-char)
			   ("D" . ?l)	; Left Arrow (backward-char)
			   ("H" . ?7)	; Home (move-to-window-line 0)
			   ("Y" . ?1)   ; End (move-to-window-line -1)
			   ("G" . ?5)	; Clear (recenter)
			   ("U" . ?9)	; Page up (scroll-down)
			   ("V" . ?3)   ; Page down (scroll-up)
			   ("S" . ?-)   ; - key (line-to-top)
			   ("T" . ?+)   ; + key (line-to-bottom)
			   ("@" . ?I)   ; Insert (insert-character)
			   )))

(if AT386-meta-map
    nil
  (setq AT386-meta-map (copy-keymap esc-map))) ; ALT map

(enable-at386-keys)

;; Change the keyboard translation to interpret:
;; C-h as DEL
;; C-? as C-h (actually C-? generates C-_)
;; First make a translate table that does the identity translation.
(setq keyboard-translate-table (make-string 256 0))
(let ((i 0))
 (while (< i 256)
  (aset keyboard-translate-table i i)
  (setq i (1+ i))))
 
;; Translate C-h to DEL and C-? to C-h
(aset keyboard-translate-table ?\^H ?\^?)
(aset keyboard-translate-table ?\^_ ?\^H)

--
Dan Rich                    | ARPA: drich%dialogic@uunet.uu.net 
UNIX Systems Administrator  | UUCP: uunet!dialogic!drich
Dialogic Corporation        | - Time is an illusion.  Lunchtime, doubly so. -
(201) 334-1268 x213         |                           Douglas Adams