diff options
| author | Stefan Monnier | 2000-10-08 18:50:43 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-10-08 18:50:43 +0000 |
| commit | 908bb42fa10fee60a8e84dd698da504d8e8ef9f6 (patch) | |
| tree | 781108db96c18d9d0b3ff23c911ea84556460944 | |
| parent | 4c724b3225afad427149a934d66da4e88565d1f6 (diff) | |
| download | emacs-908bb42fa10fee60a8e84dd698da504d8e8ef9f6.tar.gz emacs-908bb42fa10fee60a8e84dd698da504d8e8ef9f6.zip | |
(regexp-opt): Add \< and \> if PAREN=`words'.
| -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 | |||
| 93 | is enclosed by at least one regexp grouping construct. | 93 | is enclosed by at least one regexp grouping construct. |
| 94 | The returned regexp is typically more efficient than the equivalent regexp: | 94 | The returned regexp is typically more efficient than the equivalent regexp: |
| 95 | 95 | ||
| 96 | (let ((open-paren (if PAREN \"\\\\(\" \"\")) (close-paren (if PAREN \"\\\\)\" \"\"))) | 96 | (let ((open (if PAREN \"\\\\(\" \"\")) (close (if PAREN \"\\\\)\" \"\"))) |
| 97 | (concat open-paren (mapconcat 'regexp-quote STRINGS \"\\\\|\") close-paren))" | 97 | (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close)) |
| 98 | |||
| 99 | If PAREN is `words', then the resulting regexp is additionally surrounded | ||
| 100 | by \\=\\< and \\>." | ||
| 98 | (save-match-data | 101 | (save-match-data |
| 99 | ;; Recurse on the sorted list. | 102 | ;; Recurse on the sorted list. |
| 100 | (let ((max-lisp-eval-depth (* 1024 1024)) | 103 | (let* ((max-lisp-eval-depth (* 1024 1024)) |
| 101 | (completion-ignore-case nil)) | 104 | (completion-ignore-case nil) |
| 102 | (setq paren (cond ((stringp paren) paren) (paren "\\("))) | 105 | (words (eq paren 'words)) |
| 103 | (regexp-opt-group (sort (copy-sequence strings) 'string-lessp) paren)))) | 106 | (open (cond ((stringp paren) paren) (paren "\\("))) |
| 107 | (sorted-strings (sort (copy-sequence strings) 'string-lessp)) | ||
| 108 | (re (regexp-opt-group sorted-strings open))) | ||
| 109 | (if words (concat "\\<" re "\\>") re)))) | ||
| 104 | 110 | ||
| 105 | ;;;###autoload | 111 | ;;;###autoload |
| 106 | (defun regexp-opt-depth (regexp) | 112 | (defun regexp-opt-depth (regexp) |