home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / edt / edt-vt100.el < prev    next >
Encoding:
Text File  |  1991-10-25  |  6.9 KB  |  179 lines

  1. ;;; File:  edt-vt100.el, v 1.0
  2. ;;;
  3. ;;;            -----   -----------   -------   -----------------
  4. ;;;            E D T   K e y p a d   M o d e   E m u l a t i o n
  5. ;;;            -----   -----------   -------   -----------------
  6. ;;;
  7. ;;;       -----   ----------  ----------  ---------   -----------------
  8. ;;;       F o r   V T 1 0 0,  V T 2 0 0,  V T 3 0 0   T e r m i n a l s
  9. ;;;       -----   ----------  ----------  ---------   -----------------
  10. ;;;
  11. ;;;                        BETA Distribution Version 0.5
  12. ;;;
  13. ;;; Copyright (C) 1986 Free Software Foundation, Inc.
  14. ;;; Copyright (C) 1991 Kevin Gallagher
  15. ;;;
  16. ;;;
  17. ;;; This file contains GNU Emacs VT100, VT200, and VT300 series terminal
  18. ;;; specific EDT bindings and functions.
  19. ;;;
  20. ;;; Send bug reports and suggestions for improvement to Kevin Gallagher
  21. ;;; (kgallagh@digi.lonestar.org).
  22. ;;;
  23.  
  24. ;;;;
  25. ;;;; KEY TRANSLATIONS
  26. ;;;;
  27.  
  28. (defvar *vt100-keys*
  29.   '(("KP0" . "p") ("KP1" . "q") ("KP2" . "r") ("KP3" . "s") ("KP4" . "t")
  30.     ("KP5" . "u") ("KP6" . "v") ("KP7" . "w") ("KP8" . "x") ("KP9" . "y")
  31.     ("KP," . "l") ("KP-" . "m") ("KPP" . "n") ("KPE" . "M") ("PF1" . "P")
  32.     ("PF2" . "Q") ("PF3" . "R") ("PF4" . "S") ("UP" . "A") ("DOWN" . "B")
  33.     ("RIGHT" . "C") ("LEFT" . "D")))
  34.  
  35. (defvar *vt200-keys*
  36.   '(("FIND" . "1~") ("INSERT" . "2~") ("REMOVE" . "3~") ("SELECT" . "4~")
  37.     ("PREVIOUS" . "5~") ("NEXT" . "6~") ("F6" . "17~") ("F7" . "18~")
  38.     ("F8" . "19~") ("F9" . "20~") ("F10" . "21~") ("F11" . "23~")
  39.     ("F12" . "24~") ("F13" . "25~") ("F14" . "26~") ("HELP" . "28~")
  40.     ("DO" . "29~") ("F17" . "31~") ("F18" . "32~") ("F19" . "33~")
  41.     ("F20" . "34~") ("UP" . "A") ("DOWN" . "B") ("RIGHT" . "C")
  42.     ("LEFT" . "D")))
  43.  
  44. ;;;;
  45. ;;;; BINDS VT100/VT200/VT300 FUNCTION KEYS
  46. ;;;;
  47. ;; The function edt-bind-function-key is keyboard/terminal dependent.
  48.  
  49. ;; The arrow keys appear in both maps, so special logic has been
  50. ;; added to ensure that they get defined in both maps.
  51.  
  52. (defun edt-bind-function-key 
  53.     (function-key binding gold-binding &optional default)
  54.   "Terminal specific function which binds commands to keyboard function keys in
  55. the EDT Emulator."
  56.   (let ((key-code (cdr (assoc function-key *vt100-keys*)))
  57.         (key-sequence)
  58.         (key-found nil))
  59.     (if (not (null key-code))
  60.         (progn
  61.           (setq key-found t)
  62.           (setq key-sequence (concat "\eO" key-code))
  63.           (if default
  64.               (progn
  65.                 (define-key edt-default-global-map key-sequence binding)
  66.                 (define-key 'edt-default-gold-map key-sequence gold-binding))
  67.               (progn
  68.                 (define-key edt-user-global-map key-sequence binding)
  69.                 (define-key 'edt-user-gold-map key-sequence gold-binding)))))
  70.     (setq key-code (cdr (assoc function-key *vt200-keys*)))
  71.     (if (not (null key-code))
  72.         (progn
  73.           (setq key-sequence (concat "\e[" key-code))
  74.           (if default
  75.               (progn
  76.                 (define-key edt-default-global-map key-sequence binding)
  77.                 (define-key 'edt-default-gold-map key-sequence gold-binding))
  78.               (progn
  79.                 (define-key edt-user-global-map key-sequence binding)
  80.                 (define-key 'edt-user-gold-map key-sequence gold-binding))))
  81.         (if (not key-found)
  82.             (error "%s is not a legal function key name" function-key)))))
  83.  
  84. ;;;;
  85. ;;;; Setup extra default EDT key bindings.
  86. ;;;;
  87.  
  88. ;;; The following function, edt-setup-extra-default-bindings, is
  89. ;;; optional.  If defined, it is called during EDT emulation setup.
  90. ;;; It permits the EDT emulation binding of extra function keys not
  91. ;;; found on VT100/VT200/VT300 terminals.
  92. ;;;
  93. ;;; Since this file IS the VT100/VT200/VT300 terminal file, there are no
  94. ;;; extra function keys to bind.  All the default EDT bindings for the
  95. ;;; standard VT100/VT200/VT300 keys are made in edt.el, so no bindings are
  96. ;;; made here.  See one of the other terminal specific files for an example
  97. ;;; of how this function is set up (edt-apollo.el, for example).
  98.  
  99.  
  100. ;;;;
  101. ;;;; SET UP ADDITIONAL PREFIX MAPS.
  102. ;;;;
  103.  
  104. ;;; The following functions are also optional.  If defined, they are
  105. ;;; called during EDT emulation setup.  If a terminal generates more
  106. ;;; than one character sequence prefix for its function keys, then
  107. ;;; separate keymaps must be maintained for each additional prefix.
  108. ;;; The VT200/VT300 series terminals have "\eO" and "\e[" as function
  109. ;;; key prefixes.  These maps must be created and assigned to the
  110. ;;; prefix character sequences in the appropriate global map.
  111. ;;; 
  112. ;;; By default, edt.el sets up the initial set of prefix maps for a
  113. ;;; single prefix.  edt-bind-function-key, above, assigns the prefix
  114. ;;; "\eO" to those initial maps and "\e[" to the maps defined here.
  115.  
  116. (defun edt-additional-default-prefix-map-setup ()
  117.   "Setup additional terminal specific default prefix maps."
  118.   (define-prefix-command 'edt-vt200-default-prefix-map)
  119.   (define-key edt-default-global-map "\e[" 'edt-vt200-default-prefix-map))
  120.  
  121. (defun edt-additional-user-prefix-map-setup ()
  122.   "Setup additional terminal specific user prefix maps."
  123.   (fset 'edt-vt200-user-prefix-map (copy-keymap 'edt-vt200-default-prefix-map))
  124.   (define-key edt-user-global-map "\e[" 'edt-vt200-user-prefix-map))
  125.  
  126.  
  127. ;;;;
  128. ;;;; TERMINAL SPECIFIC VERSIONS OF COMMANDS
  129. ;;;;
  130.  
  131. ;;; Screen width commands often need terminal specific enhancements.
  132. ;;;
  133. ;;; Need to tell VT100/VT200/VT300 terminals to use the appropriate
  134. ;;; character set.
  135. ;;;
  136.  
  137. (defun edt-set-screen-width-80 ()
  138.   "Set screen width to 80 columns."
  139.   (interactive)
  140.   (send-string-to-terminal "\e[?3l")
  141.   (set-screen-width 80)
  142.   (message "%sScreen width 80"))
  143.  
  144. (defun edt-set-screen-width-132 ()
  145.   "Set screen width to 132 columns."
  146.   (interactive)
  147.   (send-string-to-terminal "\e[?3h")
  148.   (set-screen-width 132)
  149.   (message "%sScreen width 132"))
  150.  
  151. ;;;
  152. ;;; DEFAULT EDT KEYPAD HELP
  153. ;;;
  154. ;; The default keypad help function is defined in edt.el, so there is
  155. ;; no need to define on here. 
  156.  
  157. ;;;
  158. ;;; CUSTOMIZE DEFAULT EMACS BINDINGS
  159. ;;;
  160. ;; Some site-specific and/or computer-specific Emacs installations may
  161. ;; contain some built-in support for function keys on a given terminal
  162. ;; and may provide some default bindings to those keys.  Sometimes
  163. ;; these bindings are made by using Emacs macros to equate the
  164. ;; function key to control key, for example.  This means that when the
  165. ;; EDT emulation re-defines that control key, the function key default
  166. ;; definition is re-defined, as well, often causing undesired results.
  167. ;; To avoid this problem, when EDT emulation begins initialization, it
  168. ;; looks to see if the function edt-customize-default-emacs-bindings
  169. ;; has been defined.  If so, it calls this function before starting
  170. ;; the EDT Emulation initialization.  (See edt-apollo.el for an example.)
  171.  
  172. ;; A user version of this function is available: 
  173. ;;
  174. ;;          edt-user-customize-default-emacs-bindings
  175. ;;
  176. ;; If defined in edt-user.el, it will be called immediately after 
  177. ;; edt-customize-default-emacs-bindings and before EDT emulation
  178. ;; initialization begins.
  179.