]> git.eshelyaron.com Git - emacs.git/commitdiff
Tramp string-search and string-replace compatibility functions
authorMattias Engdegård <mattiase@acm.org>
Tue, 10 Aug 2021 13:05:51 +0000 (15:05 +0200)
committerMattias Engdegård <mattiase@acm.org>
Tue, 10 Aug 2021 13:05:51 +0000 (15:05 +0200)
Add a `string-search` compatibility function for use in Tramp with
Emacs version prior to 28, and fix the existing `string-replace`
compatibility function so that it uses the right semantics.

* lisp/net/tramp-compat.el (tramp-compat-string-replace):
Use case-sensitive matching and literal replacement.
(tramp-compat-string-search): New function.
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-name-all-completions):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-name-all-completions)
(tramp-do-copy-or-rename-file-out-of-band)
(tramp-sh-handle-make-process, tramp-sh-handle-process-file):
* lisp/net/tramp.el (tramp-handle-make-process):
Use `tramp-compat-string-search` instead of `string-match-p`.

lisp/net/tramp-compat.el
lisp/net/tramp-gvfs.el
lisp/net/tramp-sh.el
lisp/net/tramp.el

index 6e4640733799b637479812747d1e144aafb88a6e..b713d5eae825853c9f56bad469938e67390e2ab4 100644 (file)
@@ -351,7 +351,17 @@ A nil value for either argument stands for the current time."
   (if (fboundp 'string-replace)
       #'string-replace
     (lambda (fromstring tostring instring)
-      (replace-regexp-in-string (regexp-quote fromstring) tostring instring))))
+      (let ((case-fold-search nil))
+        (replace-regexp-in-string
+         (regexp-quote fromstring) tostring instring 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
index eff14a2912f4f2a71b7c4f5724a5787581ffe0a8..e4f54cf4c468b6ddcd8d7fefbbae2c9ca94fa53d 100644 (file)
@@ -1401,7 +1401,7 @@ If FILE-SYSTEM is non-nil, return file system attributes."
 
 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
-  (unless (string-match-p "/" filename)
+  (unless (tramp-compat-string-search "/" filename)
     (all-completions
      filename
      (with-parsed-tramp-file-name (expand-file-name directory) nil
index e7d2634c587f0409122b37c305a0be9903f777e3..c3b8df9e5797f1a99ad737ec820a3b4da66f9f44 100644 (file)
@@ -1740,7 +1740,7 @@ ID-FORMAT valid values are `string' and `integer'."
 ;; files.
 (defun tramp-sh-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
-  (unless (string-match-p "/" filename)
+  (unless (tramp-compat-string-search "/" filename)
     (all-completions
      filename
      (with-parsed-tramp-file-name (expand-file-name directory) nil
@@ -2309,7 +2309,8 @@ The method used must be an out-of-band method."
              copy-args
              (tramp-compat-flatten-tree
               (mapcar
-               (lambda (x) (if (string-match-p " " x) (split-string x) x))
+               (lambda (x) (if (tramp-compat-string-search " " x)
+                                (split-string x) x))
                copy-args))
              copy-env (apply #'tramp-expand-args v 'tramp-copy-env spec)
              remote-copy-program
@@ -2828,7 +2829,7 @@ implementation will be used."
                 (env (dolist (elt (cons prompt process-environment) env)
                        (or (member
                             elt (default-toplevel-value 'process-environment))
-                           (if (string-match-p "=" elt)
+                           (if (tramp-compat-string-search "=" elt)
                                (setq env (append env `(,elt)))
                              (setq uenv (cons elt uenv))))))
                 (env (setenv-internal
@@ -3039,7 +3040,7 @@ implementation will be used."
       ;; We use as environment the difference to toplevel `process-environment'.
       (dolist (elt process-environment)
         (or (member elt (default-toplevel-value 'process-environment))
-            (if (string-match-p "=" elt)
+            (if (tramp-compat-string-search "=" elt)
                 (setq env (append env `(,elt)))
               (setq uenv (cons elt uenv)))))
       (setenv-internal env "INSIDE_EMACS" (tramp-inside-emacs) 'keep)
index 3a392dd5f8af944f990d7b79164d5a4564aa0e47..fd426960fd2729da70cadc922b1f48067b9fa6b5 100644 (file)
@@ -4130,14 +4130,14 @@ substitution.  SPEC-LIST is a list of char/value pairs used for
                  (generate-new-buffer tramp-temp-buffer-name)))
               (env (mapcar
                     (lambda (elt)
-                      (when (string-match-p "=" elt) elt))
+                      (when (tramp-compat-string-search "=" elt) elt))
                     tramp-remote-process-environment))
               ;; We use as environment the difference to toplevel
               ;; `process-environment'.
               (env (dolist (elt process-environment env)
                      (when
                          (and
-                          (string-match-p "=" elt)
+                          (tramp-compat-string-search "=" elt)
                           (not
                            (member
                             elt (default-toplevel-value 'process-environment))))