]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/regexp-opt.el
Merge from emacs-23; up to 2010-06-29T18:17:31Z!cyd@stupidchicken.com.
[gnu-emacs] / lisp / emacs-lisp / regexp-opt.el
index a1494741572aa096cc759907dcc523ea6688a105..ac391fed2c28da5ada8d9ea2ea2c282694925f9e 100644 (file)
@@ -1,7 +1,6 @@
 ;;; regexp-opt.el --- generate efficient regexps to match strings
 
-;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-;;   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1994-2012 Free Software Foundation, Inc.
 
 ;; Author: Simon Marshall <simon@gnu.org>
 ;; Maintainer: FSF
@@ -96,19 +95,24 @@ The returned regexp is typically more efficient than the equivalent regexp:
    (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close))
 
 If PAREN is `words', then the resulting regexp is additionally surrounded
-by \\=\\< and \\>."
+by \\=\\< and \\>.
+If PAREN is `symbols', then the resulting regexp is additionally surrounded
+by \\=\\_< and \\_>."
   (save-match-data
     ;; Recurse on the sorted list.
     (let* ((max-lisp-eval-depth 10000)
           (max-specpdl-size 10000)
           (completion-ignore-case nil)
           (completion-regexp-list nil)
-          (words (eq paren 'words))
           (open (cond ((stringp paren) paren) (paren "\\(")))
           (sorted-strings (delete-dups
                            (sort (copy-sequence strings) 'string-lessp)))
           (re (regexp-opt-group sorted-strings (or open t) (not open))))
-      (if words (concat "\\<" re "\\>") re))))
+      (cond ((eq paren 'words)
+            (concat "\\<" re "\\>"))
+           ((eq paren 'symbols)
+            (concat "\\_<" re "\\_>"))
+           (t re)))))
 
 ;;;###autoload
 (defun regexp-opt-depth (regexp)
@@ -136,11 +140,10 @@ This means the number of non-shy regexp grouping constructs
   (require 'cl))
 
 (defun regexp-opt-group (strings &optional paren lax)
-  ;; Return a regexp to match a string in the sorted list STRINGS.
-  ;; If PAREN non-nil, output regexp parentheses around returned regexp.
-  ;; If LAX non-nil, don't output parentheses if it doesn't require them.
-  ;; Merges keywords to avoid backtracking in Emacs' regexp matcher.
-
+  "Return a regexp to match a string in the sorted list STRINGS.
+If PAREN non-nil, output regexp parentheses around returned regexp.
+If LAX non-nil, don't output parentheses if it doesn't require them.
+Merges keywords to avoid backtracking in Emacs' regexp matcher."
   ;; The basic idea is to find the shortest common prefix or suffix, remove it
   ;; and recurse.  If there is no prefix, we divide the list into two so that
   ;; \(at least) one half will have at least a one-character common prefix.
@@ -234,9 +237,7 @@ This means the number of non-shy regexp grouping constructs
 
 
 (defun regexp-opt-charset (chars)
-  ;;
-  ;; Return a regexp to match a character in CHARS.
-  ;;
+  "Return a regexp to match a character in CHARS."
   ;; The basic idea is to find character ranges.  Also we take care in the
   ;; position of character set meta characters in the character set regexp.
   ;;
@@ -291,5 +292,4 @@ This means the number of non-shy regexp grouping constructs
 
 (provide 'regexp-opt)
 
-;; arch-tag: 6c5a66f4-29af-4fd6-8c3b-4b554d5b4370
 ;;; regexp-opt.el ends here