diff options
author | immerrr <immerrr@gmail.com> | 2016-02-07 12:46:37 +0300 |
---|---|---|
committer | Noam Postavsky <npostavs@gmail.com> | 2016-09-03 23:50:42 -0400 |
commit | 56bf7d7e274e1ab68c28516026d0510173c41904 (patch) | |
tree | fc86bca30cf126c65ff3d116f04b24b18c96b96e /lisp/emacs-lisp/regexp-opt.el | |
parent | 803ad6f7e7a9c6bcf8a6cbf8eaad17501b114a33 (diff) | |
download | emacs-56bf7d7e274e1ab68c28516026d0510173c41904.tar.gz emacs-56bf7d7e274e1ab68c28516026d0510173c41904.tar.bz2 emacs-56bf7d7e274e1ab68c28516026d0510173c41904.zip |
Fix regexp-opt documentation (bug #17862)
* lisp/emacs-lisp/regexp-opt.el (regexp-opt):
* doc/lispref/searching.texi (Regexp Functions): Update PAREN doc.
Diffstat (limited to 'lisp/emacs-lisp/regexp-opt.el')
-rw-r--r-- | lisp/emacs-lisp/regexp-opt.el | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index b1e132a76e3..27db4773b1d 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el @@ -86,18 +86,44 @@ ;;;###autoload (defun regexp-opt (strings &optional paren) "Return a regexp to match a string in the list STRINGS. -Each string should be unique in STRINGS and should not contain any regexps, -quoted or not. If optional PAREN is non-nil, ensure that the returned regexp -is enclosed by at least one regexp grouping construct. -The returned regexp is typically more efficient than the equivalent regexp: +Each string should be unique in STRINGS and should not contain +any regexps, quoted or not. Optional PAREN specifies how the +returned regexp is surrounded by grouping constructs. - (let ((open (if PAREN \"\\\\(\" \"\")) (close (if PAREN \"\\\\)\" \"\"))) - (concat open (mapconcat \\='regexp-quote STRINGS \"\\\\|\") close)) +The optional argument PAREN can be any of the following: -If PAREN is `words', then the resulting regexp is additionally surrounded -by \\=\\< and \\>. -If PAREN is `symbols', then the resulting regexp is additionally surrounded -by \\=\\_< and \\_>." +a string + the resulting regexp is preceded by PAREN and followed by + \\), e.g. use \"\\\\(?1:\" to produce an explicitly numbered + group. + +`words' + the resulting regexp is surrounded by \\=\\<\\( and \\)\\>. + +`symbols' + the resulting regexp is surrounded by \\_<\\( and \\)\\_>. + +non-nil + the resulting regexp is surrounded by \\( and \\). + +nil + the resulting regexp is surrounded by \\(?: and \\), if it is + necessary to ensure that a postfix operator appended to it will + apply to the whole expression. + +The resulting regexp is equivalent to but usually more efficient +than that of a simplified version: + + (defun simplified-regexp-opt (strings &optional paren) + (let ((parens + (cond ((stringp paren) (cons paren \"\\\\)\")) + ((eq paren 'words) '(\"\\\\\\=<\\\\(\" . \"\\\\)\\\\>\")) + ((eq paren 'symbols) '(\"\\\\_<\\\\(\" . \"\\\\)\\\\_>\")) + ((null paren) '(\"\\\\(?:\" . \"\\\\)\")) + (t '(\"\\\\(\" . \"\\\\)\"))))) + (concat (car paren) + (mapconcat 'regexp-quote strings \"\\\\|\") + (cdr paren))))" (save-match-data ;; Recurse on the sorted list. (let* ((max-lisp-eval-depth 10000) |