1 ;;; tramp-cmds.el --- Interactive commands for Tramp
3 ;; Copyright (C) 2007, 2008, 2009 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 Before reproducing the bug, you might apply
224 M-x tramp-cleanup-all-connections
226 This allows to investigate from a clean environment. Another
227 useful thing to do is to put
229 (setq tramp-verbose 8)
231 in the ~/.emacs file and to repeat the bug. Then, include the
232 contents of the *tramp/foo* buffer and the *debug tramp/foo*
233 buffer in your bug report.
235 --bug report follows this line--
238 (defun tramp-reporter-dump-variable (varsym mailbuf
)
239 "Pretty-print the value of the variable in symbol VARSYM.
240 Used for non-7bit chars in strings."
241 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer
))
242 (val (with-current-buffer reporter-eval-buffer
243 (symbol-value varsym
))))
245 (if (hash-table-p val
)
246 ;; Pretty print the cache.
247 (set varsym
(read (format "(%s)" (tramp-cache-print val
))))
248 ;; There are characters to be masked.
249 (when (and (boundp 'mm-7bit-chars
)
251 (concat "[^" (symbol-value 'mm-7bit-chars
) "]") val
))
252 (with-current-buffer reporter-eval-buffer
253 (set varsym
(format "(base64-decode-string \"%s\""
254 (base64-encode-string val
))))))
257 (funcall (symbol-function 'reporter-dump-variable
) varsym mailbuf
)
259 (unless (hash-table-p val
)
260 ;; Remove string quotation.
263 (concat "\\(^.*\\)" "\"" ;; \1 "
264 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
265 "\\(\".*\\)" "\\\\" ;; \3 \
266 "\\(\")\\)" "\"$")) ;; \4 "
267 (replace-match "\\1\\2\\3\\4")
269 (insert " ;; variable encoded due to non-printable characters\n"))
272 ;; Reset VARSYM to old value.
273 (with-current-buffer reporter-eval-buffer
276 (defun tramp-load-report-modules ()
277 "Load needed modules for reporting."
279 ;; We load message.el and mml.el from Gnus.
280 (if (featurep 'xemacs
)
282 (load "message" 'noerror
)
283 (load "mml" 'noerror
))
284 (require 'message nil
'noerror
)
285 (require 'mml nil
'noerror
))
286 (when (functionp 'message-mode
)
287 (funcall (symbol-function 'message-mode
)))
288 (when (functionp 'mml-mode
)
289 (funcall (symbol-function '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 (funcall (symbol-function 'reporter-dump-variable
)
312 '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
))
318 (symbol-function 'reporter-dump-variable
)
319 varsym
(current-buffer)))))
322 (insert-buffer-substring elbuf
)))
324 ;; Append buffers only when we are in message mode.
326 (eq major-mode
'message-mode
)
328 (symbol-value 'mml-mode
))
330 (let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
331 (buffer-list (funcall (symbol-function 'tramp-list-tramp-buffers
)))
332 (curbuf (current-buffer)))
334 ;; There is at least one Tramp buffer.
336 (switch-to-buffer (list-buffers-noselect nil
))
337 (delete-other-windows)
338 (setq buffer-read-only nil
)
339 (goto-char (point-min))
341 (if (re-search-forward
342 tramp-buf-regexp
(tramp-compat-line-end-position) t
)
345 (let ((start (point)))
347 (kill-region start
(point)))))
349 The buffer(s) above will be appended to this message. If you
350 don't want to append a buffer because it contains sensitive data,
351 or because the buffer is too large, you should delete the
352 respective buffer. The buffer(s) will contain user and host
353 names. Passwords will never be included there.")
355 (when (>= tramp-verbose
6)
357 (let ((start (point)))
359 Please note that you have set `tramp-verbose' to a value of at
360 least 6. Therefore, the contents of files might be included in
361 the debug buffer(s).")
362 (add-text-properties start
(point) (list 'face
'italic
))))
364 (set-buffer-modified-p nil
)
365 (setq buffer-read-only t
)
366 (goto-char (point-min))
368 (if (y-or-n-p "Do you want to append the buffer(s)? ")
369 ;; OK, let's send. First we delete the buffer list.
372 (switch-to-buffer curbuf
)
373 (goto-char (point-max))
375 This is a special notion of the `gnus/message' package. If you
376 use another mail agent (by copying the contents of this buffer)
377 please ensure that the buffers are attached to your email.\n\n")
378 (dolist (buffer buffer-list
)
379 (funcall (symbol-function 'mml-insert-empty-tag
)
380 'part
'type
"text/plain" 'encoding
"base64"
381 'disposition
"attachment" 'buffer buffer
382 'description buffer
))
383 (set-buffer-modified-p nil
))
385 ;; Don't send. Delete the message buffer.
387 (set-buffer-modified-p nil
)
389 (throw 'dont-send nil
))))))
391 (defalias 'tramp-submit-bug
'tramp-bug
)
393 (provide 'tramp-cmds
)
397 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
398 ;; * WIBNI there was an interactive command prompting for Tramp
399 ;; method, hostname, username and filename and translates the user
400 ;; input into the correct filename syntax (depending on the Emacs
401 ;; flavor) (Reiner Steib)
402 ;; * Let the user edit the connection properties interactively.
403 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
404 ;; * It's just that when I come to Customize `tramp-default-user-alist'
405 ;; I'm presented with a mismatch and raw lisp for a value. It is my
406 ;; understanding that a variable declared with defcustom is a User
407 ;; Option and should not be modified by the code. add-to-list is
408 ;; called in several places. One way to handle that is to have a new
409 ;; ordinary variable that gets its initial value from
410 ;; tramp-default-user-alist and then is added to. (Pete Forman)
412 ;; arch-tag: 190d4c33-76bb-4e99-8b6f-71741f23d98c
413 ;;; tramp-cmds.el ends here