aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorMattias EngdegÄrd2019-02-24 22:12:52 +0100
committerMattias EngdegÄrd2019-03-02 15:35:28 +0100
commitda758046da74e33273265cd2e72a8aa1a0c9c7e3 (patch)
tree4337523f0b56c12d69f27a91ee0a1b61376c0e7e /doc
parentdbffbe08815644fd30404891ef81496277ed27da (diff)
downloademacs-da758046da74e33273265cd2e72a8aa1a0c9c7e3.tar.gz
emacs-da758046da74e33273265cd2e72a8aa1a0c9c7e3.zip
rx: fix `or' ordering by adding argument to regexp-opt
The rx `or' form may reorder its arguments in an unpredictable way, contrary to user expectation, since it sometimes uses `regexp-opt'. Add a NOREORDER option to `regexp-opt' for preventing it from producing a reordered regexp (Bug#34641). * doc/lispref/searching.texi (Regular Expression Functions): * etc/NEWS (Lisp Changes in Emacs 27.1): Describe the new regexp-opt NOREORDER argument. * lisp/emacs-lisp/regexp-opt.el (regexp-opt): Add NOREORDER. Make no attempt at regexp improvement if the set of strings contains a prefix of another string. (regexp-opt--contains-prefix): New. * lisp/emacs-lisp/rx.el (rx-or): Call regexp-opt with NOREORDER. * test/lisp/emacs-lisp/rx-tests.el: Test rx `or' form match order.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/searching.texi13
1 files changed, 10 insertions, 3 deletions
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index cfbd2449b13..fb7f48474d5 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -950,7 +950,7 @@ whitespace:
950@end defun 950@end defun
951 951
952@cindex optimize regexp 952@cindex optimize regexp
953@defun regexp-opt strings &optional paren 953@defun regexp-opt strings &optional paren noreorder
954This function returns an efficient regular expression that will match 954This function returns an efficient regular expression that will match
955any of the strings in the list @var{strings}. This is useful when you 955any of the strings in the list @var{strings}. This is useful when you
956need to make matching or searching as fast as possible---for example, 956need to make matching or searching as fast as possible---for example,
@@ -985,8 +985,15 @@ if it is necessary to ensure that a postfix operator appended to
985it will apply to the whole expression. 985it will apply to the whole expression.
986@end table 986@end table
987 987
988The resulting regexp of @code{regexp-opt} is equivalent to but usually 988The optional argument @var{noreorder}, if @code{nil} or omitted,
989more efficient than that of a simplified version: 989allows the returned regexp to match the strings in any order. If
990non-@code{nil}, the match is guaranteed to be performed in the order
991given, as if the strings were made into a regexp by joining them with
992the @samp{\|} operator.
993
994Up to reordering, the resulting regexp of @code{regexp-opt} is
995equivalent to but usually more efficient than that of a simplified
996version:
990 997
991@example 998@example
992(defun simplified-regexp-opt (strings &optional paren) 999(defun simplified-regexp-opt (strings &optional paren)