comparison lisp/emacs-lisp/regexp-opt.el @ 110801:37b955157790

(regexp-opt): Add `symbols' mode.
author Miles Bader <miles@gnu.org>
date Thu, 07 Oct 2010 16:24:21 +0900
parents b10051866f51
children 1e7d8f405703
comparison
equal deleted inserted replaced
110800:751b2ae689b5 110801:37b955157790
94 94
95 (let ((open (if PAREN \"\\\\(\" \"\")) (close (if PAREN \"\\\\)\" \"\"))) 95 (let ((open (if PAREN \"\\\\(\" \"\")) (close (if PAREN \"\\\\)\" \"\")))
96 (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close)) 96 (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close))
97 97
98 If PAREN is `words', then the resulting regexp is additionally surrounded 98 If PAREN is `words', then the resulting regexp is additionally surrounded
99 by \\=\\< and \\>." 99 by \\=\\< and \\>.
100 If PAREN is `symbols', then the resulting regexp is additionally surrounded
101 by \\=\\_< and \\_>."
100 (save-match-data 102 (save-match-data
101 ;; Recurse on the sorted list. 103 ;; Recurse on the sorted list.
102 (let* ((max-lisp-eval-depth 10000) 104 (let* ((max-lisp-eval-depth 10000)
103 (max-specpdl-size 10000) 105 (max-specpdl-size 10000)
104 (completion-ignore-case nil) 106 (completion-ignore-case nil)
105 (completion-regexp-list nil) 107 (completion-regexp-list nil)
106 (words (eq paren 'words))
107 (open (cond ((stringp paren) paren) (paren "\\("))) 108 (open (cond ((stringp paren) paren) (paren "\\(")))
108 (sorted-strings (delete-dups 109 (sorted-strings (delete-dups
109 (sort (copy-sequence strings) 'string-lessp))) 110 (sort (copy-sequence strings) 'string-lessp)))
110 (re (regexp-opt-group sorted-strings (or open t) (not open)))) 111 (re (regexp-opt-group sorted-strings (or open t) (not open))))
111 (if words (concat "\\<" re "\\>") re)))) 112 (cond ((eq paren 'words)
113 (concat "\\<" re "\\>"))
114 ((eq paren 'symbols)
115 (concat "\\_<" re "\\_>"))
116 (t re)))))
112 117
113 ;;;###autoload 118 ;;;###autoload
114 (defun regexp-opt-depth (regexp) 119 (defun regexp-opt-depth (regexp)
115 "Return the depth of REGEXP. 120 "Return the depth of REGEXP.
116 This means the number of non-shy regexp grouping constructs 121 This means the number of non-shy regexp grouping constructs