From: Michael Albinus Date: Thu, 17 Dec 2009 13:18:03 +0000 (+0000) Subject: * files.el (file-expand-wildcards): In case of remote files, check X-Git-Tag: emacs-pretest-23.1.91~53 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1f3611c61a81326ae8a7af8ada880b3c64afdeee;p=emacs.git * 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) --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ed32bd2db82..f3cff6c8137 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,19 @@ +2009-12-17 Michael Albinus + + 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 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." ;; 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))) @@ -5392,6 +5395,9 @@ default directory. However, if FULL is non-nil, they are absolute." (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. 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 @@ (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. @@ -143,7 +144,35 @@ (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). 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." (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. @@ -8429,36 +8432,6 @@ Only works for Bourne-like shells." 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'