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