diff options
| author | Mattias EngdegÄrd | 2020-02-13 20:06:48 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2020-02-13 20:43:42 +0100 |
| commit | 9f6a4bbcc96bef451c75a8a78e442dec87a0ddf0 (patch) | |
| tree | bde1d7ad47c8cea91a80c4391593515b3fd0d2ea /lisp | |
| parent | d1e8ce8bb6fadf3d034ae437ff1c1b81be7d5209 (diff) | |
| download | emacs-9f6a4bbcc96bef451c75a8a78e442dec87a0ddf0.tar.gz emacs-9f6a4bbcc96bef451c75a8a78e442dec87a0ddf0.zip | |
Remove the optional KEEP-ORDER argument to regexp-opt
This argument was added for the 'or' clause in rx, but it turned out
to be a bad idea (bug#37659), and there seems to be little other use
for it.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt): Remove KEEP-ORDER.
* doc/lispref/searching.texi (Regexp Functions):
* etc/NEWS: Remove it from the documentation.
* test/lisp/emacs-lisp/regexp-opt-tests.el (regexp-opt-test--match-all)
(regexp-opt-test--check-perm, regexp-opt-test--explain-perm)
(regexp-opt-keep-order, regexp-opt-longest-match): Simplify test.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/regexp-opt.el | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index 2cce4e63539..35a5fda184f 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el | |||
| @@ -84,7 +84,7 @@ | |||
| 84 | ;;; Code: | 84 | ;;; Code: |
| 85 | 85 | ||
| 86 | ;;;###autoload | 86 | ;;;###autoload |
| 87 | (defun regexp-opt (strings &optional paren keep-order) | 87 | (defun regexp-opt (strings &optional paren) |
| 88 | "Return a regexp to match a string in the list STRINGS. | 88 | "Return a regexp to match a string in the list STRINGS. |
| 89 | Each member of STRINGS is treated as a fixed string, not as a regexp. | 89 | Each member of STRINGS is treated as a fixed string, not as a regexp. |
| 90 | Optional PAREN specifies how the returned regexp is surrounded by | 90 | Optional PAREN specifies how the returned regexp is surrounded by |
| @@ -114,11 +114,8 @@ nil | |||
| 114 | necessary to ensure that a postfix operator appended to it will | 114 | necessary to ensure that a postfix operator appended to it will |
| 115 | apply to the whole expression. | 115 | apply to the whole expression. |
| 116 | 116 | ||
| 117 | The optional argument KEEP-ORDER, if non-nil, forces the match to | 117 | The returned regexp is ordered in such a way that it will always |
| 118 | be performed in the order given, as if the strings were made into | 118 | match the longest string possible. |
| 119 | a regexp by joining them with the `\\|' operator. If nil or | ||
| 120 | omitted, the returned regexp is will always match the longest | ||
| 121 | string possible. | ||
| 122 | 119 | ||
| 123 | Up to reordering, the resulting regexp is equivalent to but | 120 | Up to reordering, the resulting regexp is equivalent to but |
| 124 | usually more efficient than that of a simplified version: | 121 | usually more efficient than that of a simplified version: |
| @@ -140,34 +137,12 @@ usually more efficient than that of a simplified version: | |||
| 140 | (completion-ignore-case nil) | 137 | (completion-ignore-case nil) |
| 141 | (completion-regexp-list nil) | 138 | (completion-regexp-list nil) |
| 142 | (open (cond ((stringp paren) paren) (paren "\\("))) | 139 | (open (cond ((stringp paren) paren) (paren "\\("))) |
| 143 | (re | 140 | (re (if strings |
| 144 | (cond | 141 | (regexp-opt-group |
| 145 | ;; No strings: return an unmatchable regexp. | 142 | (delete-dups (sort (copy-sequence strings) 'string-lessp)) |
| 146 | ((null strings) | 143 | (or open t) (not open)) |
| 147 | (concat (or open "\\(?:") regexp-unmatchable "\\)")) | 144 | ;; No strings: return an unmatchable regexp. |
| 148 | 145 | (concat (or open "\\(?:") regexp-unmatchable "\\)")))) | |
| 149 | ;; The algorithm will generate a pattern that matches | ||
| 150 | ;; longer strings in the list before shorter. If the | ||
| 151 | ;; list order matters, then no string must come after a | ||
| 152 | ;; proper prefix of that string. To check this, verify | ||
| 153 | ;; that a straight or-pattern matches each string | ||
| 154 | ;; entirely. | ||
| 155 | ((and keep-order | ||
| 156 | (let* ((case-fold-search nil) | ||
| 157 | (alts (mapconcat #'regexp-quote strings "\\|"))) | ||
| 158 | (and (let ((s strings)) | ||
| 159 | (while (and s | ||
| 160 | (string-match alts (car s)) | ||
| 161 | (= (match-end 0) (length (car s)))) | ||
| 162 | (setq s (cdr s))) | ||
| 163 | ;; If we exited early, we found evidence that | ||
| 164 | ;; regexp-opt-group cannot be used. | ||
| 165 | s) | ||
| 166 | (concat (or open "\\(?:") alts "\\)"))))) | ||
| 167 | (t | ||
| 168 | (regexp-opt-group | ||
| 169 | (delete-dups (sort (copy-sequence strings) 'string-lessp)) | ||
| 170 | (or open t) (not open)))))) | ||
| 171 | (cond ((eq paren 'words) | 146 | (cond ((eq paren 'words) |
| 172 | (concat "\\<" re "\\>")) | 147 | (concat "\\<" re "\\>")) |
| 173 | ((eq paren 'symbols) | 148 | ((eq paren 'symbols) |