samperi@marob.MASA.COM (Dominick Samperi) (02/20/89)
I'm sorry if this questions has been asked many times before, but could someone explain what is the best way to navigate around the problem that is caused by the use of command sequences in emacs that involve C-s, in the presence of xon/xoff flow control? Thanks! -- Dominick Samperi -- ESCC samperi@marob.masa.com uunet!hombre!samperi
jr@bbn.com (John Robinson) (02/22/89)
In article <561@marob.MASA.COM>, samperi@marob (Dominick Samperi) writes: >I'm sorry if this questions has been asked many times before, but could >someone explain what is the best way to navigate around the problem that >is caused by the use of command sequences in emacs that involve C-s, in >the presence of xon/xoff flow control? Thanks! I post this file from time to time. More info is in the distribution, as mentioned below. -------- GNU emacs (version 18.48 and later) provides several options for coping with terminals or front-ends that insist on using flow control characters. Listed in estimated order of preference. 1. Have Emacs run in CBREAK mode with the kernel handling flow control. Issue (set-input-mode nil t) from .emacs. It is now necessary to find other keys to bind to the commands isearch-forward and quoted-insert. Traditional nominees are C-^ and C-\. There are two ways to get this effect: 1a. Use the keyboard-translate-table to cause C-^ and C-\ to be received by Emacs as though C-S and C-Q were typed. Emacs (except at its very lowest level) never knows that the characters typed were anything but C-S and C-Q, so the use of these keys inside isearch still works - typing C-^ while incremental searching will move the cursor to the next match, etc. Here's some code for this: (setq keyboard-translate-table (make-string 128 0)) (let ((i 0)) (while (< i 128) (aset keyboard-translate-table i i) (setq i (1+ i)))) (aset keyboard-translate-table ?\^\\ ?\^s) (aset keyboard-translate-table ?\^^ ?\^q) 1b. Simply rebind the keys C-^ and C-\ to isearch-forward and quoted-insert. To get continued searches inside isearch it is also necessary to set search-repeat-char to C-^. 2. Don't use CBREAK mode, and cause C-S and C-Q to be bound to a null command. The problem with this is that whatever sent the flow control characters is apt to be falling behind the characters being sent to it, and so what finds its way to the terminal screen will not in general be what is intended. It will be still be necessary to find other keys to bind to isearch-forward and quoted-insert; see 1a and 1b above. Here is a suitable null command: (defun noop () "Do nothing; return nil." (interactive)) 3. Don't use CBREAK mode, and global-unset-key the keys C-S and C-Q. This is similar to #2, except that the flow control characters will probably cause beeps or visible bells. Note that, if the terminal is the source of flow control characters and kernel flow control handling is enabled, it will not in general be necessary to send padding characters as specified in a termcap or terminfo entry. It may be possible to customize a termcap entry to provide better Emacs performance on the assumption that flow control is in use. This effect can also be simulated by announcing (with stty(1) or its equivalent) that the terminal is running at a very slow speed, provided the terminal is not directly wired to the host. Some Background This section attempts to answer the question "Why does emacs choose to use flow-control characters in its command character set?" For another view, please read the comments on flow control in emacs/INSTALL from the distribution; for help with termcaps and DEC terminal concentrators see emacs/etc/TERMS. Flow control was not necessary for most terminals once upon a time, so use of C-S and C-Q for command characters was reasonable. Emacs, for economy of keystrokes and portability, chose to use the control characters in the ASCII character set for its functions, and tried to use mnemonic assignments (S for search, Q for quote). There are other (albeit less common in practice) ways to do flow control that preserve transparency of the character stream. Once emacs' precedent was established, it was too hard to undo. One might even argue that emacs' use of these control characters predates their use by terminals and front-ends for flow control. Notice also that the latter use is ONLY a de-facto standard. In fact, on the model 33 teletype with a paper tape punch (which is VERY old), they were used for the host to turn the punch on and off! So which usage is "right", emacs' or the terminal/front-end manufacturer's? This is a rhetorical (or religious) question; it has no simple answer. -- /jr jr@bbn.com or bbn!jr