Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / play / yow.el
CommitLineData
8b2120f4 1;;; yow.el --- quote random zippyisms
6cf0d154 2
73b0cd50 3;; Copyright (C) 1993-1995, 2000-2011 Free Software Foundation, Inc.
58142744 4
6cf0d154 5;; Maintainer: FSF
f6dd89c6 6;; Author: Richard Mlynarik
6251ee24 7;; Keywords: games
76d7458e 8
a18d567f
RS
9;; This file is part of GNU Emacs.
10
b1fc2b50 11;; GNU Emacs is free software: you can redistribute it and/or modify
a18d567f 12;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
a18d567f
RS
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b1fc2b50 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a18d567f 23
6cf0d154
ER
24;;; Commentary:
25
eb8c3be9 26;; Important pinheadery for GNU Emacs.
ed73b256 27;;
269d869f 28;; See cookie1.el for implementation. Note --- the `n' argument of yow
ed73b256
ER
29;; from the 18.xx implementation is no longer; we only support *random*
30;; random access now.
6cf0d154
ER
31
32;;; Code:
33
269d869f 34(require 'cookie1)
ed73b256 35
323f7c49
SE
36(defgroup yow nil
37 "Quote random zippyisms."
38 :prefix "yow-"
39 :group 'games)
40
41(defcustom yow-file (concat data-directory "yow.lines")
42 "File containing pertinent pinhead phrases."
43 :type 'file
44 :group 'yow)
a18d567f 45
6f579a69
NF
46(defconst yow-load-message "Am I CONSING yet?...")
47(defconst yow-after-load-message "I have SEEN the CONSING!!")
48
7229064d 49;;;###autoload
b85b15f3 50(defun yow (&optional insert display)
b6173cae 51 "Return or display a random Zippy quotation. With prefix arg, insert it."
b85b15f3 52 (interactive "P\np")
6f579a69 53 (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
b6173cae
RM
54 (cond (insert
55 (insert yow))
b85b15f3 56 ((not display)
a18d567f 57 yow)
a18d567f 58 (t
1be14568 59 (message "%s" yow)))))
a18d567f 60
2694dfb9
RM
61(defsubst read-zippyism (prompt &optional require-match)
62 "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
63If optional second arg is non-nil, require input to match a completion."
6f579a69 64 (read-cookie prompt yow-file yow-load-message yow-after-load-message
2694dfb9 65 require-match))
b6173cae
RM
66
67;;;###autoload
68(defun insert-zippyism (&optional zippyism)
69 "Prompt with completion for a known Zippy quotation, and insert it at point."
70 (interactive (list (read-zippyism "Pinhead wisdom: " t)))
71 (insert zippyism))
6f579a69
NF
72
73;;;###autoload
74(defun apropos-zippy (regexp)
75 "Return a list of all Zippy quotes matching REGEXP.
76If called interactively, display a list of matches."
77 (interactive "sApropos Zippy (regexp): ")
78 ;; Make sure yows are loaded
79 (cookie yow-file yow-load-message yow-after-load-message)
80 (let* ((case-fold-search t)
81 (cookie-table-symbol (intern yow-file cookie-cache))
82 (string-table (symbol-value cookie-table-symbol))
83 (matches nil)
84 (len (length string-table))
85 (i 0))
86 (save-match-data
87 (while (< i len)
88 (and (string-match regexp (aref string-table i))
89 (setq matches (cons (aref string-table i) matches)))
90 (setq i (1+ i))))
91 (and matches
92 (setq matches (sort matches 'string-lessp)))
32226619 93 (and (called-interactively-p 'interactive)
6f579a69
NF
94 (cond ((null matches)
95 (message "No matches found."))
96 (t
97 (let ((l matches))
98 (with-output-to-temp-buffer "*Zippy Apropos*"
99 (while l
100 (princ (car l))
101 (setq l (cdr l))
7a5ea63f 102 (and l (princ "\n\n")))
d5d105e8 103 (help-print-return-message))))))
6f579a69
NF
104 matches))
105
a18d567f 106\f
6f579a69
NF
107;; Yowza!! Feed zippy quotes to the doctor. Watch results.
108;; fun, fun, fun. Entertainment for hours...
109;;
110;; written by Kayvan Aghaiepour
a18d567f 111
004a00f4
DN
112(declare-function doctor-ret-or-read "doctor" (arg))
113
7229064d 114;;;###autoload
a18d567f
RS
115(defun psychoanalyze-pinhead ()
116 "Zippy goes to the analyst."
117 (interactive)
118 (doctor) ; start the psychotherapy
a18d567f
RS
119 (message "")
120 (switch-to-buffer "*doctor*")
121 (sit-for 0)
122 (while (not (input-pending-p))
967732f6 123 (insert (yow))
a18d567f
RS
124 (sit-for 0)
125 (doctor-ret-or-read 1)
126 (doctor-ret-or-read 1)))
127
49116ac0
JB
128(provide 'yow)
129
76d7458e 130;;; yow.el ends here