From: Juri Linkov Date: Sat, 18 Sep 2021 18:42:17 +0000 (+0300) Subject: * lisp/subr.el (string-replace): Add dashes to arg names (bug#50644) X-Git-Tag: emacs-28.0.90~855 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4b3dc7a139c426bad52d3aa145b4868c9b44a325;p=emacs.git * lisp/subr.el (string-replace): Add dashes to arg names (bug#50644) * lisp/net/tramp-compat.el (tramp-compat-string-replace): Idem. * doc/lispref/searching.texi (Search and Replace): Idem. --- diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index 68061f0b09f..0dcf3889a59 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi @@ -2620,9 +2620,9 @@ replacement string. The match data at this point are the result of matching @var{regexp} against a substring of @var{string}. @end defun -@defun string-replace fromstring tostring instring -This function replaces all occurrences of @var{fromstring} with -@var{tostring} in @var{instring} and returns the result. It may +@defun string-replace from-string to-string in-string +This function replaces all occurrences of @var{from-string} with +@var{to-string} in @var{in-string} and returns the result. It may return one of its arguments unchanged, a constant string or a new string. Case is significant, and text properties are ignored. @end defun diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 125f82592f4..e6f1d9df70f 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -359,10 +359,10 @@ CONDITION can also be a list of error conditions." (defalias 'tramp-compat-string-replace (if (fboundp 'string-replace) #'string-replace - (lambda (fromstring tostring instring) + (lambda (from-string to-string in-string) (let ((case-fold-search nil)) (replace-regexp-in-string - (regexp-quote fromstring) tostring instring t t))))) + (regexp-quote from-string) to-string in-string t t))))) ;; Function `string-search' is new in Emacs 28.1. (defalias 'tramp-compat-string-search diff --git a/lisp/subr.el b/lisp/subr.el index a2266b1d576..c2cfc18bd7a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4937,25 +4937,25 @@ Unless optional argument INPLACE is non-nil, return a new string." (aset newstr i tochar))) newstr)) -(defun string-replace (fromstring tostring instring) - "Replace FROMSTRING with TOSTRING in INSTRING each time it occurs." +(defun string-replace (from-string to-string in-string) + "Replace FROM-STRING with TO-STRING in IN-STRING each time it occurs." (declare (pure t) (side-effect-free t)) - (when (equal fromstring "") + (when (equal from-string "") (signal 'wrong-length-argument '(0))) (let ((start 0) (result nil) pos) - (while (setq pos (string-search fromstring instring start)) + (while (setq pos (string-search from-string in-string start)) (unless (= start pos) - (push (substring instring start pos) result)) - (push tostring result) - (setq start (+ pos (length fromstring)))) + (push (substring in-string start pos) result)) + (push to-string result) + (setq start (+ pos (length from-string)))) (if (null result) ;; No replacements were done, so just return the original string. - instring + in-string ;; Get any remaining bit. - (unless (= start (length instring)) - (push (substring instring start) result)) + (unless (= start (length in-string)) + (push (substring in-string start) result)) (apply #'concat (nreverse result))))) (defun replace-regexp-in-string (regexp rep string &optional