# HG changeset patch # User Michael Albinus # Date 1146489735 0 # Node ID 77201b466c80e6601c187f13221dfb9449211e22 # Parent 48f9beb0cfdc521120e5dafacba60630d307f584 * net/tramp.el (tramp-completion-file-name-handler-alist) (tramp-run-real-handler, tramp-completion-run-real-handler) (tramp-completion-handle-file-name-all-completions) (tramp-completion-handle-file-name-completion): Autoload them. (tramp-completion-handle-file-exists-p) (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-nondirectory) (tramp-completion-handle-expand-file-name): Remove them. (tramp-handle-file-name-directory): Return the real directory name. Returning "/" only doesn't need to be necessary any longer. (tramp-file-name-handler): Make special attention when in hostname completion mode. (tramp-completion-file-name-handler): Revert patch from 2006-04-28. (tramp-register-file-name-handlers): Register `tramp-completion-file-name-handler' only when `partial-completion-mode? is enabled. (tramp-completion-handle-file-name-all-completions): Delete directory part from results. (tramp-get-completion-methods, tramp-get-completion-user-host): Discard deleting "/", it doesn't work after the change of `tramp-handle-file-name-directory' above. diff -r 48f9beb0cfdc -r 77201b466c80 lisp/ChangeLog --- a/lisp/ChangeLog Mon May 01 13:09:24 2006 +0000 +++ b/lisp/ChangeLog Mon May 01 13:22:15 2006 +0000 @@ -1,3 +1,28 @@ +2006-05-01 Michael Albinus + + * net/tramp.el (tramp-completion-file-name-handler-alist) + (tramp-run-real-handler, tramp-completion-run-real-handler) + (tramp-completion-handle-file-name-all-completions) + (tramp-completion-handle-file-name-completion): Autoload them. + (tramp-completion-handle-file-exists-p) + (tramp-completion-handle-file-name-directory) + (tramp-completion-handle-file-name-nondirectory) + (tramp-completion-handle-expand-file-name): Remove them. + (tramp-handle-file-name-directory): Return the real directory + name. Returning "/" only doesn't need to be necessary any longer. + (tramp-file-name-handler): Make special attention when in hostname + completion mode. + (tramp-completion-file-name-handler): Revert patch from + 2006-04-28. + (tramp-register-file-name-handlers): Register + `tramp-completion-file-name-handler' only when + `partial-completion-mode´ is enabled. + (tramp-completion-handle-file-name-all-completions): Delete + directory part from results. + (tramp-get-completion-methods, tramp-get-completion-user-host): + Discard deleting "/", it doesn't work after the change of + `tramp-handle-file-name-directory' above. + 2006-05-01 Kim F. Storm * progmodes/grep.el (grep-expand-template): Use save-match-data. diff -r 48f9beb0cfdc -r 77201b466c80 lisp/net/tramp.el --- a/lisp/net/tramp.el Mon May 01 13:09:24 2006 +0000 +++ b/lisp/net/tramp.el Mon May 01 13:22:15 2006 +0000 @@ -1821,8 +1821,6 @@ Escape sequence %s is replaced with name of Perl binary. This string is passed to `format', so percent characters need to be doubled.") -; These values conform to `file-attributes' from XEmacs 21.2. -; Emacs and other tools not checked. (defconst tramp-file-mode-type-map '((0 . "-") ; Normal file (SVID-v2 and XPG2) (1 . "p") ; fifo (2 . "c") ; character device @@ -1927,12 +1925,11 @@ "Alist of handler functions. Operations not mentioned here will be handled by the normal Emacs functions.") - ;; Handlers for partial tramp file names. For Emacs just ;; `file-name-all-completions' is needed. +;;;###autoload (defconst tramp-completion-file-name-handler-alist - '( - (file-name-all-completions . tramp-completion-handle-file-name-all-completions) + '((file-name-all-completions . tramp-completion-handle-file-name-all-completions) (file-name-completion . tramp-completion-handle-file-name-completion)) "Alist of completion handler functions. Used for file names matching `tramp-file-name-regexp'. Operations not @@ -2168,28 +2165,11 @@ ;; Localname manipulation functions that grok TRAMP localnames... (defun tramp-handle-file-name-directory (file) "Like `file-name-directory' but aware of TRAMP files." - ;; everything except the last filename thing is the directory + ;; Everything except the last filename thing is the directory. (with-parsed-tramp-file-name file nil - ;; For the following condition, two possibilities should be tried: - ;; (1) (string= localname "") - ;; (2) (or (string= localname "") (string= localname "/")) - ;; The second variant fails when completing a "/" directory on - ;; the remote host, that is a filename which looks like - ;; "/user@host:/". But maybe wildcards fail with the first variant. - ;; We should do some investigation. - (if (string= localname "") - ;; For a filename like "/[foo]", we return "/". The `else' - ;; case would return "/[foo]" unchanged. But if we do that, - ;; then `file-expand-wildcards' ceases to work. It's not - ;; quite clear to me what's the intuition that tells that this - ;; behavior is the right behavior, but oh, well. - "/" - ;; run the command on the localname portion only - ;; CCC: This should take into account the remote machine type, no? - ;; --daniel - (tramp-make-tramp-file-name multi-method method user host - ;; This will not recurse... - (or (file-name-directory localname) ""))))) + ;; Run the command on the localname portion only. + (tramp-make-tramp-file-name + multi-method method user host (file-name-directory (or localname ""))))) (defun tramp-handle-file-name-nondirectory (file) "Like `file-name-nondirectory' but aware of TRAMP files." @@ -4140,7 +4120,8 @@ ;; (inhibit-file-name-operation operation)) ;; (apply operation args))) -(defun tramp-run-real-handler (operation args) +;;;###autoload +(progn (defun tramp-run-real-handler (operation args) "Invoke normal file name handler for OPERATION. First arg specifies the OPERATION, second arg is a list of arguments to pass to the OPERATION." @@ -4153,13 +4134,14 @@ ,(and (eq inhibit-file-name-operation operation) inhibit-file-name-handlers))) (inhibit-file-name-operation operation)) - (apply operation args))) + (apply operation args)))) ;; This function is used from `tramp-completion-file-name-handler' functions ;; only, if `tramp-completion-mode' is true. But this cannot be checked here ;; because the check is based on a full filename, not available for all ;; basic I/O operations. -(defun tramp-completion-run-real-handler (operation args) +;;;###autoload +(progn (defun tramp-completion-run-real-handler (operation args) "Invoke `tramp-file-name-handler' for OPERATION. First arg specifies the OPERATION, second arg is a list of arguments to pass to the OPERATION." @@ -4171,7 +4153,7 @@ ,(and (eq inhibit-file-name-operation operation) inhibit-file-name-handlers))) (inhibit-file-name-operation operation)) - (apply operation args))) + (apply operation args)))) ;; We handle here all file primitives. Most of them have the file ;; name as first parameter; nevertheless we check for them explicitly @@ -4268,12 +4250,25 @@ (defun tramp-file-name-handler (operation &rest args) "Invoke Tramp file name handler. Falls back to normal file name handler if no tramp file name handler exists." +;; (setq edebug-trace t) +;; (edebug-trace "%s" (with-output-to-string (backtrace))) (save-match-data (let* ((filename (apply 'tramp-file-name-for-operation operation args)) + (completion (tramp-completion-mode filename)) (foreign (tramp-find-foreign-file-name-handler filename))) - (cond - (foreign (apply foreign operation args)) - (t (tramp-run-real-handler operation args)))))) + (with-parsed-tramp-file-name filename nil + (cond + ;; When we are in completion mode, some operations shouldn' be + ;; handled by backend. + ((and completion (memq operation '(expand-file-name))) + (tramp-run-real-handler operation args)) + ((and completion (zerop (length localname)) + (memq operation '(file-exists-p file-directory-p))) + t) + ;; Call the backend function. + (foreign (apply foreign operation args)) + ;; Nothing to do for us. + (t (tramp-run-real-handler operation args))))))) ;; In Emacs, there is some concurrency due to timers. If a timer @@ -4320,52 +4315,37 @@ (tramp-run-real-handler operation args)))))) (setq tramp-locked tl)))) -;; Preload this DEFUN with the progn trick. This avoids cyclic -;; loading, because the `load-in-progress' check can be performed. ;;;###autoload (progn (defun tramp-completion-file-name-handler (operation &rest args) "Invoke tramp file name completion handler. Falls back to normal file name handler if no tramp file name handler exists." -;; (setq tramp-debug-buffer t) -;; (tramp-message 1 "%s %s" operation args) -;; (tramp-message 1 "%s %s\n%s" -;; operation args (with-output-to-string (backtrace))) - (if load-in-progress - ;; We are while loading Tramp. - (let (file-name-handler-alist) - (apply operation args)) - ;; If Tramp is not loaded yet, do it now. - (require 'tramp) - (let ((fn (assoc operation tramp-completion-file-name-handler-alist))) - (if fn - (save-match-data (apply (cdr fn) args)) - (tramp-completion-run-real-handler operation args)))))) - -;; Register in `file-name-handler-alist'. -;; `tramp-completion-file-name-handler' must not be active when temacs -;; dumps. And it makes no sense in batch mode anyway. This must be -;; an autoloaded DEFSUBST, because Tramp would be loaded otherwise -;; applying the `after-init-hook'. +;; (setq edebug-trace t) +;; (edebug-trace "%s" (with-output-to-string (backtrace))) + (let ((fn (assoc operation tramp-completion-file-name-handler-alist))) + (if fn + (save-match-data (apply (cdr fn) args)) + (tramp-completion-run-real-handler operation args))))) + ;;;###autoload (defsubst tramp-register-file-name-handlers () "Add tramp file name handlers to `file-name-handler-alist'." - (unless noninteractive - (add-to-list 'file-name-handler-alist - (cons tramp-file-name-regexp 'tramp-file-name-handler)) + (add-to-list 'file-name-handler-alist + (cons tramp-file-name-regexp 'tramp-file-name-handler)) + (when partial-completion-mode (add-to-list 'file-name-handler-alist (cons tramp-completion-file-name-regexp 'tramp-completion-file-name-handler)) - (put 'tramp-completion-file-name-handler 'safe-magic t) - ;; If jka-compr is already loaded, move it to the front of - ;; `file-name-handler-alist'. - (let ((jka (rassoc 'jka-compr-handler file-name-handler-alist))) - (when jka - (setq file-name-handler-alist - (cons jka (delete jka file-name-handler-alist))))))) - -;; `tramp-register-file-name-handlers' cannot be autoloaded as-it-is, -;; because the `noninteractive' check would prevent functionality to -;; be dumped in temacs. + (put 'tramp-completion-file-name-handler 'safe-magic t)) + ;; If jka-compr is already loaded, move it to the front of + ;; `file-name-handler-alist'. + (let ((jka (rassoc 'jka-compr-handler file-name-handler-alist))) + (when jka + (setq file-name-handler-alist + (cons jka (delete jka file-name-handler-alist)))))) + +;; During autoload, it shall be checked whether +;; `partial-completion-mode' is active. Therefore registering will be +;; delayed. ;;;###autoload(add-hook ;;;###autoload 'after-init-hook ;;;###autoload '(lambda () (tramp-register-file-name-handlers))) @@ -4495,31 +4475,10 @@ last-input-event) ?\ )))))) t))) -(defun tramp-completion-handle-file-exists-p (filename) - "Like `file-exists-p' for tramp files." - (if (tramp-completion-mode filename) - (tramp-run-real-handler - 'file-exists-p (list filename)) - (tramp-completion-run-real-handler - 'file-exists-p (list filename)))) - -;; Localname manipulation in case of partial TRAMP file names. -(defun tramp-completion-handle-file-name-directory (file) - "Like `file-name-directory' but aware of TRAMP files." - (if (tramp-completion-mode file) - "/" - (tramp-completion-run-real-handler - 'file-name-directory (list file)))) - -;; Localname manipulation in case of partial TRAMP file names. -(defun tramp-completion-handle-file-name-nondirectory (file) - "Like `file-name-nondirectory' but aware of TRAMP files." - (substring - file (length (tramp-completion-handle-file-name-directory file)))) - ;; Method, host name and user name completion. ;; `tramp-completion-dissect-file-name' returns a list of ;; tramp-file-name structures. For all of them we return possible completions. +;;;###autoload (defun tramp-completion-handle-file-name-all-completions (filename directory) "Like `file-name-all-completions' for partial tramp files." @@ -4574,7 +4533,8 @@ ;; unify list, remove nil elements (while result (let ((car (car result))) - (when car (add-to-list 'result1 car)) + (when car (add-to-list + 'result1 (substring car (length directory)))) (setq result (cdr result)))) ;; Complete local parts @@ -4593,6 +4553,7 @@ (setq tramp-completion-mode nil))) ;; Method, host name and user name completion for a file. +;;;###autoload (defun tramp-completion-handle-file-name-completion (filename directory) "Like `file-name-completion' for tramp files." (try-completion filename @@ -4719,8 +4680,7 @@ (lambda (method) (and method (string-match (concat "^" (regexp-quote partial-method)) method) - ;; we must remove leading "/". - (substring (tramp-make-tramp-file-name nil method nil nil nil) 1))) + (tramp-make-tramp-file-name nil method nil nil nil))) (delete "multi" (mapcar 'car tramp-methods)))) ;; Compares partial user and host names with possible completions. @@ -4753,8 +4713,7 @@ host nil))) (unless (zerop (+ (length user) (length host))) - ;; we must remove leading "/". - (substring (tramp-make-tramp-file-name nil method user host nil) 1))) + (tramp-make-tramp-file-name nil method user host nil))) (defun tramp-parse-rhosts (filename) "Return a list of (user host) tuples allowed to access. @@ -4973,15 +4932,6 @@ (forward-line 1) result)) -(defun tramp-completion-handle-expand-file-name (name &optional dir) - "Like `expand-file-name' for tramp files." - (let ((fullname (concat (or dir default-directory) name))) - (if (tramp-completion-mode fullname) - (tramp-run-real-handler - 'expand-file-name (list name dir)) - (tramp-completion-run-real-handler - 'expand-file-name (list name dir))))) - ;;; Internal Functions: (defun tramp-maybe-send-perl-script (multi-method method user host script name)