annotate lisp/comint/rlogin.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 376386a54a3c
children 34a5b81f86ba
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 ;;; rlogin.el --- remote login interface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Author: Noah Friedman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Maintainer: Noah Friedman <friedman@prep.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: unix, comm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
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 program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with this program; if not, write to: The Free Software Foundation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Inc.; 675 Massachusetts Avenue.; Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 0
diff changeset
23 ;; $Id: rlogin.el,v 1.1.1.1 1996/12/18 22:42:36 steve Exp $
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Support for remote logins using `rlogin'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; This program is layered on top of shell.el; the code here only accounts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; for the variations needed to handle a remote process, e.g. directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; tracking and the sending of some special characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; If you wish for rlogin mode to prompt you in the minibuffer for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; passwords when a password prompt appears, just enter m-x send-invisible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; and type in your line, or add `comint-watch-for-password-prompt' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; `comint-output-filter-functions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (require 'shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defvar rlogin-program "rlogin"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "*Name of program to invoke rlogin")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar rlogin-explicit-args nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "*List of arguments to pass to rlogin on the command line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (defvar rlogin-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "*Hooks to run after setting current buffer to rlogin-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defvar rlogin-process-connection-type nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "*If non-`nil', use a pty for the local rlogin process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 If `nil', use a pipe (if pipes are supported on the local system).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Generally it is better not to waste ptys on systems which have a static
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 number of them. On the other hand, some implementations of `rlogin' assume
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 a pty is being used, and errors will result from using a pipe instead.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar rlogin-directory-tracking-mode 'local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "*Control whether and how to do directory tracking in an rlogin buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 nil means don't do directory tracking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 t means do so using an ftp remote file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 Any other value means do directory tracking using local file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 This works only if the remote machine and the local one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 share the same directories (through NFS). This is the default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 This variable becomes local to a buffer when set in any fashion for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 It is better to use the function of the same name to change the behavior of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 directory tracking in an rlogin session once it has begun, rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 simply setting this variable, since the function does the necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 re-synching of directories.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (make-variable-buffer-local 'rlogin-directory-tracking-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defvar rlogin-host nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 "*The name of the remote host. This variable is buffer-local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defvar rlogin-remote-user nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "*The username used on the remote host.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 This variable is buffer-local and defaults to your local user name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 If rlogin is invoked with the `-l' option to specify the remote username,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 this variable is set from that.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; Initialize rlogin mode map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defvar rlogin-mode-map '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ((null rlogin-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq rlogin-mode-map (if (consp shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (cons 'keymap shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (copy-keymap shell-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (define-key rlogin-mode-map "\C-c\C-c" 'rlogin-send-Ctrl-C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (define-key rlogin-mode-map "\C-c\C-d" 'rlogin-send-Ctrl-D)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (define-key rlogin-mode-map "\C-c\C-z" 'rlogin-send-Ctrl-Z)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (define-key rlogin-mode-map "\C-c\C-\\" 'rlogin-send-Ctrl-backslash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (define-key rlogin-mode-map "\C-d" 'rlogin-delchar-or-send-Ctrl-D)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (define-key rlogin-mode-map "\C-i" 'rlogin-tab-or-complete)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;;###autoload (add-hook 'same-window-regexps "^\\*rlogin-.*\\*\\(\\|<[0-9]+>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defvar rlogin-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defun rlogin (input-args &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "Open a network login connection to HOST via the `rlogin' program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Input is sent line-at-a-time to the remote connection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 Communication with the remote host is recorded in a buffer `*rlogin-HOST*'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 \(or `*rlogin-USER@HOST*' if the remote username differs\).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 If a prefix argument is given and the buffer `*rlogin-HOST*' already exists,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 a new buffer with a different connection will be made.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 When called from a program, if the optional second argument is a string or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 buffer, it names the buffer to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 The variable `rlogin-program' contains the name of the actual program to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 run. It can be a relative or absolute path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 The variable `rlogin-explicit-args' is a list of arguments to give to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 the rlogin when starting. They are added after any arguments given in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 INPUT-ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 If the default value of `rlogin-directory-tracking-mode' is t, then the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 default directory in that buffer is set to a remote (FTP) file name to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 access your home directory on the remote machine. Occasionally this causes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 an error, if you cannot access the home directory on that machine. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 error is harmless as long as you don't try to use that default directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 If `rlogin-directory-tracking-mode' is neither t nor nil, then the default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 directory is initially set up to your (local) home directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 This is useful if the remote machine and your local machine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 share the same files via NFS. This is the default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 If you wish to change directory tracking styles during a session, use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 function `rlogin-directory-tracking-mode' rather than simply setting the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 variable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (interactive (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (read-from-minibuffer "rlogin arguments (hostname first): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 nil nil nil 'rlogin-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (let* ((process-connection-type rlogin-process-connection-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (args (if rlogin-explicit-args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (append (rlogin-parse-words input-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 rlogin-explicit-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (rlogin-parse-words input-args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (host (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (user (or (car (cdr (member "-l" args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (user-login-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (buffer-name (if (string= user (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (format "*rlogin-%s*" host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (format "*rlogin-%s@%s*" user host)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (cond ((null buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ((or (stringp buffer) (bufferp buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq buffer-name buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ((numberp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq buffer-name (format "%s<%d>" buffer-name buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq buffer-name (generate-new-buffer-name buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (pop-to-buffer buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ((comint-check-proc buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (comint-exec (current-buffer) buffer-name rlogin-program nil args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (setq proc (get-process buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; Set process-mark to point-max in case there is text in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; buffer from a previous exited process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (set-marker (process-mark proc) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (rlogin-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; comint-output-filter-functions is just like a hook, except that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; functions in that list are passed arguments. add-hook serves well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; enough for modifying it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (add-hook 'comint-output-filter-functions 'rlogin-carriage-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (make-local-variable 'rlogin-host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq rlogin-host host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (make-local-variable 'rlogin-remote-user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq rlogin-remote-user user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ((eq rlogin-directory-tracking-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Do this here, rather than calling the tracking mode function, to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; avoid a gratuitous resync check; the default should be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; user's home directory, be it local or remote.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (setq comint-file-name-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (concat "/" rlogin-remote-user "@" rlogin-host ":"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (cd-absolute comint-file-name-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ((null rlogin-directory-tracking-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (cd-absolute (concat comint-file-name-prefix "~/"))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun rlogin-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Set major-mode for rlogin sessions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 If `rlogin-mode-hook' is set, run it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (shell-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (setq major-mode 'rlogin-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (setq mode-name "rlogin")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (use-local-map rlogin-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (setq shell-dirtrackp rlogin-directory-tracking-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (make-local-variable 'comint-file-name-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (run-hooks 'rlogin-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (defun rlogin-directory-tracking-mode (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 "Do remote or local directory tracking, or disable entirely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 If called with no prefix argument or a unspecified prefix argument (just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ``\\[universal-argument]'' with no number) do remote directory tracking via
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ange-ftp. If called as a function, give it no argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 If called with a negative prefix argument, disable directory tracking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 entirely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 If called with a positive, numeric prefix argument, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ``\\[universal-argument] 1 M-x rlogin-directory-tracking-mode\'',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 then do directory tracking but assume the remote filesystem is the same as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 the local system. This only works in general if the remote machine and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 local one share the same directories (through NFS)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ((or (null prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (consp prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq rlogin-directory-tracking-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setq shell-dirtrackp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq comint-file-name-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (concat "/" rlogin-remote-user "@" rlogin-host ":")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ((< prefix 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq rlogin-directory-tracking-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq shell-dirtrackp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq rlogin-directory-tracking-mode 'local)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq comint-file-name-prefix "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (setq shell-dirtrackp t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (shell-dirtrackp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (let* ((proc (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (proc-mark (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (current-input (buffer-substring proc-mark (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (orig-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (offset (and (>= orig-point proc-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (- (point-max) orig-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (delete-region proc-mark (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (shell-resync-dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (goto-char proc-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (insert current-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (goto-char (- (point-max) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (goto-char orig-point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Parse a line into its constituent parts (words separated by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; whitespace). Return a list of the words.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (defun rlogin-parse-words (line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (let ((list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (posn 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (match-data (match-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (while (string-match "[^ \t\n]+" line posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq list (cons (substring line (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq posn (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (store-match-data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (nreverse list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defun rlogin-carriage-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (let* ((point-marker (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (end (process-mark (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (beg (or (and (boundp 'comint-last-output-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 comint-last-output-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (- end (length string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (while (search-forward "\C-m" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (goto-char point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defun rlogin-send-Ctrl-C ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (send-string nil "\C-c"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun rlogin-send-Ctrl-D ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (send-string nil "\C-d"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (defun rlogin-send-Ctrl-Z ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (send-string nil "\C-z"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (defun rlogin-send-Ctrl-backslash ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (send-string nil "\C-\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (defun rlogin-delchar-or-send-Ctrl-D (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Delete ARG characters forward, or send a C-d to process if at end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (rlogin-send-Ctrl-D)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (delete-char arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (defun rlogin-tab-or-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 "Complete file name if doing directory tracking, or just insert TAB."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (if rlogin-directory-tracking-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (insert "\C-i")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;;; rlogin.el ends here