Commit | Line | Data |
---|---|---|
a18d567f RS |
1 | ;; Copyright (C) 1985, 1987 Free Software Foundation, Inc. |
2 | ||
3 | ;; This file is part of GNU Emacs. | |
4 | ||
5 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
6 | ;; it under the terms of the GNU General Public License as published by | |
7 | ;; the Free Software Foundation; either version 1, or (at your option) | |
8 | ;; any later version. | |
9 | ||
10 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | ;; GNU General Public License for more details. | |
14 | ||
15 | ;; You should have received a copy of the GNU General Public License | |
16 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
17 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | ||
19 | (provide 'yow) | |
20 | ||
21 | ; Randomize the seed in the random number generator. | |
22 | (random t) | |
23 | ||
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. | |
7229064d | 28 | ;;;###autoload |
a18d567f RS |
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)) | |
43 | (t | |
44 | (message "Yow!") | |
45 | (with-output-to-temp-buffer "*Help*" | |
46 | (princ yow)))))) | |
47 | ||
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" exec-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))))) | |
67 | \f | |
68 | ; Yowza!! Feed zippy quotes to the doctor. Watch results. | |
69 | ; fun, fun, fun. Entertainment for hours... | |
70 | ; | |
71 | ; written by Kayvan Aghaiepour | |
72 | ||
7229064d | 73 | ;;;###autoload |
a18d567f RS |
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))) | |
88 |