]> code.delx.au - gnu-emacs/blobdiff - lisp/net/telnet.el
Changes from arch/CVS synchronization
[gnu-emacs] / lisp / net / telnet.el
index 8cdc2884bab7b472a7bcad88b4c8dbb492b25d3b..6452c26c114277bd6ce61a90f119ae1ece887234 100644 (file)
@@ -1,6 +1,7 @@
 ;;; telnet.el --- run a telnet session from within an Emacs buffer
 
-;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1988, 1992, 1994, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: William F. Schelter
 ;; Maintainer: FSF
@@ -20,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -30,7 +31,7 @@
 ;; sessions are supported.
 ;;
 ;; Normally, input is sent to the remote telnet/rsh line-by-line, as you
-;; type RET or LFD.  C-c C-c sends a C-c to the remote immediately; 
+;; type RET or LFD.  C-c C-c sends a C-c to the remote immediately;
 ;; C-c C-z sends C-z immediately.  C-c C-q followed by any character
 ;; sends that character immediately.
 ;;
@@ -89,21 +90,21 @@ Should be set to the number of terminal writes telnet will make
 rejecting one login and prompting again for a username and password.")
 
 (defun telnet-interrupt-subjob ()
-  (interactive)
   "Interrupt the program running through telnet on the remote host."
-  (send-string nil telnet-interrupt-string))
+  (interactive)
+  (process-send-string nil telnet-interrupt-string))
 
 (defun telnet-c-z ()
   (interactive)
-  (send-string nil "\C-z"))
+  (process-send-string nil "\C-z"))
 
 (defun send-process-next-char ()
   (interactive)
-  (send-string nil
-              (char-to-string
-               (let ((inhibit-quit t))
-                 (prog1 (read-char)
-                   (setq quit-flag nil))))))
+  (process-send-string nil
+                       (char-to-string
+                        (let ((inhibit-quit t))
+                          (prog1 (read-char)
+                            (setq quit-flag nil))))))
 
 ; initialization on first load.
 (if telnet-mode-map
@@ -112,7 +113,7 @@ rejecting one login and prompting again for a username and password.")
   (define-key telnet-mode-map "\C-m" 'telnet-send-input)
 ;  (define-key telnet-mode-map "\C-j" 'telnet-send-input)
   (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char)
-  (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob) 
+  (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob)
   (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z))
 
 ;;maybe should have a flag for when have found type
@@ -141,8 +142,8 @@ rejecting one login and prompting again for a username and password.")
            ((string-match "passw" string)
             (telnet-filter proc string)
             (setq telnet-count 0)
-            (send-string proc (concat (comint-read-noecho "Password: " t)
-                                      telnet-new-line))
+            (process-send-string proc (concat (comint-read-noecho "Password: " t)
+                                               telnet-new-line))
             (clear-this-command-keys))
            (t (telnet-check-software-type-initialize string)
               (telnet-filter proc string)
@@ -155,7 +156,7 @@ rejecting one login and prompting again for a username and password.")
 (defun telnet-simple-send (proc string)
   (comint-send-string proc string)
   (if comint-input-sender-no-newline
-      (if (not (string-equal input ""))
+      (if (not (string-equal string ""))
          (process-send-eof))
     (comint-send-string proc telnet-new-line)))
 
@@ -197,53 +198,56 @@ rejecting one login and prompting again for a username and password.")
 ;;;###autoload (add-hook 'same-window-regexps "\\*telnet-.*\\*\\(\\|<[0-9]+>\\)")
 
 ;;;###autoload
-(defun telnet (host)
+(defun telnet (host &optional port)
   "Open a network login connection to host named HOST (a string).
+Optional arg PORT specifies alternative port to connect to.
+Interactively, use \\[universal-argument] prefix to be prompted for port number.
+
 Communication with HOST is recorded in a buffer `*PROGRAM-HOST*'
 where PROGRAM is the telnet program being used.  This program
 is controlled by the contents of the global variable `telnet-host-properties',
 falling back on the value of the global variable `telnet-program'.
 Normally input is edited in Emacs and sent a line at a time."
-  (interactive "sOpen connection to host: ")
+  (interactive (list (read-string "Open connection to host: ")
+                    (cond
+                     ((null current-prefix-arg) nil)
+                     ((consp current-prefix-arg) (read-string "Port: "))
+                     (t (prefix-numeric-value current-prefix-arg)))))
+  (if (and port (numberp port))
+      (setq port (int-to-string port)))
   (let* ((comint-delimiter-argument-list '(?\  ?\t))
         (properties (cdr (assoc host telnet-host-properties)))
         (telnet-program (if properties (car properties) telnet-program))
-         (name (concat telnet-program "-" (comint-arguments host 0 nil) ))
+        (hname (if port (concat host ":" port) host))
+         (name (concat telnet-program "-" (comint-arguments hname 0 nil) ))
         (buffer (get-buffer (concat "*" name "*")))
         (telnet-options (if (cdr properties) (cons "-l" (cdr properties))))
         process)
     (if (and buffer (get-buffer-process buffer))
        (pop-to-buffer (concat "*" name "*"))
-      (pop-to-buffer 
+      (pop-to-buffer
        (apply 'make-comint name telnet-program nil telnet-options))
       (setq process (get-buffer-process (current-buffer)))
       (set-process-filter process 'telnet-initial-filter)
       ;; Don't send the `open' cmd till telnet is ready for it.
       (accept-process-output process)
       (erase-buffer)
-      (send-string process (concat "open " host "\n"))
+      (process-send-string process (concat "open " host
+                                           (if port " " "") (or port "")
+                                           "\n"))
       (telnet-mode)
       (setq comint-input-sender 'telnet-simple-send)
       (setq telnet-count telnet-initial-count))))
 
 (put 'telnet-mode 'mode-class 'special)
 
-(defun telnet-mode ()
+(define-derived-mode telnet-mode comint-mode "Telnet"
   "This mode is for using telnet (or rsh) from a buffer to another host.
 It has most of the same commands as comint-mode.
 There is a variable ``telnet-interrupt-string'' which is the character
 sent to try to stop execution of a job on the remote host.
-Data is sent to the remote host when RET is typed.
-
-\\{telnet-mode-map}
-"
-  (interactive)
-  (comint-mode)
-  (setq major-mode 'telnet-mode
-       mode-name "Telnet"
-       comint-prompt-regexp telnet-prompt-pattern)
-  (use-local-map telnet-mode-map)
-  (run-hooks 'telnet-mode-hook))
+Data is sent to the remote host when RET is typed."
+  (set (make-local-variable 'comint-prompt-regexp) telnet-prompt-pattern))
 
 ;;;###autoload (add-hook 'same-window-regexps "\\*rsh-[^-]*\\*\\(\\|<[0-9]*>\\)")
 
@@ -262,4 +266,5 @@ Normally input is edited in Emacs and sent a line at a time."
 
 (provide 'telnet)
 
+;;; arch-tag: 98218821-d04a-48b6-9058-57d0d4677a56
 ;;; telnet.el ends here