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