home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-18.59-bin.lha / lib / emacs / 18.59 / lisp / spook.el < prev    next >
Lisp/Scheme  |  1991-02-05  |  4KB  |  110 lines

  1. ;; Spook phrase utility
  2. ;; Copyright (C) 1988 Free Software Foundation
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  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)
  9. ;; any later version.
  10.  
  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.
  15.  
  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.
  19.  
  20.  
  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.
  24. ; May 1987
  25.  
  26. ; To use this:
  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.
  32. ;
  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
  36. ;  keyword scanners.
  37.  
  38. ; Variables
  39. (defvar spook-phrases-file (concat exec-directory "spook.lines")
  40.    "Keep your favorite phrases here.")
  41.  
  42. (defvar spook-phrase-default-count 15
  43.    "Default number of phrases to insert")
  44.  
  45. (defvar spook-vector nil
  46.   "Important phrases for NSA mail-watchers")
  47.  
  48. ; Randomize the seed in the random number generator.
  49. (random t)
  50.  
  51. ; Call this with M-x spook.
  52. (defun spook ()
  53.   "Adds that special touch of class to your outgoing mail."
  54.   (interactive)
  55.   (if (null spook-vector)
  56.       (setq spook-vector (snarf-spooks)))
  57.   (shuffle-vector spook-vector)
  58.   (let ((start (point)))
  59.     (insert ?\n)
  60.     (spook1 (min (- (length spook-vector) 1) spook-phrase-default-count))
  61.     (insert ?\n)
  62.     (fill-region-as-paragraph start (point) nil)))
  63.  
  64. (defun spook1 (arg)
  65.   "Inserts a spook phrase ARG times."
  66.   (cond ((zerop arg) t)
  67.     (t (insert (aref spook-vector arg))
  68.        (insert " ")
  69.        (spook1 (1- arg)))))
  70.  
  71. (defun snarf-spooks ()
  72.   "Reads in the phrase file"
  73.   (message "Checking authorization...")
  74.   (save-excursion
  75.     (let ((buf (generate-new-buffer "*spook*"))
  76.       (result '()))
  77.       (set-buffer buf)
  78.       (insert-file-contents (expand-file-name spook-phrases-file))
  79.       (search-forward "\0")
  80.       (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
  81.     (let ((beg (point)))
  82.       (search-forward "\0")
  83.       (setq result (cons (buffer-substring beg (1- (point)))
  84.                  result))))
  85.       (kill-buffer buf)
  86.       (message "Checking authorization... Approved.")
  87.       (setq spook-vector (apply 'vector result)))))
  88.  
  89. (defun pick-random (n)
  90.   "Returns a random number from 0 to N-1 inclusive."
  91.   (% (logand 0777777 (random)) n))
  92.  
  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.
  96. ;
  97. (defun shuffle-vector (vector)
  98.   "Randomly permute the elements of VECTOR (all permutations equally likely)"
  99.   (let ((i 0)
  100.     j
  101.     temp
  102.     (len (length vector)))
  103.     (while (< i len)
  104.       (setq j (+ i (pick-random (- len i))))
  105.       (setq temp (aref vector i))
  106.       (aset vector i (aref vector j))
  107.       (aset vector j temp)
  108.       (setq i (1+ i))))
  109.   vector)
  110.