*** empty log message ***
[emacs.git] / lisp / play / dissociate.el
blobb0998320f7e1178fc1618f282fd4a1c69ce0b6ca
1 ;;; dissociate.el --- scramble text amusingly for Emacs.
3 ;; Maintainer: FSF
4 ;; Last-Modified: 09 May 1991
5 ;; Keywords: games
7 ;; Copyright (C) 1985 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; Code:
27 ;;;###autoload
28 (defun dissociated-press (&optional arg)
29 "Dissociate the text of the current buffer.
30 Output goes in buffer named *Dissociation*,
31 which is redisplayed each time text is added to it.
32 Every so often the user must say whether to continue.
33 If ARG is positive, require ARG chars of continuity.
34 If ARG is negative, require -ARG words of continuity.
35 Default is 2."
36 (interactive "P")
37 (setq arg (if arg (prefix-numeric-value arg) 2))
38 (let* ((inbuf (current-buffer))
39 (outbuf (get-buffer-create "*Dissociation*"))
40 (move-function (if (> arg 0) 'forward-char 'forward-word))
41 (move-amount (if (> arg 0) arg (- arg)))
42 (search-function (if (> arg 0) 'search-forward 'word-search-forward))
43 (last-query-point 0))
44 (switch-to-buffer outbuf)
45 (erase-buffer)
46 (while
47 (save-excursion
48 (goto-char last-query-point)
49 (vertical-motion (- (window-height) 4))
50 (or (= (point) (point-max))
51 (and (progn (goto-char (point-max))
52 (y-or-n-p "Continue dissociation? "))
53 (progn
54 (message "")
55 (recenter 1)
56 (setq last-query-point (point-max))
57 t))))
58 (let (start end)
59 (save-excursion
60 (set-buffer inbuf)
61 (setq start (point))
62 (if (eq move-function 'forward-char)
63 (progn
64 (setq end (+ start (+ move-amount (random 16))))
65 (if (> end (point-max))
66 (setq end (+ 1 move-amount (random 16))))
67 (goto-char end))
68 (funcall move-function
69 (+ move-amount (random 16))))
70 (setq end (point)))
71 (let ((opoint (point)))
72 (insert-buffer-substring inbuf start end)
73 (save-excursion
74 (goto-char opoint)
75 (end-of-line)
76 (and (> (current-column) fill-column)
77 (do-auto-fill)))))
78 (save-excursion
79 (set-buffer inbuf)
80 (if (eobp)
81 (goto-char (point-min))
82 (let ((overlap
83 (buffer-substring (prog1 (point)
84 (funcall move-function
85 (- move-amount)))
86 (point))))
87 (let (ranval)
88 (while (< (setq ranval (random)) 0))
89 (goto-char (1+ (% ranval (1- (point-max))))))
90 (or (funcall search-function overlap nil t)
91 (let ((opoint (point)))
92 (goto-char 1)
93 (funcall search-function overlap opoint t))))))
94 (sit-for 0))))
96 ;;; dissociate.el ends here