Mercurial > emacs
comparison lisp/net/telnet.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; telnet.el --- run a telnet session from within an Emacs buffer | 1 ;;; telnet.el --- run a telnet session from within an Emacs buffer |
2 | 2 |
3 ;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1988, 1992, 1994, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: William F. Schelter | 6 ;; Author: William F. Schelter |
6 ;; Maintainer: FSF | 7 ;; Maintainer: FSF |
7 ;; Keywords: unix, comm | 8 ;; Keywords: unix, comm |
8 | 9 |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 ;; GNU General Public License for more details. | 20 ;; GNU General Public License for more details. |
20 | 21 |
21 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02110-1301, USA. |
25 | 26 |
26 ;;; Commentary: | 27 ;;; Commentary: |
27 | 28 |
28 ;; This mode is intended to be used for telnet or rsh to a remote host; | 29 ;; This mode is intended to be used for telnet or rsh to a remote host; |
29 ;; `telnet' and `rsh' are the two entry points. Multiple telnet or rsh | 30 ;; `telnet' and `rsh' are the two entry points. Multiple telnet or rsh |
87 After this many passes, we stop looking for initial setup data. | 88 After this many passes, we stop looking for initial setup data. |
88 Should be set to the number of terminal writes telnet will make | 89 Should be set to the number of terminal writes telnet will make |
89 rejecting one login and prompting again for a username and password.") | 90 rejecting one login and prompting again for a username and password.") |
90 | 91 |
91 (defun telnet-interrupt-subjob () | 92 (defun telnet-interrupt-subjob () |
92 (interactive) | |
93 "Interrupt the program running through telnet on the remote host." | 93 "Interrupt the program running through telnet on the remote host." |
94 (send-string nil telnet-interrupt-string)) | 94 (interactive) |
95 (process-send-string nil telnet-interrupt-string)) | |
95 | 96 |
96 (defun telnet-c-z () | 97 (defun telnet-c-z () |
97 (interactive) | 98 (interactive) |
98 (send-string nil "\C-z")) | 99 (process-send-string nil "\C-z")) |
99 | 100 |
100 (defun send-process-next-char () | 101 (defun send-process-next-char () |
101 (interactive) | 102 (interactive) |
102 (send-string nil | 103 (process-send-string nil |
103 (char-to-string | 104 (char-to-string |
104 (let ((inhibit-quit t)) | 105 (let ((inhibit-quit t)) |
105 (prog1 (read-char) | 106 (prog1 (read-char) |
106 (setq quit-flag nil)))))) | 107 (setq quit-flag nil)))))) |
107 | 108 |
108 ; initialization on first load. | 109 ; initialization on first load. |
109 (if telnet-mode-map | 110 (if telnet-mode-map |
110 nil | 111 nil |
111 (setq telnet-mode-map (nconc (make-sparse-keymap) comint-mode-map)) | 112 (setq telnet-mode-map (nconc (make-sparse-keymap) comint-mode-map)) |
139 (kill-buffer (process-buffer proc)) | 140 (kill-buffer (process-buffer proc)) |
140 (error "No such host")) | 141 (error "No such host")) |
141 ((string-match "passw" string) | 142 ((string-match "passw" string) |
142 (telnet-filter proc string) | 143 (telnet-filter proc string) |
143 (setq telnet-count 0) | 144 (setq telnet-count 0) |
144 (send-string proc (concat (comint-read-noecho "Password: " t) | 145 (process-send-string proc (concat (comint-read-noecho "Password: " t) |
145 telnet-new-line)) | 146 telnet-new-line)) |
146 (clear-this-command-keys)) | 147 (clear-this-command-keys)) |
147 (t (telnet-check-software-type-initialize string) | 148 (t (telnet-check-software-type-initialize string) |
148 (telnet-filter proc string) | 149 (telnet-filter proc string) |
149 (cond ((> telnet-count telnet-maximum-count) | 150 (cond ((> telnet-count telnet-maximum-count) |
150 (set-process-filter proc 'telnet-filter)) | 151 (set-process-filter proc 'telnet-filter)) |
195 comint-last-input-end))) | 196 comint-last-input-end))) |
196 | 197 |
197 ;;;###autoload (add-hook 'same-window-regexps "\\*telnet-.*\\*\\(\\|<[0-9]+>\\)") | 198 ;;;###autoload (add-hook 'same-window-regexps "\\*telnet-.*\\*\\(\\|<[0-9]+>\\)") |
198 | 199 |
199 ;;;###autoload | 200 ;;;###autoload |
200 (defun telnet (host) | 201 (defun telnet (host &optional port) |
201 "Open a network login connection to host named HOST (a string). | 202 "Open a network login connection to host named HOST (a string). |
203 Optional arg PORT specifies alternative port to connect to. | |
204 Interactively, use \\[universal-argument] prefix to be prompted for port number. | |
205 | |
202 Communication with HOST is recorded in a buffer `*PROGRAM-HOST*' | 206 Communication with HOST is recorded in a buffer `*PROGRAM-HOST*' |
203 where PROGRAM is the telnet program being used. This program | 207 where PROGRAM is the telnet program being used. This program |
204 is controlled by the contents of the global variable `telnet-host-properties', | 208 is controlled by the contents of the global variable `telnet-host-properties', |
205 falling back on the value of the global variable `telnet-program'. | 209 falling back on the value of the global variable `telnet-program'. |
206 Normally input is edited in Emacs and sent a line at a time." | 210 Normally input is edited in Emacs and sent a line at a time." |
207 (interactive "sOpen connection to host: ") | 211 (interactive (list (read-string "Open connection to host: ") |
212 (cond | |
213 ((null current-prefix-arg) nil) | |
214 ((consp current-prefix-arg) (read-string "Port: ")) | |
215 (t (prefix-numeric-value current-prefix-arg))))) | |
216 (if (and port (numberp port)) | |
217 (setq port (int-to-string port))) | |
208 (let* ((comint-delimiter-argument-list '(?\ ?\t)) | 218 (let* ((comint-delimiter-argument-list '(?\ ?\t)) |
209 (properties (cdr (assoc host telnet-host-properties))) | 219 (properties (cdr (assoc host telnet-host-properties))) |
210 (telnet-program (if properties (car properties) telnet-program)) | 220 (telnet-program (if properties (car properties) telnet-program)) |
211 (name (concat telnet-program "-" (comint-arguments host 0 nil) )) | 221 (hname (if port (concat host ":" port) host)) |
222 (name (concat telnet-program "-" (comint-arguments hname 0 nil) )) | |
212 (buffer (get-buffer (concat "*" name "*"))) | 223 (buffer (get-buffer (concat "*" name "*"))) |
213 (telnet-options (if (cdr properties) (cons "-l" (cdr properties)))) | 224 (telnet-options (if (cdr properties) (cons "-l" (cdr properties)))) |
214 process) | 225 process) |
215 (if (and buffer (get-buffer-process buffer)) | 226 (if (and buffer (get-buffer-process buffer)) |
216 (pop-to-buffer (concat "*" name "*")) | 227 (pop-to-buffer (concat "*" name "*")) |
219 (setq process (get-buffer-process (current-buffer))) | 230 (setq process (get-buffer-process (current-buffer))) |
220 (set-process-filter process 'telnet-initial-filter) | 231 (set-process-filter process 'telnet-initial-filter) |
221 ;; Don't send the `open' cmd till telnet is ready for it. | 232 ;; Don't send the `open' cmd till telnet is ready for it. |
222 (accept-process-output process) | 233 (accept-process-output process) |
223 (erase-buffer) | 234 (erase-buffer) |
224 (send-string process (concat "open " host "\n")) | 235 (process-send-string process (concat "open " host |
236 (if port " " "") (or port "") | |
237 "\n")) | |
225 (telnet-mode) | 238 (telnet-mode) |
226 (setq comint-input-sender 'telnet-simple-send) | 239 (setq comint-input-sender 'telnet-simple-send) |
227 (setq telnet-count telnet-initial-count)))) | 240 (setq telnet-count telnet-initial-count)))) |
228 | 241 |
229 (put 'telnet-mode 'mode-class 'special) | 242 (put 'telnet-mode 'mode-class 'special) |
230 | 243 |
231 (defun telnet-mode () | 244 (define-derived-mode telnet-mode comint-mode "Telnet" |
232 "This mode is for using telnet (or rsh) from a buffer to another host. | 245 "This mode is for using telnet (or rsh) from a buffer to another host. |
233 It has most of the same commands as comint-mode. | 246 It has most of the same commands as comint-mode. |
234 There is a variable ``telnet-interrupt-string'' which is the character | 247 There is a variable ``telnet-interrupt-string'' which is the character |
235 sent to try to stop execution of a job on the remote host. | 248 sent to try to stop execution of a job on the remote host. |
236 Data is sent to the remote host when RET is typed. | 249 Data is sent to the remote host when RET is typed." |
237 | 250 (set (make-local-variable 'comint-prompt-regexp) telnet-prompt-pattern)) |
238 \\{telnet-mode-map} | |
239 " | |
240 (interactive) | |
241 (comint-mode) | |
242 (setq major-mode 'telnet-mode | |
243 mode-name "Telnet" | |
244 comint-prompt-regexp telnet-prompt-pattern) | |
245 (use-local-map telnet-mode-map) | |
246 (run-hooks 'telnet-mode-hook)) | |
247 | 251 |
248 ;;;###autoload (add-hook 'same-window-regexps "\\*rsh-[^-]*\\*\\(\\|<[0-9]*>\\)") | 252 ;;;###autoload (add-hook 'same-window-regexps "\\*rsh-[^-]*\\*\\(\\|<[0-9]*>\\)") |
249 | 253 |
250 ;;;###autoload | 254 ;;;###autoload |
251 (defun rsh (host) | 255 (defun rsh (host) |
260 (telnet-mode) | 264 (telnet-mode) |
261 (setq telnet-count -16))) | 265 (setq telnet-count -16))) |
262 | 266 |
263 (provide 'telnet) | 267 (provide 'telnet) |
264 | 268 |
269 ;;; arch-tag: 98218821-d04a-48b6-9058-57d0d4677a56 | |
265 ;;; telnet.el ends here | 270 ;;; telnet.el ends here |