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