|
|
1.1 root 1: ;; Copyright (C) 1985 Free Software Foundation
2:
3: ;; This file is part of GNU Emacs.
4:
5: ;; GNU Emacs is distributed in the hope that it will be useful,
6: ;; but WITHOUT ANY WARRANTY. No author or distributor
7: ;; accepts responsibility to anyone for the consequences of using it
8: ;; or for whether it serves any particular purpose or works at all,
9: ;; unless he says so in writing. Refer to the GNU Emacs General Public
10: ;; License for full details.
11:
12: ;; Everyone is granted permission to copy, modify and redistribute
13: ;; GNU Emacs, but only under the conditions described in the
14: ;; GNU Emacs General Public License. A copy of this license is
15: ;; supposed to have been given to you along with GNU Emacs so you
16: ;; can know your rights and responsibilities. It should be in a
17: ;; file named COPYING. Among other things, the copyright notice
18: ;; and this notice must be preserved on all copies.
19:
20:
21: ;; Author William F. Schelter
22:
23: ;;to do fix software types for lispm:
24: ;;to eval current expression. Also to try to send escape keys correctly.
25: ;;essentially we'll want the rubout-handler off.
26:
27: (defvar telnet-new-line "\r")
28: (defvar telnet-mode-map nil)
29: (defvar telnet-prompt-pattern "^[^#$%>]*[#$%>] *")
30: (defvar telnet-interrupt-string "\^c" "String sent by C-c.")
31: (defvar telnet-count 0)
32: (defvar telnet-replace-c-g nil)
33: (defvar telnet-remote-echoes nil)
34:
35: (defun telnet-interrupt-subjob ()
36: (interactive)
37: "Interrupt the program running through telnet on the remote host."
38: (send-string nil telnet-interrupt-string))
39:
40: (defun telnet-c-z ()
41: (interactive)
42: (send-string nil ""))
43:
44: (defun send-process-next-char ()
45: (interactive)
46: (send-string nil
47: (char-to-string
48: (let ((inhibit-quit t))
49: (prog1 (read-char)
50: (setq quit-flag nil))))))
51:
52: (if telnet-mode-map
53: nil
54: (setq telnet-mode-map (make-keymap))
55: (define-key telnet-mode-map "\C-m" 'telnet-send-input)
56: (define-key telnet-mode-map "\C-d" 'shell-send-eof)
57: (define-key telnet-mode-map "\C-q" 'send-process-next-char)
58: (define-key telnet-mode-map "\C-u" 'kill-shell-input)
59: (define-key telnet-mode-map "\C-w" 'backward-kill-word)
60: (define-key telnet-mode-map "\C-c" 'telnet-interrupt-subjob)
61: (define-key telnet-mode-map "\C-z" 'telnet-c-z)
62: )
63:
64: ;;maybe should have a flag for when have found type
65: (defun telnet-check-software-type-initialize (string)
66: "Tries to put correct initializations in. Needs work."
67: (cond ((string-match "unix" string)
68: (setq telnet-prompt-pattern shell-prompt-pattern)
69: (setq telnet-new-line "\n"))
70: ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g
71: (setq telnet-prompt-pattern "[@>]*"))
72: ((string-match "its" string)
73: (setq telnet-prompt-pattern "^[^*>]*[*>] *"))
74: ((string-match "explorer" string) ;;explorer telnet needs work
75: (setq telnet-replace-c-g ?\n))
76: ))
77:
78: (defun telnet-initial-filter (proc string)
79: ;For reading up to and including password; also will get machine type.
80: (cond ((string-match "passw" string)
81: (telnet-filter proc string)
82: (setq password (read-password))
83: (setq telnet-count 0)
84: (send-string proc (concat password telnet-new-line)))
85: (t (telnet-check-software-type-initialize string)
86: (telnet-filter proc string)
87: (cond ((> telnet-count 4)
88: (set-process-filter proc 'telnet-filter))
89: (t (setq telnet-count (1+ telnet-count)))))))
90:
91: (defun telnet-filter (proc string)
92: (save-excursion
93: (set-buffer (process-buffer proc))
94: (goto-char (point-max))
95: (let ((now (point)))
96: (insert string)
97: (subst-char-in-region now (point) ?\^m ?\ )
98: (and telnet-replace-c-g (subst-char-in-region now (point) ?\^g telnet-replace-c-g)))
99: (if (process-mark proc)
100: (set-marker (process-mark proc) (point)))
101: (if (and (integer-or-marker-p last-input-start)
102: (marker-position last-input-start)
103: telnet-remote-echoes)
104: (delete-region last-input-start last-input-end)))
105: (if (eq (process-buffer proc)
106: (current-buffer))
107: (goto-char (point-max))))
108:
109: (defun delete-char-or-send-eof (arg killp)
110: "At end of buffer, send eof to subshell. Otherwise delete character."
111: (interactive "p\nP")
112: (if (and (eobp) (not killp))
113: (process-send-eof)
114: (delete-char arg killp)))
115:
116: (defun telnet-send-input ()
117: "Send input to remote host
118: At end of buffer, sends all text after last output
119: as input to the telnet, including a telnet-new-line inserted at the end.
120: Not at end, copies current line to the end of the buffer and sends it,
121: after first attempting to discard any prompt at the beginning of the line
122: by matching the regexp that is the value of telnet-prompt-pattern if possible."
123: (interactive)
124: (let (copied)
125: (end-of-line)
126: (if (eobp)
127: (progn
128: (move-marker last-input-start
129: (process-mark (get-buffer-process (current-buffer))))
130: (move-marker last-input-end (point)))
131: (beginning-of-line)
132: (re-search-forward telnet-prompt-pattern nil t)
133: (let ((copy (buffer-substring (point)
134: (progn (forward-line 1) (point)))))
135: (goto-char (point-max))
136: (move-marker last-input-start (point))
137: (insert copy) (setq copied t)
138: (move-marker last-input-end (point))))
139: (save-excursion
140: (goto-char last-input-start)
141: (let ((process (get-buffer-process (current-buffer))))
142: (send-region process last-input-start last-input-end)
143: (if (not copied) (send-string process telnet-new-line))
144: (set-marker (process-mark process) (point))))))
145:
146: (defun telnet (arg)
147: "Open a network login connection to host named HOST (a string).
148: Communication with HOST is recorded in a buffer *HOST-telnet*.
149: Normally input is edited in Emacs and sent a line at a time."
150: (interactive "sOpen telnet connection to host: ")
151: (require 'shell)
152: (let ((name (concat arg "-telnet" )))
153: (switch-to-buffer (make-shell name "telnet"))
154: (set-process-filter (get-process name) 'telnet-initial-filter)
155: (erase-buffer)
156: (send-string name (concat "open " arg "\n"))
157: (telnet-mode)
158: (setq telnet-count -16)))
159:
160: (defun read-password ()
161: (let ((answ "") tem)
162: (while (not (= (setq tem (read-char)) ?\^m))
163: (setq answ (concat answ (char-to-string tem))))
164: answ))
165:
166: (defun telnet-mode ()
167: "This mode is for use during telnet from a buffer to another
168: host. It has most of the same commands as shell mode.
169: There is a variable `telnet-interrupt-string' which is the character
170: sent to try to stop execution of a job on the remote host.
171: Data is sent to the remote host when `return' is typed.
172: Thus if you may need to edit the data before sending you
173: should use c-n to move down a line. Then you can return
174: to alter a previous line. Of course you should not use this
175: mode of telnet if you want to run emacs like programs on the
176: remote host (at least not yet!).
177:
178: \\[telnet-send-input] Causes the last string of input to be sent to remote host
179: \\[delete-char-or-send-eof] Will delete a character (or send eof if it is the last character.
180: \\[kill-shell-input] Kills the last shell-input
181: \\[backward-kill-word] runs backward-kill-word.
182: \\[send-process-next-char] sends the next keystroke directly without
183: interpretation eg. useful for sending c-q or ` ' to continue typeout
184: with more processing.
185: \\[telnet-interrupt-subjob] interrupts the current program running on the remote host.
186: \\[telnet-c-z] Sends a c-z to the remote host
187:
188: Bugs:
189: --Replace
by a space, really should remove.
190: --For Unix interacts poorly with tcsh although csh,sh,ksh are ok."
191: (interactive)
192: (kill-all-local-variables)
193: (setq major-mode 'telnet-mode)
194: (setq mode-name "telnet")
195: (setq mode-line-format
196: "--%1*%1*-Emacs: %17b %M %[(%m: %s)%]----%3p--%-")
197: (make-local-variable 'last-input-start)
198: (use-local-map telnet-mode-map)
199: (let ((tem telnet-prompt-pattern))
200: (make-local-variable 'telnet-prompt-pattern)
201: (setq telnet-prompt-pattern tem))
202: (make-local-variable 'telnet-interrupt-string)
203: (setq telnet-interrupt-string "")
204: (make-local-variable 'telnet-new-line)
205: (setq telnet-new-line "\r")
206: (make-local-variable 'last-input-start)
207: (setq last-input-start (make-marker))
208: (make-local-variable 'last-input-end)
209: (setq last-input-end (make-marker))
210: (make-local-variable 'telnet-remote-echoes)
211: (setq telnet-remote-echoes t)
212: (make-local-variable 'telnet-replace-c-g)
213: (setq telnet-replace-c-g nil))
214:
215:
216:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.