entered into RCS
[bpt/emacs.git] / lisp / play / spook.el
CommitLineData
c88ab9ce
ER
1;;; spook.el --- spook phrase utility for overloading the NSA line eater
2
a2535589
JA
3;; Copyright (C) 1988 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
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.
11
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.
16
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.
20
21
22; Steve Strassmann (straz@media-lab.media.mit.edu) didn't write
23; this, and even if he did, he really didn't mean for you to use it
24; in an anarchistic way.
25; May 1987
26
27; To use this:
28; Make sure you have the variable SPOOK-PHRASES-FILE pointing to
29; a valid phrase file. Phrase files are in the same format as
30; zippy's yow.lines (ITS-style LINS format).
31; Strings are terminated by ascii 0 characters. Leading whitespace ignored.
32; Everything up to the first \000 is a comment.
33;
34; Just before sending mail, do M-x spook.
35; A number of phrases will be inserted into your buffer, to help
36; give your message that extra bit of attractiveness for automated
37; keyword scanners.
38
39; Variables
1e6dacf6 40(defvar spook-phrases-file (concat data-directory "spook.lines")
a2535589
JA
41 "Keep your favorite phrases here.")
42
43(defvar spook-phrase-default-count 15
44 "Default number of phrases to insert")
45
46(defvar spook-vector nil
47 "Important phrases for NSA mail-watchers")
48
49; Randomize the seed in the random number generator.
50(random t)
51
52; Call this with M-x spook.
53(defun spook ()
54 "Adds that special touch of class to your outgoing mail."
55 (interactive)
56 (if (null spook-vector)
57 (setq spook-vector (snarf-spooks)))
58 (shuffle-vector spook-vector)
59 (let ((start (point)))
60 (insert ?\n)
61 (spook1 (min (- (length spook-vector) 1) spook-phrase-default-count))
62 (insert ?\n)
63 (fill-region-as-paragraph start (point) nil)))
64
65(defun spook1 (arg)
66 "Inserts a spook phrase ARG times."
67 (cond ((zerop arg) t)
68 (t (insert (aref spook-vector arg))
69 (insert " ")
70 (spook1 (1- arg)))))
71
72(defun snarf-spooks ()
73 "Reads in the phrase file"
74 (message "Checking authorization...")
75 (save-excursion
76 (let ((buf (generate-new-buffer "*spook*"))
77 (result '()))
78 (set-buffer buf)
79 (insert-file-contents (expand-file-name spook-phrases-file))
80 (search-forward "\0")
81 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
82 (let ((beg (point)))
83 (search-forward "\0")
84 (setq result (cons (buffer-substring beg (1- (point)))
85 result))))
86 (kill-buffer buf)
87 (message "Checking authorization... Approved.")
88 (setq spook-vector (apply 'vector result)))))
89
90(defun pick-random (n)
91 "Returns a random number from 0 to N-1 inclusive."
92 (% (logand 0777777 (random)) n))
93
94; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK>
95; [of the University of Birmingham Computer Science Department]
96; for the iterative version of this shuffle.
97;
98(defun shuffle-vector (vector)
99 "Randomly permute the elements of VECTOR (all permutations equally likely)"
100 (let ((i 0)
101 j
102 temp
103 (len (length vector)))
104 (while (< i len)
105 (setq j (+ i (pick-random (- len i))))
106 (setq temp (aref vector i))
107 (aset vector i (aref vector j))
108 (aset vector j temp)
109 (setq i (1+ i))))
110 vector)
c88ab9ce
ER
111
112;;; spook.el ends here