home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / fix-my-terminal / function-key-fix.el < prev    next >
Encoding:
Text File  |  1993-03-26  |  6.5 KB  |  142 lines

  1. ;;; File:  function-key-fix.el, v 1.1 (emacs 18[.58] version)
  2. ;;;
  3. ;;;               -----   ---------------   -------
  4. ;;;               F i x   F u n c t i o n   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. ;; fix-my-terminal|Jeff Morgenthaler|jpmorgen@wisp4.physics.wisc.edu|
  14. ;; Fixes:  flow control, arrow keys, and vt200 function keys|
  15. ;; 93-03-23|1.0|~/packages/fix-my-terminal.tar.Z
  16.  
  17. ;; Archived at archive.cis.ohio-state.edu.
  18.  
  19.  
  20. ;;; GNU Emacs is distributed in the hope that it will be useful, but
  21. ;;; WITHOUT ANY WARRANTY.  No author or distributor accepts
  22. ;;; RESPONSIBILITY TO anyone for the consequences of using it or for
  23. ;;; whether it serves any particular purpose or works at all, unless 
  24. ;;; he says so in writing.  Refer to the GNU Emacs General Public
  25. ;;; License for full details.
  26. ;;;
  27. ;;;  Send bug reports and suggestions for improvement to Jeff Morgenthaler
  28. ;;;  (jpmorgen@wisp4.physics.wisc.edu).
  29. ;;;
  30. ;;; Everyone is granted permission to copy, modify and redistribute
  31. ;;; GNU Emacs, but only under the conditions described in the GNU
  32. ;;; Emacs General Public License.  A copy of this license is supposed
  33. ;;; to have been given to you along with GNU Emacs so you can know
  34. ;;; your rights and responsibilities.  It should be in a file named
  35. ;;; COPYING.  Among other things, the Copyright notice and this notice
  36. ;;; must be preserved on all copies.
  37. ;;;
  38.  
  39. ;; When emacs first starts up, it knows nothing about the arrow or
  40. ;; function keys.  Emacs was designed to work just fine this way!
  41. ;; However, many users are accustomed to using these keys from other
  42. ;; editors.  This is where the problem begins.  Emacs runs on all
  43. ;; kinds of hardware, much of which has different ways of handling the
  44. ;; function keys.  You can see that adding support for all of them
  45. ;; 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/function keys on ANSI terminals are transmitted
  51. ;; via a complicated set of characters which have the unfortunate
  52. ;; feature of starting with ESC-[ and that in emacs, ESC-[ means
  53. ;; backward-paragraph.
  54.  
  55. ;; Due to some elisp magic (sparse key maps), vt100 terminal arrow
  56. ;; keys have been working for a long time.  However, this magic does
  57. ;; not extend to the vt200 type function keys.  Users who like to use
  58. ;; these keys should put the following lines in their .emacs files.
  59.  
  60. ;;        (require 'function-key-fix)                   
  61. ;;        (auto-function-key-fix)                       
  62. ;;        ;; ESC-[ as backward-paragraph is lost.       
  63. ;;        ;; !!! No term-setup-hook below this point !!!
  64.  
  65. ;; or call function-key-fix from their term-setup-hook (see vtxxx.el
  66. ;; for an example).
  67.  
  68. ;; WARNING!  Not all of emacs is set up to work well with ANSI
  69. ;; arrow/function keys.  Just try terminating an I-search with an
  70. ;; arrow key.  Getting used to C-p C-n, etc. is not such a bad idea.
  71.  
  72. ;; This code depends on the terminal setup stuff that comes standard
  73. ;; with the emacs 18 version.  If you don't have your environment
  74. ;; variable TERM properly defined (e.g. vt100 or vt200), it might not
  75. ;; work right.
  76.  
  77. ;; NOTE: extending setup-hooks is tricky business.  I had to define a
  78. ;; variable in which to save the already existing term-setup-hook (I
  79. ;; called it site-term-setup-hook).  If you want to have more
  80. ;; automatic term setup stuff for your site, YOU MUST USE A DIFFERENT
  81. ;; NAME in which to save the user's setup hook (e.g.
  82. ;; user-term-setup-hook).  Here is an example (to be put in the
  83. ;; default.el file):
  84.  
  85. ;;(setq user-term-setup-hook term-setup-hook)                             
  86. ;;(setq term-setup-hook                                                   
  87. ;;      (function                                                         
  88. ;;       (lambda ()                                                       
  89. ;;         ;; A horrible hack to get remove key on VT200 keyboards        
  90. ;;         ;; working in emacs' own xterms.  You must feed the following  
  91. ;;         ;; code to xmodmap to get this to work:                        
  92. ;;                                                                        
  93. ;;         ;; keycode 140 = F17                                           
  94. ;;         ;; ! Fix dead "Remove" key for emacs by mapping it to F17      
  95. ;;         ;; ! Code in default.el maps F17 to 'kill-region.              
  96. ;;         ;; ! Note that remove key is thus messed up for other software.
  97. ;;         ;; ! Hope that emacs-19 has a better fix.                      
  98. ;;                                                                        
  99. ;;         (and (fboundp 'enable-arrow-keys)                              
  100. ;;              (progn                                                    
  101. ;;                (enable-arrow-keys)                                     
  102. ;;                (define-key CSI-map "31~" 'kill-region))   ; F17        
  103. ;;              )                                                         
  104. ;;         (and user-term-setup-hook                                      
  105. ;;              (funcall user-term-setup-hook))                           
  106. ;;         )                                                              
  107. ;;       ))                                                               
  108.  
  109. (provide 'function-key-fix)
  110.  
  111. (defun auto-function-key-fix ()
  112.   "Turns on the arrow/function keys without overmapping a previously
  113. defined term-setup-hook.  To use this, put the following lines in your
  114. .emacs file:
  115.  
  116. (require 'function-key-fix)                   
  117. (auto-function-key-fix)                       
  118. ;; ESC-[ as backward-paragraph is lost.       
  119. ;; !!! No term-setup-hook below this point !!!"
  120.  
  121.   ;; Save existing term-setup-hook here.  Note: the order of execution
  122.   ;; is important (and confusing): the function auto-function-key-fix
  123.   ;; must be called after the term-setup-hook is defined, but
  124.   ;; term-setup-hook itself won't be executed until later.  Hence any
  125.   ;; variables containing old term-setup-hooks must be global and have
  126.   ;; unique names. 
  127.  
  128.   (setq site-term-setup-hook term-setup-hook)
  129.   (setq term-setup-hook
  130.     (function
  131.      (lambda ()
  132.        (and 
  133.         ;; Make sure vtxxx has been read in
  134.         (fboundp 'enable-arrow-keys)
  135.         (enable-arrow-keys))
  136.        ;; Call the old term-setup-hook whether or not the function
  137.        ;; keys were enabled.  
  138.        (and site-term-setup-hook
  139.         (funcall site-term-setup-hook))
  140.        )))
  141.   )
  142.