+2009-12-17 Michael Albinus <michael.albinus@gmx.de>
+
+ Make `file-expand-wildcards' work for remote files.
+
+ * 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)
+
2009-12-17 Juanma Barranquero <lekktu@gmail.com>
Some doc fixes (more needed).
;; A list of all dirs that DIRPART specifies.
;; This can be more than one dir
;; if DIRPART contains wildcards.
- (dirs (if (and dirpart (string-match "[[*?]" dirpart))
+ (dirs (if (and dirpart
+ (string-match "[[*?]"
+ (or (file-remote-p dirpart 'localname)
+ dirpart)))
(mapcar 'file-name-as-directory
(file-expand-wildcards (directory-file-name dirpart)))
(list dirpart)))
(setq dirs (cdr dirs)))
contents)))
+;; Let Tramp know that `file-expand-wildcards' does not need an advice.
+(provide 'files '(remote-wildcards))
+
(defun list-directory (dirname &optional verbose)
"Display a list of files in or matching DIRNAME, a la `ls'.
DIRNAME is globbed by the shell if necessary.
(autoload 'tramp-tramp-file-p "tramp")
(autoload 'tramp-file-name-handler "tramp")
+ (autoload 'tramp-handle-file-remote-p "tramp")
;; tramp-util offers integration into other (X)Emacs packages like
;; compile.el, gud.el etc. Not necessary in Emacs 23.
(lambda (filename &optional time)
(when (tramp-tramp-file-p filename)
(tramp-file-name-handler
- 'set-file-times filename time))))))
+ 'set-file-times filename time)))))
+
+ ;; We currently use "[" and "]" in the filename format for IPv6
+ ;; hosts of GNU Emacs. This means, that Emacs wants to expand
+ ;; wildcards if `find-file-wildcards' is non-nil, and then barfs
+ ;; because no expansion could be found. We detect this situation
+ ;; and do something really awful: we have `file-expand-wildcards'
+ ;; return the original filename if it can't expand anything. Let's
+ ;; just hope that this doesn't break anything else.
+ ;; It is not needed anymore since GNU Emacs 23.2.
+ (unless (or (featurep 'xemacs) (featurep 'files 'remote-wildcards))
+ (defadvice file-expand-wildcards
+ (around tramp-advice-file-expand-wildcards activate)
+ (let ((name (ad-get-arg 0)))
+ ;; If it's a Tramp file, look if wildcards need to be expanded
+ ;; at all.
+ (if (and
+ (tramp-tramp-file-p name)
+ (not (string-match
+ "[[*?]" (tramp-handle-file-remote-p name 'localname))))
+ (setq ad-return-value (list name))
+ ;; Otherwise, just run the original function.
+ ad-do-it)))
+ (add-hook
+ 'tramp-unload-hook
+ (lambda ()
+ (ad-remove-advice
+ 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
+ (ad-activate 'file-expand-wildcards)))))
(defsubst tramp-compat-line-beginning-position ()
"Return point at beginning of line (compat function).
(defun tramp-handle-file-remote-p (filename &optional identification connected)
"Like `file-remote-p' for Tramp files."
(when (tramp-tramp-file-p filename)
- (with-parsed-tramp-file-name (expand-file-name filename) nil
- (and (or (not connected)
- (let ((p (tramp-get-connection-process v)))
- (and p (processp p) (memq (process-status p) '(run open)))))
- (cond
- ((eq identification 'method) method)
- ((eq identification 'user) user)
- ((eq identification 'host) host)
- ((eq identification 'localname) localname)
- (t (tramp-make-tramp-file-name method user host "")))))))
+ (let* ((v (tramp-dissect-file-name filename))
+ (p (tramp-get-connection-process v))
+ (c (and p (processp p) (memq (process-status p) '(run open)))))
+ ;; We expand the file name only, if there is already a connection.
+ (with-parsed-tramp-file-name
+ (if c (expand-file-name filename) filename) nil
+ (and (or (not connected) c)
+ (cond
+ ((eq identification 'method) method)
+ ((eq identification 'user) user)
+ ((eq identification 'host) host)
+ ((eq identification 'localname) localname)
+ (t (tramp-make-tramp-file-name method user host ""))))))))
(defun tramp-find-file-name-coding-system-alist (filename tmpname)
"Like `find-operation-coding-system' for Tramp filenames.
t t result)))
result))))
-;; We currently (sometimes) use "[" and "]" in the filename format.
-;; This means that Emacs wants to expand wildcards if
-;; `find-file-wildcards' is non-nil, and then barfs because no
-;; expansion could be found. We detect this situation and do
-;; something really awful: we have `file-expand-wildcards' return the
-;; original filename if it can't expand anything. Let's just hope
-;; that this doesn't break anything else.
-;; CCC: This check is now also really awful; we should search all
-;; of the filename format, not just the prefix.
-(when (string-match "\\[" tramp-prefix-format)
- (defadvice file-expand-wildcards
- (around tramp-advice-file-expand-wildcards activate)
- (let ((name (ad-get-arg 0)))
- ;; If it's a Tramp file, dissect it and look if wildcards need
- ;; to be expanded at all.
- (if (and
- (tramp-tramp-file-p name)
- (not (string-match
- "[[*?]"
- (tramp-file-name-localname (tramp-dissect-file-name name)))))
- (setq ad-return-value (list name))
- ;; Otherwise, just run the original function.
- ad-do-it)))
- (add-hook
- 'tramp-unload-hook
- (lambda ()
- (ad-remove-advice
- 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
- (ad-activate 'file-expand-wildcards))))
-
;; Checklist for `tramp-unload-hook'
;; - Unload all `tramp-*' packages
;; - Reset `file-name-handler-alist'