Annotation of 43BSDReno/contrib/emacs-18.55/lisp/spook.el, revision 1.1

1.1     ! root        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 distributed in the hope that it will be useful,
        !             7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
        !             8: ;; accepts responsibility to anyone for the consequences of using it
        !             9: ;; or for whether it serves any particular purpose or works at all,
        !            10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
        !            11: ;; License for full details.
        !            12: 
        !            13: ;; Everyone is granted permission to copy, modify and redistribute
        !            14: ;; GNU Emacs, but only under the conditions described in the
        !            15: ;; GNU Emacs General Public License.   A copy of this license is
        !            16: ;; supposed to have been given to you along with GNU Emacs so you
        !            17: ;; can know your rights and responsibilities.  It should be in a
        !            18: ;; file named COPYING.  Among other things, the copyright notice
        !            19: ;; and this notice must be preserved on all copies.
        !            20: 
        !            21: 
        !            22: ; Steve Strassmann ([email protected]) 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
        !            40: (defvar spook-phrases-file (concat exec-directory "spook.lines")
        !            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 <[email protected]>
        !            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)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.