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

  1. ;;; File:  arrow-key-fix.el, v 1.1 (emacs 18[.58] version)
  2. ;;;
  3. ;;;               -----   ---------   -------
  4. ;;;               F i x   A r r o w   K e y s
  5. ;;;               -----   ---------   -------
  6. ;;;
  7. ;;;
  8. ;;; Copyright (C) 1990 Free Software Foundation, Inc.
  9. ;;; Copyright (C) 1993 Jeff Morgenthaler
  10. ;;;
  11.  
  12. ;; LCD Archive Entry:
  13. ;; arrow-key-fix|Jeff Morgenthaler|jpmorgen@wisp4.physics.wisc.edu|
  14. ;; Turns on the arrow AND function keys.|
  15. ;; 22-Mar-1993|1.1|~/terms/arrow-key-fix.el.Z|
  16.  
  17.  
  18. ;; Archived at archive.cis.ohio-state.edu.
  19.  
  20.  
  21. ;;; GNU Emacs is distributed in the hope that it will be useful, but
  22. ;;; WITHOUT ANY WARRANTY.  No author or distributor accepts
  23. ;;; RESPONSIBILITY TO anyone for the consequences of using it or for
  24. ;;; whether it serves any particular purpose or works at all, unless 
  25. ;;; he says so in writing.  Refer to the GNU Emacs General Public
  26. ;;; License for full details.
  27. ;;;
  28. ;;;  Send bug reports and suggestions for improvement to Jeff Morgenthaler
  29. ;;;  (jpmorgen@wisp4.physics.wisc.edu).
  30. ;;;
  31. ;;; Everyone is granted permission to copy, modify and redistribute
  32. ;;; GNU Emacs, but only under the conditions described in the GNU
  33. ;;; Emacs General Public License.  A copy of this license is supposed
  34. ;;; to have been given to you along with GNU Emacs so you can know
  35. ;;; your rights and responsibilities.  It should be in a file named
  36. ;;; COPYING.  Among other things, the Copyright notice and this notice
  37. ;;; must be preserved on all copies.
  38. ;;;
  39.  
  40. ;; When emacs first starts up, it knows nothing about the arrow keys.
  41. ;; Emacs was designed to work just fine this way!  However, many users
  42. ;; are accustomed to using the arrow keys from other editors.  This is
  43. ;; where the problem begins.  Emacs runs on all kinds of hardware,
  44. ;; much of which has different ways of handling the arrow keys.  You
  45. ;; can see that adding support for all of them could be hellish.
  46.  
  47. ;; Fortunately, support for emacs users on ANSI terminals (e.g. vt100,
  48. ;; vt200, etc.), has been added through code in keypad.el and the
  49. ;; files in lisp/term.  However, if you read these files, you will
  50. ;; find that the arrow keys on ANSI terminals are transmitted via a
  51. ;; complicated set of characters which have the unfortunate feature of
  52. ;; starting with ESC-[ and that in emacs, ESC-[ means
  53. ;; backward-paragraph.
  54.  
  55. ;; Why not just overmap backwards-paragraph for all emacs users?
  56. ;; That's just what many sites do, since many more people like the
  57. ;; arrow keys than backward-paragraph.  Since each site does the setup
  58. ;; in a slightly different way, a user usually can't get
  59. ;; backward-paragraph back if they like it over the arrow keys.  Also,
  60. ;; to turn on the arrow keys, the site must use a term-setup-hook,
  61. ;; which may conflict with the user's term-setup-hook.
  62.  
  63. ;; Isn't there a way to turn on the arrow/function keys by default,
  64. ;; but allow someone to define ESC-[ as backward-paragraph if they
  65. ;; want?  That's just what this code does.
  66.  
  67. ;; WARNING!  Not all of emacs is set up to work well with ANSI arrow
  68. ;; keys.  Just try terminating an I-search with an arrow key.  Getting
  69. ;; used to C-p C-n, etc. is not such a bad idea.
  70.  
  71. ;; INSTALLATION
  72.  
  73. ;; Copy this file into a directory recognized by emacs and put the line
  74. ;; (load "arrow-key-fix")
  75. ;; in your site's site-init.el file and the line
  76. ;; (auto-enable-arrow-keys) 
  77. ;; in the default.el file _after_ defining any term-setup-hook (see
  78. ;; below).  In order for everything to work properly, YOU MUST
  79. ;; RECOMPILE EMACS.
  80.  
  81. ;; If you can't recompile your emacs for some reason, you can fix the
  82. ;; arrow keys for yourself by putting the lines:
  83.  
  84. ;; (load "arrow-key-fix" nil t)
  85. ;; (auto-enable-arrow-keys) 
  86.  
  87. ;; in your .emacs file AFTER you define a term-setup-hook (if any).  
  88.  
  89. ;; This code depends on the terminal setup stuff that comes standard
  90. ;; with the emacs 18 version.  If you don't have your terminal type
  91. ;; properly defined (e.g. vt100 or vt200), it might not work right.
  92.  
  93. ;; NOTE: extending setup-hooks is tricky business.  I had to define a
  94. ;; variable in which to save the already existing term-setup-hook (I
  95. ;; called it site-term-setup-hook).  If you want to have more
  96. ;; automatic term setup stuff for your site, YOU MUST USE A DIFFERENT
  97. ;; NAME in which to save the user's setup hook (e.g.
  98. ;; user-term-setup-hook).  Here is an example (to be put in the
  99. ;; default.el file):
  100.  
  101. ;;(setq user-term-setup-hook term-setup-hook)
  102. ;;(setq term-setup-hook
  103. ;;      (function
  104. ;;       (lambda ()
  105. ;;     ;; A horrible hack to get remove key on LK105 keyboards
  106. ;;     ;; working in emacs' own xterms.  You must feed the following
  107. ;;     ;; code to xmodmap to get this to work:
  108. ;;
  109. ;;     ;; keycode 140 = F17
  110. ;;     ;; ! Fix dead "Remove" key for emacs by mapping it to F17
  111. ;;     ;; ! Code in default.el maps F17 to 'kill-region.  
  112. ;;     ;; ! Note that remove key is thus messed up for other software.
  113. ;;     ;; ! Hope that emacs-19 has a better fix.
  114. ;;
  115. ;;     (define-key CSI-map "31~" 'kill-region)
  116. ;;     (and user-term-setup-hook
  117. ;;          (funcall user-term-setup-hook))
  118. ;;     )))
  119.  
  120.  
  121. (define-key esc-map "[" nil)
  122. ;; ESC-[ (backward-paragraph) will be overmapped by the terminal
  123. ;; setup code that gets the arrow keys working.  Set it to nil here so
  124. ;; when called from default.el, auto-enable-arrow-keys knows whether
  125. ;; or not a user has mucked with it (e.g. really wants it to be
  126. ;; backwards-paragraph or anything else for that matter).
  127.  
  128. (defun auto-enable-arrow-keys ()
  129.   "Politely turns on the arrow/function keys without overmapping the
  130. user's term-setup-hook or a preference for ESC-[.  To reset ESC-[ to
  131. its default value, put the code:
  132. \(define-key esc-map ""["" 'backwards-paragraph\)
  133. in your .emacs file."
  134.  
  135.   ;; Save existing term-setup-hook here.  Note: the order of execution
  136.   ;; is important (and confusing): the function auto-enable-arrow-keys
  137.   ;; must be called after the term-setup-hook is defined, but
  138.   ;; term-setup-hook itself won't be executed until later.  Hence any
  139.   ;; variables containing old term-setup-hooks must be global and have
  140.   ;; unique names. 
  141.  
  142.   (setq site-term-setup-hook term-setup-hook)
  143.   (setq term-setup-hook
  144.     (function
  145.      (lambda ()
  146.        (and 
  147.         ;; Make sure the vt100/200 keymaps have been read in:
  148.         (fboundp 'enable-arrow-keys)
  149.         ;; and user hasn't expressed an opinion about ESC-[
  150.         (not (lookup-key esc-map "["))
  151.         (enable-arrow-keys))
  152.        ;; Call the old term-setup-hook whether or not the arrow
  153.        ;; keys were enabled.  
  154.        (and site-term-setup-hook
  155.         (funcall site-term-setup-hook))
  156.        )))
  157.   )
  158.