1 ;;; dissociate.el --- scramble text amusingly for Emacs.
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
8 ;; This file is part of XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;;; Synched up with: FSF 19.34.
29 ;; The single entry point, `dissociated-press', applies a travesty
30 ;; generator to the current buffer. The results can be quite amusing.
35 (defun dissociated-press (&optional arg)
36 "Dissociate the text of the current buffer.
37 Output goes in buffer named *Dissociation*,
38 which is redisplayed each time text is added to it.
39 Every so often the user must say whether to continue.
40 If ARG is positive, require ARG chars of continuity.
41 If ARG is negative, require -ARG words of continuity.
44 (setq arg (if arg (prefix-numeric-value arg) 2))
45 (let* ((inbuf (current-buffer))
46 (outbuf (get-buffer-create "*Dissociation*"))
47 (move-function (if (> arg 0) 'forward-char 'forward-word))
48 (move-amount (if (> arg 0) arg (- arg)))
49 (search-function (if (> arg 0) 'search-forward 'word-search-forward))
51 (if (= (point-max) (point-min))
52 (error "The buffer contains no text to start from"))
53 (switch-to-buffer outbuf)
57 (goto-char last-query-point)
58 (vertical-motion (- (window-height) 4))
59 (or (= (point) (point-max))
60 (and (progn (goto-char (point-max))
61 (y-or-n-p "Continue dissociation? "))
65 (setq last-query-point (point-max))
71 (if (eq move-function 'forward-char)
73 (setq end (+ start (+ move-amount (random 16))))
74 (if (> end (point-max))
75 (setq end (+ 1 move-amount (random 16))))
77 (funcall move-function
78 (+ move-amount (random 16))))
80 (let ((opoint (point)))
81 (insert-buffer-substring inbuf start end)
85 (and (> (current-column) fill-column)
90 (goto-char (point-min))
92 (buffer-substring (prog1 (point)
93 (funcall move-function
96 (goto-char (1+ (random (1- (point-max)))))
97 (or (funcall search-function overlap nil t)
98 (let ((opoint (point)))
100 (funcall search-function overlap opoint t))))))
103 ;;; dissociate.el ends here