annotate lisp/games/yow.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents b82b59fe008d
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; yow.el --- quote random zippyisms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Richard Mlynarik
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: games
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
24 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Important pinheadery for GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; See cookie1.el for implementation. Note --- the `n' argument of yow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; from the 18.xx implementation is no longer; we only support *random*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; random access now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (require 'cookie1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defvar yow-file (concat data-directory "yow.lines")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
41 "File containing pertinent Pinhead Phrases.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
42
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
43 (defconst yow-load-message "Am I CONSING yet?...")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
44 (defconst yow-after-load-message "I have SEEN the CONSING!!")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defun yow (&optional insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "Return or display a random Zippy quotation. With prefix arg, insert it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (interactive "P")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
50 (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (cond (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (insert yow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ((not (interactive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 yow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ((not (string-match "\n" yow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (delete-windows-on (get-buffer-create "*Help*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (message "%s" yow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (message "Yow!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (princ yow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (help-mode)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun read-zippyism (prompt &optional require-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 If optional second arg is non-nil, require input to match a completion."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
69 (read-cookie prompt yow-file yow-load-message yow-after-load-message
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 require-match))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
71
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defun insert-zippyism (&optional zippyism)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "Prompt with completion for a known Zippy quotation, and insert it at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (interactive (list (read-zippyism "Pinhead wisdom: " t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (insert zippyism))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
77
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
78 ;;;###autoload
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
79 (defun apropos-zippy (regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
80 "Return a list of all Zippy quotes matching REGEXP.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
81 If called interactively, display a list of matches."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
82 (interactive "sApropos Zippy (regexp): ")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
83 ;; Make sure yows are loaded
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
84 (cookie yow-file yow-load-message yow-after-load-message)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
85 (let* ((case-fold-search t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
86 (cookie-table-symbol (intern yow-file cookie-cache))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
87 (string-table (symbol-value cookie-table-symbol))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
88 (matches nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
89 (len (length string-table))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
90 (i 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
91 (save-match-data
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
92 (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
93 (and (string-match regexp (aref string-table i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
94 (setq matches (cons (aref string-table i) matches)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
95 (setq i (1+ i))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
96 (and matches
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
97 (setq matches (sort matches 'string-lessp)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
98 (and (interactive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
99 (cond ((null matches)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
100 (message "No matches found."))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
101 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
102 (let ((l matches))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
103 (with-output-to-temp-buffer "*Zippy Apropos*"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
104 (while l
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
105 (princ (car l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
106 (setq l (cdr l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
107 (and l (princ "\n\n"))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
108 matches))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
109
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
111 ;; Yowza!! Feed zippy quotes to the doctor. Watch results.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
112 ;; fun, fun, fun. Entertainment for hours...
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
113 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
114 ;; written by Kayvan Aghaiepour
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defun psychoanalyze-pinhead ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "Zippy goes to the analyst."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (doctor) ; start the psychotherapy
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
121 (message "")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (switch-to-buffer "*doctor*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (while (not (input-pending-p))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
125 (insert-string (yow))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (doctor-ret-or-read 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (doctor-ret-or-read 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (provide 'yow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;; yow.el ends here