]> git.eshelyaron.com Git - emacs.git/commitdiff
(regexp-opt-depth): Use subregexp-context-p.
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 6 Dec 2004 15:12:46 +0000 (15:12 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 6 Dec 2004 15:12:46 +0000 (15:12 +0000)
(regexp-opt-not-groupie*-re): Remove.
(regexp-opt): Properly handle inputs with duplicate entries.

lisp/ChangeLog
lisp/emacs-lisp/regexp-opt.el

index 45612389e0e38580e12d85d8cc494a820ca797b4..73331951608b7eb3d1fdfe9445af1d6a2e77ed34 100644 (file)
@@ -1,3 +1,13 @@
+2004-12-06  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * subr.el (subregexp-context-p): New function.
+
+       * isearch.el (isearch-quote-char): Use it.
+
+       * emacs-lisp/regexp-opt.el (regexp-opt-depth): Use it.
+       (regexp-opt-not-groupie*-re): Remove.
+       (regexp-opt): Properly handle inputs with duplicate entries.
+
 2004-12-06  Richard M. Stallman  <rms@gnu.org>
 
        * info-look.el (info-lookup-maybe-add-help cfengine-mode): Regexp typo.
 
 2004-12-05  Sam Steingold  <sds@gnu.org>
 
-       * net/tramp.el (tramp-handle-file-accessible-directory-p): Fixed
-       `tramp-time-diff' comparison logic
+       * net/tramp.el (tramp-handle-file-accessible-directory-p):
+       Fix `tramp-time-diff' comparison logic
 
 2004-12-05  Paul Pogonyshev  <pogonyshev@gmx.net>
 
-       * progmodes/which-func.el (which-function): Use
-       `run-hook-with-args-until-success' instead of a custom loop.
+       * progmodes/which-func.el (which-function):
+       Use `run-hook-with-args-until-success' instead of a custom loop.
        Fixes bug with local hooks.
 
 2004-12-05  Roland Winkler  <Roland.Winkler@physik.uni-erlangen.de>
index f24789eb4a14ad338724482bdd74c2f3851f39a0..3537a83c3c1346215bc70ac28c47e2aee9bc49eb 100644 (file)
@@ -1,6 +1,7 @@
 ;;; regexp-opt.el --- generate efficient regexps to match strings
 
-;; Copyright (C) 1994,95,96,97,98,99,2000 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004
+;;           Free Software Foundation, Inc.
 
 ;; Author: Simon Marshall <simon@gnu.org>
 ;; Maintainer: FSF
@@ -106,44 +107,29 @@ by \\=\\< and \\>."
           (completion-regexp-list nil)
           (words (eq paren 'words))
           (open (cond ((stringp paren) paren) (paren "\\(")))
-          (sorted-strings (sort (copy-sequence strings) 'string-lessp))
+          (sorted-strings (delete-dups
+                           (sort (copy-sequence strings) 'string-lessp)))
           (re (regexp-opt-group sorted-strings open)))
       (if words (concat "\\<" re "\\>") re))))
 
-(defconst regexp-opt-not-groupie*-re
-  (let* ((harmless-ch "[^\\\\[]")
-         (esc-pair-not-lp "\\\\[^(]")
-         (class-harmless-ch "[^][]")
-         (class-lb-harmless "[^]:]")
-         (class-lb-colon-maybe-charclass ":\\([a-z]+:]\\)?")
-         (class-lb (concat "\\[\\(" class-lb-harmless
-                           "\\|" class-lb-colon-maybe-charclass "\\)"))
-         (class
-          (concat "\\[^?]?"
-                  "\\(" class-harmless-ch
-                  "\\|" class-lb "\\)*"
-                  "\\[?]"))         ; special handling for bare [ at end of re
-         (shy-lp "\\\\(\\?:"))
-    (concat "\\(" harmless-ch "\\|" esc-pair-not-lp
-            "\\|" class "\\|" shy-lp "\\)*"))
-  "Matches any part of a regular expression EXCEPT for non-shy \"\\\\(\"s")
-
 ;;;###autoload
 (defun regexp-opt-depth (regexp)
   "Return the depth of REGEXP.
-This means the number of regexp grouping constructs (parenthesised expressions)
-in REGEXP."
+This means the number of non-shy regexp grouping constructs
+\(parenthesised expressions) in REGEXP."
   (save-match-data
     ;; Hack to signal an error if REGEXP does not have balanced parentheses.
     (string-match regexp "")
     ;; Count the number of open parentheses in REGEXP.
-    (let ((count 0) start)
-      (while
-          (progn
-            (string-match regexp-opt-not-groupie*-re regexp start)
-            (setq start ( + (match-end 0) 2))  ; +2 for "\\(" after match-end.
-            (<= start (length regexp)))
-        (setq count (1+ count)))
+    (let ((count 0) start last)
+      (while (string-match "\\\\(\\(\\?:\\)?" regexp start)
+       (setq start (match-end 0))            ; Start of next search.
+       (when (and (not (match-beginning 1))
+                  (subregexp-context-p regexp (match-beginning 0) last))
+         ;; It's not a shy group and it's not inside brackets or after
+         ;; a backslash: it's really a group-open marker.
+         (setq last start)         ; Speed up next regexp-opt-re-context-p.
+         (setq count (1+ count))))
       count)))
 \f
 ;;; Workhorse functions.
@@ -299,5 +285,5 @@ in REGEXP."
 
 (provide 'regexp-opt)
 
-;;; arch-tag: 6c5a66f4-29af-4fd6-8c3b-4b554d5b4370
+;; arch-tag: 6c5a66f4-29af-4fd6-8c3b-4b554d5b4370
 ;;; regexp-opt.el ends here