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