mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-20 04:30:55 -08:00
* doc/misc/tramp.texi (Remote programs, Remote processes) (Frequently Asked Questions): Adapt Emacs versions. * doc/misc/trampver.texi: * lisp/net/trampver.el: Change version to "2.6.0-pre". * lisp/net/tramp-adb.el (top): Don't use `tramp-compat-funcall' for connection-local functions. * lisp/net/tramp-compat.el (tramp-unload-file-name-handlers) (tramp-handle-temporary-file-directory) (tramp-compat-temporary-file-directory-function) (tramp-compat-file-attribute-type) (tramp-compat-file-attribute-link-number) (tramp-compat-file-attribute-user-id) (tramp-compat-file-attribute-group-id) (tramp-compat-file-attribute-access-time) (tramp-compat-file-attribute-modification-time) (tramp-compat-file-attribute-status-change-time) (tramp-compat-file-attribute-size) (tramp-compat-file-attribute-modes, tramp-file-missing) (tramp-compat-file-missing, tramp-compat-file-local-name): Remove. (tramp-compat-file-name-quoted-p, tramp-compat-file-name-quote) (tramp-compat-file-name-unquote) (tramp-compat-progress-reporter-update) (tramp-compat-file-modes, tramp-compat-set-file-modes) (tramp-compat-set-file-times, tramp-compat-directory-files) (tramp-compat-directory-files-and-attributes): Adapt implementation. * lisp/net/tramp.el: * lisp/net/tramp-adb.el: * lisp/net/tramp-archive.el: * lisp/net/tramp-crypt.el: * lisp/net/tramp-fuse.el: * lisp/net/tramp-gvfs.el: * lisp/net/tramp-rclone.el: * lisp/net/tramp-sh.el: * lisp/net/tramp-smb.el: * lisp/net/tramp-sudoedit.el: Adapt callees. * lisp/net/tramp-crypt.el (tramp-crypt-config-file-name): Expand file name. * lisp/net/tramp-fuse.el (tramp-fuse-handle-file-readable-p): Remove. * lisp/net/tramp-gvfs.el (tramp-gvfs-enabled): Don't check Emacs version. (tramp-gvfs-handler-mounted-unmounted): Use `make-tramp-file-name'. * lisp/net/tramp-integration.el (rfn-eshadow-overlay): Remove declaration. (top): Don't use `tramp-compat-funcall' for connection-local functions. * lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist): Use `tramp-rclone-handle-file-readable-p'. (tramp-rclone-handle-file-readable-p): New defun. * lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist): Use `tramp-handle-file-readable-p'. * lisp/net/tramp.el (tramp-temp-name-prefix, tramp-lookup-syntax): Adapt docstring. (tramp-set-connection-local-variables) (tramp-set-connection-local-variables-for-buffer): Don't use `tramp-compat-funcall' for connection-local functions. (tramp-file-name-for-operation): Reorder list. (tramp-handle-make-symbolic-link): Don't handle TARGET and OK-IF-ALREADY-EXISTS. (tramp-read-passwd): Don't use `read-passwd' any longer. (top): Don't check for `interrupt-process-functions'. * test/lisp/net/tramp-archive-tests.el (tramp-archive--test-emacs26-p): Remove. (tramp-archive-test02-file-name-dissect): Use `make-tramp-file-name'. (all): Replace Emacs 26 compatibility functions with their original name. (tramp-archive-test46-auto-load) (tramp-archive-test46-delay-load): Rename. * test/lisp/net/tramp-tests.el (dired-aux, seq): Require them. (dired-compress, connection-local-criteria-alist) (connection-local-profile-alist, async-shell-command-width): Don't declare. (all): Replace Emacs 26 compatibility functions with their original name. (tramp-test04-substitute-in-file-name) (tramp-test10-write-region, tramp-test11-copy-file) (tramp-test12-rename-file, tramp-test15-copy-directory) (tramp-test17-insert-directory) (tramp-test17-dired-with-wildcards, tramp-test21-file-links) (tramp-test31-interrupt-process) (tramp-test34-connection-local-variables) (tramp-test34-explicit-shell-file-name) (tramp-test40-make-nearby-temp-file) (tramp-test41-special-characters, tramp-test42-utf8) (tramp-test46-delay-load, tramp-test46-remote-load-path) (tramp-test47-unload): Don't check for Emacs 26 special features. (tramp--test-emacs26-p): Remove. (tramp--test-emacs29-p): New defun. (tramp-test45-dired-compress-file) (tramp-test45-dired-compress-dir): Use it. (tramp-test44-asynchronous-requests): Use `seq-random-elt'.
293 lines
11 KiB
EmacsLisp
293 lines
11 KiB
EmacsLisp
;;; tramp-compat.el --- Tramp compatibility functions -*- lexical-binding:t -*-
|
|
|
|
;; Copyright (C) 2007-2021 Free Software Foundation, Inc.
|
|
|
|
;; Author: Michael Albinus <michael.albinus@gmx.de>
|
|
;; Keywords: comm, processes
|
|
;; Package: tramp
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Tramp's main Emacs version for development is Emacs 29. This
|
|
;; package provides compatibility functions for Emacs 26, Emacs 27 and
|
|
;; Emacs 28.
|
|
|
|
;;; Code:
|
|
|
|
(require 'auth-source)
|
|
(require 'format-spec)
|
|
(require 'ls-lisp) ;; Due to `tramp-handle-insert-directory'.
|
|
(require 'parse-time)
|
|
(require 'shell)
|
|
(require 'subr-x)
|
|
|
|
(declare-function tramp-error "tramp")
|
|
(declare-function tramp-tramp-file-p "tramp")
|
|
(defvar tramp-temp-name-prefix)
|
|
|
|
(defconst tramp-compat-emacs-compiled-version (eval-when-compile emacs-version)
|
|
"The Emacs version used for compilation.")
|
|
|
|
(unless (= emacs-major-version
|
|
(car (version-to-list tramp-compat-emacs-compiled-version)))
|
|
(warn "Tramp has been compiled with Emacs %s, this is Emacs %s"
|
|
tramp-compat-emacs-compiled-version emacs-version))
|
|
|
|
;; 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.
|
|
(defmacro tramp-compat-funcall (function &rest arguments)
|
|
"Call FUNCTION with ARGUMENTS if it exists. Do not raise compiler warnings."
|
|
`(when (functionp ,function)
|
|
(with-no-warnings (funcall ,function ,@arguments))))
|
|
|
|
;; We must use a local directory. If it is remote, we could run into
|
|
;; an infloop.
|
|
(defconst tramp-compat-temporary-file-directory
|
|
(eval (car (get 'temporary-file-directory 'standard-value)) t)
|
|
"The default value of `temporary-file-directory'.")
|
|
|
|
(defsubst tramp-compat-make-temp-name ()
|
|
"Generate a local temporary file name (compat function)."
|
|
(make-temp-name
|
|
(expand-file-name
|
|
tramp-temp-name-prefix tramp-compat-temporary-file-directory)))
|
|
|
|
(defsubst tramp-compat-make-temp-file (f &optional dir-flag)
|
|
"Create a local temporary file (compat function).
|
|
Add the extension of F, if existing."
|
|
(make-temp-file
|
|
(expand-file-name
|
|
tramp-temp-name-prefix tramp-compat-temporary-file-directory)
|
|
dir-flag (file-name-extension f t)))
|
|
|
|
;; `file-name-quoted-p', `file-name-quote' and `file-name-unquote' got
|
|
;; a second argument in Emacs 27.1.
|
|
(defalias 'tramp-compat-file-name-quoted-p
|
|
(if (equal (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 "/:" (file-local-name name))))))
|
|
|
|
(defalias 'tramp-compat-file-name-quote
|
|
(if (equal (func-arity #'file-name-quote) '(1 . 2))
|
|
#'file-name-quote
|
|
(lambda (name &optional top)
|
|
"Add the quotation prefix \"/:\" to file NAME.
|
|
If NAME is a remote file name and TOP is nil, the local part of NAME is quoted."
|
|
(let ((file-name-handler-alist (unless top file-name-handler-alist)))
|
|
(if (tramp-compat-file-name-quoted-p name top)
|
|
name
|
|
(concat (file-remote-p name) "/:" (file-local-name name)))))))
|
|
|
|
(defalias 'tramp-compat-file-name-unquote
|
|
(if (equal (func-arity #'file-name-unquote) '(1 . 2))
|
|
#'file-name-unquote
|
|
(lambda (name &optional top)
|
|
"Remove quotation prefix \"/:\" from file NAME.
|
|
If NAME is a remote file name and TOP is nil, the local part of
|
|
NAME is unquoted."
|
|
(let* ((file-name-handler-alist (unless top file-name-handler-alist))
|
|
(localname (file-local-name name)))
|
|
(when (tramp-compat-file-name-quoted-p localname top)
|
|
(setq
|
|
localname (if (= (length localname) 2) "/" (substring localname 2))))
|
|
(concat (file-remote-p name) localname)))))
|
|
|
|
;; `tramp-syntax' has changed its meaning in Emacs 26.1. We still
|
|
;; 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)))
|
|
|
|
;; The signature of `tramp-make-tramp-file-name' has been changed.
|
|
;; Therefore, we cannot use `url-tramp-convert-url-to-tramp' prior
|
|
;; Emacs 26.1. We use `temporary-file-directory' as indicator.
|
|
(defconst tramp-compat-use-url-tramp-p (fboundp 'temporary-file-directory)
|
|
"Whether to use url-tramp.el.")
|
|
|
|
;; `exec-path' is new in Emacs 27.1.
|
|
(defalias 'tramp-compat-exec-path
|
|
(if (fboundp 'exec-path)
|
|
#'exec-path
|
|
(lambda ()
|
|
"List of directories to search programs to run in remote subprocesses."
|
|
(if-let ((handler (find-file-name-handler default-directory 'exec-path)))
|
|
(funcall handler 'exec-path)
|
|
exec-path))))
|
|
|
|
;; `time-equal-p' has appeared in Emacs 27.1.
|
|
(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))))))
|
|
|
|
;; `flatten-tree' has appeared in Emacs 27.1.
|
|
(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)))))
|
|
|
|
;; `progress-reporter-update' got argument SUFFIX in Emacs 27.1.
|
|
(defalias 'tramp-compat-progress-reporter-update
|
|
(if (equal (func-arity #'progress-reporter-update) '(1 . 3))
|
|
#'progress-reporter-update
|
|
(lambda (reporter &optional value _suffix)
|
|
(progress-reporter-update reporter value))))
|
|
|
|
;; `ignore-error' is new in Emacs Emacs 27.1.
|
|
(defmacro tramp-compat-ignore-error (condition &rest body)
|
|
"Execute BODY; if the error CONDITION occurs, return nil.
|
|
Otherwise, return result of last form in BODY.
|
|
|
|
CONDITION can also be a list of error conditions."
|
|
(declare (debug t) (indent 1))
|
|
`(condition-case nil (progn ,@body) (,condition nil)))
|
|
|
|
;; `file-modes', `set-file-modes' and `set-file-times' got argument
|
|
;; FLAG in Emacs 28.1.
|
|
(defalias 'tramp-compat-file-modes
|
|
(if (equal (func-arity #'file-modes) '(1 . 2))
|
|
#'file-modes
|
|
(lambda (filename &optional _flag)
|
|
(file-modes filename))))
|
|
|
|
(defalias 'tramp-compat-set-file-modes
|
|
(if (equal (func-arity #'set-file-modes) '(2 . 3))
|
|
#'set-file-modes
|
|
(lambda (filename mode &optional _flag)
|
|
(set-file-modes filename mode))))
|
|
|
|
(defalias 'tramp-compat-set-file-times
|
|
(if (equal (func-arity #'set-file-times) '(1 . 3))
|
|
#'set-file-times
|
|
(lambda (filename &optional timestamp _flag)
|
|
(set-file-times filename timestamp))))
|
|
|
|
;; `directory-files' and `directory-files-and-attributes' got argument
|
|
;; COUNT in Emacs 28.1.
|
|
(defalias 'tramp-compat-directory-files
|
|
(if (equal (func-arity #'directory-files) '(1 . 5))
|
|
#'directory-files
|
|
(lambda (directory &optional full match nosort _count)
|
|
(directory-files directory full match nosort))))
|
|
|
|
(defalias 'tramp-compat-directory-files-and-attributes
|
|
(if (equal (func-arity #'directory-files-and-attributes) '(1 . 6))
|
|
#'directory-files-and-attributes
|
|
(lambda (directory &optional full match nosort id-format _count)
|
|
(directory-files-and-attributes directory full match nosort id-format))))
|
|
|
|
;; `directory-empty-p' is new in Emacs 28.1.
|
|
(defalias 'tramp-compat-directory-empty-p
|
|
(if (fboundp 'directory-empty-p)
|
|
#'directory-empty-p
|
|
(lambda (dir)
|
|
(and (file-directory-p dir)
|
|
(null (tramp-compat-directory-files
|
|
dir nil directory-files-no-dot-files-regexp t 1))))))
|
|
|
|
;; Function `null-device' is new in Emacs 28.1.
|
|
(defalias 'tramp-compat-null-device
|
|
(if (fboundp 'null-device)
|
|
#'null-device
|
|
(lambda ()
|
|
(if (tramp-tramp-file-p default-directory) "/dev/null" null-device))))
|
|
|
|
;; Function `string-replace' is new in Emacs 28.1.
|
|
(defalias 'tramp-compat-string-replace
|
|
(if (fboundp 'string-replace)
|
|
#'string-replace
|
|
(lambda (from-string to-string in-string)
|
|
(let ((case-fold-search nil))
|
|
(replace-regexp-in-string
|
|
(regexp-quote from-string) to-string in-string t t)))))
|
|
|
|
;; Function `string-search' is new in Emacs 28.1.
|
|
(defalias 'tramp-compat-string-search
|
|
(if (fboundp 'string-search)
|
|
#'string-search
|
|
(lambda (needle haystack &optional start-pos)
|
|
(let ((case-fold-search nil))
|
|
(string-match-p (regexp-quote needle) haystack start-pos)))))
|
|
|
|
;; Function `make-lock-file-name' is new in Emacs 28.1.
|
|
(defalias 'tramp-compat-make-lock-file-name
|
|
(if (fboundp 'make-lock-file-name)
|
|
#'make-lock-file-name
|
|
(lambda (filename)
|
|
(expand-file-name
|
|
(concat
|
|
".#" (file-name-nondirectory filename))
|
|
(file-name-directory filename)))))
|
|
|
|
;; Function `file-name-concat' is new in Emacs 28.1.
|
|
(defalias 'tramp-compat-file-name-concat
|
|
(if (fboundp 'file-name-concat)
|
|
#'file-name-concat
|
|
(lambda (directory &rest components)
|
|
(let ((components (cl-remove-if (lambda (el)
|
|
(or (null el) (equal "" el)))
|
|
components))
|
|
file-name-handler-alist)
|
|
(if (null components)
|
|
directory
|
|
(apply #'tramp-compat-file-name-concat
|
|
(concat (unless (or (equal "" directory) (null directory))
|
|
(file-name-as-directory directory))
|
|
(car components))
|
|
(cdr components)))))))
|
|
|
|
(dolist (elt (all-completions "tramp-compat-" obarray 'functionp))
|
|
(put (intern elt) 'tramp-suppress-trace t))
|
|
|
|
(add-hook 'tramp-unload-hook
|
|
(lambda ()
|
|
(unload-feature 'tramp-loaddefs 'force)
|
|
(unload-feature 'tramp-compat 'force)))
|
|
|
|
(provide 'tramp-compat)
|
|
|
|
;;; TODO:
|
|
;;
|
|
;; * Starting with Emacs 27.1, there's no need to escape open
|
|
;; parentheses with a backslash in docstrings anymore.
|
|
;;
|
|
;; * Starting with Emacs 27.1, there's `make-empty-file'. Could be
|
|
;; used instead of `write-region'.
|
|
|
|
;;; tramp-compat.el ends here
|