0
|
1 ;;; flow-ctrl.el --- help for lusers on cu(1) or ttys with wired-in ^S/^Q flow control
|
|
2
|
|
3 ;;; Copyright (C) 1990, 1991, 1994 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author Kevin Gallagher
|
|
6 ;; Maintainer: FSF
|
|
7 ;; Adapted-By: ESR
|
|
8 ;; Keywords: hardware
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
4
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
0
|
26
|
4
|
27 ;;; Synched up with: FSF 19.34.
|
0
|
28
|
|
29 ;;; Commentary:
|
|
30
|
4
|
31 ;; Terminals that use XON/XOFF flow control can cause problems with
|
|
32 ;; GNU Emacs users. This file contains Emacs Lisp code that makes it
|
|
33 ;; easy for a user to deal with this problem, when using such a
|
|
34 ;; terminal.
|
|
35 ;;
|
|
36 ;; To invoke these adjustments, a user need only invoke the function
|
|
37 ;; enable-flow-control-on with a list of terminal types in his/her own
|
|
38 ;; .emacs file. As arguments, give it the names of one or more terminal
|
|
39 ;; types in use by that user which require flow control adjustments.
|
|
40 ;; Here's an example:
|
|
41 ;;
|
|
42 ;; (enable-flow-control-on "vt200" "vt300" "vt101" "vt131")
|
0
|
43
|
4
|
44 ;; Portability note: This uses (getenv "TERM"), and therefore probably
|
|
45 ;; won't work outside of UNIX-like environments.
|
0
|
46
|
|
47 ;;; Code:
|
|
48
|
|
49 (defvar flow-control-c-s-replacement ?\034
|
|
50 "Character that replaces C-s, when flow control handling is enabled.")
|
|
51 (defvar flow-control-c-q-replacement ?\036
|
|
52 "Character that replaces C-q, when flow control handling is enabled.")
|
|
53
|
4
|
54 ;(put 'keyboard-translate-table 'char-table-extra-slots 0)
|
|
55
|
0
|
56 ;;;###autoload
|
|
57 (defun enable-flow-control (&optional argument)
|
|
58 "Toggle flow control handling.
|
|
59 When handling is enabled, user can type C-s as C-\\, and C-q as C-^.
|
|
60 With arg, enable flow control mode if arg is positive, otherwise disable."
|
|
61 (interactive "P")
|
|
62 (if (if argument
|
|
63 ;; Argument means enable if arg is positive.
|
|
64 (<= (prefix-numeric-value argument) 0)
|
|
65 ;; No arg means toggle.
|
|
66 (nth 1 (current-input-mode)))
|
|
67 (progn
|
|
68 ;; Turn flow control off, and stop exchanging chars.
|
|
69 (set-input-mode t nil (nth 2 (current-input-mode)))
|
4
|
70 ;; XEmacs
|
0
|
71 (keyboard-translate flow-control-c-s-replacement nil)
|
|
72 (keyboard-translate ?\^s nil)
|
|
73 (keyboard-translate flow-control-c-q-replacement nil)
|
|
74 (keyboard-translate ?\^q nil))
|
|
75 ;; Turn flow control on.
|
|
76 ;; Tell emacs to pass C-s and C-q to OS.
|
|
77 (set-input-mode nil t (nth 2 (current-input-mode)))
|
|
78 ;; Initialize translate table, saving previous mappings, if any.
|
|
79 ;; Swap C-s and C-\
|
4
|
80 ;; XEmacs
|
0
|
81 (keyboard-translate flow-control-c-s-replacement ?\^s)
|
|
82 (keyboard-translate ?\^s flow-control-c-s-replacement)
|
|
83 ;; Swap C-q and C-^
|
|
84 (keyboard-translate flow-control-c-q-replacement ?\^q)
|
|
85 (keyboard-translate ?\^q flow-control-c-q-replacement)
|
|
86 (message (concat
|
|
87 "XON/XOFF adjustment for "
|
|
88 (getenv "TERM")
|
|
89 ": use C-\\ for C-s and use C-^ for C-q."))
|
|
90 (sleep-for 2))) ; Give user a chance to see message.
|
|
91
|
|
92 ;;;###autoload
|
|
93 (defun enable-flow-control-on (&rest losing-terminal-types)
|
|
94 "Enable flow control if using one of a specified set of terminal types.
|
|
95 Use `(enable-flow-control-on \"vt100\" \"h19\")' to enable flow control
|
|
96 on VT-100 and H19 terminals. When flow control is enabled,
|
|
97 you must type C-\\ to get the effect of a C-s, and type C-^
|
2
|
98 to get the effect of a C-q.
|
|
99
|
|
100 This function has no effect unless the current device is a tty.
|
|
101
|
|
102 The tty terminal type is determined from the TERM environment variable.
|
|
103 Trailing hyphens and everything following is stripped, so a TERM
|
|
104 value of \"vt100-nam\" is treated the same as \"vt100\"."
|
4
|
105 (let ((term (getenv "TERM"))
|
|
106 hyphend)
|
|
107 ;; Look for TERM in LOSING-TERMINAL-TYPES.
|
|
108 ;; If we don't find it literally, try stripping off words
|
|
109 ;; from the end, one by one.
|
|
110 (while (and term (not (member term losing-terminal-types)))
|
|
111 ;; Strip off last hyphen and what follows, then try again.
|
|
112 (if (setq hyphend (string-match "[-_][^-_]+$" term))
|
|
113 (setq term (substring term 0 hyphend))
|
|
114 (setq term nil)))
|
|
115 (if term
|
|
116 (enable-flow-control))))
|
0
|
117
|
|
118 (provide 'flow-ctrl)
|
|
119
|
|
120 ;;; flow-ctrl.el ends here
|