diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2000-10-08 18:50:43 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2000-10-08 18:50:43 +0000 |
commit | 908bb42fa10fee60a8e84dd698da504d8e8ef9f6 (patch) | |
tree | 781108db96c18d9d0b3ff23c911ea84556460944 /lisp/emacs-lisp/regexp-opt.el | |
parent | 4c724b3225afad427149a934d66da4e88565d1f6 (diff) | |
download | emacs-908bb42fa10fee60a8e84dd698da504d8e8ef9f6.tar.gz |
(regexp-opt): Add \< and \> if PAREN=`words'.
Diffstat (limited to 'lisp/emacs-lisp/regexp-opt.el')
-rw-r--r-- | lisp/emacs-lisp/regexp-opt.el | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index b938db6c82b..de36f1d5446 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el @@ -93,14 +93,20 @@ 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: - (let ((open-paren (if PAREN \"\\\\(\" \"\")) (close-paren (if PAREN \"\\\\)\" \"\"))) - (concat open-paren (mapconcat 'regexp-quote STRINGS \"\\\\|\") close-paren))" + (let ((open (if PAREN \"\\\\(\" \"\")) (close (if PAREN \"\\\\)\" \"\"))) + (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close)) + +If PAREN is `words', then the resulting regexp is additionally surrounded +by \\=\\< and \\>." (save-match-data ;; Recurse on the sorted list. - (let ((max-lisp-eval-depth (* 1024 1024)) - (completion-ignore-case nil)) - (setq paren (cond ((stringp paren) paren) (paren "\\("))) - (regexp-opt-group (sort (copy-sequence strings) 'string-lessp) paren)))) + (let* ((max-lisp-eval-depth (* 1024 1024)) + (completion-ignore-case nil) + (words (eq paren 'words)) + (open (cond ((stringp paren) paren) (paren "\\("))) + (sorted-strings (sort (copy-sequence strings) 'string-lessp)) + (re (regexp-opt-group sorted-strings open))) + (if words (concat "\\<" re "\\>") re)))) ;;;###autoload (defun regexp-opt-depth (regexp) |