|
|
1.1 ! root 1: ;;Additions to shell mode for use with kermit, etc. ! 2: ;;Feb 1988, Jeff Norden - [email protected] ! 3: ;; Copyright (C) 1988 Free Software Foundation, Inc. ! 4: ! 5: ;; This file is part of GNU Emacs. ! 6: ! 7: ;; GNU Emacs is distributed in the hope that it will be useful, ! 8: ;; but WITHOUT ANY WARRANTY. No author or distributor ! 9: ;; accepts responsibility to anyone for the consequences of using it ! 10: ;; or for whether it serves any particular purpose or works at all, ! 11: ;; unless 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 ! 16: ;; GNU Emacs General Public License. A copy of this license is ! 17: ;; supposed to have been given to you along with GNU Emacs so you ! 18: ;; can know your rights and responsibilities. It should be in a ! 19: ;; file named COPYING. Among other things, the copyright notice ! 20: ;; and this notice must be preserved on all copies. ! 21: ! 22: (require 'shell) ! 23: ! 24: ;; I'm not sure, but I think somebody asked about running kermit under shell ! 25: ;; mode a while ago. Anyway, here is some code that I find useful. The result ! 26: ;; is that I can log onto machines with primitive operating systems (VMS and ! 27: ;; ATT system V :-), and still have the features of shell-mode available for ! 28: ;; command history, etc. It's also handy to be able to run a file transfer in ! 29: ;; an emacs window. The transfer is in the "background", but you can also ! 30: ;; monitor or stop it easily. ! 31: ! 32: ;; The ^\ key is bound to a function for sending escape sequences to kermit, ! 33: ;; and ^C^Q can be used to send any control characters needed thru to the ! 34: ;; system you connect to. A more serious problem is that some brain-dead ! 35: ;; systems will not recognize a ^J as an end-of-line character. So LFD is ! 36: ;; bound to a new function which acts just like CR usually does in shell-mode, ! 37: ;; but a ^M is sent as an end-of-line. Funcions are also provied to swap the ! 38: ;; bindings of CR and LFD. I've also included a filter which will clean out ! 39: ;; any ^M's or ^@'s that get typed at you, but I don't really recommend it. ! 40: ;; There doesn't seem to be an acceptably fast way to do this via emacs-lisp. ! 41: ;; Invoking kermit by the command " kermit | tr -d '\015' " seems to work ! 42: ;; better (on my system anyway). ! 43: ! 44: ;; Here's how I've been using this setup. We have several machines connected ! 45: ;; thru a fairly stupid terminal switch. If I want to connect to unix system, ! 46: ;; then I use the LFD key to talk to the switch, and ignore any ^M's in the ! 47: ;; buffer, and do a " stty -echo nl " after I log in. Then the only real ! 48: ;; differnce from being in local shell-mode is that it is you need to to type ! 49: ;; ^C^Q^C to send an interrupt, and ^C^Q^Z for a stop signal, etc. (since ^C^C ! 50: ;; just generates a local stop signal, which kermit ignores). ! 51: ;; To connect to a VMS system, I use a shell script to invoke kermit thru the ! 52: ;; tr filter, do "M-X kermit-send-cr", and then tell VMS that I'm on a half-duplex ! 53: ;; terminal. ! 54: ! 55: ;; Some caveats: ! 56: ;; 1) Kermit under shell mode is a real pain if you don't have pty's. I ! 57: ;; recently discovered this on our 3b2/400. When kermit can't find a tty, it ! 58: ;; assumes it is supposed to be in remote mode. So the simple command "kermit" ! 59: ;; won't work in shell mode on such a system. You can get around this by using ! 60: ;; the -c (connect) command line option, which means you also have to specify a ! 61: ;; line and baud on the command line, as in "kermit -l /dev/tty53 -b 9600 -c". ! 62: ;; However, this will cause kermit to exit when the connection is closed. So ! 63: ;; in order to do a file transfer, you have to think ahead and and add -r ! 64: ;; (receive) to the command line. This means that you can't use the server ! 65: ;; feature. The only fix I can see is to muck around with the source code for ! 66: ;; kermit, although this problably wouldn't be too hard. What is needed is an ! 67: ;; option to force kermit to be local, to use stdin and stdout for interactive ! 68: ;; speech, and to forget about cbreak mode. ! 69: ! 70: ;; 2) The "clean-filter" can be a troublesome item. The main problem arises if ! 71: ;; you are running a program under shell-mode which is doing periodic output, ! 72: ;; and you then try to switch to another buffer. I came across this while ! 73: ;; running kermit file transfers - kermit prints a dot each time a packet is ! 74: ;; received. Since emacs is interrupted each time a dot is printed, it becomes ! 75: ;; impossible to edit the other buffer. If you hit a key while the filter code ! 76: ;; is running, that character will wind up in the *shell* buffer instead of the ! 77: ;; current one! So you need to be careful to turn the filter off before ! 78: ;; leaving the buffer if a program is still running. In fact, you can't even ! 79: ;; use "M-x clean-shell-off" to do this, because you won't be able to type ! 80: ;; "clean-shell-off" in the minibuffer!! So you need to have this command ! 81: ;; bound to a keystroke. ! 82: ! 83: ;; Please let me know if any bugs turn up. ! 84: ;; Feb 1988, Jeff Norden - [email protected] ! 85: ! 86: (defvar kermit-esc-char "\C-\\" "*Kermit's escape char") ! 87: ! 88: (defun kermit-esc () ! 89: "For sending escape sequences to a kermit running in shell mode." ! 90: (interactive) ! 91: (process-send-string ! 92: (get-buffer-process (current-buffer)) ! 93: (concat kermit-esc-char (char-to-string (read-char))))) ! 94: ! 95: (defun kermit-send-char () ! 96: "Send an arbitrary character to a program in shell mode." ! 97: (interactive) ! 98: (process-send-string ! 99: (get-buffer-process (current-buffer)) ! 100: (char-to-string (read-char)))) ! 101: ! 102: (define-key shell-mode-map "\C-\\" 'kermit-esc) ! 103: (define-key shell-mode-map "\C-c\C-q" 'kermit-send-char) ! 104: ;; extra bindings for folks suffering form ^S/^Q braindamage: ! 105: (define-key shell-mode-map "\C-c\\" 'kermit-esc) ! 106: ! 107: (defun shell-send-input-cr () ! 108: "Like \\[shell-send-input] but end the line with carriage-return." ! 109: (interactive) ! 110: (end-of-line) ! 111: (if (eobp) ! 112: (progn ! 113: (move-marker last-input-start ! 114: (process-mark (get-buffer-process (current-buffer)))) ! 115: (insert ?\n) ! 116: (move-marker last-input-end (point))) ! 117: (beginning-of-line) ! 118: (re-search-forward shell-prompt-pattern nil t) ! 119: (let ((copy (buffer-substring (point) ! 120: (progn (forward-line 1) (point))))) ! 121: (goto-char (point-max)) ! 122: (move-marker last-input-start (point)) ! 123: (insert copy) ! 124: (move-marker last-input-end (point)))) ! 125: (condition-case () ! 126: (save-excursion ! 127: (goto-char last-input-start) ! 128: (shell-set-directory)) ! 129: (error (funcall shell-set-directory-error-hook))) ! 130: (let ((process (get-buffer-process (current-buffer)))) ! 131: (process-send-region process last-input-start (- last-input-end 1)) ! 132: (process-send-string process "\r") ! 133: (set-marker (process-mark process) (point)))) ! 134: ! 135: ;; This is backwards of what makes sense, but ... ! 136: (define-key shell-mode-map "\n" 'shell-send-input-cr) ! 137: ! 138: (defun kermit-default-cr () ! 139: "Make RETURN end the line with carriage-return and LFD end it with a newline. ! 140: This is useful for talking to other systems on which carriage-return ! 141: is the normal way to end a line." ! 142: (interactive) ! 143: (define-key shell-mode-map "\r" 'shell-send-input-cr) ! 144: (define-key shell-mode-map "\n" 'shell-send-input)) ! 145: ! 146: (defun kermit-default-nl () ! 147: "Make RETURN end the line with a newline char. This is the default state. ! 148: In this state, use LFD to send a line and end it with a carriage-return." ! 149: (interactive) ! 150: (define-key shell-mode-map "\n" 'shell-send-input-cr) ! 151: (define-key shell-mode-map "\r" 'shell-send-input)) ! 152: ! 153: ;; This filter works, but I don't especially recommend it. ! 154: (defun kermit-clean-filter (process string) ! 155: "A process filter which deletes all ^M's and ^@'s from the output." ! 156: (set-buffer (process-buffer process)) ! 157: (let ! 158: ((firstpos (string-match "[^\C-@\r]+" string)) ! 159: (buffermark (process-mark process)) ! 160: (oldpt (point)) ! 161: (newstring '"") ! 162: goback) ! 163: (while firstpos ! 164: (setq newstring ! 165: (concat newstring (substring string firstpos (match-end 0)))) ! 166: (setq firstpos (string-match "[^\C-@\r]+" string (match-end 0)))) ! 167: (goto-char (marker-position buffermark)) ! 168: (setq goback (< oldpt (point))) ! 169: (insert newstring) ! 170: (set-marker buffermark (point)) ! 171: (if goback (goto-char oldpt)))) ! 172: ! 173: (defun kermit-clean-on () ! 174: "Delete all null characters and ^M's from the kermit output. ! 175: Note that another (perhaps better) way to do this is to use the ! 176: command `kermit | tr -d '\\015''." ! 177: (interactive) ! 178: (set-process-filter (get-buffer-process (current-buffer)) ! 179: 'kermit-clean-filter)) ! 180: ! 181: (defun kermit-clean-off () ! 182: "Cancel a previous kermit-clean-shell-on command" ! 183: (interactive) ! 184: (set-process-filter (get-buffer-process (current-buffer)) nil)) ! 185: ! 186:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.