(require 'timer)
(require 'ucs-normalize)
-(declare-function tramp-compat-file-local-name "tramp-compat")
-(declare-function tramp-compat-file-name-quoted-p "tramp-compat")
+(declare-function tramp-handle-temporary-file-directory "tramp")
;; For not existing functions, obsolete functions, or functions with a
;; changed argument list, there are compiler warnings. We want to
(defalias 'tramp-compat-temporary-file-directory-function
(if (fboundp 'temporary-file-directory)
#'temporary-file-directory
- 'tramp-handle-temporary-file-directory))
+ #'tramp-handle-temporary-file-directory))
(defun tramp-compat-process-running-p (process-name)
"Returns t if system process PROCESS-NAME is running for `user-login-name'."
;; `file-attribute-*' are introduced in Emacs 25.1.
-(if (fboundp 'file-attribute-type)
- (defalias 'tramp-compat-file-attribute-type #'file-attribute-type)
- (defsubst tramp-compat-file-attribute-type (attributes)
- "The type field in ATTRIBUTES returned by `file-attributes'.
+(defalias 'tramp-compat-file-attribute-type
+ (if (fboundp 'file-attribute-type)
+ #'file-attribute-type
+ (lambda (attributes)
+ "The type field in ATTRIBUTES returned by `file-attributes'.
The value is either t for directory, string (name linked to) for
symbolic link, or nil."
- (nth 0 attributes)))
-
-(if (fboundp 'file-attribute-link-number)
- (defalias 'tramp-compat-file-attribute-link-number
- #'file-attribute-link-number)
- (defsubst tramp-compat-file-attribute-link-number (attributes)
- "Return the number of links in ATTRIBUTES returned by `file-attributes'."
- (nth 1 attributes)))
-
-(if (fboundp 'file-attribute-user-id)
- (defalias 'tramp-compat-file-attribute-user-id #'file-attribute-user-id)
- (defsubst tramp-compat-file-attribute-user-id (attributes)
- "The UID field in ATTRIBUTES returned by `file-attributes'.
+ (nth 0 attributes))))
+
+(defalias 'tramp-compat-file-attribute-link-number
+ (if (fboundp 'file-attribute-link-number)
+ #'file-attribute-link-number
+ (lambda (attributes)
+ "Return the number of links in ATTRIBUTES returned by `file-attributes'."
+ (nth 1 attributes))))
+
+(defalias 'tramp-compat-file-attribute-user-id
+ (if (fboundp 'file-attribute-user-id)
+ #'file-attribute-user-id
+ (lambda (attributes)
+ "The UID field in ATTRIBUTES returned by `file-attributes'.
This is either a string or a number. If a string value cannot be
looked up, a numeric value, either an integer or a float, is
returned."
- (nth 2 attributes)))
+ (nth 2 attributes))))
-(if (fboundp 'file-attribute-group-id)
- (defalias 'tramp-compat-file-attribute-group-id #'file-attribute-group-id)
- (defsubst tramp-compat-file-attribute-group-id (attributes)
- "The GID field in ATTRIBUTES returned by `file-attributes'.
+(defalias 'tramp-compat-file-attribute-group-id
+ (if (fboundp 'file-attribute-group-id)
+ #'file-attribute-group-id
+ (lambda (attributes)
+ "The GID field in ATTRIBUTES returned by `file-attributes'.
This is either a string or a number. If a string value cannot be
looked up, a numeric value, either an integer or a float, is
returned."
- (nth 3 attributes)))
+ (nth 3 attributes))))
-(if (fboundp 'file-attribute-modification-time)
- (defalias 'tramp-compat-file-attribute-modification-time
- #'file-attribute-modification-time)
- (defsubst tramp-compat-file-attribute-modification-time (attributes)
- "The modification time in ATTRIBUTES returned by `file-attributes'.
+(defalias 'tramp-compat-file-attribute-modification-time
+ (if (fboundp 'file-attribute-modification-time)
+ #'file-attribute-modification-time
+ (lambda (attributes)
+ "The modification time in ATTRIBUTES returned by `file-attributes'.
This is the time of the last change to the file's contents, and
is a Lisp timestamp in the style of `current-time'."
- (nth 5 attributes)))
+ (nth 5 attributes))))
-(if (fboundp 'file-attribute-size)
- (defalias 'tramp-compat-file-attribute-size #'file-attribute-size)
- (defsubst tramp-compat-file-attribute-size (attributes)
- "The size (in bytes) in ATTRIBUTES returned by `file-attributes'.
+(defalias 'tramp-compat-file-attribute-size
+ (if (fboundp 'file-attribute-size)
+ #'file-attribute-size
+ (lambda (attributes)
+ "The size (in bytes) in ATTRIBUTES returned by `file-attributes'.
If the size is too large for a fixnum, this is a bignum in Emacs 27
and later, and is a float in Emacs 26 and earlier."
- (nth 7 attributes)))
+ (nth 7 attributes))))
-(if (fboundp 'file-attribute-modes)
- (defalias 'tramp-compat-file-attribute-modes #'file-attribute-modes)
- (defsubst tramp-compat-file-attribute-modes (attributes)
- "The file modes in ATTRIBUTES returned by `file-attributes'.
+(defalias 'tramp-compat-file-attribute-modes
+ (if (fboundp 'file-attribute-modes)
+ #'file-attribute-modes
+ (lambda (attributes)
+ "The file modes in ATTRIBUTES returned by `file-attributes'.
This is a string of ten letters or dashes as in ls -l."
- (nth 8 attributes)))
+ (nth 8 attributes))))
;; `format-message' is new in Emacs 25.1.
(unless (fboundp 'format-message)
(defalias 'format-message #'format))
;; `directory-name-p' is new in Emacs 25.1.
-(if (fboundp 'directory-name-p)
- (defalias 'tramp-compat-directory-name-p #'directory-name-p)
- (defsubst tramp-compat-directory-name-p (name)
- "Return non-nil if NAME ends with a directory separator character."
- (let ((len (length name))
- (lastc ?.))
- (if (> len 0)
- (setq lastc (aref name (1- len))))
- (or (= lastc ?/)
- (and (memq system-type '(windows-nt ms-dos))
- (= lastc ?\\))))))
+(defalias 'tramp-compat-directory-name-p
+ (if (fboundp 'directory-name-p)
+ #'directory-name-p
+ (lambda (name)
+ "Return non-nil if NAME ends with a directory separator character."
+ (let ((len (length name))
+ (lastc ?.))
+ (if (> len 0)
+ (setq lastc (aref name (1- len))))
+ (or (= lastc ?/)
+ (and (memq system-type '(windows-nt ms-dos))
+ (= lastc ?\\)))))))
;; `file-missing' is introduced in Emacs 26.1.
(defconst tramp-file-missing
;; `file-local-name', `file-name-quoted-p', `file-name-quote' and
;; `file-name-unquote' are introduced in Emacs 26.
-(if (fboundp 'file-local-name)
- (defalias 'tramp-compat-file-local-name #'file-local-name)
- (defsubst tramp-compat-file-local-name (name)
- "Return the local name component of NAME.
+(defalias 'tramp-compat-file-local-name
+ (if (fboundp 'file-local-name)
+ #'file-local-name
+ (lambda (name)
+ "Return the local name component of NAME.
It returns a file name which can be used directly as argument of
`process-file', `start-file-process', or `shell-command'."
- (or (file-remote-p name 'localname) name)))
+ (or (file-remote-p name 'localname) name))))
;; `file-name-quoted-p' got a second argument in Emacs 27.1.
-(if (and
- (fboundp 'file-name-quoted-p)
- (equal (tramp-compat-funcall 'func-arity #'file-name-quoted-p) '(1 . 2)))
- (defalias 'tramp-compat-file-name-quoted-p #'file-name-quoted-p)
- (defsubst tramp-compat-file-name-quoted-p (name &optional top)
- "Whether NAME is quoted with prefix \"/:\".
+(defalias 'tramp-compat-file-name-quoted-p
+ (if (and
+ (fboundp 'file-name-quoted-p)
+ (equal (tramp-compat-funcall 'func-arity #'file-name-quoted-p) '(1 . 2)))
+ #'file-name-quoted-p
+ (lambda (name &optional top)
+ "Whether NAME is quoted with prefix \"/:\".
If NAME is a remote file name and TOP is nil, check the local part of NAME."
- (let ((file-name-handler-alist (unless top file-name-handler-alist)))
- (string-prefix-p "/:" (tramp-compat-file-local-name name)))))
-
-(if (fboundp 'file-name-quote)
- (defalias 'tramp-compat-file-name-quote #'file-name-quote)
- (defsubst tramp-compat-file-name-quote (name)
- "Add the quotation prefix \"/:\" to file NAME.
+ (let ((file-name-handler-alist (unless top file-name-handler-alist)))
+ (string-prefix-p "/:" (tramp-compat-file-local-name name))))))
+
+(defalias 'tramp-compat-file-name-quote
+ (if (fboundp 'file-name-quote)
+ #'file-name-quote
+ (lambda (name)
+ "Add the quotation prefix \"/:\" to file NAME.
If NAME is a remote file name, the local part of NAME is quoted."
- (if (tramp-compat-file-name-quoted-p name)
- name
- (concat
- (file-remote-p name) "/:" (tramp-compat-file-local-name name)))))
-
-(if (fboundp 'file-name-unquote)
- (defalias 'tramp-compat-file-name-unquote #'file-name-unquote)
- (defsubst tramp-compat-file-name-unquote (name)
- "Remove quotation prefix \"/:\" from file NAME.
+ (if (tramp-compat-file-name-quoted-p name)
+ name
+ (concat
+ (file-remote-p name) "/:" (tramp-compat-file-local-name name))))))
+
+(defalias 'tramp-compat-file-name-unquote
+ (if (fboundp 'file-name-unquote)
+ #'file-name-unquote
+ (lambda (name)
+ "Remove quotation prefix \"/:\" from file NAME.
If NAME is a remote file name, the local part of NAME is unquoted."
- (let ((localname (tramp-compat-file-local-name name)))
- (when (tramp-compat-file-name-quoted-p localname)
- (setq
- localname (if (= (length localname) 2) "/" (substring localname 2))))
- (concat (file-remote-p name) localname))))
+ (let ((localname (tramp-compat-file-local-name name)))
+ (when (tramp-compat-file-name-quoted-p localname)
+ (setq
+ localname (if (= (length localname) 2) "/" (substring localname 2))))
+ (concat (file-remote-p name) localname)))))
;; `tramp-syntax' has changed its meaning in Emacs 26. We still
;; support old settings.
"Whether to use url-tramp.el.")
;; `exec-path' is new in Emacs 27.1.
-(eval-and-compile
+(defalias 'tramp-compat-exec-path
(if (fboundp 'exec-path)
- (defalias 'tramp-compat-exec-path #'exec-path)
- (defun tramp-compat-exec-path ()
+ #'exec-path
+ (lambda ()
"List of directories to search programs to run in remote subprocesses."
(let ((handler (find-file-name-handler default-directory 'exec-path)))
(if handler
exec-path)))))
;; `time-equal-p' has appeared in Emacs 27.1.
-(if (fboundp 'time-equal-p)
- (defalias 'tramp-compat-time-equal-p #'time-equal-p)
- (defsubst tramp-compat-time-equal-p (t1 t2)
- "Return non-nil if time value T1 is equal to time value T2.
+(defalias 'tramp-compat-time-equal-p
+ (if (fboundp 'time-equal-p)
+ #'time-equal-p
+ (lambda (t1 t2)
+ "Return non-nil if time value T1 is equal to time value T2.
A nil value for either argument stands for the current time."
- (equal (or t1 (current-time)) (or t2 (current-time)))))
+ (equal (or t1 (current-time)) (or t2 (current-time))))))
;; `flatten-tree' has appeared in Emacs 27.1.
-(if (fboundp 'flatten-tree)
- (defalias 'tramp-compat-flatten-tree #'flatten-tree)
- (defun tramp-compat-flatten-tree (tree)
- "Take TREE and \"flatten\" it."
- (let (elems)
- (setq tree (list tree))
- (while (let ((elem (pop tree)))
- (cond ((consp elem)
- (setq tree (cons (car elem) (cons (cdr elem) tree))))
- (elem
- (push elem elems)))
- tree))
- (nreverse elems))))
+(defalias 'tramp-compat-flatten-tree
+ (if (fboundp 'flatten-tree)
+ #'flatten-tree
+ (lambda (tree)
+ "Take TREE and \"flatten\" it."
+ (let (elems)
+ (setq tree (list tree))
+ (while (let ((elem (pop tree)))
+ (cond ((consp elem)
+ (setq tree (cons (car elem) (cons (cdr elem) tree))))
+ (elem
+ (push elem elems)))
+ tree))
+ (nreverse elems)))))
(add-hook 'tramp-unload-hook
(lambda ()