Commit | Line | Data |
---|---|---|
8b2120f4 | 1 | ;;; yow.el --- quote random zippyisms |
6cf0d154 | 2 | |
f2e3589a | 3 | ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, |
d7a0267c | 4 | ;; 2005, 2006, 2007 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 | ||
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 | |
5a9dffec | 14 | ;; the Free Software Foundation; either version 3, or (at your option) |
a18d567f RS |
15 | ;; any later version. |
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 | |
b578f267 | 23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
3a35cf56 LK |
24 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | ;; Boston, MA 02110-1301, USA. | |
a18d567f | 26 | |
6cf0d154 ER |
27 | ;;; Commentary: |
28 | ||
eb8c3be9 | 29 | ;; Important pinheadery for GNU Emacs. |
ed73b256 | 30 | ;; |
269d869f | 31 | ;; See cookie1.el for implementation. Note --- the `n' argument of yow |
ed73b256 ER |
32 | ;; from the 18.xx implementation is no longer; we only support *random* |
33 | ;; random access now. | |
6cf0d154 ER |
34 | |
35 | ;;; Code: | |
36 | ||
269d869f | 37 | (require 'cookie1) |
ed73b256 | 38 | |
323f7c49 SE |
39 | (defgroup yow nil |
40 | "Quote random zippyisms." | |
41 | :prefix "yow-" | |
42 | :group 'games) | |
43 | ||
44 | (defcustom yow-file (concat data-directory "yow.lines") | |
45 | "File containing pertinent pinhead phrases." | |
46 | :type 'file | |
47 | :group 'yow) | |
a18d567f | 48 | |
6f579a69 NF |
49 | (defconst yow-load-message "Am I CONSING yet?...") |
50 | (defconst yow-after-load-message "I have SEEN the CONSING!!") | |
51 | ||
7229064d | 52 | ;;;###autoload |
b85b15f3 | 53 | (defun yow (&optional insert display) |
b6173cae | 54 | "Return or display a random Zippy quotation. With prefix arg, insert it." |
b85b15f3 | 55 | (interactive "P\np") |
6f579a69 | 56 | (let ((yow (cookie yow-file yow-load-message yow-after-load-message))) |
b6173cae RM |
57 | (cond (insert |
58 | (insert yow)) | |
b85b15f3 | 59 | ((not display) |
a18d567f | 60 | yow) |
a18d567f | 61 | (t |
1be14568 | 62 | (message "%s" yow))))) |
a18d567f | 63 | |
2694dfb9 RM |
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." | |
6f579a69 | 67 | (read-cookie prompt yow-file yow-load-message yow-after-load-message |
2694dfb9 | 68 | require-match)) |
b6173cae RM |
69 | |
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)) | |
6f579a69 NF |
75 | |
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.")) | |
99 | (t | |
100 | (let ((l matches)) | |
101 | (with-output-to-temp-buffer "*Zippy Apropos*" | |
102 | (while l | |
103 | (princ (car l)) | |
104 | (setq l (cdr l)) | |
7a5ea63f EZ |
105 | (and l (princ "\n\n"))) |
106 | (print-help-return-message)))))) | |
6f579a69 NF |
107 | matches)) |
108 | ||
a18d567f | 109 | \f |
6f579a69 NF |
110 | ;; Yowza!! Feed zippy quotes to the doctor. Watch results. |
111 | ;; fun, fun, fun. Entertainment for hours... | |
112 | ;; | |
113 | ;; written by Kayvan Aghaiepour | |
a18d567f | 114 | |
004a00f4 DN |
115 | (declare-function doctor-ret-or-read "doctor" (arg)) |
116 | ||
7229064d | 117 | ;;;###autoload |
a18d567f RS |
118 | (defun psychoanalyze-pinhead () |
119 | "Zippy goes to the analyst." | |
120 | (interactive) | |
121 | (doctor) ; start the psychotherapy | |
a18d567f RS |
122 | (message "") |
123 | (switch-to-buffer "*doctor*") | |
124 | (sit-for 0) | |
125 | (while (not (input-pending-p)) | |
967732f6 | 126 | (insert (yow)) |
a18d567f RS |
127 | (sit-for 0) |
128 | (doctor-ret-or-read 1) | |
129 | (doctor-ret-or-read 1))) | |
130 | ||
49116ac0 JB |
131 | (provide 'yow) |
132 | ||
ab5796a9 | 133 | ;;; arch-tag: d13db89b-84f1-4141-a5ce-261d1733a65c |
76d7458e | 134 | ;;; yow.el ends here |