1 ;;; tramp-cmds.el --- Interactive commands for Tramp
3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This package provides all interactive commands which are releated
32 (defun tramp-list-tramp-buffers ()
33 "Return a list of all Tramp connection buffers."
36 "*tramp" (mapcar 'list
(mapcar 'buffer-name
(buffer-list))))
38 "*debug tramp" (mapcar 'list
(mapcar 'buffer-name
(buffer-list))))))
40 (defun tramp-list-remote-buffers ()
41 "Return a list of all buffers with remote default-directory."
46 (with-current-buffer x
47 (when (and (stringp default-directory
)
48 (file-remote-p default-directory
))
52 (defun tramp-cleanup-connection (vec)
53 "Flush all connection related objects.
54 This includes password cache, file cache, connection cache, buffers.
55 When called interactively, a Tramp connection has to be selected."
57 ;; When interactive, select the Tramp remote identification.
58 ;; Return nil when there is no Tramp connection.
63 (tramp-make-tramp-file-name
64 (tramp-file-name-method x
)
65 (tramp-file-name-user x
)
66 (tramp-file-name-host x
)
67 (tramp-file-name-localname x
)))
68 (tramp-list-connections)))
74 "Enter Tramp connection: " connections nil t
75 (try-completion "" connections
)))
76 (when (and name
(file-remote-p name
))
77 (with-parsed-tramp-file-name name nil v
))))))
81 (message "No Tramp connection found.")
83 ;; Flush password cache.
84 (tramp-clear-passwd vec
)
87 (tramp-flush-directory-property vec
"/")
89 ;; Flush connection cache.
90 (tramp-flush-connection-property (tramp-get-connection-process vec
))
91 (tramp-flush-connection-property vec
)
95 (buf (list (get-buffer (tramp-buffer-name vec
))
96 (get-buffer (tramp-debug-buffer-name vec
))
97 (tramp-get-connection-property vec
"process-buffer" nil
)))
98 (when (bufferp buf
) (kill-buffer buf
)))))
100 (defun tramp-cleanup-all-connections ()
101 "Flush all Tramp internal objects.
102 This includes password cache, file cache, connection cache, buffers."
106 (setq tramp-locked nil
)
108 ;; Flush password cache.
109 (when (functionp 'password-reset
)
110 (funcall (symbol-function 'password-reset
)))
112 ;; Flush file and connection cache.
113 (clrhash tramp-cache-data
)
116 (dolist (name (tramp-list-tramp-buffers))
117 (when (bufferp (get-buffer name
)) (kill-buffer name
))))
119 (defun tramp-cleanup-all-buffers ()
120 "Kill all remote buffers."
123 ;; Remove all Tramp related buffers.
124 (tramp-cleanup-all-connections)
126 ;; Remove all buffers with a remote default-directory.
127 (dolist (name (tramp-list-remote-buffers))
128 (when (bufferp (get-buffer name
)) (kill-buffer name
))))
130 ;; Tramp version is useful in a number of situations.
132 (defun tramp-version (arg)
133 "Print version number of tramp.el in minibuffer or current buffer."
135 (if arg
(insert tramp-version
) (message tramp-version
)))
137 ;; Make the `reporter` functionality available for making bug reports about
138 ;; the package. A most useful piece of code.
140 (autoload 'reporter-submit-bug-report
"reporter")
143 "Submit a bug report to the Tramp developers."
147 (let ((reporter-prompt-for-summary-p t
))
148 (reporter-submit-bug-report
149 tramp-bug-report-address
; to-address
150 (format "tramp (%s)" tramp-version
) ; package name and version
158 tramp-auto-save-directory
; vars to dump
160 tramp-default-method-alist
162 tramp-default-proxies-alist
164 tramp-default-user-alist
165 tramp-rsh-end-of-line
166 tramp-default-password-end-of-line
167 tramp-login-prompt-regexp
168 ;; Mask non-7bit characters
169 (tramp-password-prompt-regexp . tramp-reporter-dump-variable
)
170 tramp-wrong-passwd-regexp
171 tramp-yesno-prompt-regexp
172 tramp-yn-prompt-regexp
173 tramp-terminal-prompt-regexp
174 tramp-temp-name-prefix
175 tramp-file-name-structure
176 tramp-file-name-regexp
179 tramp-local-coding-commands
180 tramp-remote-coding-commands
181 tramp-actions-before-shell
182 tramp-actions-copy-out-of-band
184 ;; Mask non-7bit characters
185 (tramp-shell-prompt-pattern . tramp-reporter-dump-variable
)
186 ,(when (boundp 'tramp-backup-directory-alist
)
187 'tramp-backup-directory-alist
)
188 ,(when (boundp 'tramp-bkup-backup-directory-info
)
189 'tramp-bkup-backup-directory-info
)
191 (tramp-cache-data . tramp-reporter-dump-variable
)
193 ;; Non-tramp variables of interest
194 ;; Mask non-7bit characters
195 (shell-prompt-pattern . tramp-reporter-dump-variable
)
197 backup-by-copying-when-linked
198 backup-by-copying-when-mismatch
199 ,(when (boundp 'backup-by-copying-when-privileged-mismatch
)
200 'backup-by-copying-when-privileged-mismatch
)
201 ,(when (boundp 'password-cache
)
203 ,(when (boundp 'password-cache-expiry
)
204 'password-cache-expiry
)
205 ,(when (boundp 'backup-directory-alist
)
206 'backup-directory-alist
)
207 ,(when (boundp 'bkup-backup-directory-info
)
208 'bkup-backup-directory-info
)
209 file-name-handler-alist
))
211 'tramp-load-report-modules
; pre-hook
212 'tramp-append-tramp-buffers
; post-hook
214 Enter your bug report in this message, including as much detail
215 as you possibly can about the problem, what you did to cause it
216 and what the local and remote machines are.
218 If you can give a simple set of instructions to make this bug
219 happen reliably, please include those. Thank you for helping
222 Another useful thing to do is to put
224 (setq tramp-verbose 8)
226 in the ~/.emacs file and to repeat the bug. Then, include the
227 contents of the *tramp/foo* buffer and the *debug tramp/foo*
228 buffer in your bug report.
230 --bug report follows this line--
233 (defun tramp-reporter-dump-variable (varsym mailbuf
)
234 "Pretty-print the value of the variable in symbol VARSYM.
235 Used for non-7bit chars in strings."
236 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer
))
237 (val (with-current-buffer reporter-eval-buffer
238 (symbol-value varsym
))))
240 (if (hash-table-p val
)
241 ;; Pretty print the cache.
242 (set varsym
(read (format "(%s)" (tramp-cache-print val
))))
243 ;; There are characters to be masked.
244 (when (and (boundp 'mm-7bit-chars
)
246 (concat "[^" (symbol-value 'mm-7bit-chars
) "]") val
))
247 (with-current-buffer reporter-eval-buffer
248 (set varsym
(format "(base64-decode-string \"%s\""
249 (base64-encode-string val
))))))
252 (funcall (symbol-function 'reporter-dump-variable
) varsym mailbuf
)
254 (unless (hash-table-p val
)
255 ;; Remove string quotation.
258 (concat "\\(^.*\\)" "\"" ;; \1 "
259 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
260 "\\(\".*\\)" "\\\\" ;; \3 \
261 "\\(\")\\)" "\"$")) ;; \4 "
262 (replace-match "\\1\\2\\3\\4")
264 (insert " ;; variable encoded due to non-printable characters\n"))
267 ;; Reset VARSYM to old value.
268 (with-current-buffer reporter-eval-buffer
271 (defun tramp-load-report-modules ()
272 "Load needed modules for reporting."
274 ;; We load message.el and mml.el from Gnus.
275 (if (featurep 'xemacs
)
277 (load "message" 'noerror
)
278 (load "mml" 'noerror
))
279 (require 'message nil
'noerror
)
280 (require 'mml nil
'noerror
))
281 (when (functionp 'message-mode
)
282 (funcall (symbol-function 'message-mode
)))
283 (when (functionp 'mml-mode
)
284 (funcall (symbol-function 'mml-mode
) t
)))
286 (defun tramp-append-tramp-buffers ()
287 "Append Tramp buffers and buffer local variables into the bug report."
289 (goto-char (point-max))
291 ;; Dump buffer local variables.
296 (when (string-match "\\*tramp/" (buffer-name b
)) b
))
298 (let ((reporter-eval-buffer buffer
)
299 (buffer-name (buffer-name buffer
))
300 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
301 (with-current-buffer elbuf
306 (funcall (symbol-function 'reporter-dump-variable
)
307 'buffer-name
(current-buffer))
308 (dolist (varsym-or-cons-cell (buffer-local-variables buffer
))
309 (let ((varsym (or (car-safe varsym-or-cons-cell
)
310 varsym-or-cons-cell
)))
311 (when (string-match "tramp" (symbol-name varsym
))
313 (symbol-function 'reporter-dump-variable
)
314 varsym
(current-buffer)))))
317 (insert-buffer-substring elbuf
)))
319 ;; Append buffers only when we are in message mode.
321 (eq major-mode
'message-mode
)
323 (symbol-value 'mml-mode
))
325 (let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
326 (buffer-list (funcall (symbol-function 'tramp-list-tramp-buffers
)))
327 (curbuf (current-buffer)))
329 ;; There is at least one Tramp buffer.
331 (switch-to-buffer (list-buffers-noselect nil
))
332 (delete-other-windows)
333 (setq buffer-read-only nil
)
334 (goto-char (point-min))
336 (if (re-search-forward
337 tramp-buf-regexp
(tramp-compat-line-end-position) t
)
340 (let ((start (point)))
342 (kill-region start
(point)))))
344 The buffer(s) above will be appended to this message. If you
345 don't want to append a buffer because it contains sensitive data,
346 or because the buffer is too large, you should delete the
347 respective buffer. The buffer(s) will contain user and host
348 names. Passwords will never be included there.")
350 (when (>= tramp-verbose
6)
352 (let ((start (point)))
354 Please note that you have set `tramp-verbose' to a value of at
355 least 6. Therefore, the contents of files might be included in
356 the debug buffer(s).")
357 (add-text-properties start
(point) (list 'face
'italic
))))
359 (set-buffer-modified-p nil
)
360 (setq buffer-read-only t
)
361 (goto-char (point-min))
363 (if (y-or-n-p "Do you want to append the buffer(s)? ")
364 ;; OK, let's send. First we delete the buffer list.
367 (switch-to-buffer curbuf
)
368 (goto-char (point-max))
370 This is a special notion of the `gnus/message' package. If you
371 use another mail agent (by copying the contents of this buffer)
372 please ensure that the buffers are attached to your email.\n\n")
373 (dolist (buffer buffer-list
)
374 (funcall (symbol-function 'mml-insert-empty-tag
)
375 'part
'type
"text/plain" 'encoding
"base64"
376 'disposition
"attachment" 'buffer buffer
377 'description buffer
))
378 (set-buffer-modified-p nil
))
380 ;; Don't send. Delete the message buffer.
382 (set-buffer-modified-p nil
)
384 (throw 'dont-send nil
))))))
386 (defalias 'tramp-submit-bug
'tramp-bug
)
388 (provide 'tramp-cmds
)
392 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
393 ;; * WIBNI there was an interactive command prompting for Tramp
394 ;; method, hostname, username and filename and translates the user
395 ;; input into the correct filename syntax (depending on the Emacs
396 ;; flavor) (Reiner Steib)
397 ;; * Let the user edit the connection properties interactively.
398 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
399 ;; * It's just that when I come to Customize `tramp-default-user-alist'
400 ;; I'm presented with a mismatch and raw lisp for a value. It is my
401 ;; understanding that a variable declared with defcustom is a User
402 ;; Option and should not be modified by the code. add-to-list is
403 ;; called in several places. One way to handle that is to have a new
404 ;; ordinary variable that gets its initial value from
405 ;; tramp-default-user-alist and then is added to. (Pete Forman)
407 ;; arch-tag: 190d4c33-76bb-4e99-8b6f-71741f23d98c
408 ;;; tramp-cmds.el ends here