aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond1993-03-22 22:44:49 +0000
committerEric S. Raymond1993-03-22 22:44:49 +0000
commited73b2568d16197d327c7d00d3116ae72caffa67 (patch)
tree6b1c372f96cc0f1b489247f8e24f81d42fbacbe7
parentc91c4e6d7f2287a65bec3fd1b93997f518a5c4ea (diff)
downloademacs-ed73b2568d16197d327c7d00d3116ae72caffa67.tar.gz
emacs-ed73b2568d16197d327c7d00d3116ae72caffa67.zip
Modified to use cookie.el
-rw-r--r--lisp/play/spook.el80
-rw-r--r--lisp/play/yow.el48
2 files changed, 25 insertions, 103 deletions
diff --git a/lisp/play/spook.el b/lisp/play/spook.el
index 1ba0b2dabb6..1b4bce46a8b 100644
--- a/lisp/play/spook.el
+++ b/lisp/play/spook.el
@@ -24,17 +24,11 @@
24 24
25;;; Commentary: 25;;; Commentary:
26 26
27; Steve Strassmann (straz@media-lab.media.mit.edu) didn't write 27; Steve Strassmann <straz@media-lab.media.mit.edu> didn't write
28; this, and even if he did, he really didn't mean for you to use it 28; this, and even if he did, he really didn't mean for you to use it
29; in an anarchistic way. 29; in an anarchistic way.
30; 30;
31; To use this: 31; To use this:
32; Make sure you have the variable SPOOK-PHRASES-FILE pointing to
33; a valid phrase file. Phrase files are in the same format as
34; zippy's yow.lines (ITS-style LINS format).
35; Strings are terminated by ascii 0 characters. Leading whitespace ignored.
36; Everything up to the first \000 is a comment.
37;
38; Just before sending mail, do M-x spook. 32; Just before sending mail, do M-x spook.
39; A number of phrases will be inserted into your buffer, to help 33; A number of phrases will be inserted into your buffer, to help
40; give your message that extra bit of attractiveness for automated 34; give your message that extra bit of attractiveness for automated
@@ -42,6 +36,8 @@
42 36
43;;; Code: 37;;; Code:
44 38
39(require 'cookie)
40
45; Variables 41; Variables
46(defvar spook-phrases-file (concat data-directory "spook.lines") 42(defvar spook-phrases-file (concat data-directory "spook.lines")
47 "Keep your favorite phrases here.") 43 "Keep your favorite phrases here.")
@@ -49,71 +45,17 @@
49(defvar spook-phrase-default-count 15 45(defvar spook-phrase-default-count 15
50 "Default number of phrases to insert") 46 "Default number of phrases to insert")
51 47
52(defvar spook-vector nil
53 "Important phrases for NSA mail-watchers")
54
55; Randomize the seed in the random number generator.
56(random t)
57
58; Call this with M-x spook.
59;;;###autoload 48;;;###autoload
60(defun spook () 49(defun spook ()
61 "Adds that special touch of class to your outgoing mail." 50 "Adds that special touch of class to your outgoing mail."
62 (interactive) 51 (interactive)
63 (if (null spook-vector) 52 (cookie-insert
64 (setq spook-vector (snarf-spooks))) 53 spook-phrases-file
65 (shuffle-vector spook-vector) 54 spook-phrase-default-count
66 (let ((start (point))) 55 "Checking authorization"
67 (insert ?\n) 56 "Checking authorization...Approved"))
68 (spook1 (min (- (length spook-vector) 1) spook-phrase-default-count)) 57
69 (insert ?\n) 58;; Note: the implementation that used to take up most of this file has
70 (fill-region-as-paragraph start (point) nil))) 59;; been cleaned up and generalized and now resides in cookie.el.
71
72(defun spook1 (arg)
73 "Inserts a spook phrase ARG times."
74 (cond ((zerop arg) t)
75 (t (insert (aref spook-vector arg))
76 (insert " ")
77 (spook1 (1- arg)))))
78
79(defun snarf-spooks ()
80 "Reads in the phrase file"
81 (message "Checking authorization...")
82 (save-excursion
83 (let ((buf (generate-new-buffer "*spook*"))
84 (result '()))
85 (set-buffer buf)
86 (insert-file-contents (expand-file-name spook-phrases-file))
87 (search-forward "\0")
88 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
89 (let ((beg (point)))
90 (search-forward "\0")
91 (setq result (cons (buffer-substring beg (1- (point)))
92 result))))
93 (kill-buffer buf)
94 (message "Checking authorization... Approved.")
95 (setq spook-vector (apply 'vector result)))))
96
97(defun pick-random (n)
98 "Returns a random number from 0 to N-1 inclusive."
99 (% (logand 0777777 (random)) n))
100
101; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK>
102; [of the University of Birmingham Computer Science Department]
103; for the iterative version of this shuffle.
104;
105(defun shuffle-vector (vector)
106 "Randomly permute the elements of VECTOR (all permutations equally likely)"
107 (let ((i 0)
108 j
109 temp
110 (len (length vector)))
111 (while (< i len)
112 (setq j (+ i (pick-random (- len i))))
113 (setq temp (aref vector i))
114 (aset vector i (aref vector j))
115 (aset vector j temp)
116 (setq i (1+ i))))
117 vector)
118 60
119;;; spook.el ends here 61;;; spook.el ends here
diff --git a/lisp/play/yow.el b/lisp/play/yow.el
index e226f74db2a..006cf992edd 100644
--- a/lisp/play/yow.el
+++ b/lisp/play/yow.el
@@ -1,6 +1,6 @@
1;;; yow.el --- generate random zippyisms 1;;; yow.el --- generate random zippyisms
2 2
3;; Copyright (C) 1985, 1987 Free Software Foundation, Inc. 3;; Copyright (C) 1993 Free Software Foundation, Inc.
4 4
5;; Maintainer: FSF 5;; Maintainer: FSF
6;; Keywords: games 6;; Keywords: games
@@ -24,25 +24,24 @@
24;;; Commentary: 24;;; Commentary:
25 25
26;; Important pinheaddery for GNU Emacs. 26;; Important pinheaddery for GNU Emacs.
27;; Expects file emacs/etc/yow.lines to be in ITS-style LINS format 27;;
28;; (ie strings terminated by ascii 0 characters. Leading whitespace ignored) 28;; See cookie.el for implementation. Note --- the `n' argument of yow
29;; Everything up to the first \000 is a comment. 29;; from the 18.xx implementation is no longer; we only support *random*
30;; random access now.
30 31
31;;; Code: 32;;; Code:
32 33
33; Randomize the seed in the random number generator. 34(require 'cookie)
34(random t) 35
36(defvar yow-file (concat data-directory "yow.lines")
37 "Pertinent pinhead phrases.")
35 38
36;;;###autoload 39;;;###autoload
37(defun yow (&optional n interactive) 40(defun yow (&optional interactive)
38 "Return or display a Zippy quotation." 41 "Return or display a random Zippy quotation."
39 (interactive "P\np") 42 (interactive "P")
40 (if (null yow-vector) 43 (let ((yow (cookie
41 (setq yow-vector (snarf-yows))) 44 yow-file "Am I CONSING yet?..." "I have SEEN the CONSING!!")))
42 (cond (n (setq n (prefix-numeric-value n)))
43 ((>= (setq n (random (length yow-vector))) 0))
44 (t (setq n (- n))))
45 (let ((yow (aref yow-vector n)))
46 (cond ((not interactive) 45 (cond ((not interactive)
47 yow) 46 yow)
48 ((not (string-match "\n" yow)) 47 ((not (string-match "\n" yow))
@@ -53,25 +52,6 @@
53 (with-output-to-temp-buffer "*Help*" 52 (with-output-to-temp-buffer "*Help*"
54 (princ yow)))))) 53 (princ yow))))))
55 54
56(defvar yow-vector nil "Pertinent pinhead statements")
57(defun snarf-yows (&optional file)
58 (save-excursion
59 (let ((buf (generate-new-buffer " yow"))
60 (result '())
61 (cursor-in-echo-area t))
62 (message "Am I CONSING yet?...")
63 (set-buffer buf)
64 (insert-file-contents (or file
65 (expand-file-name "yow.lines" data-directory)))
66 (search-forward "\0")
67 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
68 (let ((beg (point)))
69 (search-forward "\0")
70 (setq result (cons (buffer-substring beg (1- (point)))
71 result))))
72 (kill-buffer buf)
73 (message "I have SEEN the CONSING!!" (length result))
74 (apply 'vector (nreverse result)))))
75 55
76; Yowza!! Feed zippy quotes to the doctor. Watch results. 56; Yowza!! Feed zippy quotes to the doctor. Watch results.
77; fun, fun, fun. Entertainment for hours... 57; fun, fun, fun. Entertainment for hours...