1 ;; Spook phrase utility
2 ;; Copyright (C) 1988 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 ; Steve Strassmann (straz@media-lab.media.mit.edu) didn't write
22 ; this, and even if he did, he really didn't mean for you to use it
23 ; in an anarchistic way.
27 ; Make sure you have the variable SPOOK-PHRASES-FILE pointing to
28 ; a valid phrase file. Phrase files are in the same format as
29 ; zippy's yow.lines (ITS-style LINS format).
30 ; Strings are terminated by ascii 0 characters. Leading whitespace ignored.
31 ; Everything up to the first \000 is a comment.
33 ; Just before sending mail, do M-x spook.
34 ; A number of phrases will be inserted into your buffer, to help
35 ; give your message that extra bit of attractiveness for automated
39 (defvar spook-phrases-file
(concat exec-directory
"spook.lines")
40 "Keep your favorite phrases here.")
42 (defvar spook-phrase-default-count
15
43 "Default number of phrases to insert")
45 (defvar spook-vector nil
46 "Important phrases for NSA mail-watchers")
48 ; Randomize the seed in the random number generator.
51 ; Call this with M-x spook.
53 "Adds that special touch of class to your outgoing mail."
55 (if (null spook-vector
)
56 (setq spook-vector
(snarf-spooks)))
57 (shuffle-vector spook-vector
)
58 (let ((start (point)))
60 (spook1 (min (- (length spook-vector
) 1) spook-phrase-default-count
))
62 (fill-region-as-paragraph start
(point) nil
)))
65 "Inserts a spook phrase ARG times."
67 (t (insert (aref spook-vector arg
))
71 (defun snarf-spooks ()
72 "Reads in the phrase file"
73 (message "Checking authorization...")
75 (let ((buf (generate-new-buffer "*spook*"))
78 (insert-file-contents (expand-file-name spook-phrases-file
))
80 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
83 (setq result
(cons (buffer-substring beg
(1- (point)))
86 (message "Checking authorization... Approved.")
87 (setq spook-vector
(apply 'vector result
)))))
89 (defun pick-random (n)
90 "Returns a random number from 0 to N-1 inclusive."
91 (%
(logand 0777777 (random)) n
))
93 ; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK>
94 ; [of the University of Birmingham Computer Science Department]
95 ; for the iterative version of this shuffle.
97 (defun shuffle-vector (vector)
98 "Randomly permute the elements of VECTOR (all permutations equally likely)"
102 (len (length vector
)))
104 (setq j
(+ i
(pick-random (- len i
))))
105 (setq temp
(aref vector i
))
106 (aset vector i
(aref vector j
))