aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2009-12-17 13:18:03 +0000
committerMichael Albinus2009-12-17 13:18:03 +0000
commit1f3611c61a81326ae8a7af8ada880b3c64afdeee (patch)
treea9459bd1af71db96c23084071632c38789fcab3e
parent72707255d18e870e88bc15531bf4cb00bb597607 (diff)
downloademacs-1f3611c61a81326ae8a7af8ada880b3c64afdeee.tar.gz
emacs-1f3611c61a81326ae8a7af8ada880b3c64afdeee.zip
* files.el (file-expand-wildcards): In case of remote files, check
only local file name part for wildcards. Provide feature 'files and subfeature 'remote-wildcards. (Bug#5198) * net/tramp.el (tramp-handle-file-remote-p): Expand file name only if there is already an established connection. (tramp-advice-file-expand-wildcards): Remove it. * net/tramp-compat.el (top): Autoload `tramp-handle-file-remote-p'. (tramp-advice-file-expand-wildcards): Moved from tramp.el. Activate advice for older GNU Emacs versions. (Bug#5237)
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/files.el8
-rw-r--r--lisp/net/tramp-compat.el31
-rw-r--r--lisp/net/tramp.el53
4 files changed, 66 insertions, 42 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ed32bd2db82..f3cff6c8137 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12009-12-17 Michael Albinus <michael.albinus@gmx.de>
2
3 Make `file-expand-wildcards' work for remote files.
4
5 * files.el (file-expand-wildcards): In case of remote files, check
6 only local file name part for wildcards. Provide feature 'files
7 and subfeature 'remote-wildcards. (Bug#5198)
8
9 * net/tramp.el (tramp-handle-file-remote-p): Expand file name only
10 if there is already an established connection.
11 (tramp-advice-file-expand-wildcards): Remove it.
12
13 * net/tramp-compat.el (top): Autoload `tramp-handle-file-remote-p'.
14 (tramp-advice-file-expand-wildcards): Moved from tramp.el.
15 Activate advice for older GNU Emacs versions. (Bug#5237)
16
12009-12-17 Juanma Barranquero <lekktu@gmail.com> 172009-12-17 Juanma Barranquero <lekktu@gmail.com>
2 18
3 Some doc fixes (more needed). 19 Some doc fixes (more needed).
diff --git a/lisp/files.el b/lisp/files.el
index b848407b3ae..6cfc727686e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5365,7 +5365,10 @@ default directory. However, if FULL is non-nil, they are absolute."
5365 ;; A list of all dirs that DIRPART specifies. 5365 ;; A list of all dirs that DIRPART specifies.
5366 ;; This can be more than one dir 5366 ;; This can be more than one dir
5367 ;; if DIRPART contains wildcards. 5367 ;; if DIRPART contains wildcards.
5368 (dirs (if (and dirpart (string-match "[[*?]" dirpart)) 5368 (dirs (if (and dirpart
5369 (string-match "[[*?]"
5370 (or (file-remote-p dirpart 'localname)
5371 dirpart)))
5369 (mapcar 'file-name-as-directory 5372 (mapcar 'file-name-as-directory
5370 (file-expand-wildcards (directory-file-name dirpart))) 5373 (file-expand-wildcards (directory-file-name dirpart)))
5371 (list dirpart))) 5374 (list dirpart)))
@@ -5392,6 +5395,9 @@ default directory. However, if FULL is non-nil, they are absolute."
5392 (setq dirs (cdr dirs))) 5395 (setq dirs (cdr dirs)))
5393 contents))) 5396 contents)))
5394 5397
5398;; Let Tramp know that `file-expand-wildcards' does not need an advice.
5399(provide 'files '(remote-wildcards))
5400
5395(defun list-directory (dirname &optional verbose) 5401(defun list-directory (dirname &optional verbose)
5396 "Display a list of files in or matching DIRNAME, a la `ls'. 5402 "Display a list of files in or matching DIRNAME, a la `ls'.
5397DIRNAME is globbed by the shell if necessary. 5403DIRNAME is globbed by the shell if necessary.
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 266a3de0c70..9c5e73c724e 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -44,6 +44,7 @@
44 44
45 (autoload 'tramp-tramp-file-p "tramp") 45 (autoload 'tramp-tramp-file-p "tramp")
46 (autoload 'tramp-file-name-handler "tramp") 46 (autoload 'tramp-file-name-handler "tramp")
47 (autoload 'tramp-handle-file-remote-p "tramp")
47 48
48 ;; tramp-util offers integration into other (X)Emacs packages like 49 ;; tramp-util offers integration into other (X)Emacs packages like
49 ;; compile.el, gud.el etc. Not necessary in Emacs 23. 50 ;; compile.el, gud.el etc. Not necessary in Emacs 23.
@@ -143,7 +144,35 @@
143 (lambda (filename &optional time) 144 (lambda (filename &optional time)
144 (when (tramp-tramp-file-p filename) 145 (when (tramp-tramp-file-p filename)
145 (tramp-file-name-handler 146 (tramp-file-name-handler
146 'set-file-times filename time)))))) 147 'set-file-times filename time)))))
148
149 ;; We currently use "[" and "]" in the filename format for IPv6
150 ;; hosts of GNU Emacs. This means, that Emacs wants to expand
151 ;; wildcards if `find-file-wildcards' is non-nil, and then barfs
152 ;; because no expansion could be found. We detect this situation
153 ;; and do something really awful: we have `file-expand-wildcards'
154 ;; return the original filename if it can't expand anything. Let's
155 ;; just hope that this doesn't break anything else.
156 ;; It is not needed anymore since GNU Emacs 23.2.
157 (unless (or (featurep 'xemacs) (featurep 'files 'remote-wildcards))
158 (defadvice file-expand-wildcards
159 (around tramp-advice-file-expand-wildcards activate)
160 (let ((name (ad-get-arg 0)))
161 ;; If it's a Tramp file, look if wildcards need to be expanded
162 ;; at all.
163 (if (and
164 (tramp-tramp-file-p name)
165 (not (string-match
166 "[[*?]" (tramp-handle-file-remote-p name 'localname))))
167 (setq ad-return-value (list name))
168 ;; Otherwise, just run the original function.
169 ad-do-it)))
170 (add-hook
171 'tramp-unload-hook
172 (lambda ()
173 (ad-remove-advice
174 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
175 (ad-activate 'file-expand-wildcards)))))
147 176
148(defsubst tramp-compat-line-beginning-position () 177(defsubst tramp-compat-line-beginning-position ()
149 "Return point at beginning of line (compat function). 178 "Return point at beginning of line (compat function).
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 6d3465c6a19..8a5d1f8c413 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4647,16 +4647,19 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
4647(defun tramp-handle-file-remote-p (filename &optional identification connected) 4647(defun tramp-handle-file-remote-p (filename &optional identification connected)
4648 "Like `file-remote-p' for Tramp files." 4648 "Like `file-remote-p' for Tramp files."
4649 (when (tramp-tramp-file-p filename) 4649 (when (tramp-tramp-file-p filename)
4650 (with-parsed-tramp-file-name (expand-file-name filename) nil 4650 (let* ((v (tramp-dissect-file-name filename))
4651 (and (or (not connected) 4651 (p (tramp-get-connection-process v))
4652 (let ((p (tramp-get-connection-process v))) 4652 (c (and p (processp p) (memq (process-status p) '(run open)))))
4653 (and p (processp p) (memq (process-status p) '(run open))))) 4653 ;; We expand the file name only, if there is already a connection.
4654 (cond 4654 (with-parsed-tramp-file-name
4655 ((eq identification 'method) method) 4655 (if c (expand-file-name filename) filename) nil
4656 ((eq identification 'user) user) 4656 (and (or (not connected) c)
4657 ((eq identification 'host) host) 4657 (cond
4658 ((eq identification 'localname) localname) 4658 ((eq identification 'method) method)
4659 (t (tramp-make-tramp-file-name method user host ""))))))) 4659 ((eq identification 'user) user)
4660 ((eq identification 'host) host)
4661 ((eq identification 'localname) localname)
4662 (t (tramp-make-tramp-file-name method user host ""))))))))
4660 4663
4661(defun tramp-find-file-name-coding-system-alist (filename tmpname) 4664(defun tramp-find-file-name-coding-system-alist (filename tmpname)
4662 "Like `find-operation-coding-system' for Tramp filenames. 4665 "Like `find-operation-coding-system' for Tramp filenames.
@@ -8429,36 +8432,6 @@ Only works for Bourne-like shells."
8429 t t result))) 8432 t t result)))
8430 result)))) 8433 result))))
8431 8434
8432;; We currently (sometimes) use "[" and "]" in the filename format.
8433;; This means that Emacs wants to expand wildcards if
8434;; `find-file-wildcards' is non-nil, and then barfs because no
8435;; expansion could be found. We detect this situation and do
8436;; something really awful: we have `file-expand-wildcards' return the
8437;; original filename if it can't expand anything. Let's just hope
8438;; that this doesn't break anything else.
8439;; CCC: This check is now also really awful; we should search all
8440;; of the filename format, not just the prefix.
8441(when (string-match "\\[" tramp-prefix-format)
8442 (defadvice file-expand-wildcards
8443 (around tramp-advice-file-expand-wildcards activate)
8444 (let ((name (ad-get-arg 0)))
8445 ;; If it's a Tramp file, dissect it and look if wildcards need
8446 ;; to be expanded at all.
8447 (if (and
8448 (tramp-tramp-file-p name)
8449 (not (string-match
8450 "[[*?]"
8451 (tramp-file-name-localname (tramp-dissect-file-name name)))))
8452 (setq ad-return-value (list name))
8453 ;; Otherwise, just run the original function.
8454 ad-do-it)))
8455 (add-hook
8456 'tramp-unload-hook
8457 (lambda ()
8458 (ad-remove-advice
8459 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
8460 (ad-activate 'file-expand-wildcards))))
8461
8462;; Checklist for `tramp-unload-hook' 8435;; Checklist for `tramp-unload-hook'
8463;; - Unload all `tramp-*' packages 8436;; - Unload all `tramp-*' packages
8464;; - Reset `file-name-handler-alist' 8437;; - Reset `file-name-handler-alist'