Commit 07d88279 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/net/tramp: Rework mutual dependencies

Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.

* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads.  Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(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-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.

* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.

* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.

* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.

* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
parent e8199e76
Pipeline #296 failed with stage
in 3 seconds
......@@ -78,18 +78,16 @@ It is used for TCP/IP devices."
"Regexp for ls output.")
;;;###tramp-autoload
(add-to-list 'tramp-methods
`(,tramp-adb-method
(tramp-tmpdir "/data/local/tmp")
(tramp-default-port 5555)))
(tramp--with-startup
(add-to-list 'tramp-methods
`(,tramp-adb-method
(tramp-tmpdir "/data/local/tmp")
(tramp-default-port 5555)))
;;;###tramp-autoload
(add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil ""))
(add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil ""))
;;;###tramp-autoload
(eval-after-load 'tramp
'(tramp-set-completion-function
tramp-adb-method '((tramp-adb-parse-device-names ""))))
(tramp-set-completion-function
tramp-adb-method '((tramp-adb-parse-device-names ""))))
;;;###tramp-autoload
(defconst tramp-adb-file-name-handler-alist
......@@ -188,8 +186,9 @@ pass to the OPERATION."
(tramp-run-real-handler operation args))))
;;;###tramp-autoload
(tramp-register-foreign-file-name-handler
'tramp-adb-file-name-p 'tramp-adb-file-name-handler)
(tramp--with-startup
(tramp-register-foreign-file-name-handler
#'tramp-adb-file-name-p #'tramp-adb-file-name-handler))
;;;###tramp-autoload
(defun tramp-adb-parse-device-names (_ignore)
......
......@@ -246,17 +246,17 @@ This is suppressed for temporary buffers."
(with-parsed-tramp-file-name bfn nil
(tramp-flush-file-properties v localname)))))))
(add-hook 'before-revert-hook 'tramp-flush-file-function)
(add-hook 'eshell-pre-command-hook 'tramp-flush-file-function)
(add-hook 'kill-buffer-hook 'tramp-flush-file-function)
(add-hook 'before-revert-hook #'tramp-flush-file-function)
(add-hook 'eshell-pre-command-hook #'tramp-flush-file-function)
(add-hook 'kill-buffer-hook #'tramp-flush-file-function)
(add-hook 'tramp-cache-unload-hook
(lambda ()
(remove-hook 'before-revert-hook
'tramp-flush-file-function)
#'tramp-flush-file-function)
(remove-hook 'eshell-pre-command-hook
'tramp-flush-file-function)
#'tramp-flush-file-function)
(remove-hook 'kill-buffer-hook
'tramp-flush-file-function)))
#'tramp-flush-file-function)))
;;; -- Properties --
......@@ -452,11 +452,11 @@ used to cache connection properties of the local machine."
(pp (read (format "(%s)" (tramp-cache-print cache)))))))))))
(unless noninteractive
(add-hook 'kill-emacs-hook 'tramp-dump-connection-properties))
(add-hook 'kill-emacs-hook #'tramp-dump-connection-properties))
(add-hook 'tramp-cache-unload-hook
(lambda ()
(remove-hook 'kill-emacs-hook
'tramp-dump-connection-properties)))
#'tramp-dump-connection-properties)))
;;;###tramp-autoload
(defun tramp-parse-connection-properties (method)
......
......@@ -45,8 +45,6 @@
(require 'timer)
(require 'ucs-normalize)
(require 'tramp-loaddefs)
;; For not existing functions, obsolete functions, or functions with a
;; changed argument list, there are compiler warnings. We want to
;; avoid them in cases we know what we do.
......@@ -230,6 +228,7 @@ If NAME is a remote file name, the local part of NAME is unquoted."
;; support old settings.
(defsubst tramp-compat-tramp-syntax ()
"Return proper value of `tramp-syntax'."
(defvar tramp-syntax)
(cond ((eq tramp-syntax 'ftp) 'default)
((eq tramp-syntax 'sep) 'separate)
(t tramp-syntax)))
......
......@@ -95,22 +95,19 @@ present for backward compatibility."
;; ... and add it to the method list.
;;;###tramp-autoload
(add-to-list 'tramp-methods (cons tramp-ftp-method nil))
(tramp--with-startup
(add-to-list 'tramp-methods (cons tramp-ftp-method nil))
;; Add some defaults for `tramp-default-method-alist'.
;;;###tramp-autoload
(add-to-list 'tramp-default-method-alist
(list "\\`ftp\\." nil tramp-ftp-method))
;;;###tramp-autoload
(add-to-list 'tramp-default-method-alist
(list nil "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method))
;; Add some defaults for `tramp-default-method-alist'.
(add-to-list 'tramp-default-method-alist
(list "\\`ftp\\." nil tramp-ftp-method))
(add-to-list 'tramp-default-method-alist
(list nil "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method))
;; Add completion function for FTP method.
;;;###tramp-autoload
(eval-after-load 'tramp
'(tramp-set-completion-function
tramp-ftp-method
'((tramp-parse-netrc "~/.netrc"))))
;; Add completion function for FTP method.
(tramp-set-completion-function
tramp-ftp-method
'((tramp-parse-netrc "~/.netrc"))))
;;;###tramp-autoload
(defun tramp-ftp-file-name-handler (operation &rest args)
......@@ -188,8 +185,9 @@ pass to the OPERATION."
tramp-ftp-method)))
;;;###tramp-autoload
(add-to-list 'tramp-foreign-file-name-handler-alist
(cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler))
(tramp--with-startup
(add-to-list 'tramp-foreign-file-name-handler-alist
(cons #'tramp-ftp-file-name-p #'tramp-ftp-file-name-handler)))
(add-hook 'tramp-unload-hook
(lambda ()
......
......@@ -147,12 +147,13 @@
;; Add defaults for `tramp-default-user-alist' and `tramp-default-host-alist'.
;;;###tramp-autoload
(when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)"
user-mail-address)
(add-to-list 'tramp-default-user-alist
`("\\`gdrive\\'" nil ,(match-string 1 user-mail-address)))
(add-to-list 'tramp-default-host-alist
'("\\`gdrive\\'" nil ,(match-string 2 user-mail-address))))
(tramp--with-startup
(when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)"
user-mail-address)
(add-to-list 'tramp-default-user-alist
`("\\`gdrive\\'" nil ,(match-string 1 user-mail-address)))
(add-to-list 'tramp-default-host-alist
'("\\`gdrive\\'" nil ,(match-string 2 user-mail-address)))))
;;;###tramp-autoload
(defcustom tramp-gvfs-zeroconf-domain "local"
......@@ -165,9 +166,10 @@
;; completion.
;;;###tramp-autoload
(when (featurep 'dbusbind)
(dolist (elt tramp-gvfs-methods)
(unless (assoc elt tramp-methods)
(add-to-list 'tramp-methods (cons elt nil)))))
(tramp--with-startup
(dolist (elt tramp-gvfs-methods)
(unless (assoc elt tramp-methods)
(add-to-list 'tramp-methods (cons elt nil))))))
(defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp")
"The preceding object path for own objects.")
......@@ -621,8 +623,9 @@ pass to the OPERATION."
;;;###tramp-autoload
(when (featurep 'dbusbind)
(tramp-register-foreign-file-name-handler
'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler))
(tramp--with-startup
(tramp-register-foreign-file-name-handler
#'tramp-gvfs-file-name-p #'tramp-gvfs-file-name-handler)))
;; D-Bus helper function.
......
......@@ -50,13 +50,14 @@
:type 'string)
;;;###tramp-autoload
(add-to-list
'tramp-methods
`(,tramp-rclone-method
(tramp-mount-args nil)
(tramp-copyto-args nil)
(tramp-moveto-args nil)
(tramp-about-args ("--full"))))
(tramp--with-startup
(add-to-list
'tramp-methods
`(,tramp-rclone-method
(tramp-mount-args nil)
(tramp-copyto-args nil)
(tramp-moveto-args nil)
(tramp-about-args ("--full")))))
;;;###tramp-autoload
(eval-after-load 'tramp
......@@ -162,8 +163,9 @@ pass to the OPERATION."
(tramp-run-real-handler operation args))))
;;;###tramp-autoload
(tramp-register-foreign-file-name-handler
'tramp-rclone-file-name-p 'tramp-rclone-file-name-handler)
(tramp--with-startup
(tramp-register-foreign-file-name-handler
#'tramp-rclone-file-name-p #'tramp-rclone-file-name-handler))
;;;###tramp-autoload
(defun tramp-rclone-parse-device-names (_ignore)
......
This diff is collapsed.
......@@ -38,30 +38,31 @@
;; ... and add it to the method list.
;;;###tramp-autoload
(unless (memq system-type '(cygwin windows-nt))
(add-to-list 'tramp-methods
`(,tramp-smb-method
;; We define an empty command, because `tramp-smb-call-winexe'
;; opens already the powershell. Used in `tramp-handle-shell-command'.
(tramp-remote-shell "")
;; This is just a guess. We don't know whether the share "C$"
;; is available for public use, and whether the user has write
;; access.
(tramp-tmpdir "/C$/Temp")
;; Another guess. We might implement a better check later on.
(tramp-case-insensitive t))))
(tramp--with-startup
(add-to-list 'tramp-methods
`(,tramp-smb-method
;; We define an empty command, because
;; `tramp-smb-call-winexe' opens already the powershell.
;; Used in `tramp-handle-shell-command'.
(tramp-remote-shell "")
;; This is just a guess. We don't know whether the share "C$"
;; is available for public use, and whether the user has write
;; access.
(tramp-tmpdir "/C$/Temp")
;; Another guess. We might implement a better check later on.
(tramp-case-insensitive t)))))
;; Add a default for `tramp-default-user-alist'. Rule: For the SMB method,
;; the anonymous user is chosen.
;;;###tramp-autoload
(add-to-list 'tramp-default-user-alist
`(,(concat "\\`" tramp-smb-method "\\'") nil nil))
(tramp--with-startup
(add-to-list 'tramp-default-user-alist
`(,(concat "\\`" tramp-smb-method "\\'") nil nil))
;; Add completion function for SMB method.
;;;###tramp-autoload
(eval-after-load 'tramp
'(tramp-set-completion-function
tramp-smb-method
'((tramp-parse-netrc "~/.netrc"))))
;; Add completion function for SMB method.
(tramp-set-completion-function
tramp-smb-method
'((tramp-parse-netrc "~/.netrc"))))
;;;###tramp-autoload
(defcustom tramp-smb-program "smbclient"
......@@ -337,8 +338,9 @@ pass to the OPERATION."
;;;###tramp-autoload
(unless (memq system-type '(cygwin windows-nt))
(tramp-register-foreign-file-name-handler
'tramp-smb-file-name-p 'tramp-smb-file-name-handler))
(tramp--with-startup
(tramp-register-foreign-file-name-handler
#'tramp-smb-file-name-p #'tramp-smb-file-name-handler)))
;; File name primitives.
......
......@@ -35,6 +35,7 @@
;;; Code:
(require 'tramp)
(eval-when-compile (require 'tramp-sh)) ;For tramp-stat-marker
(require 'server)
;;;###tramp-autoload
......@@ -42,18 +43,16 @@
"When this method name is used, call sudoedit for editing a file.")
;;;###tramp-autoload
(add-to-list 'tramp-methods
`(,tramp-sudoedit-method
(tramp-sudo-login (("sudo") ("-u" "%u") ("-S") ("-H")
("-p" "Password:") ("--")))))
(tramp--with-startup
(add-to-list 'tramp-methods
`(,tramp-sudoedit-method
(tramp-sudo-login (("sudo") ("-u" "%u") ("-S") ("-H")
("-p" "Password:") ("--")))))
;;;###tramp-autoload
(add-to-list 'tramp-default-user-alist '("\\`sudoedit\\'" nil "root"))
(add-to-list 'tramp-default-user-alist '("\\`sudoedit\\'" nil "root"))
;;;###tramp-autoload
(eval-after-load 'tramp
'(tramp-set-completion-function
tramp-sudoedit-method tramp-completion-function-alist-su))
(tramp-set-completion-function
tramp-sudoedit-method tramp-completion-function-alist-su))
(defconst tramp-sudoedit-sudo-actions
'((tramp-password-prompt-regexp tramp-action-password)
......@@ -161,8 +160,9 @@ pass to the OPERATION."
(tramp-run-real-handler operation args))))
;;;###tramp-autoload
(tramp-register-foreign-file-name-handler
'tramp-sudoedit-file-name-p 'tramp-sudoedit-file-name-handler)
(tramp--with-startup
(tramp-register-foreign-file-name-handler
#'tramp-sudoedit-file-name-p #'tramp-sudoedit-file-name-handler))
;; File name primitives.
......@@ -235,7 +235,7 @@ absolute file names."
(file-modes (tramp-default-file-modes filename))
;; `file-extended-attributes' exists since Emacs 24.4.
(attributes (and preserve-extended-attributes
(apply 'file-extended-attributes (list filename))))
(apply #'file-extended-attributes (list filename))))
(sudoedit-operation
(cond
((and (eq op 'copy) preserve-uid-gid) '("cp" "-f" "-p"))
......@@ -288,7 +288,7 @@ absolute file names."
;; `set-file-extended-attributes' exists since Emacs 24.4.
(when attributes
(ignore-errors
(apply 'set-file-extended-attributes (list newname attributes))))
(apply #'set-file-extended-attributes (list newname attributes))))
(when (and t1 (eq op 'rename))
(with-parsed-tramp-file-name filename v1
......@@ -659,7 +659,7 @@ component is used as the target of the symlink."
(when (and (stringp acl-string) (tramp-sudoedit-remote-acl-p v))
;; Massage `acl-string'.
(setq acl-string
(mapconcat 'identity (split-string acl-string "\n" 'omit) ","))
(mapconcat #'identity (split-string acl-string "\n" 'omit) ","))
(prog1
(tramp-sudoedit-send-command
v "setfacl" "-m"
......@@ -809,17 +809,17 @@ in case of error, t otherwise."
(tramp-compat-flatten-list (delq nil args))))
(delete-exited-processes t)
(process-connection-type tramp-process-connection-type)
(p (apply 'start-process
(p (apply #'start-process
(tramp-get-connection-name vec) (current-buffer) args))
;; We suppress the messages `Waiting for prompts from remote shell'.
(tramp-verbose (if (= tramp-verbose 3) 2 tramp-verbose))
;; We do not want to save the password.
auth-source-save-behavior)
(tramp-message vec 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-message vec 6 "%s" (mapconcat #'identity (process-command p) " "))
;; Avoid process status message in output buffer.
(set-process-sentinel p 'ignore)
(set-process-sentinel p #'ignore)
(process-put p 'vector vec)
(process-put p 'adjust-window-size-function 'ignore)
(process-put p 'adjust-window-size-function #'ignore)
(set-process-query-on-exit-flag p nil)
(tramp-process-actions p vec nil tramp-sudoedit-sudo-actions)
(tramp-message vec 6 "%s\n%s" (process-exit-status p) (buffer-string))
......@@ -830,7 +830,7 @@ in case of error, t otherwise."
(defun tramp-sudoedit-send-command-and-read (vec &rest args)
"Run command ARGS and return the output, which must be a Lisp expression.
In case there is no valid Lisp expression, it raises an error."
(when (apply 'tramp-sudoedit-send-command vec args)
(when (apply #'tramp-sudoedit-send-command vec args)
(with-current-buffer (tramp-get-connection-buffer vec)
;; Replace stat marker.
(goto-char (point-min))
......@@ -856,7 +856,7 @@ In case there is no valid Lisp expression, it raises an error."
(defun tramp-sudoedit-send-command-string (vec &rest args)
"Run command ARGS and return the output as astring."
(when (apply 'tramp-sudoedit-send-command vec args)
(when (apply #'tramp-sudoedit-send-command vec args)
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string))
(goto-char (point-max))
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment