home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / edt / flow-ctrl.el < prev    next >
Encoding:
Text File  |  1992-03-24  |  4.2 KB  |  109 lines

  1. ;;; File:  flow-ctrl.el, v 1.3
  2. ;;;
  3. ;;;               -------   -------------   ---------------------
  4. ;;;               F l o w   C o n t r o l   A d j u s t m e n t s
  5. ;;;               -------   -------------   ---------------------
  6. ;;;
  7. ;;;
  8. ;;; Copyright (C) 1990 Free Software Foundation, Inc.
  9. ;;; Copyright (C) 1991 Kevin Gallagher
  10. ;;;
  11. ;;; GNU Emacs is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY.  No author or distributor accepts
  13. ;;; RESPONSIBILITY TO anyone for the consequences of using it or for
  14. ;;; whether it serves any particular purpose or works at all, unless 
  15. ;;; he says so in writing.  Refer to the GNU Emacs General Public
  16. ;;; License for full details.
  17. ;;;
  18. ;;;  Send bug reports and suggestions for improvement to Kevin Gallagher
  19. ;;;  (kgallagh@digi.lonestar.org).
  20. ;;;
  21. ;;; Everyone is granted permission to copy, modify and redistribute
  22. ;;; GNU Emacs, but only under the conditions described in the GNU
  23. ;;; Emacs General Public License.  A copy of this license is supposed
  24. ;;; to have been given to you along with GNU Emacs so you can know
  25. ;;; your rights and responsibilities.  It should be in a file named
  26. ;;; COPYING.  Among other things, the Copyright notice and this notice
  27. ;;; must be preserved on all copies.
  28. ;;;
  29.  
  30. ;;;; Terminals that use XON/XOFF flow control can cause problems with
  31. ;;;; GNU Emacs users.  This file contains elisp code that makes it
  32. ;;;; easy for a user to deal with this problem, when using such a
  33. ;;;; terminal. 
  34. ;;;; 
  35. ;;;; To make this facility available for use to all users, place this
  36. ;;;; file, flow-ctrl.el, into your site's public emacs/lisp
  37. ;;;; directory and add the following command to your site's default.el
  38. ;;;; file: 
  39. ;;;; 
  40. ;;;;           (require 'flow-ctrl)
  41. ;;;;      
  42. ;;;; To invoke these adjustments, a user need only define the variable
  43. ;;;; terminal-uses-flow-control-chars in his/her own .emacs file.  The
  44. ;;;; variable must contain a list of one or more terminal types in use
  45. ;;;; by that user which require flow control adjustments.  Here's an
  46. ;;;; example: 
  47. ;;;; 
  48. ;;;;           (setq terminal-uses-flow-control-chars 
  49. ;;;;                 '("vt200" "vt300" "vt101" "vt131"))
  50. ;;;; 
  51. ;;;; A message will appear, if the adjustments are made, during
  52. ;;;; initialization for at least 6 seconds informing the user that the
  53. ;;;; adjustments have been invoked.  If you wish these adjustments to
  54. ;;;; be made quietly, then add the following line to your .emacs file:
  55. ;;;; 
  56. ;;;;           (setq do-flow-control-adjustments-quietly t)
  57. ;;;; 
  58.  
  59. (defun evade-flow-control ()
  60.   "Replace C-s with C-\ and C-q with C-^ and tell emacs to pass C-s
  61. and C-q characters to OS."
  62.   (interactive)
  63.   ;; Tell emacs to pass C-s and C-q to OS.
  64.   (set-input-mode nil t)
  65.   ;; Initialize translate table, saving previous mappings, if any.
  66.   (let ((the-table (make-string 128 0)))
  67.     (let ((i 0)
  68.       (j (length keyboard-translate-table)))
  69.       (while (< i j)
  70.     (aset the-table i (elt keyboard-translate-table i))
  71.     (setq i (1+ i)))
  72.       (while (< i 128)
  73.     (aset the-table i i)
  74.     (setq i (1+ i))))
  75.     (setq keyboard-translate-table the-table))
  76.   ;; Swap C-s and C-\
  77.   (aset keyboard-translate-table ?\034 ?\^s)
  78.   (aset keyboard-translate-table ?\^s ?\034)
  79.   ;; Swap C-q and C-^
  80.   (aset keyboard-translate-table ?\036 ?\^q)
  81.   (aset keyboard-translate-table ?\^q ?\036)
  82.   (if (not (boundp 'do-flow-control-adjustments-quietly))
  83.       (progn
  84.     (message (concat 
  85.            "XON/XOFF adjustment for " 
  86.            (getenv "TERM") 
  87.            ":  use C-\\ for C-s  and  use C-^ for C-q."))
  88.     (sleep-for 6))) ; Give user a chance to see message.
  89.   )
  90. (if (boundp 'terminal-uses-flow-control-chars)
  91.     (let ((term (getenv "TERM"))
  92.           hyphend)
  93.       ;; Strip off hyphen and what follows
  94.       (while (setq hyphend (string-match "[-_][^-_]+$" term))
  95.         (setq term (substring term 0 hyphend)))
  96.       (let ((len (length terminal-uses-flow-control-chars))
  97.             (idx 0)
  98.             (temp-term nil))
  99.         (while (and (< idx len)
  100.                     (not temp-term))
  101.           (if (string-equal term 
  102.                             (nth idx terminal-uses-flow-control-chars))
  103.               (progn
  104.                 (evade-flow-control)
  105.                 (setq temp-term term))
  106.               (setq idx (1+ idx)))))))
  107.  
  108. (provide 'flow-ctrl)
  109.