1 ;;; tramp-cmds.el --- Interactive commands for Tramp
3 ;; Copyright (C) 2007-2016 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 related
33 ;; Pacify byte-compiler.
34 (declare-function mml-mode
"mml")
35 (declare-function mml-insert-empty-tag
"mml")
36 (declare-function reporter-dump-variable
"reporter")
37 (defvar reporter-eval-buffer
)
38 (defvar reporter-prompt-for-summary-p
)
40 (defun tramp-list-tramp-buffers ()
41 "Return a list of all Tramp connection buffers."
44 "*tramp" (mapcar 'list
(mapcar 'buffer-name
(buffer-list))))
46 "*debug tramp" (mapcar 'list
(mapcar 'buffer-name
(buffer-list))))))
48 (defun tramp-list-remote-buffers ()
49 "Return a list of all buffers with remote default-directory."
54 (with-current-buffer x
(when (tramp-tramp-file-p default-directory
) x
)))
58 (defun tramp-cleanup-connection (vec &optional keep-debug keep-password
)
59 "Flush all connection related objects.
60 This includes password cache, file cache, connection cache,
61 buffers. KEEP-DEBUG non-nil preserves the debug buffer.
62 KEEP-PASSWORD non-nil preserves the password cache.
63 When called interactively, a Tramp connection has to be selected."
65 ;; When interactive, select the Tramp remote identification.
66 ;; Return nil when there is no Tramp connection.
71 (tramp-make-tramp-file-name
72 (tramp-file-name-method x
)
73 (tramp-file-name-user x
)
74 (tramp-file-name-host x
)
75 (tramp-file-name-localname x
)))
76 (tramp-list-connections)))
82 "Enter Tramp connection: " connections nil t
83 (try-completion "" connections
)))
84 (and (tramp-tramp-file-p name
) (tramp-dissect-file-name name
))))
89 (message "No Tramp connection found.")
91 ;; Flush password cache.
92 (unless keep-password
(tramp-clear-passwd vec
))
94 ;; Cleanup `tramp-current-connection'. Otherwise, we would be
95 ;; suppressed in the test suite. We use `keep-password' as
96 ;; indicator; it is not worth to add a new argument.
97 (when keep-password
(setq tramp-current-connection nil
))
100 (tramp-flush-directory-property vec
"")
102 ;; Flush connection cache.
103 (when (processp (tramp-get-connection-process vec
))
104 (delete-process (tramp-get-connection-process vec
))
105 (tramp-flush-connection-property (tramp-get-connection-process vec
)))
106 (tramp-flush-connection-property vec
)
110 (buf (list (get-buffer (tramp-buffer-name vec
))
112 (get-buffer (tramp-debug-buffer-name vec
)))
113 (tramp-get-connection-property vec
"process-buffer" nil
)))
114 (when (bufferp buf
) (kill-buffer buf
)))))
117 (defun tramp-cleanup-this-connection ()
118 "Flush all connection related objects of the current buffer's connection."
120 (and (tramp-tramp-file-p default-directory
)
121 (tramp-cleanup-connection
122 (tramp-dissect-file-name default-directory
'noexpand
))))
125 (defun tramp-cleanup-all-connections ()
126 "Flush all Tramp internal objects.
127 This includes password cache, file cache, connection cache, buffers."
131 (setq tramp-locked nil
)
133 ;; Flush password cache.
136 ;; Flush file and connection cache.
137 (clrhash tramp-cache-data
)
140 (dolist (name (tramp-list-tramp-buffers))
141 (when (bufferp (get-buffer name
)) (kill-buffer name
))))
144 (defun tramp-cleanup-all-buffers ()
145 "Kill all remote buffers."
148 ;; Remove all Tramp related connections.
149 (tramp-cleanup-all-connections)
151 ;; Remove all buffers with a remote default-directory.
152 (dolist (name (tramp-list-remote-buffers))
153 (when (bufferp (get-buffer name
)) (kill-buffer name
))))
155 ;; Tramp version is useful in a number of situations.
158 (defun tramp-version (arg)
159 "Print version number of tramp.el in minibuffer or current buffer."
161 (if arg
(insert tramp-version
) (message tramp-version
)))
163 ;; Make the "reporter" functionality available for making bug reports about
164 ;; the package. A most useful piece of code.
166 (autoload 'reporter-submit-bug-report
"reporter")
170 "Submit a bug report to the Tramp developers."
173 (let ((reporter-prompt-for-summary-p t
))
174 (reporter-submit-bug-report
175 tramp-bug-report-address
; to-address
176 (format "tramp (%s)" tramp-version
) ; package name and version
180 (and x
(boundp x
) (cons x
'tramp-reporter-dump-variable
)))
182 (mapcar 'intern
(all-completions "tramp-" obarray
'boundp
))
183 ;; Non-tramp variables of interest.
184 '(shell-prompt-pattern
186 backup-by-copying-when-linked
187 backup-by-copying-when-mismatch
188 backup-by-copying-when-privileged-mismatch
189 backup-directory-alist
191 password-cache-expiry
192 remote-file-name-inhibit-cache
193 file-name-handler-alist
))))
194 (lambda (x y
) (string< (symbol-name (car x
)) (symbol-name (car y
)))))
196 'tramp-load-report-modules
; pre-hook
197 'tramp-append-tramp-buffers
; post-hook
200 Enter your bug report in this message, including as much detail
201 as you possibly can about the problem, what you did to cause it
202 and what the local and remote machines are.
204 If you can give a simple set of instructions to make this bug
205 happen reliably, please include those. Thank you for helping
208 Before reproducing the bug, you might apply
210 M-x tramp-cleanup-all-connections
212 This allows us to investigate from a clean environment. Another
213 useful thing to do is to put
215 (setq tramp-verbose 9)
217 in your init file and to repeat the bug. Then, include the
218 contents of the *tramp/foo* buffer and the *debug tramp/foo*
219 buffer in your bug report.
221 --bug report follows this line--
224 (defun tramp-reporter-dump-variable (varsym mailbuf
)
225 "Pretty-print the value of the variable in symbol VARSYM."
226 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer
))
227 (val (with-current-buffer reporter-eval-buffer
228 (symbol-value varsym
))))
230 (if (hash-table-p val
)
231 ;; Pretty print the cache.
232 (set varsym
(read (format "(%s)" (tramp-cache-print val
))))
233 ;; There are non-7bit characters to be masked.
234 (when (and (boundp 'mm-7bit-chars
)
237 (concat "[^" (symbol-value 'mm-7bit-chars
) "]") val
))
238 (with-current-buffer reporter-eval-buffer
242 "(decode-coding-string (base64-decode-string \"%s\") 'raw-text)"
243 (base64-encode-string (encode-coding-string val
'raw-text
)))))))
246 (reporter-dump-variable varsym mailbuf
)
248 (unless (hash-table-p val
)
249 ;; Remove string quotation.
252 (concat "\\(^.*\\)" "\"" ;; \1 "
253 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
254 "\\(\".*\\)" "\\\\" ;; \3 \
255 "\\(\")\\)" "\"$")) ;; \4 "
256 (replace-match "\\1\\2\\3\\4")
258 (insert " ;; Variable encoded due to non-printable characters.\n"))
261 ;; Reset VARSYM to old value.
262 (with-current-buffer reporter-eval-buffer
265 (defun tramp-load-report-modules ()
266 "Load needed modules for reporting."
270 (defun tramp-append-tramp-buffers ()
271 "Append Tramp buffers and buffer local variables into the bug report."
272 (goto-char (point-max))
274 ;; Dump buffer local variables.
275 (insert "\nlocal variables:\n================")
280 (when (string-match "\\*tramp/" (buffer-name b
)) b
))
282 (let ((reporter-eval-buffer buffer
)
283 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
284 (with-current-buffer elbuf
287 (insert (format "\n;; %s\n(setq-local\n" (buffer-name buffer
)))
295 (all-completions "tramp-" (buffer-local-variables buffer
)))
296 ;; Non-tramp variables of interest.
297 '(default-directory))
299 (reporter-dump-variable varsym elbuf
))
302 (insert-buffer-substring elbuf
)))
304 ;; Dump load-path shadows.
305 (insert "\nload-path shadows:\n==================\n")
308 (lambda (x) (when (string-match "tramp" x
) (insert x
"\n")))
309 (split-string (list-load-path-shadows t
) "\n")))
311 ;; Append buffers only when we are in message mode.
313 (eq major-mode
'message-mode
)
315 (symbol-value 'mml-mode
))
317 (let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
318 (buffer-list (tramp-list-tramp-buffers))
319 (curbuf (current-buffer)))
321 ;; There is at least one Tramp buffer.
323 (switch-to-buffer (list-buffers-noselect nil
))
324 (delete-other-windows)
325 (setq buffer-read-only nil
)
326 (goto-char (point-min))
328 (if (re-search-forward tramp-buf-regexp
(point-at-eol) t
)
331 (let ((start (point)))
333 (kill-region start
(point)))))
335 The buffer(s) above will be appended to this message. If you
336 don't want to append a buffer because it contains sensitive data,
337 or because the buffer is too large, you should delete the
338 respective buffer. The buffer(s) will contain user and host
339 names. Passwords will never be included there.")
341 (when (>= tramp-verbose
6)
343 (let ((start (point)))
345 Please note that you have set `tramp-verbose' to a value of at
346 least 6. Therefore, the contents of files might be included in
347 the debug buffer(s).")
348 (add-text-properties start
(point) (list 'face
'italic
))))
350 (set-buffer-modified-p nil
)
351 (setq buffer-read-only t
)
352 (goto-char (point-min))
354 (if (y-or-n-p "Do you want to append the buffer(s)? ")
355 ;; OK, let's send. First we delete the buffer list.
358 (switch-to-buffer curbuf
)
359 (goto-char (point-max))
360 (insert (propertize "\n" 'display
"\n\
361 This is a special notion of the `gnus/message' package. If you
362 use another mail agent (by copying the contents of this buffer)
363 please ensure that the buffers are attached to your email.\n\n"))
364 (dolist (buffer buffer-list
)
365 (mml-insert-empty-tag
366 'part
'type
"text/plain"
367 'encoding
"base64" 'disposition
"attachment" 'buffer buffer
368 'description buffer
))
369 (set-buffer-modified-p nil
))
371 ;; Don't send. Delete the message buffer.
373 (set-buffer-modified-p nil
)
375 (throw 'dont-send nil
))))))
377 (defalias 'tramp-submit-bug
'tramp-bug
)
379 (add-hook 'tramp-unload-hook
380 (lambda () (unload-feature 'tramp-cmds
'force
)))
382 (provide 'tramp-cmds
)
386 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
387 ;; * WIBNI there was an interactive command prompting for Tramp
388 ;; method, hostname, username and filename and translates the user
389 ;; input into the correct filename syntax (depending on the Emacs
390 ;; flavor) (Reiner Steib)
391 ;; * Let the user edit the connection properties interactively.
392 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
394 ;;; tramp-cmds.el ends here