Mercurial > emacs
comparison lisp/rlogin.el @ 2539:577c77cfd199
*** empty log message ***
author | Noah Friedman <friedman@splode.com> |
---|---|
date | Fri, 16 Apr 1993 13:06:01 +0000 |
parents | f51bd6676409 |
children | 843c652ebcc3 |
comparison
equal
deleted
inserted
replaced
2538:78420d74d47f | 2539:577c77cfd199 |
---|---|
1 ;;; rlogin.el --- remote login interface | 1 ;;; rlogin.el --- remote login interface |
2 | 2 |
3 ;; Author: Noah Friedman | |
3 ;; Maintainer: Noah Friedman <friedman@prep.ai.mit.edu> | 4 ;; Maintainer: Noah Friedman <friedman@prep.ai.mit.edu> |
4 ;; Keywords: unix, comm | 5 ;; Keywords: unix, comm |
5 | 6 |
6 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. | 7 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. |
7 ;; | 8 ;; |
27 | 28 |
28 ;;; Code: | 29 ;;; Code: |
29 | 30 |
30 (require 'comint) | 31 (require 'comint) |
31 | 32 |
33 ;;;###autoload | |
32 (defvar rlogin-program "rlogin" | 34 (defvar rlogin-program "rlogin" |
33 "*Name of program to invoke rlogin") | 35 "*Name of program to invoke rlogin") |
34 | 36 |
37 ;;;###autoload | |
35 (defvar rlogin-explicit-args nil | 38 (defvar rlogin-explicit-args nil |
36 "*List of arguments to pass to rlogin on the command line.") | 39 "*List of arguments to pass to rlogin on the command line.") |
37 | 40 |
41 ;;;###autoload | |
38 (defvar rlogin-mode-hook nil | 42 (defvar rlogin-mode-hook nil |
39 "*Hooks to run after setting current buffer to rlogin-mode.") | 43 "*Hooks to run after setting current buffer to rlogin-mode.") |
40 | 44 |
41 ;; I think this is so obnoxious I refuse to enable it by default. | 45 ;;;###autoload |
42 ;; In any case, there is a bug with regards to generating a quit while | 46 (defvar rlogin-process-connection-type nil |
43 ;; reading keyboard input in a process filter, so until that's fixed it's | 47 "*If non-`nil', use a pty for the local rlogin process. |
44 ;; not safe to enable this anyway. | 48 If `nil', use a pipe (if pipes are supported on the local system). |
49 | |
50 Generally it is better not to waste ptys on systems which have a static | |
51 number of them. On the other hand, some implementations of `rlogin' assume | |
52 a pty is being used, and errors will result from using a pipe instead.") | |
53 | |
54 ;; Leave this nil because it makes rlogin-filter a tiny bit faster. Plus | |
55 ;; you can still call rlogin-password by hand. | |
56 ;;;###autoload | |
45 (defvar rlogin-password-paranoia nil | 57 (defvar rlogin-password-paranoia nil |
46 "*If non-`nil', query user for a password in the minibuffer when a | 58 "*If non-`nil', query user for a password in the minibuffer when a Password: prompt appears. |
47 Password: prompt appears. Stars will echo as characters are type. | |
48 | |
49 It's also possible to selectively enter passwords without echoing them in | 59 It's also possible to selectively enter passwords without echoing them in |
50 the minibuffer using the function `rlogin-password'.") | 60 the minibuffer using the command `rlogin-password' explicitly.") |
51 | |
52 (defvar rlogin-last-input-line nil nil) | |
53 | 61 |
54 ;; Initialize rlogin mode map. | 62 ;; Initialize rlogin mode map. |
63 ;;;###autoload | |
55 (defvar rlogin-mode-map '()) | 64 (defvar rlogin-mode-map '()) |
56 (cond ((not rlogin-mode-map) | 65 (cond ((not rlogin-mode-map) |
57 (setq rlogin-mode-map (full-copy-sparse-keymap comint-mode-map)) | 66 (setq rlogin-mode-map (full-copy-sparse-keymap comint-mode-map)) |
58 ;(define-key rlogin-mode-map "\M-\t" 'comint-dynamic-complete) | 67 ;(define-key rlogin-mode-map "\M-\t" 'comint-dynamic-complete) |
59 ;(define-key rlogin-mode-map "\M-?" 'comint-dynamic-list-completions) | 68 ;(define-key rlogin-mode-map "\M-?" 'comint-dynamic-list-completions) |
76 | 85 |
77 The variable `rlogin-explicit-args' is a list of arguments to give to | 86 The variable `rlogin-explicit-args' is a list of arguments to give to |
78 the rlogin when starting." | 87 the rlogin when starting." |
79 (interactive (list current-prefix-arg | 88 (interactive (list current-prefix-arg |
80 (read-from-minibuffer "Open rlogin connection to host: "))) | 89 (read-from-minibuffer "Open rlogin connection to host: "))) |
81 (let* ((buffer-name (format "*rlogin-%s*" host)) | 90 (let* ((process-connection-type rlogin-process-connection-type) |
91 (buffer-name (format "*rlogin-%s*" host)) | |
82 (args (if (and rlogin-explicit-args (listp rlogin-explicit-args)) | 92 (args (if (and rlogin-explicit-args (listp rlogin-explicit-args)) |
83 (cons host rlogin-explicit-args) | 93 (cons host rlogin-explicit-args) |
84 (list host))) | 94 (list host))) |
85 proc) | 95 proc) |
86 (and prefix (setq buffer-name | 96 (and prefix (setq buffer-name |
89 (or (comint-check-proc buffer-name) | 99 (or (comint-check-proc buffer-name) |
90 (progn | 100 (progn |
91 (comint-mode) | 101 (comint-mode) |
92 (comint-exec (current-buffer) buffer-name rlogin-program nil args) | 102 (comint-exec (current-buffer) buffer-name rlogin-program nil args) |
93 (setq proc (get-process buffer-name)) | 103 (setq proc (get-process buffer-name)) |
94 (set-marker (process-mark proc) (point-min)) | 104 ;; Set process-mark to point-max in case there is text in the |
105 ;; buffer from a previous exited process. | |
106 (set-marker (process-mark proc) (point-max)) | |
95 (set-process-filter proc 'rlogin-filter) | 107 (set-process-filter proc 'rlogin-filter) |
96 (rlogin-mode))))) | 108 (rlogin-mode))))) |
97 | 109 |
98 ;;;###autoload | 110 ;;;###autoload |
99 (defun rlogin-with-args (host args) | 111 (defun rlogin-with-args (host args) |
104 (read-from-minibuffer "with arguments: "))) | 116 (read-from-minibuffer "with arguments: "))) |
105 (let ((old-match-data (match-data)) | 117 (let ((old-match-data (match-data)) |
106 (rlogin-explicit-args nil)) | 118 (rlogin-explicit-args nil)) |
107 (unwind-protect | 119 (unwind-protect |
108 (progn | 120 (progn |
109 (while (string-match "[ \t]*\\([^ \t]\\)+$" args) | 121 (while (string-match "[ \t]*\\([^ \t]+\\)$" args) |
110 (setq rlogin-explicit-args | 122 (setq rlogin-explicit-args |
111 (cons (substring args | 123 (cons (substring args |
112 (match-beginning 1) | 124 (match-beginning 1) |
113 (match-end 1)) | 125 (match-end 1)) |
114 rlogin-explicit-args) | 126 rlogin-explicit-args) |
115 args (substring args 0 (match-beginning 0))))) | 127 args (substring args 0 (match-beginning 0))))) |
116 (store-match-data old-match-data)) | 128 (store-match-data old-match-data)) |
117 (rlogin 1 host))) | 129 (rlogin 1 host))) |
118 | 130 |
119 ;;;###autoload | 131 ;;;###autoload |
120 (defun rlogin-password () | 132 (defun rlogin-password (&optional proc) |
121 "Play the paranoia game by not echoing entered password in buffer | 133 "Read a password and send it to an rlogin session. |
122 (stars will echo in the minibuffer instead." | 134 For each character typed, a `*' is echoed in the minibuffer. |
123 (interactive) | 135 End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. |
124 (let ((input (comint-read-noecho "Enter password: " 'stars))) | 136 C-g aborts attempt to read and send password. |
125 (insert-before-markers "\n") | 137 |
126 (comint-send-string (get-buffer-process (current-buffer)) | 138 Optional argument PROC is the process to which the password should be sent. |
127 (format "%s\n" input)))) | 139 If not provided, send to the process in the current buffer. This argument |
140 is intended primarily for use by `rlogin-filter'." | |
141 (interactive) | |
142 (or proc (setq proc (get-buffer-process (current-buffer)))) | |
143 (let* ((buffer-name (buffer-name (process-buffer proc))) | |
144 (pass (comint-read-noecho (format "Password for buffer \"%s\": " | |
145 buffer-name) | |
146 'stars))) | |
147 (and pass | |
148 (save-excursion | |
149 (set-buffer buffer-name) | |
150 (insert-before-markers "\n") | |
151 (comint-send-string proc (format "%s\n" pass)))))) | |
128 | 152 |
129 ;;;###autoload | 153 ;;;###autoload |
130 (defun rlogin-mode () | 154 (defun rlogin-mode () |
155 "Set major-mode for rlogin sessions. | |
156 If `rlogin-mode-hook' is set, run it." | |
131 (interactive) | 157 (interactive) |
132 (kill-all-local-variables) | 158 (kill-all-local-variables) |
133 (comint-mode) | 159 (comint-mode) |
134 (setq comint-prompt-regexp shell-prompt-pattern) | 160 (setq comint-prompt-regexp shell-prompt-pattern) |
135 (setq major-mode 'rlogin-mode) | 161 (setq major-mode 'rlogin-mode) |
136 (setq mode-name "rlogin") | 162 (setq mode-name "rlogin") |
137 (use-local-map rlogin-mode-map) | 163 (use-local-map rlogin-mode-map) |
138 (run-hooks 'rlogin-mode-hook)) | 164 (run-hooks 'rlogin-mode-hook)) |
139 | 165 |
166 | |
140 (defun rlogin-filter (proc string) | 167 (defun rlogin-filter (proc string) |
141 (let ((old-buffer (current-buffer)) | 168 (save-excursion |
142 (old-match-data (match-data)) | 169 (set-buffer (process-buffer proc)) |
143 at-max-pos | 170 (let ((proc-mark (process-mark proc)) |
144 moving) | 171 (region-begin (point))) |
145 (unwind-protect | 172 (goto-char proc-mark) |
146 (progn | 173 (insert-before-markers string) |
147 (set-buffer (process-buffer proc)) | 174 (goto-char region-begin) |
148 (setq moving (= (point) (process-mark proc))) | 175 (while (search-forward "\C-m" proc-mark t) |
149 (save-excursion | 176 (delete-char -1)))) |
150 (goto-char (process-mark proc)) | 177 ;; Kludgy workaround for scroll-step bug in emacs. If point is at the |
151 (save-restriction | 178 ;; top of the window, scroll step is nonzero, and you call |
152 (let ((beg (point))) | 179 ;; insert-before-markers, the text is inserted off-screen. If |
153 (insert-before-markers string) | 180 ;; scroll-step is 0, this doesn't happen. |
154 (narrow-to-region beg (point)) | 181 (and (/= scroll-step 0) |
155 (goto-char (point-min)) | 182 (eq (process-buffer proc) (window-buffer (selected-window))) |
156 (while (search-forward "\C-m" nil t) | 183 (eq (point) (window-start)) |
157 (delete-char -1)) | 184 (set-window-start (selected-window) |
158 (and rlogin-password-paranoia | 185 (save-excursion |
159 (setq string (buffer-substring (point-min) (point-max)))) | 186 (beginning-of-line) |
160 (goto-char (point-max)))) | 187 (point)) |
161 (set-marker (process-mark proc) (point))) | 188 'noforce)) |
162 (and moving | |
163 (goto-char (process-mark proc)))) | |
164 (set-buffer old-buffer) | |
165 (store-match-data old-match-data))) | |
166 (and rlogin-password-paranoia | 189 (and rlogin-password-paranoia |
167 (string= "Password:" string) | 190 (string= "Password:" string) |
168 (let ((input (comint-read-noecho "Enter password: " 'stars))) | 191 (rlogin-password proc))) |
169 (and input | 192 |
170 (progn | 193 ;;;###autoload |
171 (insert-before-markers "\n") | |
172 (comint-send-string proc (format "%s\n" input))))))) | |
173 | |
174 (defun rlogin-send-Ctrl-C () | 194 (defun rlogin-send-Ctrl-C () |
175 (interactive) | 195 (interactive) |
176 (send-string nil "\C-c")) | 196 (send-string nil "\C-c")) |
177 | 197 |
198 ;;;###autoload | |
178 (defun rlogin-send-Ctrl-Z () | 199 (defun rlogin-send-Ctrl-Z () |
179 (interactive) | 200 (interactive) |
180 (send-string nil "\C-z")) | 201 (send-string nil "\C-z")) |
181 | 202 |
203 ;;;###autoload | |
182 (defun rlogin-send-Ctrl-backslash () | 204 (defun rlogin-send-Ctrl-backslash () |
183 (interactive) | 205 (interactive) |
184 (send-string nil "\C-\\")) | 206 (send-string nil "\C-\\")) |
185 | 207 |
208 ;;;###autoload | |
186 (defun rlogin-delchar-or-send-Ctrl-D (arg) | 209 (defun rlogin-delchar-or-send-Ctrl-D (arg) |
187 "Delete ARG characters forward, or send a C-d to process if at end of | 210 "Delete ARG characters forward, or send a C-d to process if at end of |
188 buffer." | 211 buffer." |
189 (interactive "p") | 212 (interactive "p") |
190 (if (eobp) | 213 (if (eobp) |