Commit | Line | Data |
---|---|---|
8b2120f4 | 1 | ;;; yow.el --- quote random zippyisms |
6cf0d154 | 2 | |
f2e3589a | 3 | ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, |
2f043267 | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
58142744 | 5 | |
6cf0d154 | 6 | ;; Maintainer: FSF |
f6dd89c6 | 7 | ;; Author: Richard Mlynarik |
6251ee24 | 8 | ;; Keywords: games |
76d7458e | 9 | |
a18d567f RS |
10 | ;; This file is part of GNU Emacs. |
11 | ||
b1fc2b50 | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
a18d567f | 13 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
a18d567f RS |
16 | |
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. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
a18d567f | 24 | |
6cf0d154 ER |
25 | ;;; Commentary: |
26 | ||
eb8c3be9 | 27 | ;; Important pinheadery for GNU Emacs. |
ed73b256 | 28 | ;; |
269d869f | 29 | ;; See cookie1.el for implementation. Note --- the `n' argument of yow |
ed73b256 ER |
30 | ;; from the 18.xx implementation is no longer; we only support *random* |
31 | ;; random access now. | |
6cf0d154 ER |
32 | |
33 | ;;; Code: | |
34 | ||
269d869f | 35 | (require 'cookie1) |
ed73b256 | 36 | |
323f7c49 SE |
37 | (defgroup yow nil |
38 | "Quote random zippyisms." | |
39 | :prefix "yow-" | |
40 | :group 'games) | |
41 | ||
42 | (defcustom yow-file (concat data-directory "yow.lines") | |
43 | "File containing pertinent pinhead phrases." | |
44 | :type 'file | |
45 | :group 'yow) | |
a18d567f | 46 | |
6f579a69 NF |
47 | (defconst yow-load-message "Am I CONSING yet?...") |
48 | (defconst yow-after-load-message "I have SEEN the CONSING!!") | |
49 | ||
7229064d | 50 | ;;;###autoload |
b85b15f3 | 51 | (defun yow (&optional insert display) |
b6173cae | 52 | "Return or display a random Zippy quotation. With prefix arg, insert it." |
b85b15f3 | 53 | (interactive "P\np") |
6f579a69 | 54 | (let ((yow (cookie yow-file yow-load-message yow-after-load-message))) |
b6173cae RM |
55 | (cond (insert |
56 | (insert yow)) | |
b85b15f3 | 57 | ((not display) |
a18d567f | 58 | yow) |
a18d567f | 59 | (t |
1be14568 | 60 | (message "%s" yow))))) |
a18d567f | 61 | |
2694dfb9 RM |
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." | |
6f579a69 | 65 | (read-cookie prompt yow-file yow-load-message yow-after-load-message |
2694dfb9 | 66 | require-match)) |
b6173cae RM |
67 | |
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)) | |
6f579a69 NF |
73 | |
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 (interactive-p) | |
95 | (cond ((null matches) | |
96 | (message "No matches found.")) | |
97 | (t | |
98 | (let ((l matches)) | |
99 | (with-output-to-temp-buffer "*Zippy Apropos*" | |
100 | (while l | |
101 | (princ (car l)) | |
102 | (setq l (cdr l)) | |
7a5ea63f EZ |
103 | (and l (princ "\n\n"))) |
104 | (print-help-return-message)))))) | |
6f579a69 NF |
105 | matches)) |
106 | ||
a18d567f | 107 | \f |
6f579a69 NF |
108 | ;; Yowza!! Feed zippy quotes to the doctor. Watch results. |
109 | ;; fun, fun, fun. Entertainment for hours... | |
110 | ;; | |
111 | ;; written by Kayvan Aghaiepour | |
a18d567f | 112 | |
004a00f4 DN |
113 | (declare-function doctor-ret-or-read "doctor" (arg)) |
114 | ||
7229064d | 115 | ;;;###autoload |
a18d567f RS |
116 | (defun psychoanalyze-pinhead () |
117 | "Zippy goes to the analyst." | |
118 | (interactive) | |
119 | (doctor) ; start the psychotherapy | |
a18d567f RS |
120 | (message "") |
121 | (switch-to-buffer "*doctor*") | |
122 | (sit-for 0) | |
123 | (while (not (input-pending-p)) | |
967732f6 | 124 | (insert (yow)) |
a18d567f RS |
125 | (sit-for 0) |
126 | (doctor-ret-or-read 1) | |
127 | (doctor-ret-or-read 1))) | |
128 | ||
49116ac0 JB |
129 | (provide 'yow) |
130 | ||
cbee283d | 131 | ;; arch-tag: d13db89b-84f1-4141-a5ce-261d1733a65c |
76d7458e | 132 | ;;; yow.el ends here |