How to run GNU emacs over the ISN (without going crazy) Gary T. Leavens Department of Computer Science Iowa State University, Ames Iowa 50011 leavens@cs.iastate.edu THE PROBLEM When you dial up a computer by calling 294-1200 or 294-2400 at ISU, your terminal is talking to your computer of choice through the ISN. The ISN uses a brain-damaged in-band flow-control scheme, that sends a C-s character when the characters are coming too fast and a C-q when it's ready for more characters. The ISN will usually only send C-s to the computer you're connected to, unless you can type really fast. For many Unix programs, this flow-control scheme works, because the program at the other end interprets C-s as if you typed it, meaning it temporarily stops the program until you type a C-q. Alas, in emacs C-s is (by default) interpreted as a request for a the command ``isearch-forward''. Also emacs interprets (by default) C-q as a request to quote a character in the search that you're performing. Worse the ISN does not transmit the C-s and C-q characters that you type to emacs, since it is using those for its own flow control. The result of ISN's flow-control is that when you are using the default configuration of GNU emacs over the ISN, editing is virtually impossible. At what seem like random times (usually when emacs redraws the screen), ISN sends emacs a C-s, causing emacs to go into incremental search mode in the middle of whatever else you were doing. If you type quickly, by the time you realize what has happened you are far from where you thought you were in the file, doing a search you didn't want. Hitting C-g to quit the search usually repaints the screen, often causing further problems until as you panic, hitting C-g several times, things finally settle down. Then you may eventually want to do an incremental search. You hit C-s (as you usually do) and then start typing, ISN has quitely eaten your C-s (it never seems to put one in when you need it), and the text of the search string is inserted in your file. In short, it's a total mess. A SOLUTION Fortunately, if you're willing to relearn a bit of how you use emacs, you can solve these problems. I do it using the following relatively painless steps. 1. In my .emacs file, I put the following lines. ;;; additional key bindings for ISN which eats all the C-s and C-q chars (global-set-key "\M-s" 'isearch-forward-regexp) (global-set-key "\C-\\" 'quoted-insert) (setq search-repeat-char ?\C-a) (setq search-quote-char ?\C-\\) The first of these lines binds M-s to the emacs command isearch-forward-regexp, a variant of isearch-forward that handles regular expressions. This is useful, even for those not using ISN, since it makes this command available on an otherwise unused key. Think of M-s as a more powerful version of C-s. You can still use C-s when you aren't editing over ISN, and that won't cause too much confusion when you do edit over ISN. The second line binds C-\ to the function quoted-insert, which is still available on C-q for editing when not using ISN. However, it's worthwhile learning to use C-\ instead of C-q all the time, as then one isn't confused when editing over ISN. The fourth line does the same thing for quotations within searches, only this time C-q can no longer be used; you must always use C-\ within searches for quotation. The third line makes C-a the character that repeats a search (looks for another match) instead of C-s. This is perhaps the hardest to get used to, because one often confuses the other meaning of C-a (go to the beginning of a line) with this meaning, since previously an incremental search could be ended with C-a. Other possibilities exist, but I thought the mnemonic value of C-a, "a" for "again", was worth it, and I've gotten used to ending incremental searches with escape more often. 2. Set up a macro file containing emacs (lisp) code to be run when editing over ISN. I found it easiest to do this based on the feature of emacs that invokes a terminal specific macro file by the name of "term/vt102.el", when you are editing from a vt102 terminal. The file "term/vt102.el" is found by emacs searching its "load path", which it gets from the shell environment variable EMACSLOADPATH. I therefore set EMACSLOADPATH to include a directory named "emacs", which has my private emacs macro files. If you use the c-shell (csh) put the following in your .login file to tell emacs about this "emacs" directory: setenv EMACSLOADPATH "$HOME/emacs:/usr/local/emacs/lisp:" If you use the Bourne shell (/bin/sh) put the following in your .profile: EMACSLOADPATH="$HOME/emacs:/usr/local/emacs/lisp:" export EMACSLOADPATH In the emacs directory, you'll need to make a subdirectory called "term". Then place the following lines in the file "vt102.el", if when you edit over ISN you use a vt102 or a vt102 terminal emulation. (If you use an adm3a, you'll want a file "adm3a.el" with the same code. If you use the same terminal type both over ISN and not, make a command that loads this macro file when you invoke it.) ;;; ISN editing for emacs (preliminary) (global-unset-key "\C-q") (global-unset-key "\C-s") (global-unset-key "\C-s\C-q") (defun do-nothing () "do nothing, except wait for the control-q" (interactive)) (defvar control-s-map nil "The keymap for the control-s prefix") (setq control-s-map (make-sparse-keymap)) (define-key control-s-map "\C-q" 'do-nothing) (define-key global-map "\C-s" control-s-map) While editing over ISN, you can't use C-s or C-q, but then you couldn't anyway, as ISN eats them. What happens when ISN sends C-s is that emacs waits for the C-q and then does nothing. So this makes C-s and C-q do flow control after all, almost what ISN wants!