- (buffer-name (format "*rlogin-%s*" input-args))
- args
- host
- user
- proc
- (old-match-data (match-data)))
- (while (string-match "[ \t]*\\([^ \t]+\\)$" input-args)
- (setq args (cons (substring input-args
- (match-beginning 1) (match-end 1))
- args)
- input-args (substring input-args 0 (match-beginning 0))))
- (store-match-data old-match-data)
- (setq args (append args rlogin-explicit-args))
- (setq host (car args))
- (let ((tmpargs (cdr args)))
- (while (and tmpargs
- (not (string= (car tmpargs) "-l")))
- (setq tmpargs (cdr tmpargs)))
- (setq user (car (cdr tmpargs))))
- (setq buffer-name (format "*rlogin-%s*" host))
- (and prefix (setq buffer-name
- (buffer-name (generate-new-buffer buffer-name))))
- (switch-to-buffer buffer-name)
- (or (comint-check-proc buffer-name)
- (progn
- (comint-mode)
- (comint-exec (current-buffer) buffer-name rlogin-program nil args)
- (setq proc (get-process buffer-name))
- ;; 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))
- (rlogin-mode)
- ;; Set the prefix for filename completion and directory tracking
- ;; to find the remote machine's files by ftp.
- (setq comint-file-name-prefix (concat "/"
- (and user (concat user "@"))
- host ":"))
- (and rlogin-initially-track-cwd
- ;; Presume the user will start in his remote home directory.
- ;; If this is wrong, M-x dirs will fix it.
- (cd-absolute (concat "/"
- (and user (concat user "@"))
- host ":~/")))))))
+ (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)
+