1 ;;; dissociate.lisp --- scramble text amusingly for Emacs
3 ;; Copyright (C) 1985, 2002, 2003, 2004, 2005,
4 ;; 2006 Free Software Foundation, Inc.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; The single entry point, `dissociated-press', applies a travesty
27 ;; generator to the current buffer. The results can be quite amusing.
34 (defcommand 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.
43 (setq arg
(if arg
(prefix-numeric-value arg
) 2))
44 (let* ((inbuf (current-buffer))
45 (outbuf (get-buffer-create "*Dissociation*"))
46 (move-function (if (> arg
0) 'forward-char
'forward-word
))
47 (move-amount (if (> arg
0) arg
(- arg
)))
48 (search-function (if (> arg
0) 'search-forward
'word-search-forward
))
50 (if (= (point-max) (point-min))
51 (error "The buffer contains no text to start from"))
52 (switch-to-buffer outbuf
)
56 (goto-char last-query-point
)
57 (vertical-motion (- (window-height) 4))
58 (or (= (point) (point-max))
59 (and (progn (goto-char (point-max))
60 (y-or-n-p "Continue dissociation? "))
64 (setq last-query-point
(point-max))
70 (if (eq move-function
'forward-char
)
72 (setq end
(+ start
(+ move-amount
(random 16))))
73 (if (> end
(point-max))
74 (setq end
(+ 1 move-amount
(random 16))))
76 (funcall move-function
77 (+ move-amount
(random 16))))
79 (let ((opoint (point)))
80 (insert-buffer-substring inbuf start end
)
84 (and (> (current-column) *fill-column
*)
89 (goto-char (point-min))
91 (buffer-substring (prog1 (point)
92 (funcall move-function
95 (goto-char (1+ (random (1- (point-max)))))
96 (or (funcall search-function overlap
:error nil
)
97 (let ((opoint (point)))
99 (funcall search-function overlap
:bound opoint
:error nil
))))))
102 (provide 'dissociate
)
104 ;;; arch-tag: 90d197d1-409b-45c5-a0b5-fbfb2e06334f
105 ;;; dissociate.el ends here