]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-cmds.el
Update copyright year to 2015
[gnu-emacs] / lisp / net / tramp-cmds.el
index e0d15eb85f6779137c96340b76da0861a27b0085..d45c0aad1426b2ba6032fb7753a2669d79ea34f5 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tramp-cmds.el --- Interactive commands for Tramp
 
-;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
 
 ;; Author: Michael Albinus <michael.albinus@gmx.de>
 ;; Keywords: comm, processes
 
 (require 'tramp)
 
+;; Pacify byte-compiler.
+(defvar reporter-eval-buffer)
+(defvar reporter-prompt-for-summary-p)
+
 (defun tramp-list-tramp-buffers ()
   "Return a list of all Tramp connection buffers."
   (append
    nil
    (mapcar
     (lambda (x)
-      (with-current-buffer x
-       (when (and (stringp default-directory)
-                  (file-remote-p default-directory))
-         x)))
+      (with-current-buffer x (when (tramp-tramp-file-p default-directory) x)))
     (buffer-list))))
 
 ;;;###tramp-autoload
-(defun tramp-cleanup-connection (vec)
+(defun tramp-cleanup-connection (vec &optional keep-debug keep-password)
   "Flush all connection related objects.
-This includes password cache, file cache, connection cache, buffers.
+This includes password cache, file cache, connection cache,
+buffers.  KEEP-DEBUG non-nil preserves the debug buffer.
+KEEP-PASSWORD non-nil preserves the password cache.
 When called interactively, a Tramp connection has to be selected."
   (interactive
    ;; When interactive, select the Tramp remote identification.
@@ -75,27 +78,35 @@ When called interactively, a Tramp connection has to be selected."
              (completing-read
               "Enter Tramp connection: " connections nil t
               (try-completion "" connections)))
-       (when (and name (file-remote-p name))
-         (with-parsed-tramp-file-name name nil v))))))
+       (and (tramp-tramp-file-p name) (tramp-dissect-file-name name))))
+    nil nil))
 
   (if (not vec)
       ;; Nothing to do.
       (message "No Tramp connection found.")
 
     ;; Flush password cache.
-    (tramp-clear-passwd vec)
+    (unless keep-password (tramp-clear-passwd vec))
+
+    ;; Cleanup `tramp-current-connection'.  Otherwise, we would be
+    ;; suppressed in the test suite.  We use `keep-password' as
+    ;; indicator; it is not worth to add a new argument.
+    (when keep-password (setq tramp-current-connection nil))
 
     ;; Flush file cache.
     (tramp-flush-directory-property vec "")
 
     ;; Flush connection cache.
-    (tramp-flush-connection-property (tramp-get-connection-process vec))
+    (when (processp (tramp-get-connection-process vec))
+      (delete-process (tramp-get-connection-process vec))
+      (tramp-flush-connection-property (tramp-get-connection-process vec)))
     (tramp-flush-connection-property vec)
 
     ;; Remove buffers.
     (dolist
        (buf (list (get-buffer (tramp-buffer-name vec))
-                  (get-buffer (tramp-debug-buffer-name vec))
+                  (unless keep-debug
+                    (get-buffer (tramp-debug-buffer-name vec)))
                   (tramp-get-connection-property vec "process-buffer" nil)))
       (when (bufferp buf) (kill-buffer buf)))))
 
@@ -103,8 +114,7 @@ When called interactively, a Tramp connection has to be selected."
 (defun tramp-cleanup-this-connection ()
   "Flush all connection related objects of the current buffer's connection."
   (interactive)
-  (and (stringp default-directory)
-       (file-remote-p default-directory)
+  (and (tramp-tramp-file-p default-directory)
        (tramp-cleanup-connection
        (tramp-dissect-file-name default-directory 'noexpand))))
 
@@ -184,7 +194,9 @@ This includes password cache, file cache, connection cache, buffers."
 
        'tramp-load-report-modules      ; pre-hook
        'tramp-append-tramp-buffers     ; post-hook
-       "\
+       (tramp-compat-funcall
+       (if (functionp 'propertize) 'propertize 'progn)
+       "\n" 'display "\
 Enter your bug report in this message, including as much detail
 as you possibly can about the problem, what you did to cause it
 and what the local and remote machines are.
@@ -202,12 +214,12 @@ useful thing to do is to put
 
   (setq tramp-verbose 9)
 
-in the ~/.emacs file and to repeat the bug.  Then, include the
+in your init file and to repeat the bug.  Then, include the
 contents of the *tramp/foo* buffer and the *debug tramp/foo*
 buffer in your bug report.
 
 --bug report follows this line--
-"))))
+")))))
 
 (defun tramp-reporter-dump-variable (varsym mailbuf)
   "Pretty-print the value of the variable in symbol VARSYM."
@@ -264,6 +276,7 @@ buffer in your bug report.
   (goto-char (point-max))
 
   ;; Dump buffer local variables.
+  (insert "\nlocal variables:\n================")
   (dolist (buffer
           (delq nil
                 (mapcar
@@ -271,21 +284,23 @@ buffer in your bug report.
                     (when (string-match "\\*tramp/" (buffer-name b)) b))
                  (buffer-list))))
     (let ((reporter-eval-buffer buffer)
-         (buffer-name (buffer-name buffer))
          (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
       (with-current-buffer elbuf
        (emacs-lisp-mode)
        (erase-buffer)
-       (insert "\n(setq\n")
+       (insert (format "\n;; %s\n(setq-local\n" (buffer-name buffer)))
        (lisp-indent-line)
-       (tramp-compat-funcall
-        'reporter-dump-variable 'buffer-name (current-buffer))
-       (dolist (varsym-or-cons-cell (buffer-local-variables buffer))
-         (let ((varsym (or (car-safe varsym-or-cons-cell)
-                           varsym-or-cons-cell)))
-           (when (string-match "tramp" (symbol-name varsym))
-             (tramp-compat-funcall
-              'reporter-dump-variable varsym (current-buffer)))))
+       (dolist
+           (varsym
+            (sort
+             (append
+              (mapcar
+               'intern
+               (all-completions "tramp-" (buffer-local-variables buffer)))
+              ;; Non-tramp variables of interest.
+              '(default-directory))
+             'string<))
+           (tramp-compat-funcall 'reporter-dump-variable varsym elbuf))
        (lisp-indent-line)
        (insert ")\n"))
       (insert-buffer-substring elbuf)))
@@ -293,8 +308,9 @@ buffer in your bug report.
   ;; Dump load-path shadows.
   (insert "\nload-path shadows:\n==================\n")
   (ignore-errors
-    (mapc (lambda (x) (when (string-match "tramp" x) (insert x "\n")))
-         (split-string (list-load-path-shadows t) "\n")))
+    (mapc
+     (lambda (x) (when (string-match "tramp" x) (insert x "\n")))
+     (split-string (tramp-compat-funcall 'list-load-path-shadows t) "\n")))
 
   ;; Append buffers only when we are in message mode.
   (when (and
@@ -345,10 +361,10 @@ the debug buffer(s).")
              (kill-buffer nil)
              (switch-to-buffer curbuf)
              (goto-char (point-max))
-             (insert "\n\
+             (insert (tramp-compat-funcall 'propertize "\n" 'display "\n\
 This is a special notion of the `gnus/message' package.  If you
 use another mail agent (by copying the contents of this buffer)
-please ensure that the buffers are attached to your email.\n\n")
+please ensure that the buffers are attached to your email.\n\n"))
              (dolist (buffer buffer-list)
                (tramp-compat-funcall
                 'mml-insert-empty-tag 'part 'type "text/plain"