home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / terms / keypad.el < prev    next >
Encoding:
Text File  |  1993-03-22  |  6.2 KB  |  168 lines

  1. ;;; File:  keypad.el, v 2.0 (emacs 18[.58] version)
  2.  
  3. ;; Copyright (C) 1993 Jeff Morgenthaler
  4. ;; Copyright (C) 1986 Free Software Foundation, Inc.
  5.  
  6. ;; LCD Archive Entry:
  7. ;; keypad.el|Jeff Morgenthaler|jpmorgen@wisp4.physics.wisc.edu|
  8. ;; Support for all the function keys of the vt200 (LK105) keyboard|
  9. ;; 22-Mar-1993|2.9|~/terms/keypad.el|
  10.  
  11. ;; This file is not yet part of GNU Emacs.
  12.  
  13. ;; GNU Emacs is free software; you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 1, or (at your option)
  16. ;; any later version.
  17.  
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ;; GNU General Public License for more details.
  22.  
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  25. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  
  27. ;; Terminal-independent keypad and function key bindings.
  28.  
  29. ;; These keys are handled by a two-level process.
  30. ;; The first level, terminal-dependent, maps input sequences
  31. ;; into the function keys that they represent.
  32. ;; The second level, terminal-independent but customized by users,
  33. ;; map function keys into meanings.
  34.  
  35. ;; This file takes care of the second level of mapping.
  36. ;; The first, terminal-dependent, level is handled by the
  37. ;; terminal-specific files term/*.el.
  38.  
  39. ;; The second-level mapping is done by a keymap, function-keymap.
  40. ;; Here we document the meanings of the "characters" defined by
  41. ;; function-keymap.
  42.  
  43. ;; What do these letters mean?
  44. ;; When we say that ``a stands for the clear-all-tabs key'',
  45. ;; we mean that you should attach to the letter `a' in function-keymap
  46. ;; whatever command you want to be executed when you type the
  47. ;; clear-all-tabs key on any terminal.  The terminal-dependent
  48. ;; files will attempt to make this work.  If a terminal has no
  49. ;; clear-all-tabs key that can be recognized, it makes no difference
  50. ;; what binding you give to `a' in function-keymap.
  51.  
  52. ;; a -- clear all tabs key
  53. ;; c -- erase key
  54. ;; d -- down-arrow
  55. ;; e -- enter key
  56. ;; f -- find key or search key
  57. ;; h -- home-position key
  58. ;; k -- delete key or remove key.
  59. ;; l -- left-arrow
  60. ;; p -- portrait mode
  61. ;; q -- landscape mode
  62. ;; r -- right-arrow
  63. ;; s -- select key
  64. ;; t -- clear tab this column key
  65. ;; u -- up-arrow
  66. ;; x -- do key
  67. ;; ? -- help
  68.  
  69. ;; - -- keypad key labelled `-'.
  70. ;; . -- keypad key labelled `.'.
  71. ;; , -- keypad key labelled `,'.
  72. ;; 0 ... 9 -- keypad key labelled with that digit,
  73. ;;   but only if that key is not also an arrow key.
  74.  
  75. ;; C-@, C-a, ... C-x -- numbered function keys 0 through 24.
  76. ;; These are used for function keys with no labels but numbers,
  77. ;; and may also be used for function keys with labels
  78. ;; that we have not defined letters for.
  79.  
  80. ;; A -- insert line key
  81. ;; C -- clear screen key
  82. ;; D -- delete character key.
  83. ;; E -- clear to end of line key
  84. ;; F -- scroll forward key
  85. ;; H -- home-down
  86. ;; I -- insert character key
  87. ;;       If there is just an "insert" key, it should be this.
  88. ;; L -- delete line key
  89. ;; M -- exit insert mode key
  90. ;; N -- next page key
  91. ;; P -- previous page key
  92. ;; R -- scroll reverse key
  93. ;; S -- clear to end of screen key
  94. ;; T -- set tab this column key
  95.  
  96. (defun keypad-default (char definition)
  97.   (or (lookup-key function-keymap char)
  98.       (define-key function-keymap char definition)))
  99.  
  100. ;; Here are the standard command meanings we give to the various
  101. ;; function key names.  Because this file is loaded after the user's
  102. ;; init file, we are careful to avoid overriding any definitions
  103. ;; already stored in function-keymap by the init file or (less often)
  104. ;; by the terminal-specific term/*.el file.
  105.  
  106. (keypad-default "l" 'backward-char)
  107. (keypad-default "r" 'forward-char)
  108. (keypad-default "D" 'delete-char)
  109. (keypad-default "u" 'previous-line)
  110. (keypad-default "d" 'next-line)
  111. (keypad-default "N" 'scroll-up)
  112. (keypad-default "P" 'scroll-down)
  113. (keypad-default "C" 'recenter)
  114. (keypad-default "?" 'help-for-help)
  115. (keypad-default "s" 'set-mark-command)
  116. (keypad-default "k" 'kill-region)
  117. (keypad-default "f" 're-search-forward)
  118. ;; New--makes "Do" into M-x
  119. (keypad-default "x" 'execute-extended-command)
  120.  
  121. (keypad-default "\C-a" 'beginning-of-line)
  122. (keypad-default "\C-b" 'end-of-line)
  123. (keypad-default "\C-c" 'isearch-forward)
  124. (keypad-default "\C-d" 'kill-line)
  125.  
  126. ;; New stuff.
  127. (keypad-default "\C-l" 'fill-paragraph)
  128. (keypad-default "\C-m" 'fill-region)
  129. (keypad-default "\C-n" 'set-fill-prefix)
  130.  
  131. (keypad-default "." 'delete-char)
  132. (keypad-default "0" 'yank)
  133. (keypad-default "e" 'open-line)
  134. (keypad-default "1" 'backward-word)
  135. (keypad-default "3" 'forward-word)
  136. (keypad-default "7" 'backward-paragraph)
  137. (keypad-default "9" 'forward-paragraph)
  138. (keypad-default "h" 'move-to-window-line)
  139.  
  140. (defun setup-terminal-keymap (map translations)
  141.   "Set up keymap MAP to forward to function-keymap according to TRANSLATIONS.
  142. TRANSLATIONS is an alist; each element of it looks like (FROMSTRING . TOCHAR).
  143. For each such pair, we define the key sequence FROMSTRING in MAP
  144. to forward to the definition of character TOCHAR in function-keymap.
  145. \"Forwarding\" means that subsequent redefinition of TOCHAR in
  146. function-keymap will be seen automatically in MAP as well.
  147.  
  148. This function is used by files term/*.el to set up the mapping from the
  149. escape sequences sent by function keys on particular terminals (FROMSTRINGs)
  150. into Emacs standard function key slots (TOCHARs).
  151. An actual definition (such as a symbol) may be given in place of TOCHAR.
  152. Generally, MAP is a prefix keymap which will be attached to a key
  153. that is the common prefix sent by all function keys (often ESC O or ESC [)."
  154.   (while translations
  155.     (define-key map (car (car translations))
  156.       (if (numberp (cdr (car translations)))
  157.       (cons function-keymap (cdr (car translations)))
  158.     (cdr (car translations))))
  159.     (setq translations (cdr translations))))
  160.  
  161. (defun function-key-sequence (char)
  162.   "Return key sequence for function key that on this terminal
  163. translates into slot CHAR in function-keymap.
  164. Or return nil if there is none."
  165.   (car (where-is-internal (cons function-keymap char) (current-local-map))))
  166.  
  167. (provide 'keypad)
  168.