annotate lisp/comint/telnet.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents c7528f8e288d
children 6a378aca36af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; telnet.el --- run a telnet session from within an Emacs buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
3 ;;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: William F. Schelter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: comm, unix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; This mode is intended to be used for telnet or rsh to a remode host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; `telnet' and `rsh' are the two entry points. Multiple telnet or rsh
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; sessions are supported.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; Normally, input is sent to the remote telnet/rsh line-by-line, as you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; type RET or LFD. C-c C-c sends a C-c to the remote immediately;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; C-c C-z sends C-z immediately. C-c C-q followed by any character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; sends that character immediately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; All RET characters are filtered out of the output coming back from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; remote system. The mode tries to do other useful translations based
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; on what it sees coming back from the other system before the password
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; query. It knows about UNIX, ITS, TOPS-20 and Explorer systems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; to do fix software types for lispm:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; to eval current expression. Also to try to send escape keys correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; essentially we'll want the rubout-handler off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; filter is simplistic but should be okay for typical shell usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; needs hacking if it is going to deal with asynchronous output in a sane
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; manner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar telnet-new-line "\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar telnet-mode-map nil)
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
58 (defvar telnet-default-prompt-pattern "^[^#$%>\n]*[#$%>] *")
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
59 (defvar telnet-prompt-pattern telnet-default-prompt-pattern)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
60
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar telnet-replace-c-g nil)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
62 (make-variable-buffer-local
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
63 (defvar telnet-remote-echoes t
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
64 "True if the telnet process will echo input."))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
65 (make-variable-buffer-local
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
66 (defvar telnet-interrupt-string "\C-c" "String sent by C-c."))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar telnet-count 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "Number of output strings read from the telnet process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 while looking for the initial password.")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
71 (make-variable-buffer-local 'telnet-count)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 16
diff changeset
72
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
73 (defvar telnet-program "telnet"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
74 "Program to run to open a telnet connection.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
76 (defvar telnet-initial-count -75
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "Initial value of `telnet-count'. Should be set to the negative of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 number of terminal writes telnet will make setting up the host connection.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defvar telnet-maximum-count 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Maximum value `telnet-count' can have.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 After this many passes, we stop looking for initial setup data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Should be set to the number of terminal writes telnet will make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 rejecting one login and prompting again for a username and password.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun telnet-interrupt-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "Interrupt the program running through telnet on the remote host."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (process-send-string nil telnet-interrupt-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun telnet-c-z ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (process-send-string nil "\C-z"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
95 ;; XEmacs change (Keep telnet- prefix)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defun telnet-send-process-next-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (process-send-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (prog1 (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq quit-flag nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ; initialization on first load.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (if telnet-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 nil
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
107 ;; FSF
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
108 ;; (setq telnet-mode-map (nconc (make-sparse-keymap) comint-mode-map))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
109 (setq telnet-mode-map (make-sparse-keymap))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
110 (set-keymap-parents telnet-mode-map (list comint-mode-map))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
111 (define-key telnet-mode-map "\C-m" 'telnet-send-input)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
112 ; (define-key telnet-mode-map "\C-j" 'telnet-send-input)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
113 (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
114 (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
115 (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;maybe should have a flag for when have found type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defun telnet-check-software-type-initialize (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Tries to put correct initializations in. Needs work."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (cond ((string-match "unix" string)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
122 (setq telnet-prompt-pattern comint-prompt-regexp)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq telnet-new-line "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq telnet-prompt-pattern "[@>] *"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ((string-match "its" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq telnet-prompt-pattern "^[^*>\n]*[*>] *"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ((string-match "explorer" string) ;;explorer telnet needs work
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
129 (setq telnet-replace-c-g ?\n))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq comint-prompt-regexp telnet-prompt-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defun telnet-initial-filter (proc string)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
133 (let ((case-fold-search t))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
134 ;For reading up to and including password; also will get machine type.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
135 (cond ((string-match "No such host" string)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
136 (kill-buffer (process-buffer proc))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
137 (error "No such host."))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
138 ((string-match "passw" string)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (telnet-filter proc string)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
140 (let ((password (comint-read-noecho "Password: " t)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
141 (setq telnet-count 0)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
142 (process-send-string proc (concat password telnet-new-line))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
143 (t (telnet-check-software-type-initialize string)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
144 (telnet-filter proc string)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
145 (cond ((> telnet-count telnet-maximum-count)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
146 ;; (set-process-filter proc 'telnet-filter) Kludge
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
147 ;; for shell-fonts -- this is the only mode that
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
148 ;; actually changes what its process filter is at
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
149 ;; run time, which confuses shell-font. So we
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
150 ;; special-case that here.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
151 ;; #### Danger, knows an internal shell-font variable name.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
152 (let ((old-filter (process-filter proc)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
153 (if (eq old-filter 'shell-font-process-filter)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
154 (set (make-local-variable 'shell-font-process-filter)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
155 'telnet-filter)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
156 (set-process-filter proc 'telnet-filter))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
157 (t (setq telnet-count (1+ telnet-count))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; Identical to comint-simple-send, except that it sends telnet-new-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; instead of "\n".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defun telnet-simple-send (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (comint-send-string proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (comint-send-string proc telnet-new-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun telnet-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (let* ((last-insertion (marker-position (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (delta (- (point) last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (ie (and comint-last-input-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (marker-position comint-last-input-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (w (get-buffer-window (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (ws (and w (window-start w))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (goto-char last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; Insert STRING, omitting all C-m characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (insert-before-markers string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (set-marker (process-mark proc) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; the insert-before-markers may have screwed window-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; and likely moved comint-last-input-end. This is why the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; insertion-reaction should be a property of markers, not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; of the function which does the inserting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (if ws (set-window-start w ws t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if ie (set-marker comint-last-input-end ie))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (while (progn (skip-chars-backward "^\C-m" last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (> (point) last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (delete-region (1- (point)) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (and telnet-replace-c-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (subst-char-in-region last-insertion (point) ?\C-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 telnet-replace-c-g t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; If point is after the insertion place, move it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; along with the text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if (> delta 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (goto-char (+ (process-mark proc) delta)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (defun telnet-send-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((proc (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 p1 p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (if (and telnet-remote-echoes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (>= (point) (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (if comint-eol-on-send (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (setq p1 (marker-position (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 p2 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (comint-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; at this point, comint-send-input has moved the process mark, inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; a newline, and possibly inserted the (echoed) output. If the host is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; in remote-echo mode, then delete our local copy of the command, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; the newline that comint-send-input sent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (if p1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (delete-region p1 (1+ p2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;;###autoload (add-hook 'same-window-regexps "\\*telnet-.*\\*\\(\\|<[0-9]+>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defun telnet (host &optional port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 "Open a network login connection to host named HOST (a string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 With a prefix argument, prompts for the port name or number as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 Communication with HOST is recorded in a buffer `*HOST-telnet*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Normally input is edited in Emacs and sent a line at a time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 See also `\\[rsh]'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (interactive (list (read-string "Open telnet connection to host: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (read-string "Port name or number: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (let* ((comint-delimiter-argument-list '(?\ ?\t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (name (concat "telnet-" (comint-arguments host 0 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (if port (concat "/" port) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (buffer (get-buffer (concat "*" name "*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (if (and buffer (get-buffer-process buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (pop-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (pop-to-buffer (make-comint name telnet-program))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq process (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (set-process-filter process 'telnet-initial-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; SunOS and IRIX don't print "unix" in their rsh or telnet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;; login banners, so let's get a reasonable default here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; #### This patch from jwz mimics what is done in rsh done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; below. However, it (along with the one in rsh) mean that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; telnet-check-software-type-initialize is effectively a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; wastoid function. Reworking it like it claims to need is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; probably the better solution but I'm not going to do it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; --cet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (telnet-check-software-type-initialize "unix")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; Don't send the `open' cmd till telnet is ready for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (accept-process-output process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (process-send-string process (concat "open " host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (if port (concat " " port) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq comint-input-sender 'telnet-simple-send)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
257 (setq telnet-count telnet-initial-count)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;; run last so that hooks can change things.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (telnet-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defun telnet-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 "This mode is for using telnet (or rsh) from a buffer to another host.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 It has most of the same commands as comint-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 There is a variable ``telnet-interrupt-string'' which is the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 sent to try to stop execution of a job on the remote host.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Data is sent to the remote host when RET is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 \\{telnet-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq major-mode 'telnet-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 mode-name "Telnet"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 comint-prompt-regexp telnet-prompt-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (use-local-map telnet-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (run-hooks 'telnet-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;;###autoload (add-hook 'same-window-regexps "\\*rsh-[^-]*\\*\\(\\|<[0-9]*>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; Berkeley spawn of hell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defun rsh (host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 "Open a network login connection to host named HOST (a string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 Communication with HOST is recorded in a buffer `*rsh-HOST*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 Normally input is edited in Emacs and sent a line at a time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 See also `\\[telnet]'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (interactive "sOpen rsh connection to host: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (require 'shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (let ((name (concat "rsh-" host)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (pop-to-buffer (make-comint name remote-shell-program nil host))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
291 (setq telnet-count telnet-initial-count)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; SunOS doesn't print "unix" in its rsh login banner, so let's get a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; reasonable default here. There do exist non-Unix machines which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; speak the rsh protocol, but let's hope they print their OS name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; when one connects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (telnet-check-software-type-initialize "unix")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; I think we should use telnet-filter here instead of -initial-filter,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; because rsh generally doesn't prompt for a password, and gobbling the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; first line that contains "passw" is extremely antisocial. More
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; antisocial than echoing a password, and more likely than connecting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;; to a non-Unix rsh host these days...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
306 ;; (set-process-filter (get-process name) 'telnet-initial-filter)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
307 (set-process-filter (get-process name) 'telnet-filter)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;; run last so that hooks can change things.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (telnet-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (provide 'telnet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;;; telnet.el ends here