[comp.emacs] AT386.el

src@scuzzy.in-berlin.de (Heiko Blume) (03/13/91)

john@axis-design.fr (John Hughes) writes:
[his at386.el]

>;; Now we should make the ALT key be a META key, ALT + x => ESC N x
>;; But how can we do that??

try this:


;;; $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)

;;;(defun umlaut-e ()
;;;  (interactive)
;;;  (if (save-excursion
;;;	(or (bolp)
;;;	    (progn (backward-char 1) (not (looking-at "[aou]")))))
;;;      (insert "e")
;;;    (backward-char 1)
;;;    (insert "\\*")
;;;    (forward-char 1)))
;;;
;;;(defun scharfes-z ()
;;;  (interactive)
;;;  (if (save-excursion
;;;	(or (bolp)
;;;	    (progn (backward-char 1) (not (looking-at "s")))))
;;;      (insert "z")
;;;    (backward-char 1)
;;;    (insert "\\*")
;;;    (forward-char 1)))
;;;
;;;(global-set-key "e" 'umlaut-e)
;;;(global-set-key "z" 'scharfes-z)
-- 
      Heiko Blume <-+-> src@scuzzy.in-berlin.de <-+-> (+49 30) 691 88 93
                  public UNIX source archive [HST V.42bis]:
        scuzzy Any ACU,f 38400 6919520 gin:--gin: nuucp sword: nuucp
                     uucp scuzzy!/src/README /your/home