emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1572464: Tramp string-search and string-replace compatibility fun


From: Mattias Engdegård
Subject: master 1572464: Tramp string-search and string-replace compatibility functions
Date: Tue, 10 Aug 2021 09:11:53 -0400 (EDT)

branch: master
commit 1572464b9271472b8d7a36b698541afc59b44870
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Tramp string-search and string-replace compatibility functions
    
    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 | 12 +++++++++++-
 lisp/net/tramp-gvfs.el   |  2 +-
 lisp/net/tramp-sh.el     |  9 +++++----
 lisp/net/tramp.el        |  4 ++--
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 6e46407..b713d5e 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -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
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index eff14a2..e4f54cf 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -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
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index e7d2634..c3b8df9 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -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)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 3a392dd..fd42696 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]