annotate lisp/utils/flow-ctrl.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents b82b59fe008d
children b9518feda344
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
25 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
27 ;;; Synched up with: FSF 19.28.
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
31 ;;;; Terminals that use XON/XOFF flow control can cause problems with
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
32 ;;;; GNU Emacs users. This file contains Emacs Lisp code that makes it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
33 ;;;; easy for a user to deal with this problem, when using such a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
34 ;;;; terminal.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
35 ;;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
36 ;;;; To invoke these adjustments, a user need only invoke the function
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
37 ;;;; enable-flow-control-on with a list of terminal types in his/her own
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
38 ;;;; .emacs file. As arguments, give it the names of one or more terminal
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
39 ;;;; types in use by that user which require flow control adjustments.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
40 ;;;; Here's an example:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
41 ;;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
42 ;;;; (enable-flow-control-on "vt200" "vt300" "vt101" "vt131")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
44 ;;; Portability note: This uses (getenv "TERM"), and therefore probably
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defun enable-flow-control (&optional argument)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "Toggle flow control handling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 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
58 With arg, enable flow control mode if arg is positive, otherwise disable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if (if argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; Argument means enable if arg is positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (<= (prefix-numeric-value argument) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; No arg means toggle.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (nth 1 (current-input-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Turn flow control off, and stop exchanging chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (set-input-mode t nil (nth 2 (current-input-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (keyboard-translate flow-control-c-s-replacement nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (keyboard-translate ?\^s nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (keyboard-translate flow-control-c-q-replacement nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (keyboard-translate ?\^q nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; Turn flow control on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; Tell emacs to pass C-s and C-q to OS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (set-input-mode nil t (nth 2 (current-input-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; Initialize translate table, saving previous mappings, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; Swap C-s and C-\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (keyboard-translate flow-control-c-s-replacement ?\^s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (keyboard-translate ?\^s flow-control-c-s-replacement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; Swap C-q and C-^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (keyboard-translate flow-control-c-q-replacement ?\^q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (keyboard-translate ?\^q flow-control-c-q-replacement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (message (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "XON/XOFF adjustment for "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (getenv "TERM")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ": use C-\\ for C-s and use C-^ for C-q."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (sleep-for 2))) ; Give user a chance to see message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun enable-flow-control-on (&rest losing-terminal-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Enable flow control if using one of a specified set of terminal types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 Use `(enable-flow-control-on \"vt100\" \"h19\")' to enable flow control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 on VT-100 and H19 terminals. When flow control is enabled,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 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
94 to get the effect of a C-q.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
95
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
96 This function has no effect unless the current device is a tty.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
97
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
98 The tty terminal type is determined from the TERM environment variable.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
99 Trailing hyphens and everything following is stripped, so a TERM
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
100 value of \"vt100-nam\" is treated the same as \"vt100\"."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
101 (and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
102 (eq (device-type) 'tty)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
103 (getenv "TERM")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
104 (member (replace-in-string (getenv "TERM") "[-_].*$" "")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
105 losing-terminal-types)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
106 (enable-flow-control)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (provide 'flow-ctrl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; flow-ctrl.el ends here