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