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`.
This commit is contained in:
Mattias Engdegård 2021-08-10 15:05:51 +02:00
parent 75de09b9de
commit 1572464b92
4 changed files with 19 additions and 8 deletions

View 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

View 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

View 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)

View 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))))