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