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