]> code.delx.au - gnu-emacs/blobdiff - lisp/play/cookie1.el
Update copyright year to 2015
[gnu-emacs] / lisp / play / cookie1.el
index 0a53d8f4e61223cf1e1e873890c198842245459c..d4e553bc7b358b35e8e6df7440974f508c7fd575 100644 (file)
@@ -1,9 +1,9 @@
 ;;; cookie1.el --- retrieve random phrases from fortune cookie files
 
-;; Copyright (C) 1993, 2001-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 2001-2015 Free Software Foundation, Inc.
 
 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: games, extensions
 ;; Created: Mon Mar 22 17:06:26 1993
 
@@ -187,6 +187,7 @@ Argument REQUIRE-MATCH non-nil forces a matching cookie."
 
 (defun cookie-apropos (regexp phrase-file &optional display)
   "Return a list of all entries matching REGEXP from PHRASE-FILE.
+Interactively, uses `read-regexp' to read REGEXP.
 Interactively, PHRASE-FILE defaults to `cookie-file', unless that
 is nil or a prefix argument is used.
 If called interactively, or if DISPLAY is non-nil, display a list of matches."
@@ -194,34 +195,28 @@ If called interactively, or if DISPLAY is non-nil, display a list of matches."
                     (if (or current-prefix-arg (not cookie-file))
                         (read-file-name "Cookie file: " nil
                                         cookie-file t cookie-file)
-                      cookie-file)))
+                      cookie-file) t))
   (setq phrase-file (cookie-check-file phrase-file))
   ;; Make sure phrases are loaded.
   (cookie phrase-file)
   (let* ((case-fold-search t)
          (cookie-table-symbol (intern phrase-file cookie-cache))
          (string-table (symbol-value cookie-table-symbol))
-         (matches nil)
-         (len (length string-table))
-         (i 0))
-    (save-match-data
-      (while (< i len)
-        (and (string-match regexp (aref string-table i))
-             (setq matches (cons (aref string-table i) matches)))
-        (setq i (1+ i))))
-    (and matches
+         (matches nil))
+    (and (dotimes (i (length string-table) matches)
+           (and (string-match-p regexp (aref string-table i))
+                (setq matches (cons (aref string-table i) matches))))
          (setq matches (sort matches 'string-lessp)))
-    (and (or display (called-interactively-p 'interactive))
-         (cond ((null matches)
-                (message "No matches found."))
-               (t
-                (let ((l matches))
-                  (with-output-to-temp-buffer "*Cookie Apropos*"
-                    (while l
-                      (princ (car l))
-                      (setq l (cdr l))
-                      (and l (princ "\n\n")))
-                   (help-print-return-message))))))
+    (and display
+         (if matches
+             (let ((l matches))
+               (with-output-to-temp-buffer "*Cookie Apropos*"
+                 (while l
+                   (princ (car l))
+                   (setq l (cdr l))
+                   (and l (princ "\n\n")))
+                 (help-print-return-message)))
+           (message "No matches found.")))
     matches))