Mercurial > emacs
annotate lisp/telnet.el @ 1376:dd83ec6103fe
(comint-last-input-match): defvar moved up.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 10 Oct 1992 07:33:59 +0000 |
parents | 2cdce064065f |
children | 2ba9b06d4247 |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; telnet.el --- run a telnet session from within an Emacs buffer |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
2 |
841 | 3 ;;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc. |
4 | |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
5 ;; Author: William F. Schelter |
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
6 ;; Maintainer: FSF |
48 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
707 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
48 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
24 ;;; Code: |
48 | 25 |
26 ;;to do fix software types for lispm: | |
27 ;;to eval current expression. Also to try to send escape keys correctly. | |
28 ;;essentially we'll want the rubout-handler off. | |
29 | |
30 ;; filter is simplistic but should be okay for typical shell usage. | |
31 ;; needs hacking if it is going to deal with asynchronous output in a sane | |
32 ;; manner | |
33 | |
34 (require 'comint) | |
707 | 35 |
48 | 36 (defvar telnet-new-line "\r") |
37 (defvar telnet-mode-map nil) | |
38 (defvar telnet-prompt-pattern "^[^#$%>]*[#$%>] *") | |
39 (defvar telnet-replace-c-g nil) | |
40 (make-variable-buffer-local | |
41 (defvar telnet-remote-echoes t | |
42 "True if the telnet process will echo input.")) | |
43 (make-variable-buffer-local | |
44 (defvar telnet-interrupt-string "\C-c" "String sent by C-c.")) | |
45 | |
46 (defvar telnet-count 0 | |
47 "Number of output strings read from the telnet process | |
48 while looking for the initial password.") | |
49 | |
50 (defvar telnet-initial-count -50 | |
51 "Initial value of telnet-count. Should be set to the negative of the | |
52 number of terminal writes telnet will make setting up the host connection.") | |
53 | |
54 (defvar telnet-maximum-count 4 | |
55 "Maximum value telnet-count can have. | |
56 After this many passes, we stop looking for initial setup data. | |
57 Should be set to the number of terminal writes telnet will make | |
58 rejecting one login and prompting for the again for a username and password.") | |
59 | |
60 (defun telnet-interrupt-subjob () | |
61 (interactive) | |
62 "Interrupt the program running through telnet on the remote host." | |
63 (send-string nil telnet-interrupt-string)) | |
64 | |
65 (defun telnet-c-z () | |
66 (interactive) | |
67 (send-string nil "\C-z")) | |
68 | |
69 (defun send-process-next-char () | |
70 (interactive) | |
71 (send-string nil | |
72 (char-to-string | |
73 (let ((inhibit-quit t)) | |
74 (prog1 (read-char) | |
75 (setq quit-flag nil)))))) | |
76 | |
77 ; initialization on first load. | |
78 (if telnet-mode-map | |
79 nil | |
80 (setq telnet-mode-map (copy-keymap comint-mode-map)) | |
81 (define-key telnet-mode-map "\C-m" 'telnet-send-input) | |
82 ; (define-key telnet-mode-map "\C-j" 'telnet-send-input) | |
83 (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char) | |
84 (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob) | |
85 (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z)) | |
86 | |
87 ;;maybe should have a flag for when have found type | |
88 (defun telnet-check-software-type-initialize (string) | |
89 "Tries to put correct initializations in. Needs work." | |
90 (let ((case-fold-search t)) | |
91 (cond ((string-match "unix" string) | |
92 (setq telnet-prompt-pattern comint-prompt-regexp) | |
93 (setq telnet-new-line "\n")) | |
94 ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g | |
95 (setq telnet-prompt-pattern "[@>]*")) | |
96 ((string-match "its" string) | |
97 (setq telnet-prompt-pattern "^[^*>]*[*>] *")) | |
98 ((string-match "explorer" string) ;;explorer telnet needs work | |
99 (setq telnet-replace-c-g ?\n)))) | |
100 (setq comint-prompt-regexp telnet-prompt-pattern)) | |
101 | |
102 (defun telnet-initial-filter (proc string) | |
103 ;For reading up to and including password; also will get machine type. | |
104 (cond ((string-match "No such host" string) | |
105 (kill-buffer (process-buffer proc)) | |
106 (error "No such host.")) | |
107 ((string-match "passw" string) | |
108 (telnet-filter proc string) | |
109 (let* ((echo-keystrokes 0) | |
110 (password (read-password))) | |
111 (setq telnet-count 0) | |
112 (send-string proc (concat password telnet-new-line)))) | |
113 (t (telnet-check-software-type-initialize string) | |
114 (telnet-filter proc string) | |
115 (cond ((> telnet-count telnet-maximum-count) | |
116 (set-process-filter proc 'telnet-filter)) | |
117 (t (setq telnet-count (1+ telnet-count))))))) | |
118 | |
119 (defun telnet-filter (proc string) | |
120 (let ((at-end | |
121 (and (eq (process-buffer proc) (current-buffer)) | |
122 (= (point) (point-max))))) | |
123 (save-excursion | |
124 (set-buffer (process-buffer proc)) | |
125 (goto-char (process-mark proc)) | |
126 (let ((now (point))) | |
707 | 127 ;; Insert STRING, omitting all C-m characters. |
48 | 128 (let ((index 0) c-m) |
129 (while (setq c-m (string-match "\C-m" string index)) | |
130 (insert-before-markers (substring string index c-m)) | |
131 (setq index (1+ c-m))) | |
132 (insert-before-markers (substring string index))) | |
133 (and telnet-replace-c-g | |
134 (subst-char-in-region now (point) ?\C-g telnet-replace-c-g))) | |
135 ; (if (and (integer-or-marker-p last-input-start) | |
136 ; (marker-position last-input-start) | |
137 ; telnet-remote-echoes) | |
138 ; (delete-region last-input-start last-input-end)) | |
139 ) | |
140 (if at-end | |
141 (goto-char (point-max))))) | |
142 | |
143 (defun telnet-send-input () | |
144 (interactive) | |
707 | 145 ; (comint-send-input telnet-new-line telnet-remote-echoes) |
146 (comint-send-input) | |
147 (if telnet-remote-echoes | |
148 (delete-region comint-last-input-start | |
149 comint-last-input-end))) | |
48 | 150 |
258 | 151 ;;;###autoload |
48 | 152 (defun telnet (arg) |
153 "Open a network login connection to host named HOST (a string). | |
154 Communication with HOST is recorded in a buffer *HOST-telnet*. | |
155 Normally input is edited in Emacs and sent a line at a time." | |
156 (interactive "sOpen telnet connection to host: ") | |
157 (let ((name (concat arg "-telnet" ))) | |
158 (switch-to-buffer (make-comint name "telnet")) | |
159 (set-process-filter (get-process name) 'telnet-initial-filter) | |
160 (erase-buffer) | |
161 (send-string name (concat "open " arg "\n")) | |
162 (telnet-mode) | |
163 (setq telnet-count telnet-initial-count))) | |
164 | |
165 (defun telnet-mode () | |
166 "This mode is for use during telnet from a buffer to another | |
167 host. It has most of the same commands as comint-mode. | |
168 There is a variable ``telnet-interrupt-string'' which is the character | |
169 sent to try to stop execution of a job on the remote host. | |
170 Data is sent to the remote host when RET is typed. | |
171 | |
172 \\{telnet-mode-map} | |
173 | |
174 Bugs: | |
175 --Replaces by a space, really should remove." | |
176 (interactive) | |
177 (comint-mode) | |
178 (setq major-mode 'telnet-mode | |
179 mode-name "Telnet" | |
180 comint-prompt-regexp telnet-prompt-pattern) | |
181 (use-local-map telnet-mode-map) | |
182 (run-hooks 'telnet-mode-hook)) | |
183 | |
184 (defun read-password () | |
185 (let ((answ "") tem) | |
186 (message "Reading password...") | |
557 | 187 (while (prog1 (not (memq (setq tem (read-char)) '(?\C-m ?\n ?\C-g))) |
188 (setq quit-flag nil)) | |
48 | 189 (setq answ (concat answ (char-to-string tem)))) |
190 answ)) | |
584 | 191 |
192 (provide 'telnet) | |
193 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
194 ;;; telnet.el ends here |