Mercurial > hg > xemacs-beta
comparison lisp/utils/flow-ctrl.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
24 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
26 ;;; Synched up with: FSF 19.28. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;;;; Terminals that use XON/XOFF flow control can cause problems with | |
31 ;;;; GNU Emacs users. This file contains Emacs Lisp code that makes it | |
32 ;;;; easy for a user to deal with this problem, when using such a | |
33 ;;;; terminal. | |
34 ;;;; | |
35 ;;;; To invoke these adjustments, a user need only invoke the function | |
36 ;;;; enable-flow-control-on with a list of terminal types in his/her own | |
37 ;;;; .emacs file. As arguments, give it the names of one or more terminal | |
38 ;;;; types in use by that user which require flow control adjustments. | |
39 ;;;; Here's an example: | |
40 ;;;; | |
41 ;;;; (enable-flow-control-on "vt200" "vt300" "vt101" "vt131") | |
42 | |
43 ;;; Portability note: This uses (getenv "TERM"), and therefore probably | |
44 ;;; won't work outside of UNIX-like environments. | |
45 | |
46 ;;; Code: | |
47 | |
48 (defvar flow-control-c-s-replacement ?\034 | |
49 "Character that replaces C-s, when flow control handling is enabled.") | |
50 (defvar flow-control-c-q-replacement ?\036 | |
51 "Character that replaces C-q, when flow control handling is enabled.") | |
52 | |
53 ;;;###autoload | |
54 (defun enable-flow-control (&optional argument) | |
55 "Toggle flow control handling. | |
56 When handling is enabled, user can type C-s as C-\\, and C-q as C-^. | |
57 With arg, enable flow control mode if arg is positive, otherwise disable." | |
58 (interactive "P") | |
59 (if (if argument | |
60 ;; Argument means enable if arg is positive. | |
61 (<= (prefix-numeric-value argument) 0) | |
62 ;; No arg means toggle. | |
63 (nth 1 (current-input-mode))) | |
64 (progn | |
65 ;; Turn flow control off, and stop exchanging chars. | |
66 (set-input-mode t nil (nth 2 (current-input-mode))) | |
67 (keyboard-translate flow-control-c-s-replacement nil) | |
68 (keyboard-translate ?\^s nil) | |
69 (keyboard-translate flow-control-c-q-replacement nil) | |
70 (keyboard-translate ?\^q nil)) | |
71 ;; Turn flow control on. | |
72 ;; Tell emacs to pass C-s and C-q to OS. | |
73 (set-input-mode nil t (nth 2 (current-input-mode))) | |
74 ;; Initialize translate table, saving previous mappings, if any. | |
75 ;; Swap C-s and C-\ | |
76 (keyboard-translate flow-control-c-s-replacement ?\^s) | |
77 (keyboard-translate ?\^s flow-control-c-s-replacement) | |
78 ;; Swap C-q and C-^ | |
79 (keyboard-translate flow-control-c-q-replacement ?\^q) | |
80 (keyboard-translate ?\^q flow-control-c-q-replacement) | |
81 (message (concat | |
82 "XON/XOFF adjustment for " | |
83 (getenv "TERM") | |
84 ": use C-\\ for C-s and use C-^ for C-q.")) | |
85 (sleep-for 2))) ; Give user a chance to see message. | |
86 | |
87 ;;;###autoload | |
88 (defun enable-flow-control-on (&rest losing-terminal-types) | |
89 "Enable flow control if using one of a specified set of terminal types. | |
90 Use `(enable-flow-control-on \"vt100\" \"h19\")' to enable flow control | |
91 on VT-100 and H19 terminals. When flow control is enabled, | |
92 you must type C-\\ to get the effect of a C-s, and type C-^ | |
93 to get the effect of a C-q." | |
94 (let ((term (getenv "TERM")) | |
95 hyphend) | |
96 (if term | |
97 (progn | |
98 ;; Strip off hyphen and what follows | |
99 (while (setq hyphend (string-match "[-_][^-_]+$" term)) | |
100 (setq term (substring term 0 hyphend))) | |
101 (and (member term losing-terminal-types) | |
102 (enable-flow-control)))))) | |
103 | |
104 (provide 'flow-ctrl) | |
105 | |
106 ;;; flow-ctrl.el ends here |