Add arch taglines
[bpt/emacs.git] / lisp / flow-ctrl.el
CommitLineData
fc68affa
ER
1;;; flow-ctrl.el --- help for lusers on cu(1) or ttys with wired-in ^S/^Q flow control
2
b578f267 3;; Copyright (C) 1990, 1991, 1994 Free Software Foundation, Inc.
3a801d0c 4
fc68affa
ER
5;; Author Kevin Gallagher
6;; Maintainer: FSF
fc68affa 7;; Adapted-By: ESR
fd7fa35a 8;; Keywords: hardware
1a06eabd 9
59243403
RS
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
b578f267
EN
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
fc68affa
ER
26
27;;; Commentary:
0f39230e 28
b578f267
EN
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
71296446
JB
32;; terminal.
33;;
b578f267
EN
34;; To invoke these adjustments, a user need only invoke the function
35;; enable-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.
71296446
JB
38;; Here's an example:
39;;
b578f267
EN
40;; (enable-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.
0f39230e 44
fc68affa
ER
45;;; Code:
46
162de182
RS
47(defvar flow-control-c-s-replacement ?\034
48 "Character that replaces C-s, when flow control handling is enabled.")
49(defvar flow-control-c-q-replacement ?\036
50 "Character that replaces C-q, when flow control handling is enabled.")
0f39230e 51
8f21333a
RS
52(put 'keyboard-translate-table 'char-table-extra-slots 0)
53
162de182
RS
54;;;###autoload
55(defun enable-flow-control (&optional argument)
56 "Toggle flow control handling.
57When handling is enabled, user can type C-s as C-\\, and C-q as C-^.
58With arg, enable flow control mode if arg is positive, otherwise disable."
59 (interactive "P")
60 (if (if argument
61 ;; Argument means enable if arg is positive.
62 (<= (prefix-numeric-value argument) 0)
63 ;; No arg means toggle.
64 (nth 1 (current-input-mode)))
65 (progn
66 ;; Turn flow control off, and stop exchanging chars.
67 (set-input-mode t nil (nth 2 (current-input-mode)))
f87de92a
RS
68 (if keyboard-translate-table
69 (progn
8f21333a
RS
70 (aset keyboard-translate-table flow-control-c-s-replacement nil)
71 (aset keyboard-translate-table ?\^s nil)
72 (aset keyboard-translate-table flow-control-c-q-replacement nil)
73 (aset keyboard-translate-table ?\^q nil))))
162de182
RS
74 ;; Turn flow control on.
75 ;; Tell emacs to pass C-s and C-q to OS.
76 (set-input-mode nil t (nth 2 (current-input-mode)))
77 ;; Initialize translate table, saving previous mappings, if any.
8f21333a
RS
78 (cond ((null keyboard-translate-table)
79 (setq keyboard-translate-table
80 (make-char-table 'keyboard-translate-table nil)))
81 ((char-table-p keyboard-translate-table)
82 (setq keyboard-translate-table
83 (copy-sequence keyboard-translate-table)))
84 (t
85 (let ((the-table (make-char-table 'keyboard-translate-table nil)))
86 (let ((i 0)
87 (j (length keyboard-translate-table)))
88 (while (< i j)
89 (aset the-table i (elt keyboard-translate-table i))
90 (setq i (1+ i))))
91 (setq keyboard-translate-table the-table))))
162de182
RS
92 ;; Swap C-s and C-\
93 (aset keyboard-translate-table flow-control-c-s-replacement ?\^s)
94 (aset keyboard-translate-table ?\^s flow-control-c-s-replacement)
95 ;; Swap C-q and C-^
96 (aset keyboard-translate-table flow-control-c-q-replacement ?\^q)
97 (aset keyboard-translate-table ?\^q flow-control-c-q-replacement)
d8fb88d5 98 (message "XON/XOFF adjustment for %s: use %s for C-s, and use %s for C-q"
71296446 99 (getenv "TERM")
d8fb88d5
KH
100 (single-key-description flow-control-c-s-replacement)
101 (single-key-description flow-control-c-q-replacement))
162de182 102 (sleep-for 2))) ; Give user a chance to see message.
0f39230e
JB
103
104;;;###autoload
61251338 105(defun enable-flow-control-on (&rest losing-terminal-types)
9c50f912 106 "Enable flow control if using one of a specified set of terminal types.
61251338 107Use `(enable-flow-control-on \"vt100\" \"h19\")' to enable flow control
9c50f912 108on VT-100 and H19 terminals. When flow control is enabled,
328561fc 109you must type C-\\ to get the effect of a C-s, and type C-^
9c50f912 110to get the effect of a C-q."
0f39230e
JB
111 (let ((term (getenv "TERM"))
112 hyphend)
409adbc7
KH
113 ;; Look for TERM in LOSING-TERMINAL-TYPES.
114 ;; If we don't find it literally, try stripping off words
115 ;; from the end, one by one.
116 (while (and term (not (member term losing-terminal-types)))
117 ;; Strip off last hyphen and what follows, then try again.
118 (if (setq hyphend (string-match "[-_][^-_]+$" term))
119 (setq term (substring term 0 hyphend))
120 (setq term nil)))
3bf5f17a 121 (if term
409adbc7 122 (enable-flow-control))))
0f39230e 123
49116ac0
JB
124(provide 'flow-ctrl)
125
ab5796a9 126;;; arch-tag: 0eb7b19e-0d93-4e0b-9ea2-72b574076a56
1a06eabd 127;;; flow-ctrl.el ends here