# HG changeset patch # User Stefan Monnier # Date 971031043 0 # Node ID e8fca08bb4ccce1a103101083038d301a79d6a24 # Parent 58dd951541e08ce5fe82756586a91b72f69be06f (regexp-opt): Add \< and \> if PAREN=`words'. diff -r 58dd951541e0 -r e8fca08bb4cc lisp/emacs-lisp/regexp-opt.el --- a/lisp/emacs-lisp/regexp-opt.el Sun Oct 08 18:30:12 2000 +0000 +++ b/lisp/emacs-lisp/regexp-opt.el Sun Oct 08 18:50:43 2000 +0000 @@ -93,14 +93,20 @@ 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)