annotate lisp/games/yow.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents 376386a54a3c
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Important pinheadery for GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; See cookie1.el for implementation. Note --- the `n' argument of yow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; from the 18.xx implementation is no longer; we only support *random*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; random access now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (require 'cookie1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar yow-file (concat data-directory "yow.lines")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
40 "File containing pertinent Pinhead Phrases.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
41
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
42 (defconst yow-load-message "Am I CONSING yet?...")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
43 (defconst yow-after-load-message "I have SEEN the CONSING!!")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defun yow (&optional insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "Return or display a random Zippy quotation. With prefix arg, insert it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (interactive "P")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
49 (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (cond (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (insert yow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ((not (interactive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 yow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ((not (string-match "\n" yow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (delete-windows-on (get-buffer-create "*Help*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (message "%s" yow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (message "Yow!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (princ yow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (help-mode)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun read-zippyism (prompt &optional require-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 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
68 (read-cookie prompt yow-file yow-load-message yow-after-load-message
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 require-match))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
70
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun insert-zippyism (&optional zippyism)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Prompt with completion for a known Zippy quotation, and insert it at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (interactive (list (read-zippyism "Pinhead wisdom: " t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (insert zippyism))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
76
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
77 ;;;###autoload
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
78 (defun apropos-zippy (regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
79 "Return a list of all Zippy quotes matching REGEXP.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
80 If called interactively, display a list of matches."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
81 (interactive "sApropos Zippy (regexp): ")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
82 ;; Make sure yows are loaded
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
83 (cookie yow-file yow-load-message yow-after-load-message)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
84 (let* ((case-fold-search t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
85 (cookie-table-symbol (intern yow-file cookie-cache))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
86 (string-table (symbol-value cookie-table-symbol))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
87 (matches nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
88 (len (length string-table))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
89 (i 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
90 (save-match-data
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
91 (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
92 (and (string-match regexp (aref string-table i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
93 (setq matches (cons (aref string-table i) matches)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
94 (setq i (1+ i))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
95 (and matches
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
96 (setq matches (sort matches 'string-lessp)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
97 (and (interactive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
98 (cond ((null matches)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
99 (message "No matches found."))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
100 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
101 (let ((l matches))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
102 (with-output-to-temp-buffer "*Zippy Apropos*"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
103 (while l
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
104 (princ (car l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
105 (setq l (cdr l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
106 (and l (princ "\n\n"))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
107 matches))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
108
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
110 ;; Yowza!! Feed zippy quotes to the doctor. Watch results.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
111 ;; fun, fun, fun. Entertainment for hours...
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
112 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
113 ;; written by Kayvan Aghaiepour
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defun psychoanalyze-pinhead ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 "Zippy goes to the analyst."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (doctor) ; start the psychotherapy
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
120 (message "")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (switch-to-buffer "*doctor*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (while (not (input-pending-p))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
124 (insert-string (yow))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (doctor-ret-or-read 1)
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (provide 'yow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;; yow.el ends here