Mercurial > emacs
annotate lisp/play/spook.el @ 957:2619b7a9c11e
entered into RCS
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 12 Aug 1992 12:50:10 +0000 |
parents | 2cdce064065f |
children | 3e9034e7bebf |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
1 ;;; spook.el --- spook phrase utility for overloading the NSA line eater |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
2 |
841 | 3 ;; Copyright (C) 1988 Free Software Foundation, Inc. |
4 | |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
5 ;; Maintainer: FSF |
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: games |
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
7 |
36 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
787
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
24 ;;; Commentary: |
36 | 25 |
26 ; Steve Strassmann (straz@media-lab.media.mit.edu) didn't write | |
27 ; this, and even if he did, he really didn't mean for you to use it | |
28 ; in an anarchistic way. | |
29 ; May 1987 | |
30 | |
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. | |
39 ; A number of phrases will be inserted into your buffer, to help | |
40 ; give your message that extra bit of attractiveness for automated | |
41 ; keyword scanners. | |
42 | |
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
43 ;;; Code: |
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
44 |
36 | 45 ; Variables |
444 | 46 (defvar spook-phrases-file (concat data-directory "spook.lines") |
36 | 47 "Keep your favorite phrases here.") |
48 | |
49 (defvar spook-phrase-default-count 15 | |
50 "Default number of phrases to insert") | |
51 | |
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 (defun spook () | |
60 "Adds that special touch of class to your outgoing mail." | |
61 (interactive) | |
62 (if (null spook-vector) | |
63 (setq spook-vector (snarf-spooks))) | |
64 (shuffle-vector spook-vector) | |
65 (let ((start (point))) | |
66 (insert ?\n) | |
67 (spook1 (min (- (length spook-vector) 1) spook-phrase-default-count)) | |
68 (insert ?\n) | |
69 (fill-region-as-paragraph start (point) nil))) | |
70 | |
71 (defun spook1 (arg) | |
72 "Inserts a spook phrase ARG times." | |
73 (cond ((zerop arg) t) | |
74 (t (insert (aref spook-vector arg)) | |
75 (insert " ") | |
76 (spook1 (1- arg))))) | |
77 | |
78 (defun snarf-spooks () | |
79 "Reads in the phrase file" | |
80 (message "Checking authorization...") | |
81 (save-excursion | |
82 (let ((buf (generate-new-buffer "*spook*")) | |
83 (result '())) | |
84 (set-buffer buf) | |
85 (insert-file-contents (expand-file-name spook-phrases-file)) | |
86 (search-forward "\0") | |
87 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp))) | |
88 (let ((beg (point))) | |
89 (search-forward "\0") | |
90 (setq result (cons (buffer-substring beg (1- (point))) | |
91 result)))) | |
92 (kill-buffer buf) | |
93 (message "Checking authorization... Approved.") | |
94 (setq spook-vector (apply 'vector result))))) | |
95 | |
96 (defun pick-random (n) | |
97 "Returns a random number from 0 to N-1 inclusive." | |
98 (% (logand 0777777 (random)) n)) | |
99 | |
100 ; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK> | |
101 ; [of the University of Birmingham Computer Science Department] | |
102 ; for the iterative version of this shuffle. | |
103 ; | |
104 (defun shuffle-vector (vector) | |
105 "Randomly permute the elements of VECTOR (all permutations equally likely)" | |
106 (let ((i 0) | |
107 j | |
108 temp | |
109 (len (length vector))) | |
110 (while (< i len) | |
111 (setq j (+ i (pick-random (- len i)))) | |
112 (setq temp (aref vector i)) | |
113 (aset vector i (aref vector j)) | |
114 (aset vector j temp) | |
115 (setq i (1+ i)))) | |
116 vector) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
117 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
118 ;;; spook.el ends here |