aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2019-09-23 18:56:30 +0200
committerMattias EngdegÄrd2019-09-25 18:09:42 +0200
commita773a6474897356cd78aeea092d2c1a51ede23f9 (patch)
tree9935673b464dc14a03a70a36c6ce7756404f0337
parent84567150e757ee3991a4b4f96a27080f92cb6d48 (diff)
downloademacs-a773a6474897356cd78aeea092d2c1a51ede23f9.tar.gz
emacs-a773a6474897356cd78aeea092d2c1a51ede23f9.zip
Allow regexp-quote to return its argument
* src/search.c (Fregexp_quote): Only allocate a new string if needed. * doc/lispref/searching.texi (Regexp Functions): * etc/NEWS (Incompatible Lisp Changes): Document.
-rw-r--r--doc/lispref/searching.texi3
-rw-r--r--etc/NEWS4
-rw-r--r--src/search.c10
3 files changed, 13 insertions, 4 deletions
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index 1286b63446a..65f56b490fd 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -1562,6 +1562,9 @@ whitespace:
1562 (concat "\\s-" (regexp-quote string) "\\s-")) 1562 (concat "\\s-" (regexp-quote string) "\\s-"))
1563@end group 1563@end group
1564@end example 1564@end example
1565
1566The returned string may be @var{string} itself if it does not contain
1567any special characters.
1565@end defun 1568@end defun
1566 1569
1567@cindex optimize regexp 1570@cindex optimize regexp
diff --git a/etc/NEWS b/etc/NEWS
index 3072d4081b8..96b2cb129bd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2157,6 +2157,10 @@ valid event type.
2157be specified in image specs representing the entire bitmap as a single 2157be specified in image specs representing the entire bitmap as a single
2158bool vector. 2158bool vector.
2159 2159
2160+++
2161** 'regexp-quote' may return its argument string.
2162If the argument needs no quoting, it can be returned instead of a copy.
2163
2160 2164
2161* Lisp Changes in Emacs 27.1 2165* Lisp Changes in Emacs 27.1
2162 2166
diff --git a/src/search.c b/src/search.c
index 1e57d2ecbe5..9d95dcbca58 100644
--- a/src/search.c
+++ b/src/search.c
@@ -3138,10 +3138,12 @@ DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
3138 } 3138 }
3139 3139
3140 Lisp_Object result 3140 Lisp_Object result
3141 = make_specified_string (temp, 3141 = (backslashes_added > 0
3142 SCHARS (string) + backslashes_added, 3142 ? make_specified_string (temp,
3143 out - temp, 3143 SCHARS (string) + backslashes_added,
3144 STRING_MULTIBYTE (string)); 3144 out - temp,
3145 STRING_MULTIBYTE (string))
3146 : string);
3145 SAFE_FREE (); 3147 SAFE_FREE ();
3146 return result; 3148 return result;
3147} 3149}