aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2004-12-06 15:12:46 +0000
committerStefan Monnier2004-12-06 15:12:46 +0000
commit22864a4875d08e83c49069633ddd68badbbe554b (patch)
tree25ae740fd123c76fe7974903ee6d955eb6ce13a3
parent30bb14430cc6dd9bc44a5b561e2addabc592f4b0 (diff)
downloademacs-22864a4875d08e83c49069633ddd68badbbe554b.tar.gz
emacs-22864a4875d08e83c49069633ddd68badbbe554b.zip
(regexp-opt-depth): Use subregexp-context-p.
(regexp-opt-not-groupie*-re): Remove. (regexp-opt): Properly handle inputs with duplicate entries.
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/emacs-lisp/regexp-opt.el46
2 files changed, 30 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 45612389e0e..73331951608 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12004-12-06 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * subr.el (subregexp-context-p): New function.
4
5 * isearch.el (isearch-quote-char): Use it.
6
7 * emacs-lisp/regexp-opt.el (regexp-opt-depth): Use it.
8 (regexp-opt-not-groupie*-re): Remove.
9 (regexp-opt): Properly handle inputs with duplicate entries.
10
12004-12-06 Richard M. Stallman <rms@gnu.org> 112004-12-06 Richard M. Stallman <rms@gnu.org>
2 12
3 * info-look.el (info-lookup-maybe-add-help cfengine-mode): Regexp typo. 13 * info-look.el (info-lookup-maybe-add-help cfengine-mode): Regexp typo.
@@ -12,13 +22,13 @@
12 22
132004-12-05 Sam Steingold <sds@gnu.org> 232004-12-05 Sam Steingold <sds@gnu.org>
14 24
15 * net/tramp.el (tramp-handle-file-accessible-directory-p): Fixed 25 * net/tramp.el (tramp-handle-file-accessible-directory-p):
16 `tramp-time-diff' comparison logic 26 Fix `tramp-time-diff' comparison logic
17 27
182004-12-05 Paul Pogonyshev <pogonyshev@gmx.net> 282004-12-05 Paul Pogonyshev <pogonyshev@gmx.net>
19 29
20 * progmodes/which-func.el (which-function): Use 30 * progmodes/which-func.el (which-function):
21 `run-hook-with-args-until-success' instead of a custom loop. 31 Use `run-hook-with-args-until-success' instead of a custom loop.
22 Fixes bug with local hooks. 32 Fixes bug with local hooks.
23 33
242004-12-05 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> 342004-12-05 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el
index f24789eb4a1..3537a83c3c1 100644
--- a/lisp/emacs-lisp/regexp-opt.el
+++ b/lisp/emacs-lisp/regexp-opt.el
@@ -1,6 +1,7 @@
1;;; regexp-opt.el --- generate efficient regexps to match strings 1;;; regexp-opt.el --- generate efficient regexps to match strings
2 2
3;; Copyright (C) 1994,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004
4;; Free Software Foundation, Inc.
4 5
5;; Author: Simon Marshall <simon@gnu.org> 6;; Author: Simon Marshall <simon@gnu.org>
6;; Maintainer: FSF 7;; Maintainer: FSF
@@ -106,44 +107,29 @@ by \\=\\< and \\>."
106 (completion-regexp-list nil) 107 (completion-regexp-list nil)
107 (words (eq paren 'words)) 108 (words (eq paren 'words))
108 (open (cond ((stringp paren) paren) (paren "\\("))) 109 (open (cond ((stringp paren) paren) (paren "\\(")))
109 (sorted-strings (sort (copy-sequence strings) 'string-lessp)) 110 (sorted-strings (delete-dups
111 (sort (copy-sequence strings) 'string-lessp)))
110 (re (regexp-opt-group sorted-strings open))) 112 (re (regexp-opt-group sorted-strings open)))
111 (if words (concat "\\<" re "\\>") re)))) 113 (if words (concat "\\<" re "\\>") re))))
112 114
113(defconst regexp-opt-not-groupie*-re
114 (let* ((harmless-ch "[^\\\\[]")
115 (esc-pair-not-lp "\\\\[^(]")
116 (class-harmless-ch "[^][]")
117 (class-lb-harmless "[^]:]")
118 (class-lb-colon-maybe-charclass ":\\([a-z]+:]\\)?")
119 (class-lb (concat "\\[\\(" class-lb-harmless
120 "\\|" class-lb-colon-maybe-charclass "\\)"))
121 (class
122 (concat "\\[^?]?"
123 "\\(" class-harmless-ch
124 "\\|" class-lb "\\)*"
125 "\\[?]")) ; special handling for bare [ at end of re
126 (shy-lp "\\\\(\\?:"))
127 (concat "\\(" harmless-ch "\\|" esc-pair-not-lp
128 "\\|" class "\\|" shy-lp "\\)*"))
129 "Matches any part of a regular expression EXCEPT for non-shy \"\\\\(\"s")
130
131;;;###autoload 115;;;###autoload
132(defun regexp-opt-depth (regexp) 116(defun regexp-opt-depth (regexp)
133 "Return the depth of REGEXP. 117 "Return the depth of REGEXP.
134This means the number of regexp grouping constructs (parenthesised expressions) 118This means the number of non-shy regexp grouping constructs
135in REGEXP." 119\(parenthesised expressions) in REGEXP."
136 (save-match-data 120 (save-match-data
137 ;; Hack to signal an error if REGEXP does not have balanced parentheses. 121 ;; Hack to signal an error if REGEXP does not have balanced parentheses.
138 (string-match regexp "") 122 (string-match regexp "")
139 ;; Count the number of open parentheses in REGEXP. 123 ;; Count the number of open parentheses in REGEXP.
140 (let ((count 0) start) 124 (let ((count 0) start last)
141 (while 125 (while (string-match "\\\\(\\(\\?:\\)?" regexp start)
142 (progn 126 (setq start (match-end 0)) ; Start of next search.
143 (string-match regexp-opt-not-groupie*-re regexp start) 127 (when (and (not (match-beginning 1))
144 (setq start ( + (match-end 0) 2)) ; +2 for "\\(" after match-end. 128 (subregexp-context-p regexp (match-beginning 0) last))
145 (<= start (length regexp))) 129 ;; It's not a shy group and it's not inside brackets or after
146 (setq count (1+ count))) 130 ;; a backslash: it's really a group-open marker.
131 (setq last start) ; Speed up next regexp-opt-re-context-p.
132 (setq count (1+ count))))
147 count))) 133 count)))
148 134
149;;; Workhorse functions. 135;;; Workhorse functions.
@@ -299,5 +285,5 @@ in REGEXP."
299 285
300(provide 'regexp-opt) 286(provide 'regexp-opt)
301 287
302;;; arch-tag: 6c5a66f4-29af-4fd6-8c3b-4b554d5b4370 288;; arch-tag: 6c5a66f4-29af-4fd6-8c3b-4b554d5b4370
303;;; regexp-opt.el ends here 289;;; regexp-opt.el ends here