(smtpmail-via-smtp): Speciy process coding system.
[bpt/emacs.git] / lisp / play / yow.el
CommitLineData
8b2120f4 1;;; yow.el --- quote random zippyisms
6cf0d154 2
6f579a69 3;; Copyright (C) 1993, 1994, 1995 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
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
a18d567f
RS
14;; any later version.
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
b578f267
EN
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
a18d567f 25
6cf0d154
ER
26;;; Commentary:
27
eb8c3be9 28;; Important pinheadery for GNU Emacs.
ed73b256 29;;
269d869f 30;; See cookie1.el for implementation. Note --- the `n' argument of yow
ed73b256
ER
31;; from the 18.xx implementation is no longer; we only support *random*
32;; random access now.
6cf0d154
ER
33
34;;; Code:
35
269d869f 36(require 'cookie1)
ed73b256 37
323f7c49
SE
38(defgroup yow nil
39 "Quote random zippyisms."
40 :prefix "yow-"
41 :group 'games)
42
43(defcustom yow-file (concat data-directory "yow.lines")
44 "File containing pertinent pinhead phrases."
45 :type 'file
46 :group 'yow)
a18d567f 47
6f579a69
NF
48(defconst yow-load-message "Am I CONSING yet?...")
49(defconst yow-after-load-message "I have SEEN the CONSING!!")
50
7229064d 51;;;###autoload
b6173cae
RM
52(defun yow (&optional insert)
53 "Return or display a random Zippy quotation. With prefix arg, insert it."
54 (interactive "P")
6f579a69 55 (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
b6173cae
RM
56 (cond (insert
57 (insert yow))
58 ((not (interactive-p))
a18d567f
RS
59 yow)
60 ((not (string-match "\n" yow))
61 (delete-windows-on (get-buffer-create "*Help*"))
62 (message "%s" yow))
63 (t
64 (message "Yow!")
65 (with-output-to-temp-buffer "*Help*"
d10d0394
KH
66 (princ yow)
67 (save-excursion
68 (set-buffer standard-output)
69 (help-mode)))))))
a18d567f 70
2694dfb9
RM
71(defsubst read-zippyism (prompt &optional require-match)
72 "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
73If optional second arg is non-nil, require input to match a completion."
6f579a69 74 (read-cookie prompt yow-file yow-load-message yow-after-load-message
2694dfb9 75 require-match))
b6173cae
RM
76
77;;;###autoload
78(defun insert-zippyism (&optional zippyism)
79 "Prompt with completion for a known Zippy quotation, and insert it at point."
80 (interactive (list (read-zippyism "Pinhead wisdom: " t)))
81 (insert zippyism))
6f579a69
NF
82
83;;;###autoload
84(defun apropos-zippy (regexp)
85 "Return a list of all Zippy quotes matching REGEXP.
86If called interactively, display a list of matches."
87 (interactive "sApropos Zippy (regexp): ")
88 ;; Make sure yows are loaded
89 (cookie yow-file yow-load-message yow-after-load-message)
90 (let* ((case-fold-search t)
91 (cookie-table-symbol (intern yow-file cookie-cache))
92 (string-table (symbol-value cookie-table-symbol))
93 (matches nil)
94 (len (length string-table))
95 (i 0))
96 (save-match-data
97 (while (< i len)
98 (and (string-match regexp (aref string-table i))
99 (setq matches (cons (aref string-table i) matches)))
100 (setq i (1+ i))))
101 (and matches
102 (setq matches (sort matches 'string-lessp)))
103 (and (interactive-p)
104 (cond ((null matches)
105 (message "No matches found."))
106 (t
107 (let ((l matches))
108 (with-output-to-temp-buffer "*Zippy Apropos*"
109 (while l
110 (princ (car l))
111 (setq l (cdr l))
112 (and l (princ "\n\n"))))))))
113 matches))
114
a18d567f 115\f
6f579a69
NF
116;; Yowza!! Feed zippy quotes to the doctor. Watch results.
117;; fun, fun, fun. Entertainment for hours...
118;;
119;; written by Kayvan Aghaiepour
a18d567f 120
7229064d 121;;;###autoload
a18d567f
RS
122(defun psychoanalyze-pinhead ()
123 "Zippy goes to the analyst."
124 (interactive)
125 (doctor) ; start the psychotherapy
a18d567f
RS
126 (message "")
127 (switch-to-buffer "*doctor*")
128 (sit-for 0)
129 (while (not (input-pending-p))
130 (insert-string (yow))
131 (sit-for 0)
132 (doctor-ret-or-read 1)
133 (doctor-ret-or-read 1)))
134
49116ac0
JB
135(provide 'yow)
136
76d7458e 137;;; yow.el ends here