1 ;;; dissociate.el --- scramble text amusingly for Emacs
3 ;; Copyright (C) 1985, 2001-2012 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; The single entry point, `dissociated-press', applies a travesty
26 ;; generator to the current buffer. The results can be quite amusing.
31 (defun dissociated-press (&optional arg
)
32 "Dissociate the text of the current buffer.
33 Output goes in buffer named *Dissociation*,
34 which is redisplayed each time text is added to it.
35 Every so often the user must say whether to continue.
36 If ARG is positive, require ARG chars of continuity.
37 If ARG is negative, require -ARG words of continuity.
40 (setq arg
(if arg
(prefix-numeric-value arg
) 2))
41 (let* ((inbuf (current-buffer))
42 (outbuf (get-buffer-create "*Dissociation*"))
43 (move-function (if (> arg
0) 'forward-char
'forward-word
))
44 (move-amount (if (> arg
0) arg
(- arg
)))
45 (search-function (if (> arg
0) 'search-forward
'word-search-forward
))
47 (if (= (point-max) (point-min))
48 (error "The buffer contains no text to start from"))
49 (switch-to-buffer outbuf
)
53 (goto-char last-query-point
)
54 (vertical-motion (- (window-height) 4))
55 (or (= (point) (point-max))
56 (and (progn (goto-char (point-max))
57 (y-or-n-p "Continue dissociation? "))
61 (setq last-query-point
(point-max))
64 (with-current-buffer inbuf
66 (if (eq move-function
'forward-char
)
68 (setq end
(+ start
(+ move-amount
(random 16))))
69 (if (> end
(point-max))
70 (setq end
(+ 1 move-amount
(random 16))))
72 (funcall move-function
73 (+ move-amount
(random 16))))
75 (let ((opoint (point)))
76 (insert-buffer-substring inbuf start end
)
80 (and (> (current-column) fill-column
)
82 (with-current-buffer inbuf
84 (goto-char (point-min))
86 (buffer-substring (prog1 (point)
87 (funcall move-function
90 (goto-char (1+ (random (1- (point-max)))))
91 (or (funcall search-function overlap nil t
)
92 (let ((opoint (point)))
94 (funcall search-function overlap opoint t
))))))
99 ;;; dissociate.el ends here