diff options
| author | Jim Blandy | 1992-02-07 21:45:45 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-02-07 21:45:45 +0000 |
| commit | 0f39230e862e2cbeff50dcd703c27944e1740d42 (patch) | |
| tree | 9120ed828c03a81a9d8b35cb49c0299611bf3b14 | |
| parent | aea2a8dafe2bfeb03a7cb9096920265056f83a6e (diff) | |
| download | emacs-0f39230e862e2cbeff50dcd703c27944e1740d42.tar.gz emacs-0f39230e862e2cbeff50dcd703c27944e1740d42.zip | |
Initial revision
| -rw-r--r-- | lisp/flow-ctrl.el | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/lisp/flow-ctrl.el b/lisp/flow-ctrl.el new file mode 100644 index 00000000000..1e010e8133d --- /dev/null +++ b/lisp/flow-ctrl.el | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | ;;; Help for lusers on cu(1) or terminals with wired-in ^S/^Q flow control | ||
| 2 | ;;; | ||
| 3 | ;;; Copyright (C) 1990 Free Software Foundation, Inc. | ||
| 4 | ;;; Copyright (C) 1991 Kevin Gallagher | ||
| 5 | ;;; Adapted for Emacs 19 by Eric S. Raymond <eric@snark.thyrsus.com> | ||
| 6 | ;;; | ||
| 7 | ;;; GNU Emacs is distributed in the hope that it will be useful, but | ||
| 8 | ;;; WITHOUT ANY WARRANTY. No author or distributor accepts | ||
| 9 | ;;; RESPONSIBILITY TO anyone for the consequences of using it or for | ||
| 10 | ;;; whether it serves any particular purpose or works at all, unless | ||
| 11 | ;;; he says so in writing. Refer to the GNU Emacs General Public | ||
| 12 | ;;; License for full details. | ||
| 13 | ;;; | ||
| 14 | ;;; Everyone is granted permission to copy, modify and redistribute | ||
| 15 | ;;; GNU Emacs, but only under the conditions described in the GNU | ||
| 16 | ;;; Emacs General Public License. A copy of this license is supposed | ||
| 17 | ;;; to have been given to you along with GNU Emacs so you can know | ||
| 18 | ;;; your rights and responsibilities. It should be in a file named | ||
| 19 | ;;; COPYING. Among other things, the Copyright notice and this notice | ||
| 20 | ;;; must be preserved on all copies. | ||
| 21 | ;;; | ||
| 22 | |||
| 23 | ;;;; Terminals that use XON/XOFF flow control can cause problems with | ||
| 24 | ;;;; GNU Emacs users. This file contains elisp code that makes it | ||
| 25 | ;;;; easy for a user to deal with this problem, when using such a | ||
| 26 | ;;;; terminal. | ||
| 27 | ;;;; | ||
| 28 | ;;;; To invoke these adjustments, a user need only invoke the function | ||
| 29 | ;;;; evade-flow-control-on with a list of terminal types in his/her own | ||
| 30 | ;;;; .emacs file. As arguments, give it the names of one or more terminal | ||
| 31 | ;;;; types in use by that user which require flow control adjustments. | ||
| 32 | ;;;; Here's an example: | ||
| 33 | ;;;; | ||
| 34 | ;;;; (evade-flow-control-on "vt200" "vt300" "vt101" "vt131") | ||
| 35 | |||
| 36 | ;;; Portability note: This uses (getenv "TERM"), and therefore probably | ||
| 37 | ;;; won't work outside of UNIX-like environments. | ||
| 38 | |||
| 39 | (defun evade-flow-control () | ||
| 40 | "Replace C-s with C-\ and C-q with C-^ and tell emacs to pass C-s | ||
| 41 | and C-q characters to OS." | ||
| 42 | (interactive) | ||
| 43 | ;; Tell emacs to pass C-s and C-q to OS. | ||
| 44 | (set-input-mode nil t) | ||
| 45 | ;; Initialize translate table, saving previous mappings, if any. | ||
| 46 | (let ((the-table (make-string 128 0))) | ||
| 47 | (let ((i 0) | ||
| 48 | (j (length keyboard-translate-table))) | ||
| 49 | (while (< i j) | ||
| 50 | (aset the-table i (elt keyboard-translate-table i)) | ||
| 51 | (setq i (1+ i))) | ||
| 52 | (while (< i 128) | ||
| 53 | (aset the-table i i) | ||
| 54 | (setq i (1+ i)))) | ||
| 55 | (setq keyboard-translate-table the-table)) | ||
| 56 | ;; Swap C-s and C-\ | ||
| 57 | (aset keyboard-translate-table ?\034 ?\^s) | ||
| 58 | (aset keyboard-translate-table ?\^s ?\034) | ||
| 59 | ;; Swap C-q and C-^ | ||
| 60 | (aset keyboard-translate-table ?\036 ?\^q) | ||
| 61 | (aset keyboard-translate-table ?\^q ?\036) | ||
| 62 | (message (concat | ||
| 63 | "XON/XOFF adjustment for " | ||
| 64 | (getenv "TERM") | ||
| 65 | ": use C-\\ for C-s and use C-^ for C-q.")) | ||
| 66 | (sleep-for 2)) ; Give user a chance to see message. | ||
| 67 | |||
| 68 | (defun memstr= (e s) | ||
| 69 | (cond ((null s) nil) | ||
| 70 | ((string= e (car s)) t) | ||
| 71 | (t (memstr= e (cdr s))))) | ||
| 72 | |||
| 73 | ;;;###autoload | ||
| 74 | (defun evade-flow-control-on (&rest losing-terminal-types) | ||
| 75 | (let ((term (getenv "TERM")) | ||
| 76 | hyphend) | ||
| 77 | ;; Strip off hyphen and what follows | ||
| 78 | (while (setq hyphend (string-match "[-_][^-_]+$" term)) | ||
| 79 | (setq term (substring term 0 hyphend))) | ||
| 80 | (and (memstr= term losing-terminal-types) (evade-flow-control))) | ||
| 81 | ) | ||
| 82 | |||
| 83 | (provide 'flow-ctrl) | ||
| 84 | |||
| 85 | ;;; flow-ctrl.el ends here | ||
| 86 | |||