annotate lisp/comint/telnet.el @ 138:6608ceec7cf8 r20-2b3

Import from CVS: tag r20-2b3
author cvs
date Mon, 13 Aug 2007 09:31:46 +0200
parents 9b50b4588a93
children a2f645c6b9f8
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
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
56 (defgroup telnet nil
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
57 "Telnet/rsh stuff"
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
58 :group 'comint)
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
59
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defvar telnet-new-line "\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar telnet-mode-map nil)
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
62 (defvar telnet-default-prompt-pattern "^[^#$%>\n]*[#$%>] *")
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
63 (defvar telnet-prompt-pattern telnet-default-prompt-pattern)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
64
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar telnet-replace-c-g nil)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
66 (make-variable-buffer-local
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
67 (defvar telnet-remote-echoes t
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
68 "True if the telnet process will echo input."))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
69 (make-variable-buffer-local
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
70 (defvar telnet-interrupt-string "\C-c" "String sent by C-c."))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvar telnet-count 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Number of output strings read from the telnet process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 while looking for the initial password.")
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
75 ;; (make-variable-buffer-local 'telnet-count)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 16
diff changeset
76
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
77 (defcustom telnet-program "telnet"
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
78 "*Program to run to open a telnet connection."
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
79 :group 'telnet)
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
80
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
81 (defcustom rsh-eat-password-string nil
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
82 "Non-nil means rsh will look for a string matching a password prompt."
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
83 :type 'boolean
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
84 :group 'telnet)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
86 (defvar telnet-initial-count -75
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "Initial value of `telnet-count'. Should be set to the negative of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 number of terminal writes telnet will make setting up the host connection.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defvar telnet-maximum-count 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "Maximum value `telnet-count' can have.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 After this many passes, we stop looking for initial setup data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 Should be set to the number of terminal writes telnet will make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 rejecting one login and prompting again for a username and password.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defun telnet-interrupt-subjob ()
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 "Interrupt the program running through telnet on the remote host."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (process-send-string nil telnet-interrupt-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun telnet-c-z ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (process-send-string nil "\C-z"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
105 ;; XEmacs change (Keep telnet- prefix)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defun telnet-send-process-next-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (process-send-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (prog1 (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq quit-flag nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ; initialization on first load.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (if telnet-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 nil
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
117 ;; FSF
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
118 ;; (setq telnet-mode-map (nconc (make-sparse-keymap) comint-mode-map))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
119 (setq telnet-mode-map (make-sparse-keymap))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
120 (set-keymap-parents telnet-mode-map (list comint-mode-map))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
121 (define-key telnet-mode-map "\C-m" 'telnet-send-input)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
122 ; (define-key telnet-mode-map "\C-j" 'telnet-send-input)
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 124
diff changeset
123 (define-key telnet-mode-map "\C-c\C-q" 'telnet-send-process-next-char)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
124 (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
125 (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;maybe should have a flag for when have found type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defun telnet-check-software-type-initialize (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "Tries to put correct initializations in. Needs work."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (cond ((string-match "unix" string)
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
132 (setq telnet-prompt-pattern shell-prompt-pattern)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (setq telnet-new-line "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq telnet-prompt-pattern "[@>] *"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ((string-match "its" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq telnet-prompt-pattern "^[^*>\n]*[*>] *"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ((string-match "explorer" string) ;;explorer telnet needs work
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
139 (setq telnet-replace-c-g ?\n))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq comint-prompt-regexp telnet-prompt-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defun telnet-initial-filter (proc string)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
143 (let ((case-fold-search t))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
144 ;For reading up to and including password; also will get machine type.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
145 (cond ((string-match "No such host" string)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
146 (kill-buffer (process-buffer proc))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
147 (error "No such host."))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
148 ((string-match "passw" string)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (telnet-filter proc string)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
150 (let ((password (comint-read-noecho "Password: " t)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
151 (setq telnet-count 0)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
152 (process-send-string proc (concat password telnet-new-line))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
153 (t (telnet-check-software-type-initialize string)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
154 (telnet-filter proc string)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
155 (cond ((> telnet-count telnet-maximum-count)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
156 ;; (set-process-filter proc 'telnet-filter) Kludge
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
157 ;; for shell-fonts -- this is the only mode that
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
158 ;; actually changes what its process filter is at
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
159 ;; run time, which confuses shell-font. So we
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
160 ;; special-case that here.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
161 ;; #### Danger, knows an internal shell-font variable name.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
162 (let ((old-filter (process-filter proc)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
163 (if (eq old-filter 'shell-font-process-filter)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
164 (set (make-local-variable 'shell-font-process-filter)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
165 'telnet-filter)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
166 (set-process-filter proc 'telnet-filter))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
167 (t (setq telnet-count (1+ telnet-count))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; Identical to comint-simple-send, except that it sends telnet-new-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; instead of "\n".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun telnet-simple-send (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (comint-send-string proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (comint-send-string proc telnet-new-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun telnet-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (let* ((last-insertion (marker-position (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (delta (- (point) last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (ie (and comint-last-input-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (marker-position comint-last-input-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (w (get-buffer-window (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (ws (and w (window-start w))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (goto-char last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; Insert STRING, omitting all C-m characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (insert-before-markers string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (set-marker (process-mark proc) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; the insert-before-markers may have screwed window-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; and likely moved comint-last-input-end. This is why the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; insertion-reaction should be a property of markers, not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; of the function which does the inserting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if ws (set-window-start w ws t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if ie (set-marker comint-last-input-end ie))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (while (progn (skip-chars-backward "^\C-m" last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (> (point) last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (delete-region (1- (point)) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (and telnet-replace-c-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (subst-char-in-region last-insertion (point) ?\C-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 telnet-replace-c-g t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; If point is after the insertion place, move it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; along with the text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (if (> delta 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (goto-char (+ (process-mark proc) delta)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun telnet-send-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (let ((proc (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 p1 p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if (and telnet-remote-echoes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (>= (point) (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if comint-eol-on-send (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (setq p1 (marker-position (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 p2 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (comint-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; at this point, comint-send-input has moved the process mark, inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; a newline, and possibly inserted the (echoed) output. If the host is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;; in remote-echo mode, then delete our local copy of the command, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; the newline that comint-send-input sent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if p1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (delete-region p1 (1+ p2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;;;###autoload (add-hook 'same-window-regexps "\\*telnet-.*\\*\\(\\|<[0-9]+>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (defun telnet (host &optional port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 "Open a network login connection to host named HOST (a string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 With a prefix argument, prompts for the port name or number as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 Communication with HOST is recorded in a buffer `*HOST-telnet*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 Normally input is edited in Emacs and sent a line at a time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 See also `\\[rsh]'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (interactive (list (read-string "Open telnet connection to host: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (read-string "Port name or number: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (let* ((comint-delimiter-argument-list '(?\ ?\t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (name (concat "telnet-" (comint-arguments host 0 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (if port (concat "/" port) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (buffer (get-buffer (concat "*" name "*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (and buffer (get-buffer-process buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (pop-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (pop-to-buffer (make-comint name telnet-program))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (setq process (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (set-process-filter process 'telnet-initial-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; SunOS and IRIX don't print "unix" in their rsh or telnet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; login banners, so let's get a reasonable default here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; #### This patch from jwz mimics what is done in rsh done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;; below. However, it (along with the one in rsh) mean that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; telnet-check-software-type-initialize is effectively a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;; wastoid function. Reworking it like it claims to need is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; probably the better solution but I'm not going to do it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; --cet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (telnet-check-software-type-initialize "unix")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Don't send the `open' cmd till telnet is ready for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (accept-process-output process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (process-send-string process (concat "open " host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (if port (concat " " port) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq comint-input-sender 'telnet-simple-send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; run last so that hooks can change things.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (telnet-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defun telnet-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "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
272 It has most of the same commands as comint-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 There is a variable ``telnet-interrupt-string'' which is the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 sent to try to stop execution of a job on the remote host.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 Data is sent to the remote host when RET is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 \\{telnet-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (setq major-mode 'telnet-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 mode-name "Telnet"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 comint-prompt-regexp telnet-prompt-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (use-local-map telnet-mode-map)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
285 (set (make-local-variable 'telnet-count) telnet-initial-count)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (run-hooks 'telnet-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;;;###autoload (add-hook 'same-window-regexps "\\*rsh-[^-]*\\*\\(\\|<[0-9]*>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; Berkeley spawn of hell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (defun rsh (host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 "Open a network login connection to host named HOST (a string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 Communication with HOST is recorded in a buffer `*rsh-HOST*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 Normally input is edited in Emacs and sent a line at a time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 See also `\\[telnet]'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (interactive "sOpen rsh connection to host: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (require 'shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (let ((name (concat "rsh-" host)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (pop-to-buffer (make-comint name remote-shell-program nil host))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
301 (setq telnet-count telnet-initial-count)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; 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
304 ;; reasonable default here. There do exist non-Unix machines which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;; speak the rsh protocol, but let's hope they print their OS name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; when one connects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (telnet-check-software-type-initialize "unix")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;; I think we should use telnet-filter here instead of -initial-filter,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; because rsh generally doesn't prompt for a password, and gobbling the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ;; first line that contains "passw" is extremely antisocial. More
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; antisocial than echoing a password, and more likely than connecting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; to a non-Unix rsh host these days...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;;
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
316 ;; I disagree with the above. -sb
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
317 ;;
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
318 (set-process-filter (get-process name) (if rsh-eat-password-string
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
319 'telnet-initial-filter
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 82
diff changeset
320 'telnet-filter))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
321 ;; (set-process-filter (get-process name) 'telnet-filter)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;; run last so that hooks can change things.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (telnet-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (provide 'telnet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;;; telnet.el ends here