comparison lisp/net/tramp-cmds.el @ 85508:05c8e6a18913

* net/tramp.el (top): Put load of all tramp-* files into a dolist. Require tramp-cmds.el. (tramp-make-tramp-temp-file): We can get rid of DONT-CREATE. (tramp-handle-file-name-all-completions): Expand DIRECTORY. (tramp-do-copy-or-rename-file-directly): Make more rigid checks. (tramp-do-copy-or-rename-file-out-of-band) (tramp-maybe-open-connection): Use `make-temp-name'. This is possible, because we don't need to create the temporary file, but we need a prefix for ssh, which has its own temporary file handling. (tramp-handle-delete-directory): Add "-f" to rmdir. (tramp-handle-dired-recursive-delete-directory): Call "rm -rf". (tramp-handle-insert-file-contents): Don't raise a tramp-error but a signal, in order to give the callee a chance to suppress. (tramp-handle-write-region): Set owner also in case of short track. Don't use compatibility calls for `write-region' anymore. (tramp-clear-passwd): Add parameter VEC. Adapt all callees. (tramp-append-tramp-buffers): Apply `tramp-list-tramp-buffers'. * net/tramp-cmds.el: New file. * net/tramp-gw.el (tramp-gw-basic-authentication): Apply VEC to `tramp-clear-passwd'. * net/trampver.el: Update release number.
author Michael Albinus <michael.albinus@gmx.de>
date Sun, 21 Oct 2007 14:02:38 +0000
parents
children 1ee7c459e1db
comparison
equal deleted inserted replaced
85507:85ee0a16a86f 85508:05c8e6a18913
1 ;;; tramp-cmds.el --- Interactive commands for Tramp
2
3 ;; Copyright (C) 2007 Free Software Foundation, Inc.
4
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
7
8 ;; This file is part of GNU Emacs.
9
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, or (at your option)
13 ;; any later version.
14
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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, see
22 ;; <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; This package provides all interactive commands which are releated
27 ;; to Tramp.
28
29 ;;; Code:
30
31 (require 'tramp)
32
33 (defun tramp-list-tramp-buffers ()
34 "Return a list of all Tramp connection buffers."
35 (append
36 (all-completions
37 "*tramp" (mapcar 'list (mapcar 'buffer-name (buffer-list))))
38 (all-completions
39 "*debug tramp" (mapcar 'list (mapcar 'buffer-name (buffer-list))))))
40
41 (defun tramp-list-remote-buffers ()
42 "Return a list of all buffers with remote default-directory."
43 (delq
44 nil
45 (mapcar
46 (lambda (x)
47 (with-current-buffer x
48 (when (and (stringp default-directory)
49 (file-remote-p default-directory))
50 x)))
51 (buffer-list))))
52
53 (defun tramp-cleanup-connection (vec)
54 "Flush all connection related objects.
55 This includes password cache, file cache, connection cache, buffers.
56 When called interactively, a Tramp connection has to be selected."
57 (interactive
58 ;; When interactive, select the Tramp remote identification.
59 ;; Return nil when there is no Tramp connection.
60 (list
61 (let ((connections
62 (mapcar
63 (lambda (x)
64 (with-current-buffer x (list (file-remote-p default-directory))))
65 ;; We shall not count debug buffers, because their
66 ;; default-directory is random. It could be even a remote
67 ;; one from another connection.
68 (all-completions
69 "*tramp" (mapcar 'list (tramp-list-tramp-buffers)))))
70 name)
71
72 (when connections
73 (setq name
74 (completing-read
75 "Enter Tramp connection: " connections nil t
76 (try-completion "" connections)))
77 (when (and name (file-remote-p name))
78 (with-parsed-tramp-file-name name nil v))))))
79
80 (if (not vec)
81 ;; Nothing to do.
82 (message "No Tramp connection found.")
83
84 ;; Flush password cache.
85 (tramp-clear-passwd vec)
86
87 ;; Flush file cache.
88 (tramp-flush-directory-property vec "/")
89
90 ;; Flush connection cache.
91 (tramp-flush-connection-property (tramp-get-connection-process vec) nil)
92 (tramp-flush-connection-property vec nil)
93
94 ;; Remove buffers.
95 (dolist
96 (buf (list (get-buffer (tramp-buffer-name vec))
97 (get-buffer (tramp-debug-buffer-name vec))
98 (tramp-get-connection-property vec "process-buffer" nil)))
99 (when (bufferp buf) (kill-buffer buf)))))
100
101 (defun tramp-cleanup-all-connections ()
102 "Flush all Tramp internal objects.
103 This includes password cache, file cache, connection cache, buffers."
104 (interactive)
105
106 ;; Flush password cache.
107 (when (functionp 'password-reset)
108 (funcall (symbol-function 'password-reset)))
109
110 ;; Flush file and connection cache.
111 (clrhash tramp-cache-data)
112
113 ;; Remove buffers.
114 (dolist (name (tramp-list-tramp-buffers))
115 (when (bufferp (get-buffer name)) (kill-buffer name))))
116
117 (defun tramp-cleanup-all-buffers ()
118 "Kill all remote buffers."
119 (interactive)
120
121 ;; Remove all Tramp related buffers.
122 (tramp-cleanup-all-connections)
123
124 ;; Remove all buffers with a remote default-directory.
125 (dolist (name (tramp-list-remote-buffers))
126 (when (bufferp (get-buffer name)) (kill-buffer name))))
127
128 (provide 'tramp-cmds)
129
130 ;;; TODO:
131
132 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
133 ;; * WIBNI there was an interactive command prompting for tramp
134 ;; method, hostname, username and filename and translates the user
135 ;; input into the correct filename syntax (depending on the Emacs
136 ;; flavor) (Reiner Steib)
137 ;; * Let the user edit the connection properties interactively.
138 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
139 ;; * It's just that when I come to Customize `tramp-default-user-alist'
140 ;; I'm presented with a mismatch and raw lisp for a value. It is my
141 ;; understanding that a variable declared with defcustom is a User
142 ;; Option and should not be modified by the code. add-to-list is
143 ;; called in several places. One way to handle that is to have a new
144 ;; ordinary variable that gets its initial value from
145 ;; tramp-default-user-alist and then is added to. (Pete Forman)
146
147 ;;; tramp-cmds.el ends here