annotate lisp/utils/flow-ctrl.el @ 4:b82b59fe008d r19-15b3

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