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
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 (tramp-compat-funcall 'password-reset
)
111 ;; Flush file and connection cache.
112 (clrhash tramp-cache-data
)
115 (dolist (name (tramp-list-tramp-buffers))
116 (when (bufferp (get-buffer name
)) (kill-buffer name
))))
118 (defun tramp-cleanup-all-buffers ()
119 "Kill all remote buffers."
122 ;; Remove all Tramp related buffers.
123 (tramp-cleanup-all-connections)
125 ;; Remove all buffers with a remote default-directory.
126 (dolist (name (tramp-list-remote-buffers))
127 (when (bufferp (get-buffer name
)) (kill-buffer name
))))
129 ;; Tramp version is useful in a number of situations.
131 (defun tramp-version (arg)
132 "Print version number of tramp.el in minibuffer or current buffer."
134 (if arg
(insert tramp-version
) (message tramp-version
)))
136 ;; Make the `reporter` functionality available for making bug reports about
137 ;; the package. A most useful piece of code.
139 (autoload 'reporter-submit-bug-report
"reporter")
142 "Submit a bug report to the Tramp developers."
146 (let ((reporter-prompt-for-summary-p t
))
147 (reporter-submit-bug-report
148 tramp-bug-report-address
; to-address
149 (format "tramp (%s)" tramp-version
) ; package name and version
157 tramp-auto-save-directory
; vars to dump
159 tramp-default-method-alist
161 tramp-default-proxies-alist
163 tramp-default-user-alist
164 tramp-rsh-end-of-line
165 tramp-default-password-end-of-line
166 tramp-login-prompt-regexp
167 ;; Mask non-7bit characters
168 (tramp-password-prompt-regexp . tramp-reporter-dump-variable
)
169 tramp-wrong-passwd-regexp
170 tramp-yesno-prompt-regexp
171 tramp-yn-prompt-regexp
172 tramp-terminal-prompt-regexp
173 tramp-temp-name-prefix
174 tramp-file-name-structure
175 tramp-file-name-regexp
178 tramp-local-coding-commands
179 tramp-remote-coding-commands
180 tramp-actions-before-shell
181 tramp-actions-copy-out-of-band
183 ;; Mask non-7bit characters
184 (tramp-shell-prompt-pattern . tramp-reporter-dump-variable
)
185 ,(when (boundp 'tramp-backup-directory-alist
)
186 'tramp-backup-directory-alist
)
187 ,(when (boundp 'tramp-bkup-backup-directory-info
)
188 'tramp-bkup-backup-directory-info
)
190 (tramp-cache-data . tramp-reporter-dump-variable
)
192 ;; Non-tramp variables of interest
193 ;; Mask non-7bit characters
194 (shell-prompt-pattern . tramp-reporter-dump-variable
)
196 backup-by-copying-when-linked
197 backup-by-copying-when-mismatch
198 ,(when (boundp 'backup-by-copying-when-privileged-mismatch
)
199 'backup-by-copying-when-privileged-mismatch
)
200 ,(when (boundp 'password-cache
)
202 ,(when (boundp 'password-cache-expiry
)
203 'password-cache-expiry
)
204 ,(when (boundp 'backup-directory-alist
)
205 'backup-directory-alist
)
206 ,(when (boundp 'bkup-backup-directory-info
)
207 'bkup-backup-directory-info
)
208 file-name-handler-alist
))
210 'tramp-load-report-modules
; pre-hook
211 'tramp-append-tramp-buffers
; post-hook
213 Enter your bug report in this message, including as much detail
214 as you possibly can about the problem, what you did to cause it
215 and what the local and remote machines are.
217 If you can give a simple set of instructions to make this bug
218 happen reliably, please include those. Thank you for helping
221 Before reproducing the bug, you might apply
223 M-x tramp-cleanup-all-connections
225 This allows to investigate from a clean environment. Another
226 useful thing to do is to put
228 (setq tramp-verbose 8)
230 in the ~/.emacs file and to repeat the bug. Then, include the
231 contents of the *tramp/foo* buffer and the *debug tramp/foo*
232 buffer in your bug report.
234 --bug report follows this line--
237 (defun tramp-reporter-dump-variable (varsym mailbuf
)
238 "Pretty-print the value of the variable in symbol VARSYM.
239 Used for non-7bit chars in strings."
240 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer
))
241 (val (with-current-buffer reporter-eval-buffer
242 (symbol-value varsym
))))
244 (if (hash-table-p val
)
245 ;; Pretty print the cache.
246 (set varsym
(read (format "(%s)" (tramp-cache-print val
))))
247 ;; There are characters to be masked.
248 (when (and (boundp 'mm-7bit-chars
)
250 (concat "[^" (symbol-value 'mm-7bit-chars
) "]") val
))
251 (with-current-buffer reporter-eval-buffer
252 (set varsym
(format "(base64-decode-string \"%s\""
253 (base64-encode-string val
))))))
256 (tramp-compat-funcall 'reporter-dump-variable varsym mailbuf
)
258 (unless (hash-table-p val
)
259 ;; Remove string quotation.
262 (concat "\\(^.*\\)" "\"" ;; \1 "
263 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
264 "\\(\".*\\)" "\\\\" ;; \3 \
265 "\\(\")\\)" "\"$")) ;; \4 "
266 (replace-match "\\1\\2\\3\\4")
268 (insert " ;; variable encoded due to non-printable characters\n"))
271 ;; Reset VARSYM to old value.
272 (with-current-buffer reporter-eval-buffer
275 (defun tramp-load-report-modules ()
276 "Load needed modules for reporting."
278 ;; We load message.el and mml.el from Gnus.
279 (if (featurep 'xemacs
)
281 (load "message" 'noerror
)
282 (load "mml" 'noerror
))
283 (require 'message nil
'noerror
)
284 (require 'mml nil
'noerror
))
285 (tramp-compat-funcall 'message-mode
)
286 (tramp-compat-funcall 'mml-mode t
))
288 (defun tramp-append-tramp-buffers ()
289 "Append Tramp buffers and buffer local variables into the bug report."
291 (goto-char (point-max))
293 ;; Dump buffer local variables.
298 (when (string-match "\\*tramp/" (buffer-name b
)) b
))
300 (let ((reporter-eval-buffer buffer
)
301 (buffer-name (buffer-name buffer
))
302 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
303 (with-current-buffer elbuf
308 (tramp-compat-funcall
309 'reporter-dump-variable
'buffer-name
(current-buffer))
310 (dolist (varsym-or-cons-cell (buffer-local-variables buffer
))
311 (let ((varsym (or (car-safe varsym-or-cons-cell
)
312 varsym-or-cons-cell
)))
313 (when (string-match "tramp" (symbol-name varsym
))
314 (tramp-compat-funcall
315 'reporter-dump-variable varsym
(current-buffer)))))
318 (insert-buffer-substring elbuf
)))
320 ;; Append buffers only when we are in message mode.
322 (eq major-mode
'message-mode
)
324 (symbol-value 'mml-mode
))
326 (let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
327 (buffer-list (tramp-compat-funcall 'tramp-list-tramp-buffers
))
328 (curbuf (current-buffer)))
330 ;; There is at least one Tramp buffer.
332 (switch-to-buffer (list-buffers-noselect nil
))
333 (delete-other-windows)
334 (setq buffer-read-only nil
)
335 (goto-char (point-min))
337 (if (re-search-forward
338 tramp-buf-regexp
(tramp-compat-line-end-position) t
)
341 (let ((start (point)))
343 (kill-region start
(point)))))
345 The buffer(s) above will be appended to this message. If you
346 don't want to append a buffer because it contains sensitive data,
347 or because the buffer is too large, you should delete the
348 respective buffer. The buffer(s) will contain user and host
349 names. Passwords will never be included there.")
351 (when (>= tramp-verbose
6)
353 (let ((start (point)))
355 Please note that you have set `tramp-verbose' to a value of at
356 least 6. Therefore, the contents of files might be included in
357 the debug buffer(s).")
358 (add-text-properties start
(point) (list 'face
'italic
))))
360 (set-buffer-modified-p nil
)
361 (setq buffer-read-only t
)
362 (goto-char (point-min))
364 (if (y-or-n-p "Do you want to append the buffer(s)? ")
365 ;; OK, let's send. First we delete the buffer list.
368 (switch-to-buffer curbuf
)
369 (goto-char (point-max))
371 This is a special notion of the `gnus/message' package. If you
372 use another mail agent (by copying the contents of this buffer)
373 please ensure that the buffers are attached to your email.\n\n")
374 (dolist (buffer buffer-list
)
375 (tramp-compat-funcall
376 'mml-insert-empty-tag
'part
'type
"text/plain"
377 'encoding
"base64" 'disposition
"attachment" 'buffer buffer
378 'description buffer
))
379 (set-buffer-modified-p nil
))
381 ;; Don't send. Delete the message buffer.
383 (set-buffer-modified-p nil
)
385 (throw 'dont-send nil
))))))
387 (defalias 'tramp-submit-bug
'tramp-bug
)
389 (provide 'tramp-cmds
)
393 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
394 ;; * WIBNI there was an interactive command prompting for Tramp
395 ;; method, hostname, username and filename and translates the user
396 ;; input into the correct filename syntax (depending on the Emacs
397 ;; flavor) (Reiner Steib)
398 ;; * Let the user edit the connection properties interactively.
399 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
400 ;; * It's just that when I come to Customize `tramp-default-user-alist'
401 ;; I'm presented with a mismatch and raw lisp for a value. It is my
402 ;; understanding that a variable declared with defcustom is a User
403 ;; Option and should not be modified by the code. add-to-list is
404 ;; called in several places. One way to handle that is to have a new
405 ;; ordinary variable that gets its initial value from
406 ;; tramp-default-user-alist and then is added to. (Pete Forman)
408 ;; arch-tag: 190d4c33-76bb-4e99-8b6f-71741f23d98c
409 ;;; tramp-cmds.el ends here