;;; yow.el --- quote random zippyisms
-;; Copyright (C) 1993 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1995, 2000, 2002, 2003, 2004,
+;; 2005, 2006 Free Software Foundation, Inc.
;; Maintainer: FSF
+;; Author: Richard Mlynarik
;; Keywords: games
;; This file is part of GNU Emacs.
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
-;; Important pinheaddery for GNU Emacs.
+;; Important pinheadery for GNU Emacs.
;;
-;; See cookie.el for implementation. Note --- the `n' argument of yow
+;; See cookie1.el for implementation. Note --- the `n' argument of yow
;; from the 18.xx implementation is no longer; we only support *random*
;; random access now.
;;; Code:
-(require 'cookie)
+(require 'cookie1)
-(defvar yow-file (concat data-directory "yow.lines")
- "Pertinent pinhead phrases.")
+(defgroup yow nil
+ "Quote random zippyisms."
+ :prefix "yow-"
+ :group 'games)
+
+(defcustom yow-file (concat data-directory "yow.lines")
+ "File containing pertinent pinhead phrases."
+ :type 'file
+ :group 'yow)
+
+(defconst yow-load-message "Am I CONSING yet?...")
+(defconst yow-after-load-message "I have SEEN the CONSING!!")
;;;###autoload
-(defun yow (&optional interactive)
- "Return or display a random Zippy quotation."
- (interactive "p")
- (let ((yow (cookie
- yow-file "Am I CONSING yet?..." "I have SEEN the CONSING!!")))
- (cond ((not interactive)
+(defun yow (&optional insert display)
+ "Return or display a random Zippy quotation. With prefix arg, insert it."
+ (interactive "P\np")
+ (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
+ (cond (insert
+ (insert yow))
+ ((not display)
yow)
- ((not (string-match "\n" yow))
- (delete-windows-on (get-buffer-create "*Help*"))
- (message "%s" yow))
(t
- (message "Yow!")
- (with-output-to-temp-buffer "*Help*"
- (princ yow))))))
+ (message "%s" yow)))))
+
+(defsubst read-zippyism (prompt &optional require-match)
+ "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
+If optional second arg is non-nil, require input to match a completion."
+ (read-cookie prompt yow-file yow-load-message yow-after-load-message
+ require-match))
+
+;;;###autoload
+(defun insert-zippyism (&optional zippyism)
+ "Prompt with completion for a known Zippy quotation, and insert it at point."
+ (interactive (list (read-zippyism "Pinhead wisdom: " t)))
+ (insert zippyism))
+
+;;;###autoload
+(defun apropos-zippy (regexp)
+ "Return a list of all Zippy quotes matching REGEXP.
+If called interactively, display a list of matches."
+ (interactive "sApropos Zippy (regexp): ")
+ ;; Make sure yows are loaded
+ (cookie yow-file yow-load-message yow-after-load-message)
+ (let* ((case-fold-search t)
+ (cookie-table-symbol (intern yow-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
+ (setq matches (sort matches 'string-lessp)))
+ (and (interactive-p)
+ (cond ((null matches)
+ (message "No matches found."))
+ (t
+ (let ((l matches))
+ (with-output-to-temp-buffer "*Zippy Apropos*"
+ (while l
+ (princ (car l))
+ (setq l (cdr l))
+ (and l (princ "\n\n")))
+ (print-help-return-message))))))
+ matches))
\f
-; Yowza!! Feed zippy quotes to the doctor. Watch results.
-; fun, fun, fun. Entertainment for hours...
-;
-; written by Kayvan Aghaiepour
+;; Yowza!! Feed zippy quotes to the doctor. Watch results.
+;; fun, fun, fun. Entertainment for hours...
+;;
+;; written by Kayvan Aghaiepour
;;;###autoload
(defun psychoanalyze-pinhead ()
(switch-to-buffer "*doctor*")
(sit-for 0)
(while (not (input-pending-p))
- (insert-string (yow))
+ (insert (yow))
(sit-for 0)
(doctor-ret-or-read 1)
(doctor-ret-or-read 1)))
(provide 'yow)
+;;; arch-tag: d13db89b-84f1-4141-a5ce-261d1733a65c
;;; yow.el ends here