diff options
| author | Juanma Barranquero | 2003-04-26 23:29:45 +0000 |
|---|---|---|
| committer | Juanma Barranquero | 2003-04-26 23:29:45 +0000 |
| commit | 59b2ee6929bad652fab10c85addc02e7394b1bf6 (patch) | |
| tree | c6bff0a168bf4beee1bf89eab0d9dd71460c7bcf | |
| parent | 569236cc98033ce85b42a8e35438f2616b6f921d (diff) | |
| download | emacs-59b2ee6929bad652fab10c85addc02e7394b1bf6.tar.gz emacs-59b2ee6929bad652fab10c85addc02e7394b1bf6.zip | |
(regexp-opt-depth): Don't count a "//(" which appears inside a character set.
(regexp-opt-not-groupie*-re): New constant.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/regexp-opt.el | 29 |
2 files changed, 30 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e04771d2188..f69e562a898 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2003-04-27 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | * emacs-lisp/regexp-opt.el (regexp-opt-depth): Don't count a "//(" | ||
| 4 | which appears inside a character set. | ||
| 5 | (regexp-opt-not-groupie*-re): New constant. | ||
| 6 | |||
| 1 | 2003-04-26 John Paul Wallington <jpw@gnu.org> | 7 | 2003-04-26 John Paul Wallington <jpw@gnu.org> |
| 2 | 8 | ||
| 3 | * ibuffer.el (ibuffer-name-map, ibuffer-mode-name-map) | 9 | * ibuffer.el (ibuffer-name-map, ibuffer-mode-name-map) |
diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index 486cf006e4b..11a66aa2a14 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el | |||
| @@ -110,6 +110,24 @@ by \\=\\< and \\>." | |||
| 110 | (re (regexp-opt-group sorted-strings open))) | 110 | (re (regexp-opt-group sorted-strings open))) |
| 111 | (if words (concat "\\<" re "\\>") re)))) | 111 | (if words (concat "\\<" re "\\>") re)))) |
| 112 | 112 | ||
| 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 | |||
| 113 | ;;;###autoload | 131 | ;;;###autoload |
| 114 | (defun regexp-opt-depth (regexp) | 132 | (defun regexp-opt-depth (regexp) |
| 115 | "Return the depth of REGEXP. | 133 | "Return the depth of REGEXP. |
| @@ -120,11 +138,12 @@ in REGEXP." | |||
| 120 | (string-match regexp "") | 138 | (string-match regexp "") |
| 121 | ;; Count the number of open parentheses in REGEXP. | 139 | ;; Count the number of open parentheses in REGEXP. |
| 122 | (let ((count 0) start) | 140 | (let ((count 0) start) |
| 123 | (while (string-match "\\(\\`\\|[^\\]\\)\\\\\\(\\\\\\\\\\)*([^?]" | 141 | (while |
| 124 | regexp start) | 142 | (progn |
| 125 | (setq count (1+ count) | 143 | (string-match regexp-opt-not-groupie*-re regexp start) |
| 126 | ;; Go back 2 chars (one for [^?] and one for [^\\]). | 144 | (setq start ( + (match-end 0) 2)) ; +2 for "\\(" after match-end. |
| 127 | start (- (match-end 0) 2))) | 145 | (<= start (length regexp))) |
| 146 | (setq count (1+ count))) | ||
| 128 | count))) | 147 | count))) |
| 129 | 148 | ||
| 130 | ;;; Workhorse functions. | 149 | ;;; Workhorse functions. |