-(cond ((not rlogin-mode-map)
- (setq rlogin-mode-map (full-copy-sparse-keymap comint-mode-map))
- ;(define-key rlogin-mode-map "\M-\t" 'comint-dynamic-complete)
- ;(define-key rlogin-mode-map "\M-?" 'comint-dynamic-list-completions)
- (define-key rlogin-mode-map "\C-c\C-c" 'rlogin-send-Ctrl-C)
- (define-key rlogin-mode-map "\C-c\C-z" 'rlogin-send-Ctrl-Z)
- (define-key rlogin-mode-map "\C-c\C-\\" 'rlogin-send-Ctrl-backslash)
- (define-key rlogin-mode-map "\C-d" 'rlogin-delchar-or-send-Ctrl-D)))
-
-(defun rlogin (host)
- (interactive "sOpen rlogin connection to host: ")
- (let* ((buffer-name (concat "rlogin-" host))
- (*buffer-name* (concat "*" buffer-name "*")))
- (cond ((not (comint-check-proc *buffer-name*))
- (let* ((xargs-name (intern-soft "explicit-rlogin-args"))
- (xargs (and xargs-name (boundp xargs-name) (symbol-value xargs-name)))
- (process-connection-type nil)
- proc)
- (if xargs
- (setq xargs (append xargs host))
- (setq xargs (list host)))
- (set-buffer (apply 'make-comint buffer-name rlogin-program nil xargs))
- (setq proc (get-process buffer-name))
- (set-process-filter proc 'rlogin-filter)
- (rlogin-mode))))
- (switch-to-buffer *buffer-name*)))
+(cond
+ ((null rlogin-mode-map)
+ (setq rlogin-mode-map (if (consp shell-mode-map)
+ (cons 'keymap shell-mode-map)
+ (copy-keymap shell-mode-map)))
+ (define-key rlogin-mode-map "\C-c\C-c" 'rlogin-send-Ctrl-C)
+ (define-key rlogin-mode-map "\C-c\C-d" 'rlogin-send-Ctrl-D)
+ (define-key rlogin-mode-map "\C-c\C-z" 'rlogin-send-Ctrl-Z)
+ (define-key rlogin-mode-map "\C-c\C-\\" 'rlogin-send-Ctrl-backslash)
+ (define-key rlogin-mode-map "\C-d" 'rlogin-delchar-or-send-Ctrl-D)
+ (define-key rlogin-mode-map "\C-i" 'rlogin-tab-or-complete)))
+
+\f
+;;;###autoload (add-hook 'same-window-regexps "^\\*rlogin-.*\\*\\(\\|<[0-9]+>\\)")
+
+(defvar rlogin-history nil)
+
+;;;###autoload
+(defun rlogin (input-args &optional buffer)
+ "Open a network login connection via `rlogin' with args INPUT-ARGS.
+INPUT-ARGS should start with a host name; it may also contain
+other arguments for `rlogin'.
+
+Input is sent line-at-a-time to the remote connection.
+
+Communication with the remote host is recorded in a buffer `*rlogin-HOST*'
+\(or `*rlogin-USER@HOST*' if the remote username differs\).
+If a prefix argument is given and the buffer `*rlogin-HOST*' already exists,
+a new buffer with a different connection will be made.
+
+When called from a program, if the optional second argument BUFFER is
+a string or buffer, it specifies the buffer to use.
+
+The variable `rlogin-program' contains the name of the actual program to
+run. It can be a relative or absolute path.
+
+The variable `rlogin-explicit-args' is a list of arguments to give to
+the rlogin when starting. They are added after any arguments given in
+INPUT-ARGS.
+
+If the default value of `rlogin-directory-tracking-mode' is t, then the
+default directory in that buffer is set to a remote (FTP) file name to
+access your home directory on the remote machine. Occasionally this causes
+an error, if you cannot access the home directory on that machine. This
+error is harmless as long as you don't try to use that default directory.
+
+If `rlogin-directory-tracking-mode' is neither t nor nil, then the default
+directory is initially set up to your (local) home directory.
+This is useful if the remote machine and your local machine
+share the same files via NFS. This is the default.
+
+If you wish to change directory tracking styles during a session, use the
+function `rlogin-directory-tracking-mode' rather than simply setting the
+variable."
+ (interactive (list
+ (read-from-minibuffer "rlogin arguments (hostname first): "
+ nil nil nil 'rlogin-history)
+ current-prefix-arg))
+
+ (let* ((process-connection-type rlogin-process-connection-type)
+ (args (if rlogin-explicit-args
+ (append (rlogin-parse-words input-args)
+ rlogin-explicit-args)
+ (rlogin-parse-words input-args)))
+ (host (car args))
+ (user (or (car (cdr (member "-l" args)))
+ (user-login-name)))
+ (buffer-name (if (string= user (user-login-name))
+ (format "*rlogin-%s*" host)
+ (format "*rlogin-%s@%s*" user host)))
+ proc)
+
+ (cond ((null buffer))
+ ((stringp buffer)
+ (setq buffer-name buffer))
+ ((bufferp buffer)
+ (setq buffer-name (buffer-name buffer)))
+ ((numberp buffer)
+ (setq buffer-name (format "%s<%d>" buffer-name buffer)))
+ (t
+ (setq buffer-name (generate-new-buffer-name buffer-name))))
+
+ (setq buffer (get-buffer-create buffer-name))
+ (pop-to-buffer buffer-name)
+
+ (cond
+ ((comint-check-proc buffer-name))
+ (t
+ (comint-exec buffer buffer-name rlogin-program nil args)
+ (setq proc (get-buffer-process buffer))
+ ;; Set process-mark to point-max in case there is text in the
+ ;; buffer from a previous exited process.
+ (set-marker (process-mark proc) (point-max))
+
+ ;; comint-output-filter-functions is just like a hook, except that the
+ ;; functions in that list are passed arguments. add-hook serves well
+ ;; enough for modifying it.
+ ;; comint-output-filter-functions should already have a
+ ;; permanent-local property, at least in emacs 19.27 or later.
+ (if (fboundp 'make-local-hook)
+ (make-local-hook 'comint-output-filter-functions)
+ (make-local-variable 'comint-output-filter-functions))
+ (add-hook 'comint-output-filter-functions 'rlogin-carriage-filter)
+
+ (rlogin-mode)
+
+ (make-local-variable 'rlogin-host)
+ (setq rlogin-host host)
+ (make-local-variable 'rlogin-remote-user)
+ (setq rlogin-remote-user user)
+
+ (condition-case ()
+ (cond ((eq rlogin-directory-tracking-mode t)
+ ;; Do this here, rather than calling the tracking mode
+ ;; function, to avoid a gratuitous resync check; the default
+ ;; should be the user's home directory, be it local or remote.
+ (setq comint-file-name-prefix
+ (concat "/" rlogin-remote-user "@" rlogin-host ":"))
+ (cd-absolute comint-file-name-prefix))
+ ((null rlogin-directory-tracking-mode))
+ (t
+ (cd-absolute (concat comint-file-name-prefix "~/"))))
+ (error nil))))))
+
+(put 'rlogin-mode 'mode-class 'special)