diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2017-09-11 17:12:32 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2017-09-11 17:12:32 +0200 |
commit | 7004545244ea5efbe7a37db72431f982c70576e6 (patch) | |
tree | ce64bd36195091d72a4a2ef86eb80d624be4fcc5 /lisp/net | |
parent | 29963648dd11d53088f753e4f9b0491a7b981c0f (diff) | |
download | emacs-7004545244ea5efbe7a37db72431f982c70576e6.tar.gz |
Further optimization in Tramp's file name decomposition
* lisp/net/tramp.el (tramp-syntax): Recompute all file name
components. Call `custom-set-variables' after loading.
(tramp-build-prefix-format, tramp-build-prefix-regexp)
(tramp-build-method-regexp)
(tramp-build-postfix-method-format)
(tramp-build-postfix-method-regexp)
(tramp-build-prefix-ipv6-format)
(tramp-build-prefix-ipv6-regexp)
(tramp-build-postfix-ipv6-format)
(tramp-build-postfix-ipv6-regexp)
(tramp-build-postfix-host-format)
(tramp-build-postfix-host-regexp)
(tramp-build-file-name-regexp)
(tramp-build-completion-file-name-regexp): New defuns.
(tramp-prefix-format, tramp-prefix-regexp)
(tramp-method-regexp, tramp-postfix-method-format)
(tramp-postfix-method-regexp, tramp-prefix-ipv6-format)
(tramp-prefix-ipv6-regexp, tramp-postfix-ipv6-format)
(tramp-postfix-ipv6-regexp, tramp-postfix-host-format)
(tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp)
(tramp-file-name-structure, tramp-file-name-regexp)
(tramp-completion-file-name-regexp): Convert defuns into defvars.
(tramp-prefix-regexp-alist)
(tramp-postfix-method-regexp-alist)
(tramp-prefix-ipv6-regexp-alist)
(tramp-postfix-ipv6-regexp-alist)
(tramp-postfix-host-regexp-alist)
(tramp-remote-file-name-spec-regexp-alist): Remove.
(tramp-build-remote-file-name-spec-regexp)
(tramp-build-file-name-structure): Simplify.
(tramp-completion-file-name-regexp-alist): New defconst.
(tramp-tramp-file-p, tramp-dissect-file-name)
(tramp-make-tramp-file-name)
(tramp-completion-make-tramp-file-name)
(tramp-rfn-eshadow-update-overlay-regexp)
(tramp-register-file-name-handlers)
(tramp-completion-handle-file-name-all-completions)
(tramp-completion-dissect-file-name, tramp-clear-passwd):
* lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler):
* lisp/net/tramp-sh.el (tramp-sh-handle-vc-registered)
(tramp-compute-multi-hops): Use variables but functions for
file name components.
* test/lisp/net/tramp-tests.el (tramp-test24-file-name-completion):
Use variables but functions for file name components.
Diffstat (limited to 'lisp/net')
-rw-r--r-- | lisp/net/tramp-ftp.el | 8 | ||||
-rw-r--r-- | lisp/net/tramp-sh.el | 4 | ||||
-rw-r--r-- | lisp/net/tramp.el | 366 |
3 files changed, 184 insertions, 194 deletions
diff --git a/lisp/net/tramp-ftp.el b/lisp/net/tramp-ftp.el index 8e489eee801..85afd52bf42 100644 --- a/lisp/net/tramp-ftp.el +++ b/lisp/net/tramp-ftp.el @@ -121,10 +121,10 @@ pass to the OPERATION." (or (boundp 'ange-ftp-name-format) (let (file-name-handler-alist) (require 'ange-ftp))) (let ((ange-ftp-name-format - (list (nth 0 (tramp-file-name-structure)) - (nth 3 (tramp-file-name-structure)) - (nth 2 (tramp-file-name-structure)) - (nth 4 (tramp-file-name-structure)))) + (list (nth 0 tramp-file-name-structure) + (nth 3 tramp-file-name-structure) + (nth 2 tramp-file-name-structure) + (nth 4 tramp-file-name-structure))) ;; ange-ftp uses `ange-ftp-ftp-name-arg' and `ange-ftp-ftp-name-res' ;; for optimization in `ange-ftp-ftp-name'. If Tramp wasn't active, ;; there could be incorrect values from previous calls in case the diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 597ca6a6202..01fe335963b 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -3437,7 +3437,7 @@ the result will be a local, non-Tramp, file name." (let (tramp-vc-registered-file-names (remote-file-name-inhibit-cache (current-time)) (file-name-handler-alist - `((,(tramp-file-name-regexp) . tramp-vc-file-name-handler)))) + `((,tramp-file-name-regexp . tramp-vc-file-name-handler)))) ;; Here we collect only file names, which need an operation. (tramp-with-demoted-errors @@ -4468,7 +4468,7 @@ Goes through the list `tramp-inline-compress-commands'." (let ((user (tramp-file-name-user item)) (host (tramp-file-name-host item)) (proxy (concat - (tramp-prefix-format) proxy (tramp-postfix-host-format)))) + tramp-prefix-format proxy tramp-postfix-host-format))) (tramp-message vec 5 "Add proxy (\"%s\" \"%s\" \"%s\")" (and (stringp host) (regexp-quote host)) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 118960be5ed..14624593e0c 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -689,11 +689,34 @@ Do not change the value by `setq', it must be changed only by (tramp-cleanup-all-buffers)) ;; Set the value: (set-default symbol value) - ;; Reset `tramp-file-name-regexp'. - (setq tramp-file-name-regexp (tramp-file-name-regexp)) + ;; Reset the depending variables. + (with-no-warnings + (setq tramp-prefix-format (tramp-build-prefix-format) + tramp-prefix-regexp (tramp-build-prefix-regexp) + tramp-method-regexp (tramp-build-method-regexp) + tramp-postfix-method-format (tramp-build-postfix-method-format) + tramp-postfix-method-regexp (tramp-build-postfix-method-regexp) + tramp-prefix-ipv6-format (tramp-build-prefix-ipv6-format) + tramp-prefix-ipv6-regexp (tramp-build-prefix-ipv6-regexp) + tramp-postfix-ipv6-format (tramp-build-postfix-ipv6-format) + tramp-postfix-ipv6-regexp (tramp-build-postfix-ipv6-regexp) + tramp-postfix-host-format (tramp-build-postfix-host-format) + tramp-postfix-host-regexp (tramp-build-postfix-host-regexp) + tramp-remote-file-name-spec-regexp + (tramp-build-remote-file-name-spec-regexp) + tramp-file-name-structure (tramp-build-file-name-structure) + tramp-file-name-regexp (tramp-build-file-name-regexp) + tramp-completion-file-name-regexp + (tramp-build-completion-file-name-regexp))) ;; Rearrange file name handlers. (tramp-register-file-name-handlers))) +;; Initialize the Tramp syntax variables. We want to override initial +;; values of `tramp-file-name-regexp' and +;; `tramp-completion-file-name-regexp'. +(eval-after-load 'tramp + '(custom-set-variables `(tramp-syntax ',(tramp-compat-tramp-syntax)))) + (defun tramp-syntax-values () "Return possible values of `tramp-syntax', a list" (let ((values (cdr (get 'tramp-syntax 'custom-type)))) @@ -712,22 +735,19 @@ Raise an error if `tramp-syntax' is invalid." (separate . "/[")) "Alist mapping Tramp syntax to strings beginning Tramp file names.") -(defun tramp-prefix-format () - "String matching the very beginning of Tramp file names. -Used in `tramp-make-tramp-file-name'." +(defun tramp-build-prefix-format () (tramp-lookup-syntax tramp-prefix-format-alist)) -(defconst tramp-prefix-regexp-alist - (mapcar (lambda (x) - (cons (car x) (concat "^" (regexp-quote (cdr x))))) - tramp-prefix-format-alist) - "Alist of regexps matching the beginnings of Tramp file names. -Keyed by Tramp syntax. Derived from `tramp-prefix-format-alist'.") +(defvar tramp-prefix-format (tramp-build-prefix-format) + "String matching the very beginning of Tramp file names. +Used in `tramp-make-tramp-file-name'.") + +(defun tramp-build-prefix-regexp () + (concat "^" (regexp-quote tramp-prefix-format))) -(defun tramp-prefix-regexp () +(defvar tramp-prefix-regexp (tramp-build-prefix-regexp) "Regexp matching the very beginning of Tramp file names. -Should always start with \"^\". Derived from `tramp-prefix-format'." - (tramp-lookup-syntax tramp-prefix-regexp-alist)) +Should always start with \"^\". Derived from `tramp-prefix-format'.") (defconst tramp-method-regexp-alist '((default . "[a-zA-Z0-9-]+") @@ -735,34 +755,33 @@ Should always start with \"^\". Derived from `tramp-prefix-format'." (separate . "[a-zA-Z0-9-]*")) "Alist mapping Tramp syntax to regexps matching methods identifiers.") -(defun tramp-method-regexp () - "Regexp matching methods identifiers. -The `ftp' syntax does not support methods." +(defun tramp-build-method-regexp () (tramp-lookup-syntax tramp-method-regexp-alist)) +(defvar tramp-method-regexp (tramp-build-method-regexp) + "Regexp matching methods identifiers. +The `ftp' syntax does not support methods.") + (defconst tramp-postfix-method-format-alist '((default . ":") (simplified . "") (separate . "/")) "Alist mapping Tramp syntax to the delimiter after the method.") -(defun tramp-postfix-method-format () +(defun tramp-build-postfix-method-format () + (tramp-lookup-syntax tramp-postfix-method-format-alist)) + +(defvar tramp-postfix-method-format (tramp-build-postfix-method-format) "String matching delimiter between method and user or host names. The `ftp' syntax does not support methods. -Used in `tramp-make-tramp-file-name'." - (tramp-lookup-syntax tramp-postfix-method-format-alist)) +Used in `tramp-make-tramp-file-name'.") -(defconst tramp-postfix-method-regexp-alist - (mapcar (lambda (x) - (cons (car x) (regexp-quote (cdr x)))) - tramp-postfix-method-format-alist) - "Alist mapping Tramp syntax to regexp matching delimiter after method. -Derived from `tramp-postfix-method-format-alist'.") +(defun tramp-build-postfix-method-regexp () + (regexp-quote tramp-postfix-method-format)) -(defun tramp-postfix-method-regexp () +(defvar tramp-postfix-method-regexp (tramp-build-postfix-method-regexp) "Regexp matching delimiter between method and user or host names. -Derived from `tramp-postfix-method-format'." - (tramp-lookup-syntax tramp-postfix-method-regexp-alist)) +Derived from `tramp-postfix-method-format'.") (defconst tramp-user-regexp "[^/|: \t]+" "Regexp matching user names.") @@ -772,8 +791,7 @@ Derived from `tramp-postfix-method-format'." "String matching delimiter between user and domain names.") ;;;###tramp-autoload -(defconst tramp-prefix-domain-regexp - (regexp-quote tramp-prefix-domain-format) +(defconst tramp-prefix-domain-regexp (regexp-quote tramp-prefix-domain-format) "Regexp matching delimiter between user and domain names. Derived from `tramp-prefix-domain-format'.") @@ -790,8 +808,7 @@ Derived from `tramp-prefix-domain-format'.") "String matching delimiter between user and host names. Used in `tramp-make-tramp-file-name'.") -(defconst tramp-postfix-user-regexp - (regexp-quote tramp-postfix-user-format) +(defconst tramp-postfix-user-regexp (regexp-quote tramp-postfix-user-format) "Regexp matching delimiter between user and host names. Derived from `tramp-postfix-user-format'.") @@ -804,28 +821,24 @@ Derived from `tramp-postfix-user-format'.") (separate . "")) "Alist mapping Tramp syntax to strings prefixing IPv6 addresses.") -(defun tramp-prefix-ipv6-format () - "String matching left hand side of IPv6 addresses. -Used in `tramp-make-tramp-file-name'." +(defun tramp-build-prefix-ipv6-format () (tramp-lookup-syntax tramp-prefix-ipv6-format-alist)) -(defconst tramp-prefix-ipv6-regexp-alist - (mapcar (lambda (x) - (cons (car x) (regexp-quote (cdr x)))) - tramp-prefix-ipv6-format-alist) - "Alist mapping Tramp syntax to regexp matching prefix of IPv6 addresses. -Derived from `tramp-prefix-ipv6-format-alist'") +(defvar tramp-prefix-ipv6-format (tramp-build-prefix-ipv6-format) + "String matching left hand side of IPv6 addresses. +Used in `tramp-make-tramp-file-name'.") + +(defun tramp-build-prefix-ipv6-regexp () + (regexp-quote tramp-prefix-ipv6-format)) -(defun tramp-prefix-ipv6-regexp () +(defvar tramp-prefix-ipv6-regexp (tramp-build-prefix-ipv6-regexp) "Regexp matching left hand side of IPv6 addresses. -Derived from `tramp-prefix-ipv6-format'." - (tramp-lookup-syntax tramp-prefix-ipv6-regexp-alist)) +Derived from `tramp-prefix-ipv6-format'.") ;; The following regexp is a bit sloppy. But it shall serve our ;; purposes. It covers also IPv4 mapped IPv6 addresses, like in ;; "::ffff:192.168.0.1". -(defconst tramp-ipv6-regexp - "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9.]+" +(defconst tramp-ipv6-regexp "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9.]+" "Regexp matching IPv6 addresses.") (defconst tramp-postfix-ipv6-format-alist @@ -834,28 +847,24 @@ Derived from `tramp-prefix-ipv6-format'." (separate . "")) "Alist mapping Tramp syntax to suffix for IPv6 addresses.") -(defun tramp-postfix-ipv6-format () - "String matching right hand side of IPv6 addresses. -Used in `tramp-make-tramp-file-name'." +(defun tramp-build-postfix-ipv6-format () (tramp-lookup-syntax tramp-postfix-ipv6-format-alist)) -(defconst tramp-postfix-ipv6-regexp-alist - (mapcar (lambda (x) - (cons (car x) (regexp-quote (cdr x)))) - tramp-postfix-ipv6-format-alist) - "Alist mapping Tramp syntax to regexps matching IPv6 suffixes. -Derived from `tramp-postfix-ipv6-format-alist'.") +(defvar tramp-postfix-ipv6-format (tramp-build-postfix-ipv6-format) + "String matching right hand side of IPv6 addresses. +Used in `tramp-make-tramp-file-name'.") + +(defun tramp-build-postfix-ipv6-regexp () + (regexp-quote tramp-postfix-ipv6-format)) -(defun tramp-postfix-ipv6-regexp () +(defvar tramp-postfix-ipv6-regexp (tramp-build-postfix-ipv6-regexp) "Regexp matching right hand side of IPv6 addresses. -Derived from `tramp-postfix-ipv6-format'." - (tramp-lookup-syntax tramp-postfix-ipv6-format-alist)) +Derived from `tramp-postfix-ipv6-format'.") (defconst tramp-prefix-port-format "#" "String matching delimiter between host names and port numbers.") -(defconst tramp-prefix-port-regexp - (regexp-quote tramp-prefix-port-format) +(defconst tramp-prefix-port-regexp (regexp-quote tramp-prefix-port-format) "Regexp matching delimiter between host names and port numbers. Derived from `tramp-prefix-port-format'.") @@ -871,8 +880,7 @@ Derived from `tramp-prefix-port-format'.") (defconst tramp-postfix-hop-format "|" "String matching delimiter after ad-hoc hop definitions.") -(defconst tramp-postfix-hop-regexp - (regexp-quote tramp-postfix-hop-format) +(defconst tramp-postfix-hop-regexp (regexp-quote tramp-postfix-hop-format) "Regexp matching delimiter after ad-hoc hop definitions. Derived from `tramp-postfix-hop-format'.") @@ -882,22 +890,19 @@ Derived from `tramp-postfix-hop-format'.") (separate . "]")) "Alist mapping Tramp syntax to strings between host and local names.") -(defun tramp-postfix-host-format () - "String matching delimiter between host names and localnames. -Used in `tramp-make-tramp-file-name'." +(defun tramp-build-postfix-host-format () (tramp-lookup-syntax tramp-postfix-host-format-alist)) -(defconst tramp-postfix-host-regexp-alist - (mapcar (lambda (x) - (cons (car x) (regexp-quote (cdr x)))) - tramp-postfix-host-format-alist) - "Alist mapping Tramp syntax to regexp matching name delimiters. -Derived from `tramp-postfix-host-format-alist'.") +(defvar tramp-postfix-host-format (tramp-build-postfix-host-format) + "String matching delimiter between host names and localnames. +Used in `tramp-make-tramp-file-name'.") -(defun tramp-postfix-host-regexp () +(defun tramp-build-postfix-host-regexp () + (regexp-quote tramp-postfix-host-format)) + +(defvar tramp-postfix-host-regexp (tramp-build-postfix-host-regexp) "Regexp matching delimiter between host names and localnames. -Derived from `tramp-postfix-host-format'." - (tramp-lookup-syntax tramp-postfix-host-regexp-alist)) +Derived from `tramp-postfix-host-format'.") (defconst tramp-localname-regexp ".*$" "Regexp matching localnames.") @@ -910,48 +915,35 @@ Derived from `tramp-postfix-host-format'." ;;; File name format: -(defun tramp-build-remote-file-name-spec-regexp (syntax) - "Construct a regexp matching a Tramp file name for a Tramp SYNTAX." - (let ((tramp-syntax syntax)) - (concat - "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) - "\\(?:" "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp "\\)?" - "\\(" "\\(?:" tramp-host-regexp "\\|" - (tramp-prefix-ipv6-regexp) - "\\(?:" tramp-ipv6-regexp "\\)?" - (tramp-postfix-ipv6-regexp) "\\)?" - "\\(?:" tramp-prefix-port-regexp tramp-port-regexp "\\)?" "\\)?"))) - -(defconst tramp-remote-file-name-spec-regexp-alist - `((default . ,(tramp-build-remote-file-name-spec-regexp 'default)) - (simplified . ,(tramp-build-remote-file-name-spec-regexp 'simplified)) - (separate . ,(tramp-build-remote-file-name-spec-regexp 'separate))) - "Alist mapping Tramp syntax to regexps matching Tramp file names.") - -(defun tramp-remote-file-name-spec-regexp () - "Regular expression matching a Tramp file name between prefix and postfix." - (tramp-lookup-syntax tramp-remote-file-name-spec-regexp-alist)) - -(defun tramp-build-file-name-structure (syntax) - "Construct the Tramp file name structure for SYNTAX. +(defun tramp-build-remote-file-name-spec-regexp () + "Construct a regexp matching a Tramp file name for a Tramp syntax. +It is expected, that `tramp-syntax' has the proper value." + (concat + "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp + "\\(?:" "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp "\\)?" + "\\(" "\\(?:" tramp-host-regexp "\\|" + tramp-prefix-ipv6-regexp "\\(?:" tramp-ipv6-regexp "\\)?" + tramp-postfix-ipv6-regexp "\\)" + "\\(?:" tramp-prefix-port-regexp tramp-port-regexp "\\)?" "\\)?")) + +(defvar tramp-remote-file-name-spec-regexp + (tramp-build-remote-file-name-spec-regexp) + "Regular expression matching a Tramp file name between prefix and postfix.") + +(defun tramp-build-file-name-structure () + "Construct the Tramp file name structure for a Tramp syntax. +It is expected, that `tramp-syntax' has the proper value. See `tramp-file-name-structure'." - (let ((tramp-syntax syntax)) - (list - (concat - (tramp-prefix-regexp) - "\\(" "\\(?:" (tramp-remote-file-name-spec-regexp) - tramp-postfix-hop-regexp "\\)+" "\\)?" - (tramp-remote-file-name-spec-regexp) (tramp-postfix-host-regexp) - "\\(" tramp-localname-regexp "\\)") - 5 6 7 8 1))) - -(defconst tramp-file-name-structure-alist - `((default . ,(tramp-build-file-name-structure 'default)) - (simplified . ,(tramp-build-file-name-structure 'simplified)) - (separate . ,(tramp-build-file-name-structure 'separate))) - "Alist mapping Tramp syntax to the file name structure for that syntax.") - -(defun tramp-file-name-structure () + (list + (concat + tramp-prefix-regexp + "\\(" "\\(?:" tramp-remote-file-name-spec-regexp + tramp-postfix-hop-regexp "\\)+" "\\)?" + tramp-remote-file-name-spec-regexp tramp-postfix-host-regexp + "\\(" tramp-localname-regexp "\\)") + 5 6 7 8 1)) + +(defvar tramp-file-name-structure (tramp-build-file-name-structure) "List of six elements (REGEXP METHOD USER HOST FILE HOP), detailing \ the Tramp file name structure. @@ -969,25 +961,22 @@ cascade of several hops. These numbers are passed directly to `match-string', which see. That means the opening parentheses are counted to identify the pair. -See also `tramp-file-name-regexp'." - (tramp-lookup-syntax tramp-file-name-structure-alist)) +See also `tramp-file-name-regexp'.") -(defun tramp-file-name-regexp () - "Regular expression matching file names handled by Tramp. -This regexp should match Tramp file names but no other file names." - (car (tramp-file-name-structure))) +(defun tramp-build-file-name-regexp () + (car tramp-file-name-structure)) ;;;###autoload (defconst tramp-initial-file-name-regexp "\\`/.+:.*:" "Value for `tramp-file-name-regexp' for autoload. It must match the initial `tramp-syntax' settings.") -;; External packages use constant `tramp-file-name-regexp'. In order -;; not to break them, we still provide it. It is a variable now. ;;;###autoload (defvar tramp-file-name-regexp tramp-initial-file-name-regexp - "Value for `tramp-file-name-regexp' for autoload. -It must match the initial `tramp-syntax' settings.") + "Regular expression matching file names handled by Tramp. +This regexp should match Tramp file names but no other file +names. When calling `tramp-register-file-name-handlers', the +initial value is overwritten by the car of `tramp-file-name-structure'.") ;;;###autoload (defconst tramp-completion-file-name-regexp-default @@ -1031,7 +1020,17 @@ On W32 systems, the volume letter must be ignored.") "Value for `tramp-completion-file-name-regexp' for separate remoting. See `tramp-file-name-structure' for more explanations.") -(defun tramp-completion-file-name-regexp () +(defconst tramp-completion-file-name-regexp-alist + `((default . ,tramp-completion-file-name-regexp-default) + (simplified . ,tramp-completion-file-name-regexp-simplified) + (separate . ,tramp-completion-file-name-regexp-separate)) + "Alist mapping incomplete Tramp file names.") + +(defun tramp-build-completion-file-name-regexp () + (tramp-lookup-syntax tramp-completion-file-name-regexp-alist)) + +(defvar tramp-completion-file-name-regexp + (tramp-build-completion-file-name-regexp) "Regular expression matching file names handled by Tramp completion. This regexp should match partial Tramp file names only. @@ -1040,14 +1039,7 @@ this file \(tramp.el) is loaded. This means that this variable must be set before loading tramp.el. Alternatively, `file-name-handler-alist' can be updated after changing this variable. -Also see `tramp-file-name-structure'." - (cond ((eq (tramp-compat-tramp-syntax) 'default) - tramp-completion-file-name-regexp-default) - ((eq (tramp-compat-tramp-syntax) 'simplified) - tramp-completion-file-name-regexp-simplified) - ((eq (tramp-compat-tramp-syntax) 'separate) - tramp-completion-file-name-regexp-separate) - (t (error "Wrong `tramp-syntax' %s" tramp-syntax)))) +Also see `tramp-file-name-structure'.") ;;;###autoload (defconst tramp-initial-completion-file-name-regexp @@ -1284,7 +1276,7 @@ entry does not exist, return nil." (if (memq system-type '(cygwin windows-nt)) "^/[[:alpha:]]?:" "^/:") name)) - (string-match (tramp-file-name-regexp) name)))) + (string-match tramp-file-name-regexp name)))) (defun tramp-find-method (method user host) "Return the right method string to use. @@ -1356,13 +1348,13 @@ values." (save-match-data (unless (tramp-tramp-file-p name) (tramp-compat-user-error nil "Not a Tramp file name: \"%s\"" name)) - (if (not (string-match (nth 0 (tramp-file-name-structure)) name)) + (if (not (string-match (nth 0 tramp-file-name-structure) name)) (error "`tramp-file-name-structure' didn't match!") - (let ((method (match-string (nth 1 (tramp-file-name-structure)) name)) - (user (match-string (nth 2 (tramp-file-name-structure)) name)) - (host (match-string (nth 3 (tramp-file-name-structure)) name)) - (localname (match-string (nth 4 (tramp-file-name-structure)) name)) - (hop (match-string (nth 5 (tramp-file-name-structure)) name)) + (let ((method (match-string (nth 1 tramp-file-name-structure) name)) + (user (match-string (nth 2 tramp-file-name-structure) name)) + (host (match-string (nth 3 tramp-file-name-structure) name)) + (localname (match-string (nth 4 tramp-file-name-structure) name)) + (hop (match-string (nth 5 tramp-file-name-structure) name)) domain port) (when user (when (string-match tramp-user-with-domain-regexp user) @@ -1373,9 +1365,9 @@ values." (when (string-match tramp-host-with-port-regexp host) (setq port (match-string 2 host) host (match-string 1 host))) - (when (string-match (tramp-prefix-ipv6-regexp) host) + (when (string-match tramp-prefix-ipv6-regexp host) (setq host (replace-match "" nil t host))) - (when (string-match (tramp-postfix-ipv6-regexp) host) + (when (string-match tramp-postfix-ipv6-regexp host) (setq host (replace-match "" nil t host)))) (unless nodefault @@ -1400,42 +1392,41 @@ values." (method user domain host port localname &optional hop) "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME. When not nil, optional DOMAIN, PORT and HOP are used." - (concat (tramp-prefix-format) hop + (concat tramp-prefix-format hop (unless (or (zerop (length method)) - (zerop (length (tramp-postfix-method-format)))) - (concat method (tramp-postfix-method-format))) + (zerop (length tramp-postfix-method-format))) + (concat method tramp-postfix-method-format)) user (unless (zerop (length domain)) (concat tramp-prefix-domain-format domain)) (unless (zerop (length user)) - tramp-postfix-user-format) + tramp-postfix-user-format) (when host (if (string-match tramp-ipv6-regexp host) - (concat - (tramp-prefix-ipv6-format) host (tramp-postfix-ipv6-format)) + (concat tramp-prefix-ipv6-format host tramp-postfix-ipv6-format) host)) (unless (zerop (length port)) (concat tramp-prefix-port-format port)) - (tramp-postfix-host-format) + tramp-postfix-host-format (when localname localname))) (defun tramp-completion-make-tramp-file-name (method user host localname) "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME. It must not be a complete Tramp file name, but as long as there are necessary only. This function will be used in file name completion." - (concat (tramp-prefix-format) + (concat tramp-prefix-format (unless (or (zerop (length method)) - (zerop (length (tramp-postfix-method-format)))) - (concat method (tramp-postfix-method-format))) + (zerop (length tramp-postfix-method-format))) + (concat method tramp-postfix-method-format)) (unless (zerop (length user)) (concat user tramp-postfix-user-format)) (unless (zerop (length host)) (concat (if (string-match tramp-ipv6-regexp host) (concat - (tramp-prefix-ipv6-format) host (tramp-postfix-ipv6-format)) + tramp-prefix-ipv6-format host tramp-postfix-ipv6-format) host) - (tramp-postfix-host-format))) + tramp-postfix-host-format)) (when localname localname))) (defun tramp-get-buffer (vec) @@ -1947,7 +1938,7 @@ special handling of `substitute-in-file-name'." 'tramp-rfn-eshadow-setup-minibuffer))) (defun tramp-rfn-eshadow-update-overlay-regexp () - (format "[^%s/~]*\\(/\\|~\\)" (tramp-postfix-host-format))) + (format "[^%s/~]*\\(/\\|~\\)" tramp-postfix-host-format)) (defun tramp-rfn-eshadow-update-overlay () "Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input. @@ -2365,11 +2356,11 @@ remote file names." ;; property of `tramp-file-name-handler', this shall be done by the ;; respective foreign handlers. (add-to-list 'file-name-handler-alist - (cons (tramp-file-name-regexp) 'tramp-file-name-handler)) + (cons tramp-file-name-regexp 'tramp-file-name-handler)) (put 'tramp-file-name-handler 'safe-magic t) (add-to-list 'file-name-handler-alist - (cons (tramp-completion-file-name-regexp) + (cons tramp-completion-file-name-regexp 'tramp-completion-file-name-handler)) (put 'tramp-completion-file-name-handler 'safe-magic t) ;; Mark `operations' the handler is responsible for. @@ -2473,8 +2464,8 @@ not in completion mode." ;; Suppress hop from completion. (when (string-match (concat - (tramp-prefix-regexp) - "\\(" "\\(" (tramp-remote-file-name-spec-regexp) + tramp-prefix-regexp + "\\(" "\\(" tramp-remote-file-name-spec-regexp tramp-postfix-hop-regexp "\\)+" "\\)") fullname) @@ -2519,9 +2510,8 @@ not in completion mode." ;; Unify list, add hop, remove nil elements. (dolist (elt result) (when elt - (string-match (tramp-prefix-regexp) elt) - (setq elt - (replace-match (concat (tramp-prefix-format) hop) nil nil elt)) + (string-match tramp-prefix-regexp elt) + (setq elt (replace-match (concat tramp-prefix-format hop) nil nil elt)) (push (substring elt (length (tramp-drop-volume-letter directory))) result1))) @@ -2569,58 +2559,58 @@ They are collected by `tramp-completion-dissect-file-name1'." (tramp-completion-ipv6-regexp (format "[^%s]*" - (if (zerop (length (tramp-postfix-ipv6-format))) - (tramp-postfix-host-format) - (tramp-postfix-ipv6-format)))) + (if (zerop (length tramp-postfix-ipv6-format)) + tramp-postfix-host-format + tramp-postfix-ipv6-format))) ;; "/method" "/[method" (tramp-completion-file-name-structure1 (list (concat - (tramp-prefix-regexp) - "\\(" (tramp-method-regexp) x-nil "\\)$") + tramp-prefix-regexp + "\\(" tramp-method-regexp x-nil "\\)$") 1 nil nil nil)) ;; "/method:user" "/[method/user" (tramp-completion-file-name-structure2 (list (concat - (tramp-prefix-regexp) - "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) - "\\(" tramp-user-regexp x-nil "\\)$") + tramp-prefix-regexp + "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp + "\\(" tramp-user-regexp x-nil "\\)$") 1 2 nil nil)) ;; "/method:host" "/[method/host" (tramp-completion-file-name-structure3 (list (concat - (tramp-prefix-regexp) - "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) - "\\(" tramp-host-regexp x-nil "\\)$") + tramp-prefix-regexp + "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp + "\\(" tramp-host-regexp x-nil "\\)$") 1 nil 2 nil)) ;; "/method:[ipv6" "/[method/ipv6" (tramp-completion-file-name-structure4 (list (concat - (tramp-prefix-regexp) - "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) - (tramp-prefix-ipv6-regexp) + tramp-prefix-regexp + "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp + tramp-prefix-ipv6-regexp "\\(" tramp-completion-ipv6-regexp x-nil "\\)$") 1 nil 2 nil)) ;; "/method:user@host" "/[method/user@host" (tramp-completion-file-name-structure5 (list (concat - (tramp-prefix-regexp) - "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) - "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp - "\\(" tramp-host-regexp x-nil "\\)$") + tramp-prefix-regexp + "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp + "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp + "\\(" tramp-host-regexp x-nil "\\)$") 1 2 3 nil)) ;; "/method:user@[ipv6" "/[method/user@ipv6" (tramp-completion-file-name-structure6 (list (concat - (tramp-prefix-regexp) - "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) - "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp - (tramp-prefix-ipv6-regexp) + tramp-prefix-regexp + "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp + "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp + tramp-prefix-ipv6-regexp "\\(" tramp-completion-ipv6-regexp x-nil "\\)$") 1 2 3 nil))) (delq @@ -4479,10 +4469,10 @@ Invokes `password-read' if available, `read-passwd' else." (tramp-clear-passwd (tramp-dissect-file-name (concat - (tramp-prefix-format) + tramp-prefix-format (replace-regexp-in-string (concat tramp-postfix-hop-regexp "$") - (tramp-postfix-host-format) hop))))) + tramp-postfix-host-format hop))))) (auth-source-forget `(:max 1 ,(and user-domain :user) ,user-domain :host ,host-port :port ,method)) |