*** empty log message ***
[bpt/emacs.git] / lisp / flow-ctrl.el
1 ;;; flow-ctrl.el --- help for lusers on cu(1) or ttys with wired-in ^S/^Q flow control
2
3 ;; Author Kevin Gallagher
4 ;; Maintainer: FSF
5 ;; Last-Modified: 03 Jun 1992
6 ;; Adapted-By: ESR
7 ;; Keywords: hardware
8
9 ;;; Copyright (C) 1990 Free Software Foundation, Inc.
10 ;;; Copyright (C) 1991 Kevin Gallagher
11 ;;;
12 ;;; GNU Emacs is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY. No author or distributor accepts
14 ;;; RESPONSIBILITY TO anyone for the consequences of using it or for
15 ;;; whether it serves any particular purpose or works at all, unless
16 ;;; he says so in writing. Refer to the GNU Emacs General Public
17 ;;; License for full details.
18 ;;;
19 ;;; Everyone is granted permission to copy, modify and redistribute
20 ;;; GNU Emacs, but only under the conditions described in the GNU
21 ;;; Emacs General Public License. A copy of this license is supposed
22 ;;; to have been given to you along with GNU Emacs so you can know
23 ;;; your rights and responsibilities. It should be in a file named
24 ;;; COPYING. Among other things, the Copyright notice and this notice
25 ;;; must be preserved on all copies.
26
27 ;;; Commentary:
28
29 ;;;; Terminals that use XON/XOFF flow control can cause problems with
30 ;;;; GNU Emacs users. This file contains Emacs Lisp code that makes it
31 ;;;; easy for a user to deal with this problem, when using such a
32 ;;;; terminal.
33 ;;;;
34 ;;;; To invoke these adjustments, a user need only invoke the function
35 ;;;; evade-flow-control-on with a list of terminal types in his/her own
36 ;;;; .emacs file. As arguments, give it the names of one or more terminal
37 ;;;; types in use by that user which require flow control adjustments.
38 ;;;; Here's an example:
39 ;;;;
40 ;;;; (evade-flow-control-on "vt200" "vt300" "vt101" "vt131")
41
42 ;;; Portability note: This uses (getenv "TERM"), and therefore probably
43 ;;; won't work outside of UNIX-like environments.
44
45 ;;; Code:
46
47 (defun evade-flow-control ()
48 "Enable use of flow control; let user type C-s as C-\ and C-q as C-^."
49 (interactive)
50 ;; Tell emacs to pass C-s and C-q to OS.
51 (set-input-mode nil t)
52 ;; Initialize translate table, saving previous mappings, if any.
53 (let ((the-table (make-string 128 0)))
54 (let ((i 0)
55 (j (length keyboard-translate-table)))
56 (while (< i j)
57 (aset the-table i (elt keyboard-translate-table i))
58 (setq i (1+ i)))
59 (while (< i 128)
60 (aset the-table i i)
61 (setq i (1+ i))))
62 (setq keyboard-translate-table the-table))
63 ;; Swap C-s and C-\
64 (aset keyboard-translate-table ?\034 ?\^s)
65 (aset keyboard-translate-table ?\^s ?\034)
66 ;; Swap C-q and C-^
67 (aset keyboard-translate-table ?\036 ?\^q)
68 (aset keyboard-translate-table ?\^q ?\036)
69 (message (concat
70 "XON/XOFF adjustment for "
71 (getenv "TERM")
72 ": use C-\\ for C-s and use C-^ for C-q."))
73 (sleep-for 2)) ; Give user a chance to see message.
74
75 (defun evade-flow-control-memstr= (e s)
76 (cond ((null s) nil)
77 ((string= e (car s)) t)
78 (t (evade-flow-control-memstr= e (cdr s)))))
79
80 ;;;###autoload
81 (defun evade-flow-control-on (&rest losing-terminal-types)
82 "Enable flow control if using one of a specified set of terminal types.
83 Use `(evade-flow-control-on \"vt100\" \"h19\")' to enable flow control
84 on VT-100 and H19 terminals. When flow control is enabled,
85 you must type C-\\ to get the effect of a C-s, and type C-^
86 to get the effect of a C-q."
87 (let ((term (getenv "TERM"))
88 hyphend)
89 ;; Strip off hyphen and what follows
90 (while (setq hyphend (string-match "[-_][^-_]+$" term))
91 (setq term (substring term 0 hyphend)))
92 (and (evade-flow-control-memstr= term losing-terminal-types) (evade-flow-control)))
93 )
94
95 (provide 'flow-ctrl)
96
97 ;;; flow-ctrl.el ends here