*** empty log message ***
[emacs.git] / lisp / play / yow.el
blob4f142d3264781ce042277d8eed63ca09e8d3d2cf
1 yow.el --- generate random zippyisms
3 ;; Copyright (C) 1985, 1987 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
10 ;; any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 ; Randomize the seed in the random number generator.
22 (random t)
24 ; Important pinheaddery for GNU Emacs.
25 ; Expects file emacs/etc/yow.lines to be in ITS-style LINS format
26 ; (ie strings terminated by ascii 0 characters. Leading whitespace ignored)
27 ; Everything up to the first \000 is a comment.
28 ;;;###autoload
29 (defun yow (&optional n interactive)
30 "Return or display a Zippy quotation."
31 (interactive "P\np")
32 (if (null yow-vector)
33 (setq yow-vector (snarf-yows)))
34 (cond (n (setq n (prefix-numeric-value n)))
35 ((>= (setq n (random (length yow-vector))) 0))
36 (t (setq n (- n))))
37 (let ((yow (aref yow-vector n)))
38 (cond ((not interactive)
39 yow)
40 ((not (string-match "\n" yow))
41 (delete-windows-on (get-buffer-create "*Help*"))
42 (message "%s" yow))
44 (message "Yow!")
45 (with-output-to-temp-buffer "*Help*"
46 (princ yow))))))
48 (defvar yow-vector nil "Pertinent pinhead statements")
49 (defun snarf-yows (&optional file)
50 (save-excursion
51 (let ((buf (generate-new-buffer " yow"))
52 (result '())
53 (cursor-in-echo-area t))
54 (message "Am I CONSING yet?...")
55 (set-buffer buf)
56 (insert-file-contents (or file
57 (expand-file-name "yow.lines" data-directory)))
58 (search-forward "\0")
59 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
60 (let ((beg (point)))
61 (search-forward "\0")
62 (setq result (cons (buffer-substring beg (1- (point)))
63 result))))
64 (kill-buffer buf)
65 (message "I have SEEN the CONSING!!" (length result))
66 (apply 'vector (nreverse result)))))
68 ; Yowza!! Feed zippy quotes to the doctor. Watch results.
69 ; fun, fun, fun. Entertainment for hours...
71 ; written by Kayvan Aghaiepour
73 ;;;###autoload
74 (defun psychoanalyze-pinhead ()
75 "Zippy goes to the analyst."
76 (interactive)
77 (doctor) ; start the psychotherapy
78 (if (null yow-vector)
79 (setq yow-vector (snarf-yows)))
80 (message "")
81 (switch-to-buffer "*doctor*")
82 (sit-for 0)
83 (while (not (input-pending-p))
84 (insert-string (yow))
85 (sit-for 0)
86 (doctor-ret-or-read 1)
87 (doctor-ret-or-read 1)))
89 (provide 'yow)
91 ;;; yow.el ends here