1 ;;; tramp-cmds.el --- Interactive commands for Tramp
3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
9 ;; This file is part of GNU Emacs.
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 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This package provides all interactive commands which are releated
33 (defun tramp-list-tramp-buffers ()
34 "Return a list of all Tramp connection buffers."
37 "*tramp" (mapcar 'list (mapcar 'buffer-name (buffer-list))))
39 "*debug tramp" (mapcar 'list (mapcar 'buffer-name (buffer-list))))))
41 (defun tramp-list-remote-buffers ()
42 "Return a list of all buffers with remote default-directory."
47 (with-current-buffer x
48 (when (and (stringp default-directory)
49 (file-remote-p default-directory))
54 (defun tramp-cleanup-connection (vec)
55 "Flush all connection related objects.
56 This includes password cache, file cache, connection cache, buffers.
57 When called interactively, a Tramp connection has to be selected."
59 ;; When interactive, select the Tramp remote identification.
60 ;; Return nil when there is no Tramp connection.
65 (tramp-make-tramp-file-name
66 (tramp-file-name-method x)
67 (tramp-file-name-user x)
68 (tramp-file-name-host x)
69 (tramp-file-name-localname x)))
70 (tramp-list-connections)))
76 "Enter Tramp connection: " connections nil t
77 (try-completion "" connections)))
78 (when (and name (file-remote-p name))
79 (with-parsed-tramp-file-name name nil v))))))
83 (message "No Tramp connection found.")
85 ;; Flush password cache.
86 (tramp-clear-passwd vec)
89 (tramp-flush-directory-property vec "")
91 ;; Flush connection cache.
92 (tramp-flush-connection-property (tramp-get-connection-process vec))
93 (tramp-flush-connection-property vec)
97 (buf (list (get-buffer (tramp-buffer-name vec))
98 (get-buffer (tramp-debug-buffer-name vec))
99 (tramp-get-connection-property vec "process-buffer" nil)))
100 (when (bufferp buf) (kill-buffer buf)))))
102 (defun tramp-cleanup-all-connections ()
103 "Flush all Tramp internal objects.
104 This includes password cache, file cache, connection cache, buffers."
108 (setq tramp-locked nil)
110 ;; Flush password cache.
111 (tramp-compat-funcall 'password-reset)
113 ;; Flush file and connection cache.
114 (clrhash tramp-cache-data)
117 (dolist (name (tramp-list-tramp-buffers))
118 (when (bufferp (get-buffer name)) (kill-buffer name))))
120 (defun tramp-cleanup-all-buffers ()
121 "Kill all remote buffers."
124 ;; Remove all Tramp related buffers.
125 (tramp-cleanup-all-connections)
127 ;; Remove all buffers with a remote default-directory.
128 (dolist (name (tramp-list-remote-buffers))
129 (when (bufferp (get-buffer name)) (kill-buffer name))))
131 ;; Tramp version is useful in a number of situations.
134 (defun tramp-version (arg)
135 "Print version number of tramp.el in minibuffer or current buffer."
137 (if arg (insert tramp-version) (message tramp-version)))
139 ;; Make the `reporter` functionality available for making bug reports about
140 ;; the package. A most useful piece of code.
142 (autoload 'reporter-submit-bug-report "reporter")
145 "Submit a bug report to the Tramp developers."
149 (let ((reporter-prompt-for-summary-p t))
150 (reporter-submit-bug-report
151 tramp-bug-report-address ; to-address
152 (format "tramp (%s)" tramp-version) ; package name and version
160 tramp-auto-save-directory ; vars to dump
162 tramp-default-method-alist
164 tramp-default-proxies-alist
166 tramp-default-user-alist
167 tramp-rsh-end-of-line
168 tramp-default-password-end-of-line
169 tramp-login-prompt-regexp
170 ;; Mask non-7bit characters
171 (tramp-password-prompt-regexp . tramp-reporter-dump-variable)
172 tramp-wrong-passwd-regexp
173 tramp-yesno-prompt-regexp
174 tramp-yn-prompt-regexp
175 tramp-terminal-prompt-regexp
176 tramp-temp-name-prefix
177 tramp-file-name-structure
178 tramp-file-name-regexp
181 tramp-local-coding-commands
182 tramp-remote-coding-commands
183 tramp-actions-before-shell
184 tramp-actions-copy-out-of-band
186 ;; Mask non-7bit characters
187 (tramp-shell-prompt-pattern . tramp-reporter-dump-variable)
188 ,(when (boundp 'tramp-backup-directory-alist)
189 'tramp-backup-directory-alist)
190 ,(when (boundp 'tramp-bkup-backup-directory-info)
191 'tramp-bkup-backup-directory-info)
193 (tramp-cache-data . tramp-reporter-dump-variable)
195 ;; Non-tramp variables of interest
196 ;; Mask non-7bit characters
197 (shell-prompt-pattern . tramp-reporter-dump-variable)
199 backup-by-copying-when-linked
200 backup-by-copying-when-mismatch
201 ,(when (boundp 'backup-by-copying-when-privileged-mismatch)
202 'backup-by-copying-when-privileged-mismatch)
203 ,(when (boundp 'password-cache)
205 ,(when (boundp 'password-cache-expiry)
206 'password-cache-expiry)
207 ,(when (boundp 'backup-directory-alist)
208 'backup-directory-alist)
209 ,(when (boundp 'bkup-backup-directory-info)
210 'bkup-backup-directory-info)
211 file-name-handler-alist))
213 'tramp-load-report-modules ; pre-hook
214 'tramp-append-tramp-buffers ; post-hook
216 Enter your bug report in this message, including as much detail
217 as you possibly can about the problem, what you did to cause it
218 and what the local and remote machines are.
220 If you can give a simple set of instructions to make this bug
221 happen reliably, please include those. Thank you for helping
224 Before reproducing the bug, you might apply
226 M-x tramp-cleanup-all-connections
228 This allows to investigate from a clean environment. Another
229 useful thing to do is to put
231 (setq tramp-verbose 9)
233 in the ~/.emacs file and to repeat the bug. Then, include the
234 contents of the *tramp/foo* buffer and the *debug tramp/foo*
235 buffer in your bug report.
237 --bug report follows this line--
240 (defun tramp-reporter-dump-variable (varsym mailbuf)
241 "Pretty-print the value of the variable in symbol VARSYM.
242 Used for non-7bit chars in strings."
243 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer))
244 (val (with-current-buffer reporter-eval-buffer
245 (symbol-value varsym))))
247 (if (hash-table-p val)
248 ;; Pretty print the cache.
249 (set varsym (read (format "(%s)" (tramp-cache-print val))))
250 ;; There are characters to be masked.
251 (when (and (boundp 'mm-7bit-chars)
253 (concat "[^" (symbol-value 'mm-7bit-chars) "]") val))
254 (with-current-buffer reporter-eval-buffer
255 (set varsym (format "(base64-decode-string \"%s\""
256 (base64-encode-string val))))))
259 (tramp-compat-funcall 'reporter-dump-variable varsym mailbuf)
261 (unless (hash-table-p val)
262 ;; Remove string quotation.
265 (concat "\\(^.*\\)" "\"" ;; \1 "
266 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
267 "\\(\".*\\)" "\\\\" ;; \3 \
268 "\\(\")\\)" "\"$")) ;; \4 "
269 (replace-match "\\1\\2\\3\\4")
271 (insert " ;; variable encoded due to non-printable characters\n"))
274 ;; Reset VARSYM to old value.
275 (with-current-buffer reporter-eval-buffer
278 (defun tramp-load-report-modules ()
279 "Load needed modules for reporting."
281 ;; We load message.el and mml.el from Gnus.
282 (if (featurep 'xemacs)
284 (load "message" 'noerror)
285 (load "mml" 'noerror))
286 (require 'message nil 'noerror)
287 (require 'mml nil 'noerror))
288 (tramp-compat-funcall 'message-mode)
289 (tramp-compat-funcall 'mml-mode t))
291 (defun tramp-append-tramp-buffers ()
292 "Append Tramp buffers and buffer local variables into the bug report."
294 (goto-char (point-max))
296 ;; Dump buffer local variables.
301 (when (string-match "\\*tramp/" (buffer-name b)) b))
303 (let ((reporter-eval-buffer buffer)
304 (buffer-name (buffer-name buffer))
305 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
306 (with-current-buffer elbuf
311 (tramp-compat-funcall
312 'reporter-dump-variable 'buffer-name (current-buffer))
313 (dolist (varsym-or-cons-cell (buffer-local-variables buffer))
314 (let ((varsym (or (car-safe varsym-or-cons-cell)
315 varsym-or-cons-cell)))
316 (when (string-match "tramp" (symbol-name varsym))
317 (tramp-compat-funcall
318 'reporter-dump-variable varsym (current-buffer)))))
321 (insert-buffer-substring elbuf)))
323 ;; Append buffers only when we are in message mode.
325 (eq major-mode 'message-mode)
327 (symbol-value 'mml-mode))
329 (let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
330 (buffer-list (tramp-compat-funcall 'tramp-list-tramp-buffers))
331 (curbuf (current-buffer)))
333 ;; There is at least one Tramp buffer.
335 (switch-to-buffer (list-buffers-noselect nil))
336 (delete-other-windows)
337 (setq buffer-read-only nil)
338 (goto-char (point-min))
340 (if (re-search-forward
341 tramp-buf-regexp (tramp-compat-line-end-position) t)
344 (let ((start (point)))
346 (kill-region start (point)))))
348 The buffer(s) above will be appended to this message. If you
349 don't want to append a buffer because it contains sensitive data,
350 or because the buffer is too large, you should delete the
351 respective buffer. The buffer(s) will contain user and host
352 names. Passwords will never be included there.")
354 (when (>= tramp-verbose 6)
356 (let ((start (point)))
358 Please note that you have set `tramp-verbose' to a value of at
359 least 6. Therefore, the contents of files might be included in
360 the debug buffer(s).")
361 (add-text-properties start (point) (list 'face 'italic))))
363 (set-buffer-modified-p nil)
364 (setq buffer-read-only t)
365 (goto-char (point-min))
367 (if (y-or-n-p "Do you want to append the buffer(s)? ")
368 ;; OK, let's send. First we delete the buffer list.
371 (switch-to-buffer curbuf)
372 (goto-char (point-max))
374 This is a special notion of the `gnus/message' package. If you
375 use another mail agent (by copying the contents of this buffer)
376 please ensure that the buffers are attached to your email.\n\n")
377 (dolist (buffer buffer-list)
378 (tramp-compat-funcall
379 'mml-insert-empty-tag 'part 'type "text/plain"
380 'encoding "base64" 'disposition "attachment" 'buffer buffer
381 'description buffer))
382 (set-buffer-modified-p nil))
384 ;; Don't send. Delete the message buffer.
386 (set-buffer-modified-p nil)
388 (throw 'dont-send nil))))))
390 (defalias 'tramp-submit-bug 'tramp-bug)
392 (add-hook 'tramp-unload-hook
393 (lambda () (unload-feature 'tramp-cmds 'force)))
395 (provide 'tramp-cmds)
399 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
400 ;; * WIBNI there was an interactive command prompting for Tramp
401 ;; method, hostname, username and filename and translates the user
402 ;; input into the correct filename syntax (depending on the Emacs
403 ;; flavor) (Reiner Steib)
404 ;; * Let the user edit the connection properties interactively.
405 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
406 ;; * It's just that when I come to Customize `tramp-default-user-alist'
407 ;; I'm presented with a mismatch and raw lisp for a value. It is my
408 ;; understanding that a variable declared with defcustom is a User
409 ;; Option and should not be modified by the code. add-to-list is
410 ;; called in several places. One way to handle that is to have a new
411 ;; ordinary variable that gets its initial value from
412 ;; tramp-default-user-alist and then is added to. (Pete Forman)
414 ;; arch-tag: 190d4c33-76bb-4e99-8b6f-71741f23d98c
415 ;;; tramp-cmds.el ends here