(bootstrap-prepare): Also chmod cal-loaddefs.el.
[emacs.git] / lisp / play / yow.el
blob9fe3ddf63154a13ed9904355506172ca056f32a2
1 ;;; yow.el --- quote random zippyisms
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Author: Richard Mlynarik
8 ;; Keywords: games
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; Important pinheadery for GNU Emacs.
31 ;; See cookie1.el for implementation. Note --- the `n' argument of yow
32 ;; from the 18.xx implementation is no longer; we only support *random*
33 ;; random access now.
35 ;;; Code:
37 (require 'cookie1)
39 (defgroup yow nil
40 "Quote random zippyisms."
41 :prefix "yow-"
42 :group 'games)
44 (defcustom yow-file (concat data-directory "yow.lines")
45 "File containing pertinent pinhead phrases."
46 :type 'file
47 :group 'yow)
49 (defconst yow-load-message "Am I CONSING yet?...")
50 (defconst yow-after-load-message "I have SEEN the CONSING!!")
52 ;;;###autoload
53 (defun yow (&optional insert display)
54 "Return or display a random Zippy quotation. With prefix arg, insert it."
55 (interactive "P\np")
56 (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
57 (cond (insert
58 (insert yow))
59 ((not display)
60 yow)
62 (message "%s" yow)))))
64 (defsubst read-zippyism (prompt &optional require-match)
65 "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
66 If optional second arg is non-nil, require input to match a completion."
67 (read-cookie prompt yow-file yow-load-message yow-after-load-message
68 require-match))
70 ;;;###autoload
71 (defun insert-zippyism (&optional zippyism)
72 "Prompt with completion for a known Zippy quotation, and insert it at point."
73 (interactive (list (read-zippyism "Pinhead wisdom: " t)))
74 (insert zippyism))
76 ;;;###autoload
77 (defun apropos-zippy (regexp)
78 "Return a list of all Zippy quotes matching REGEXP.
79 If called interactively, display a list of matches."
80 (interactive "sApropos Zippy (regexp): ")
81 ;; Make sure yows are loaded
82 (cookie yow-file yow-load-message yow-after-load-message)
83 (let* ((case-fold-search t)
84 (cookie-table-symbol (intern yow-file cookie-cache))
85 (string-table (symbol-value cookie-table-symbol))
86 (matches nil)
87 (len (length string-table))
88 (i 0))
89 (save-match-data
90 (while (< i len)
91 (and (string-match regexp (aref string-table i))
92 (setq matches (cons (aref string-table i) matches)))
93 (setq i (1+ i))))
94 (and matches
95 (setq matches (sort matches 'string-lessp)))
96 (and (interactive-p)
97 (cond ((null matches)
98 (message "No matches found."))
100 (let ((l matches))
101 (with-output-to-temp-buffer "*Zippy Apropos*"
102 (while l
103 (princ (car l))
104 (setq l (cdr l))
105 (and l (princ "\n\n")))
106 (print-help-return-message))))))
107 matches))
110 ;; Yowza!! Feed zippy quotes to the doctor. Watch results.
111 ;; fun, fun, fun. Entertainment for hours...
113 ;; written by Kayvan Aghaiepour
115 (declare-function doctor-ret-or-read "doctor" (arg))
117 ;;;###autoload
118 (defun psychoanalyze-pinhead ()
119 "Zippy goes to the analyst."
120 (interactive)
121 (doctor) ; start the psychotherapy
122 (message "")
123 (switch-to-buffer "*doctor*")
124 (sit-for 0)
125 (while (not (input-pending-p))
126 (insert (yow))
127 (sit-for 0)
128 (doctor-ret-or-read 1)
129 (doctor-ret-or-read 1)))
131 (provide 'yow)
133 ;;; arch-tag: d13db89b-84f1-4141-a5ce-261d1733a65c
134 ;;; yow.el ends here