* doc/misc/eshell.texi: Fill most of the missing sections.
[emacs.git] / lisp / play / yow.el
blobdc3a75ff6056a0ef569c867ae4f1c554e43ae5bc
1 ;;; yow.el --- quote random zippyisms
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Important pinheadery for GNU Emacs.
29 ;; See cookie1.el for implementation. Note --- the `n' argument of yow
30 ;; from the 18.xx implementation is no longer; we only support *random*
31 ;; random access now.
33 ;;; Code:
35 (require 'cookie1)
37 (defgroup yow nil
38 "Quote random zippyisms."
39 :prefix "yow-"
40 :group 'games)
42 (defcustom yow-file (concat data-directory "yow.lines")
43 "File containing pertinent pinhead phrases."
44 :type 'file
45 :group 'yow)
47 (defconst yow-load-message "Am I CONSING yet?...")
48 (defconst yow-after-load-message "I have SEEN the CONSING!!")
50 ;;;###autoload
51 (defun yow (&optional insert display)
52 "Return or display a random Zippy quotation. With prefix arg, insert it."
53 (interactive "P\np")
54 (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
55 (cond (insert
56 (insert yow))
57 ((not display)
58 yow)
60 (message "%s" yow)))))
62 (defsubst read-zippyism (prompt &optional require-match)
63 "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
64 If optional second arg is non-nil, require input to match a completion."
65 (read-cookie prompt yow-file yow-load-message yow-after-load-message
66 require-match))
68 ;;;###autoload
69 (defun insert-zippyism (&optional zippyism)
70 "Prompt with completion for a known Zippy quotation, and insert it at point."
71 (interactive (list (read-zippyism "Pinhead wisdom: " t)))
72 (insert zippyism))
74 ;;;###autoload
75 (defun apropos-zippy (regexp)
76 "Return a list of all Zippy quotes matching REGEXP.
77 If called interactively, display a list of matches."
78 (interactive "sApropos Zippy (regexp): ")
79 ;; Make sure yows are loaded
80 (cookie yow-file yow-load-message yow-after-load-message)
81 (let* ((case-fold-search t)
82 (cookie-table-symbol (intern yow-file cookie-cache))
83 (string-table (symbol-value cookie-table-symbol))
84 (matches nil)
85 (len (length string-table))
86 (i 0))
87 (save-match-data
88 (while (< i len)
89 (and (string-match regexp (aref string-table i))
90 (setq matches (cons (aref string-table i) matches)))
91 (setq i (1+ i))))
92 (and matches
93 (setq matches (sort matches 'string-lessp)))
94 (and (called-interactively-p 'interactive)
95 (cond ((null matches)
96 (message "No matches found."))
98 (let ((l matches))
99 (with-output-to-temp-buffer "*Zippy Apropos*"
100 (while l
101 (princ (car l))
102 (setq l (cdr l))
103 (and l (princ "\n\n")))
104 (help-print-return-message))))))
105 matches))
108 ;; Yowza!! Feed zippy quotes to the doctor. Watch results.
109 ;; fun, fun, fun. Entertainment for hours...
111 ;; written by Kayvan Aghaiepour
113 (declare-function doctor-ret-or-read "doctor" (arg))
115 ;;;###autoload
116 (defun psychoanalyze-pinhead ()
117 "Zippy goes to the analyst."
118 (interactive)
119 (doctor) ; start the psychotherapy
120 (message "")
121 (switch-to-buffer "*doctor*")
122 (sit-for 0)
123 (while (not (input-pending-p))
124 (insert (yow))
125 (sit-for 0)
126 (doctor-ret-or-read 1)
127 (doctor-ret-or-read 1)))
129 (provide 'yow)
131 ;; arch-tag: d13db89b-84f1-4141-a5ce-261d1733a65c
132 ;;; yow.el ends here