summaryrefslogtreecommitdiff
path: root/lisp/net/tramp-compat.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/net/tramp-compat.el')
-rw-r--r--lisp/net/tramp-compat.el38
1 files changed, 28 insertions, 10 deletions
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 6e464073379..213ab5857c5 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -63,25 +63,24 @@
`(when (functionp ,function)
(with-no-warnings (funcall ,function ,@arguments))))
-(defsubst tramp-compat-temporary-file-directory ()
- "Return name of directory for temporary files.
-It is the default value of `temporary-file-directory'."
- ;; We must return a local directory. If it is remote, we could run
- ;; into an infloop.
- (eval (car (get 'temporary-file-directory 'standard-value)) t))
+;; 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))))
+ 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))
+ tramp-temp-name-prefix tramp-compat-temporary-file-directory)
dir-flag (file-name-extension f t)))
;; `temporary-file-directory' as function is introduced with Emacs 26.1.
@@ -295,6 +294,15 @@ A nil value for either argument stands for the current time."
(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
@@ -350,8 +358,18 @@ A nil value for either argument stands for the current time."
(defalias 'tramp-compat-string-replace
(if (fboundp 'string-replace)
#'string-replace
- (lambda (fromstring tostring instring)
- (replace-regexp-in-string (regexp-quote fromstring) tostring instring))))
+ (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